src: removed sonargraph based project setup methods

This commit is contained in:
mlangkabel
2019-11-09 17:56:51 +01:00
parent 7257de9f11
commit ceb30020b5
585 changed files with 2 additions and 27109 deletions
-31
View File
@@ -381,8 +381,6 @@ add_files(
settings/source_group/component/SourceGroupSettingsWithCustomCommand.h
settings/source_group/component/SourceGroupSettingsWithExcludeFilters.cpp
settings/source_group/component/SourceGroupSettingsWithExcludeFilters.h
settings/source_group/component/SourceGroupSettingsWithSonargraphProjectPath.cpp
settings/source_group/component/SourceGroupSettingsWithSonargraphProjectPath.h
settings/source_group/component/SourceGroupSettingsWithSourceExtensions.cpp
settings/source_group/component/SourceGroupSettingsWithSourceExtensions.h
settings/source_group/component/SourceGroupSettingsWithSourceExtensionsEmpty.h
@@ -395,11 +393,9 @@ add_files(
settings/source_group/type/SourceGroupSettingsCxxCdb.h
settings/source_group/type/SourceGroupSettingsCxxCdbVs.h
settings/source_group/type/SourceGroupSettingsCxxCodeblocks.h
settings/source_group/type/SourceGroupSettingsCxxSonargraph.h
settings/source_group/type/SourceGroupSettingsJavaEmpty.h
settings/source_group/type/SourceGroupSettingsJavaGradle.h
settings/source_group/type/SourceGroupSettingsJavaMaven.h
settings/source_group/type/SourceGroupSettingsJavaSonargraph.h
settings/source_group/type/SourceGroupSettingsPythonEmpty.h
settings/source_group/SourceGroupSettings.cpp
@@ -623,33 +619,6 @@ add_files(
utility/scheduling/TaskScheduler.h
utility/scheduling/TaskSetValue.h
utility/sonargraph/SonargraphProject.cpp
utility/sonargraph/SonargraphProject.h
utility/sonargraph/SonargraphSoftwareSystem.cpp
utility/sonargraph/SonargraphSoftwareSystem.h
utility/sonargraph/SonargraphSourceRootPath.cpp
utility/sonargraph/SonargraphSourceRootPath.h
utility/sonargraph/SonargraphXsdAbstractModule.cpp
utility/sonargraph/SonargraphXsdAbstractModule.h
utility/sonargraph/SonargraphXsdAbstractSystemExtension.cpp
utility/sonargraph/SonargraphXsdAbstractSystemExtension.h
utility/sonargraph/SonargraphXsdCmakeJsonModule.cpp
utility/sonargraph/SonargraphXsdCmakeJsonModule.h
utility/sonargraph/SonargraphXsdCppManualModule.cpp
utility/sonargraph/SonargraphXsdCppManualModule.h
utility/sonargraph/SonargraphXsdCppSystemSettings.cpp
utility/sonargraph/SonargraphXsdCppSystemSettings.h
utility/sonargraph/SonargraphXsdJavaModule.cpp
utility/sonargraph/SonargraphXsdJavaModule.h
utility/sonargraph/SonargraphXsdRootPath.cpp
utility/sonargraph/SonargraphXsdRootPath.h
utility/sonargraph/SonargraphXsdRootPathWithFiles.cpp
utility/sonargraph/SonargraphXsdRootPathWithFiles.h
utility/sonargraph/SonargraphXsdSourceRootPath.cpp
utility/sonargraph/SonargraphXsdSourceRootPath.h
utility/sonargraph/utilitySonargraph.cpp
utility/sonargraph/utilitySonargraph.h
utility/text/TextAccess.cpp
utility/text/TextAccess.h
-4
View File
@@ -57,8 +57,6 @@ LanguageType getLanguageTypeForSourceGroupType(SourceGroupType t)
return LANGUAGE_CPP;
case SOURCE_GROUP_CXX_CODEBLOCKS:
return LANGUAGE_CPP;
case SOURCE_GROUP_CXX_SONARGRAPH:
return LANGUAGE_CPP;
case SOURCE_GROUP_CXX_VS:
return LANGUAGE_CPP;
case SOURCE_GROUP_JAVA_EMPTY:
@@ -67,8 +65,6 @@ LanguageType getLanguageTypeForSourceGroupType(SourceGroupType t)
return LANGUAGE_JAVA;
case SOURCE_GROUP_JAVA_GRADLE:
return LANGUAGE_JAVA;
case SOURCE_GROUP_JAVA_SONARGRAPH:
return LANGUAGE_JAVA;
case SOURCE_GROUP_PYTHON_EMPTY:
return LANGUAGE_PYTHON;
case SOURCE_GROUP_CUSTOM_COMMAND:
-8
View File
@@ -8,11 +8,9 @@
#include "SourceGroupSettingsCustomCommand.h"
#include "SourceGroupSettingsCxxCdb.h"
#include "SourceGroupSettingsCxxCodeblocks.h"
#include "SourceGroupSettingsCxxSonargraph.h"
#include "SourceGroupSettingsJavaEmpty.h"
#include "SourceGroupSettingsJavaMaven.h"
#include "SourceGroupSettingsJavaGradle.h"
#include "SourceGroupSettingsJavaSonargraph.h"
#include "SourceGroupSettingsPythonEmpty.h"
#include "logging.h"
#include "utilityFile.h"
@@ -188,9 +186,6 @@ std::vector<std::shared_ptr<SourceGroupSettings>> ProjectSettings::getAllSourceG
case SOURCE_GROUP_CXX_CODEBLOCKS:
settings = std::make_shared<SourceGroupSettingsCxxCodeblocks>(id, this);
break;
case SOURCE_GROUP_CXX_SONARGRAPH:
settings = std::make_shared<SourceGroupSettingsCxxSonargraph>(id, this);
break;
case SOURCE_GROUP_JAVA_EMPTY:
settings = std::make_shared<SourceGroupSettingsJavaEmpty>(id, this);
break;
@@ -200,9 +195,6 @@ std::vector<std::shared_ptr<SourceGroupSettings>> ProjectSettings::getAllSourceG
case SOURCE_GROUP_JAVA_GRADLE:
settings = std::make_shared<SourceGroupSettingsJavaGradle>(id, this);
break;
case SOURCE_GROUP_JAVA_SONARGRAPH:
settings = std::make_shared<SourceGroupSettingsJavaSonargraph>(id, this);
break;
case SOURCE_GROUP_PYTHON_EMPTY:
settings = std::make_shared<SourceGroupSettingsPythonEmpty>(id, this);
break;
@@ -12,8 +12,6 @@ std::string sourceGroupTypeToString(SourceGroupType v)
return "C/C++ from Compilation Database";
case SOURCE_GROUP_CXX_CODEBLOCKS:
return "C/C++ from Code::Blocks";
case SOURCE_GROUP_CXX_SONARGRAPH:
return "C/C++ from Sonargraph";
case SOURCE_GROUP_CXX_VS:
return "C/C++ from Visual Studio";
case SOURCE_GROUP_JAVA_EMPTY:
@@ -22,8 +20,6 @@ std::string sourceGroupTypeToString(SourceGroupType v)
return "Java Source Group from Maven";
case SOURCE_GROUP_JAVA_GRADLE:
return "Java Source Group from Gradle";
case SOURCE_GROUP_JAVA_SONARGRAPH:
return "Java from Sonargraph";
case SOURCE_GROUP_PYTHON_EMPTY:
return "Python Source Group";
case SOURCE_GROUP_CUSTOM_COMMAND:
@@ -46,8 +42,6 @@ std::string sourceGroupTypeToProjectSetupString(SourceGroupType v)
return "C/C++ from Compilation Database";
case SOURCE_GROUP_CXX_CODEBLOCKS:
return "C/C++ from Code::Blocks";
case SOURCE_GROUP_CXX_SONARGRAPH:
return "C/C++ from Sonargraph";
case SOURCE_GROUP_CXX_VS:
return "C/C++ from Visual Studio";
case SOURCE_GROUP_JAVA_EMPTY:
@@ -56,8 +50,6 @@ std::string sourceGroupTypeToProjectSetupString(SourceGroupType v)
return "Java Source Group from Maven";
case SOURCE_GROUP_JAVA_GRADLE:
return "Java Source Group from Gradle";
case SOURCE_GROUP_JAVA_SONARGRAPH:
return "Java from Sonargraph";
case SOURCE_GROUP_PYTHON_EMPTY:
return "Empty Python Source Group";
case SOURCE_GROUP_CUSTOM_COMMAND:
@@ -86,10 +78,6 @@ SourceGroupType stringToSourceGroupType(const std::string& v)
{
return SOURCE_GROUP_CXX_CODEBLOCKS;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_CXX_SONARGRAPH))
{
return SOURCE_GROUP_CXX_SONARGRAPH;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_CXX_VS))
{
return SOURCE_GROUP_CXX_VS;
@@ -106,10 +94,6 @@ SourceGroupType stringToSourceGroupType(const std::string& v)
{
return SOURCE_GROUP_JAVA_GRADLE;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_JAVA_SONARGRAPH))
{
return SOURCE_GROUP_JAVA_SONARGRAPH;
}
else if (v == sourceGroupTypeToString(SOURCE_GROUP_PYTHON_EMPTY))
{
return SOURCE_GROUP_PYTHON_EMPTY;
@@ -9,12 +9,10 @@ enum SourceGroupType
SOURCE_GROUP_CPP_EMPTY,
SOURCE_GROUP_CXX_CDB,
SOURCE_GROUP_CXX_CODEBLOCKS,
SOURCE_GROUP_CXX_SONARGRAPH,
SOURCE_GROUP_CXX_VS,
SOURCE_GROUP_JAVA_EMPTY,
SOURCE_GROUP_JAVA_MAVEN,
SOURCE_GROUP_JAVA_GRADLE,
SOURCE_GROUP_JAVA_SONARGRAPH,
SOURCE_GROUP_PYTHON_EMPTY,
SOURCE_GROUP_CUSTOM_COMMAND,
SOURCE_GROUP_UNKNOWN
@@ -1,40 +0,0 @@
#include "SourceGroupSettingsWithSonargraphProjectPath.h"
#include "ProjectSettings.h"
#include "utilityFile.h"
FilePath SourceGroupSettingsWithSonargraphProjectPath::getSonargraphProjectPath() const
{
return m_sonargraphProjectPath;
}
FilePath SourceGroupSettingsWithSonargraphProjectPath::getSonargraphProjectPathExpandedAndAbsolute() const
{
return utility::getExpandedAndAbsolutePath(getSonargraphProjectPath(), getProjectSettings()->getProjectDirectoryPath());
}
void SourceGroupSettingsWithSonargraphProjectPath::setSonargraphProjectPath(const FilePath& sonargraphProjectPath)
{
m_sonargraphProjectPath = sonargraphProjectPath;
}
bool SourceGroupSettingsWithSonargraphProjectPath::equals(const SourceGroupSettingsBase* other) const
{
const SourceGroupSettingsWithSonargraphProjectPath* otherPtr =
dynamic_cast<const SourceGroupSettingsWithSonargraphProjectPath*>(other);
return (
otherPtr &&
m_sonargraphProjectPath == otherPtr->m_sonargraphProjectPath
);
}
void SourceGroupSettingsWithSonargraphProjectPath::load(const ConfigManager* config, const std::string& key)
{
setSonargraphProjectPath(config->getValueOrDefault(key + "/sonargraph_project_path", FilePath(L"")));
}
void SourceGroupSettingsWithSonargraphProjectPath::save(ConfigManager* config, const std::string& key)
{
config->setValue(key + "/sonargraph_project_path", getSonargraphProjectPath().wstr());
}
@@ -1,27 +0,0 @@
#ifndef SOURCE_GROUP_SETTINGS_WITH_SONARGRAPH_PROJECT_PATH_H
#define SOURCE_GROUP_SETTINGS_WITH_SONARGRAPH_PROJECT_PATH_H
#include "FilePath.h"
#include "SourceGroupSettingsComponent.h"
class SourceGroupSettingsWithSonargraphProjectPath
: public SourceGroupSettingsComponent
{
public:
virtual ~SourceGroupSettingsWithSonargraphProjectPath() = default;
FilePath getSonargraphProjectPath() const;
FilePath getSonargraphProjectPathExpandedAndAbsolute() const;
void setSonargraphProjectPath(const FilePath& sonargraphProjectPath);
protected:
bool equals(const SourceGroupSettingsBase* other) const override;
void load(const ConfigManager* config, const std::string& key) override;
void save(ConfigManager* config, const std::string& key) override;
private:
FilePath m_sonargraphProjectPath;
};
#endif // SOURCE_GROUP_SETTINGS_WITH_SONARGRAPH_PROJECT_PATH_H
@@ -1,29 +0,0 @@
#ifndef SOURCE_GROUP_SETTINGS_CXX_SONARGRAPH_H
#define SOURCE_GROUP_SETTINGS_CXX_SONARGRAPH_H
#include "SourceGroupSettingsWithComponents.h"
#include "SourceGroupSettingsWithCppStandard.h"
#include "SourceGroupSettingsWithCxxPathsAndFlags.h"
#include "SourceGroupSettingsWithIndexedHeaderPaths.h"
#include "SourceGroupSettingsWithSonargraphProjectPath.h"
class SourceGroupSettingsCxxSonargraph
: public SourceGroupSettingsWithComponents<
SourceGroupSettingsWithCppStandard,
SourceGroupSettingsWithCxxPathsAndFlags,
SourceGroupSettingsWithIndexedHeaderPaths,
SourceGroupSettingsWithSonargraphProjectPath>
{
public:
SourceGroupSettingsCxxSonargraph(const std::string& id, const ProjectSettings* projectSettings)
: SourceGroupSettingsWithComponents(SOURCE_GROUP_CXX_SONARGRAPH, id, projectSettings)
{
}
std::shared_ptr<SourceGroupSettings> createCopy() const override
{
return std::make_shared<SourceGroupSettingsCxxSonargraph>(*this);
}
};
#endif // SOURCE_GROUP_SETTINGS_CXX_SONARGRAPH_H
@@ -1,27 +0,0 @@
#ifndef SOURCE_GROUP_SETTINGS_JAVA_SONARGRAPH_H
#define SOURCE_GROUP_SETTINGS_JAVA_SONARGRAPH_H
#include "SourceGroupSettingsWithComponents.h"
#include "SourceGroupSettingsWithClasspath.h"
#include "SourceGroupSettingsWithJavaStandard.h"
#include "SourceGroupSettingsWithSonargraphProjectPath.h"
class SourceGroupSettingsJavaSonargraph
: public SourceGroupSettingsWithComponents<
SourceGroupSettingsWithClasspath,
SourceGroupSettingsWithJavaStandard,
SourceGroupSettingsWithSonargraphProjectPath>
{
public:
SourceGroupSettingsJavaSonargraph(const std::string& id, const ProjectSettings* projectSettings)
: SourceGroupSettingsWithComponents(SOURCE_GROUP_JAVA_SONARGRAPH, id, projectSettings)
{
}
std::shared_ptr<SourceGroupSettings> createCopy() const override
{
return std::make_shared<SourceGroupSettingsJavaSonargraph>(*this);
}
};
#endif // SOURCE_GROUP_SETTINGS_JAVA_SONARGRAPH_H
@@ -1,79 +0,0 @@
#include "SonargraphProject.h"
#include "tinyxml.h"
#include "SonargraphSoftwareSystem.h"
#include "logging.h"
#include "TextAccess.h"
#include "utilityString.h"
#include "utilityXml.h"
namespace Sonargraph
{
std::shared_ptr<Project> Project::load(const FilePath& projectFilePath, LanguageType targetLanguage)
{
return load(TextAccess::createFromFile(projectFilePath), targetLanguage);
}
std::shared_ptr<Project> Project::load(std::shared_ptr<TextAccess> xmlAccess, LanguageType targetLanguage)
{
if (!xmlAccess)
{
return std::shared_ptr<Project>();
}
std::shared_ptr<Project> project = std::shared_ptr<Project>(new Project());
TiXmlDocument doc;
doc.Parse(xmlAccess->getText().c_str(), 0, TIXML_ENCODING_UTF8);
if (doc.Error())
{
LOG_ERROR(
"Unable to parse Sonargraph project because of an error in row " + std::to_string(doc.ErrorRow()) + ", col " +
std::to_string(doc.ErrorCol()) + ": " + std::string(doc.ErrorDesc())
);
return std::shared_ptr<Project>();
}
TiXmlHandle docHandle(&doc);
TiXmlElement* softwareSystemElement = docHandle.FirstChildElement("ns2:softwareSystem").ToElement();
if (softwareSystemElement == nullptr)
{
LOG_ERROR("Unable to find \"ns2:softwareSystem\" in Sonargraph project.");
return std::shared_ptr<Project>();
}
std::shared_ptr<SoftwareSystem> softwareSystem = SoftwareSystem::create(
softwareSystemElement, xmlAccess->getFilePath().getParentDirectory().getParentDirectory(), targetLanguage
);
if (!softwareSystem)
{
return std::shared_ptr<Project>();
}
project->m_softwareSystem = softwareSystem;
return project;
}
int Project::getLoadedModuleCount() const
{
return m_softwareSystem->getModules().size();
}
std::set<FilePath> Project::getAllSourceFilePathsCanonical() const
{
return m_softwareSystem->getAllSourceFilePathsCanonical();
}
std::set<FilePath> Project::getAllCxxHeaderSearchPathsCanonical() const
{
return m_softwareSystem->getAllCxxHeaderSearchPathsCanonical();
}
std::vector<std::shared_ptr<IndexerCommand>> Project::getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const
{
return m_softwareSystem->getIndexerCommands(sourceGroupSettings, appSettings);
}
}
@@ -1,49 +0,0 @@
#ifndef SONARGRAPH_PROJECT_H
#define SONARGRAPH_PROJECT_H
#include <set>
#include <memory>
#include <vector>
#include "LanguageType.h"
// xsdCppModule
// xsdCppManualModule -> basePathForIncludes(0, n), sourceFileExtensions(0, n), moduleCompilerOptions(0, n)
// xsdCmakeJsonModule -> rootPathWithFiles(0, n)
// xsdCppMakefileModule -> makefile(1), additionalCompilerOptions(0, 1)
// xsdCppVsProjectFileModule -> projectFile(1,1)
// xsdCppCaptureModule -> captureFile(1,1)
class ApplicationSettings;
class FilePath;
class IndexerCommand;
class SourceGroupSettings;
class TextAccess;
namespace Sonargraph
{
class SoftwareSystem;
class Project
{
public:
static std::shared_ptr<Project> load(const FilePath& projectFilePath, LanguageType targetLanguage);
static std::shared_ptr<Project> load(std::shared_ptr<TextAccess> xmlAccess, LanguageType targetLanguage);
int getLoadedModuleCount() const;
std::set<FilePath> getAllSourceFilePathsCanonical() const;
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const;
private:
Project() = default;
std::shared_ptr<SoftwareSystem> m_softwareSystem;
};
}
#endif // SONARGRAPH_PROJECT_H
@@ -1,200 +0,0 @@
#include "SonargraphSoftwareSystem.h"
#include "tinyxml.h"
#include "IndexerCommand.h"
#include "logging.h"
#include "utilityString.h"
#include "utilityXml.h"
#include "utility.h"
namespace Sonargraph
{
std::shared_ptr<SoftwareSystem> SoftwareSystem::create(const TiXmlElement* element, const FilePath& baseDirectory, LanguageType targetLanguage)
{
std::shared_ptr<SoftwareSystem> softwareSystem = std::shared_ptr<SoftwareSystem>(new SoftwareSystem());
if (softwareSystem->init(element, baseDirectory, targetLanguage))
{
return softwareSystem;
}
return std::shared_ptr<SoftwareSystem>();
}
std::wstring SoftwareSystem::getName() const
{
return m_name;
}
std::string SoftwareSystem::getVersion() const
{
return m_version;
}
std::wstring SoftwareSystem::getDescription() const
{
return m_description;
}
std::vector<FilePathFilter> SoftwareSystem::getExcludeFilters() const
{
return m_excludeFilters;
}
std::vector<FilePathFilter> SoftwareSystem::getIncludeFilters() const
{
return m_includeFilters;
}
const std::vector<std::shared_ptr<XsdAbstractModule>> SoftwareSystem::getModules() const
{
return m_modules;
}
const std::vector<std::shared_ptr<XsdAbstractSystemExtension>> SoftwareSystem::getSystemExtensions() const
{
return m_systemExtensions;
}
FilePath SoftwareSystem::getBaseDirectory() const
{
return m_baseDirectory;
}
std::set<FilePath> SoftwareSystem::getAllSourcePaths() const
{
std::set<FilePath> sourcePaths;
for (std::shared_ptr<XsdAbstractModule> module : m_modules)
{
utility::append(sourcePaths, module->getAllSourcePaths());
}
return sourcePaths;
}
std::set<FilePath> SoftwareSystem::getAllSourceFilePathsCanonical() const
{
std::set<FilePath> sourceFilePaths;
for (std::shared_ptr<XsdAbstractModule> module : m_modules)
{
utility::append(sourceFilePaths, module->getAllSourceFilePathsCanonical());
}
return sourceFilePaths;
}
std::set<FilePath> SoftwareSystem::getAllCxxHeaderSearchPathsCanonical() const
{
std::set<FilePath> sourceFilePaths;
for (std::shared_ptr<XsdAbstractModule> module : m_modules)
{
utility::append(sourceFilePaths, module->getAllCxxHeaderSearchPathsCanonical());
}
return sourceFilePaths;
}
std::vector<std::shared_ptr<IndexerCommand>> SoftwareSystem::getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const
{
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
for (std::shared_ptr<XsdAbstractModule> module : m_modules)
{
utility::append(indexerCommands, module->getIndexerCommands(sourceGroupSettings, appSettings));
}
return indexerCommands;
}
bool SoftwareSystem::init(const TiXmlElement* element, const FilePath& baseDirectory, LanguageType targetLanguage)
{
m_baseDirectory = baseDirectory;
if (element != nullptr)
{
{
const char* value = element->Attribute("name");
if (value != nullptr)
{
m_name = utility::decodeFromUtf8(value);
}
else
{
LOG_INFO("Unable to parse \"name\" attribute of Sonargraph softwareSystem.");
}
}
{
const char* value = element->Attribute("version");
if (value != nullptr)
{
m_version = value;
}
else
{
LOG_WARNING("Unable to parse \"version\" attribute of Sonargraph softwareSystem.");
}
}
{
const TiXmlElement* descriptionElement = element->FirstChildElement("description");
if (descriptionElement != nullptr)
{
const char* text = descriptionElement->GetText();
if (text != nullptr)
{
m_description = utility::decodeFromUtf8(text);
}
}
}
for (const TiXmlElement* excludeElement : utility::getXmlChildElementsWithName(element, "exclude"))
{
const char* text = excludeElement->GetText();
if (text != nullptr)
{
m_excludeFilters.push_back(FilePathFilter(utility::decodeFromUtf8(text)));
}
}
for (const TiXmlElement* includeElement : utility::getXmlChildElementsWithName(element, "include"))
{
const char* text = includeElement->GetText();
if (text != nullptr)
{
m_includeFilters.push_back(FilePathFilter(utility::decodeFromUtf8(text)));
}
}
for (const TiXmlElement* moduleElement : utility::getXmlChildElementsWithName(element, "module"))
{
if (std::shared_ptr<XsdAbstractModule> module = XsdAbstractModule::create(moduleElement, shared_from_this()))
{
if (module->getSupportedLanguage() == targetLanguage)
{
m_modules.push_back(module);
}
else
{
LOG_INFO(L"Discarding Sonargraph module \"" + module->getName() + L"\" because it does not match the Sourcetrail project's language type.");
}
}
else
{
LOG_ERROR("Unable to parse \"module\" element of Sonargraph softwareSystem.");
return false;
}
}
for (const TiXmlElement* systemExtensionElement : utility::getXmlChildElementsWithName(element, "systemExtension"))
{
if (std::shared_ptr<XsdAbstractSystemExtension> systemExtension = XsdAbstractSystemExtension::create(systemExtensionElement))
{
m_systemExtensions.push_back(systemExtension);
}
else
{
LOG_ERROR("Unable to parse \"systemExtension\" element of Sonargraph softwareSystem.");
return false;
}
}
return true;
}
return false;
}
}
@@ -1,74 +0,0 @@
#ifndef SONARGRAPH_SOFTWARE_SYSTEM_H
#define SONARGRAPH_SOFTWARE_SYSTEM_H
#include <string>
#include <vector>
#include "FilePathFilter.h"
#include "SonargraphXsdAbstractModule.h"
#include "SonargraphXsdAbstractSystemExtension.h"
class ApplicationSettings;
class IndexerCommand;
class SourceGroupSettings;
class TiXmlElement;
namespace Sonargraph
{
class SoftwareSystem : public std::enable_shared_from_this<SoftwareSystem>
{
public:
static std::shared_ptr<SoftwareSystem> create(const TiXmlElement* element, const FilePath& baseDirectory, LanguageType targetLanguage);
std::wstring getName() const;
std::string getVersion() const;
std::wstring getDescription() const;
std::vector<FilePathFilter> getExcludeFilters() const;
std::vector<FilePathFilter> getIncludeFilters() const;
const std::vector<std::shared_ptr<XsdAbstractModule>> getModules() const;
const std::vector<std::shared_ptr<XsdAbstractSystemExtension>> getSystemExtensions() const;
FilePath getBaseDirectory() const;
std::set<FilePath> getAllSourcePaths() const;
std::set<FilePath> getAllSourceFilePathsCanonical() const;
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const;
template <typename ExtensionType>
std::vector<std::shared_ptr<ExtensionType>> getSpecificSystemExtensions() const;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const;
protected:
SoftwareSystem() = default;
bool init(const TiXmlElement* element, const FilePath& baseDirectory, LanguageType targetLanguage);
FilePath m_baseDirectory;
std::wstring m_name;
std::string m_version;
std::wstring m_description;
std::vector<FilePathFilter> m_excludeFilters;
std::vector<FilePathFilter> m_includeFilters;
std::vector<std::shared_ptr<XsdAbstractModule>> m_modules;
std::vector<std::shared_ptr<XsdAbstractSystemExtension>> m_systemExtensions;
};
template <typename ExtensionType>
std::vector<std::shared_ptr<ExtensionType>> SoftwareSystem::getSpecificSystemExtensions() const
{
std::vector<std::shared_ptr<ExtensionType>> systemExtensions;
for (std::shared_ptr<XsdAbstractSystemExtension> systemExtension : getSystemExtensions())
{
if (std::shared_ptr<ExtensionType> castSystemExtension = std::dynamic_pointer_cast<ExtensionType>(systemExtension))
{
systemExtensions.push_back(castSystemExtension);
}
}
return systemExtensions;
}
}
#endif // SONARGRAPH_SOFTWARE_SYSTEM_H
@@ -1,67 +0,0 @@
#include "SonargraphSourceRootPath.h"
#include "tinyxml.h"
#include "IndexerCommandJava.h"
#include "logging.h"
#include "SonargraphXsdAbstractModule.h"
#include "SonargraphXsdRootPathWithFiles.h"
#include "utilitySonargraph.h"
#include "utilityString.h"
#include "utilityXml.h"
namespace Sonargraph
{
std::string SourceRootPath::getXsdTypeName()
{
return "sourceRootPath";
}
std::shared_ptr<SourceRootPath> SourceRootPath::create(const TiXmlElement* element)
{
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<SourceRootPath> rootPath = std::shared_ptr<SourceRootPath>(new SourceRootPath());
if (rootPath->init(element))
{
return rootPath;
}
}
return std::shared_ptr<SourceRootPath>();
}
std::wstring SourceRootPath::getName() const
{
return m_name;
}
FilePath SourceRootPath::getFilePath(const FilePath& baseDirectory) const
{
FilePath filePath(getName());
if (filePath.isAbsolute())
{
return filePath;
}
return baseDirectory.getConcatenated(filePath);
}
bool SourceRootPath::init(const TiXmlElement* element)
{
if (element != nullptr)
{
const char* value = element->Attribute("name");
if (value != nullptr)
{
m_name = utility::decodeFromUtf8(value);
}
else
{
LOG_ERROR("Unable to parse \"name\" of Sonargraph " + getXsdTypeName() + ".");
return false;
}
return true;
}
return false;
}
}
@@ -1,34 +0,0 @@
#ifndef SONARGRAPH_SOURCE_ROOT_PATH_H
#define SONARGRAPH_SOURCE_ROOT_PATH_H
#include <memory>
#include <string>
#include <vector>
#include "FilePath.h"
class TiXmlElement;
namespace Sonargraph
{
class SourceRootPath
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<SourceRootPath> create(const TiXmlElement* element);
virtual ~SourceRootPath() = default;
std::wstring getName() const;
FilePath getFilePath(const FilePath& baseDirectory) const;
protected:
SourceRootPath() = default;
bool init(const TiXmlElement* element);
std::wstring m_name;
};
}
#endif // SONARGRAPH_SOURCE_ROOT_PATH_H
@@ -1,153 +0,0 @@
#include "SonargraphXsdAbstractModule.h"
#include "tinyxml.h"
#include "logging.h"
#include "SonargraphXsdCmakeJsonModule.h"
#include "SonargraphXsdCppManualModule.h"
#include "SonargraphXsdJavaModule.h"
#include "SonargraphXsdRootPath.h"
#include "SonargraphSoftwareSystem.h"
#include "utilityString.h"
#include "utilityXml.h"
#include "utility.h"
namespace Sonargraph
{
std::string XsdAbstractModule::getXsdTypeName()
{
return "xsdAbstractModule";
}
std::shared_ptr<XsdAbstractModule> XsdAbstractModule::create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
if (std::shared_ptr<XsdAbstractModule> module = XsdCmakeJsonModule::create(element, parent))
{
return module;
}
if (std::shared_ptr<XsdCppManualModule> module = XsdCppManualModule::create(element, parent))
{
return module;
}
if (std::shared_ptr<XsdJavaModule> module = XsdJavaModule::create(element, parent))
{
return module;
}
return std::shared_ptr<XsdAbstractModule>();
}
std::wstring XsdAbstractModule::getName() const
{
return m_name;
}
std::wstring XsdAbstractModule::getDescription() const
{
return m_description;
}
std::vector<FilePathFilter> XsdAbstractModule::getExcludeFilters() const
{
return m_excludeFilters;
}
std::vector<FilePathFilter> XsdAbstractModule::getIncludeFilters() const
{
return m_includeFilters;
}
std::vector<std::shared_ptr<XsdRootPath>> XsdAbstractModule::getRootPaths() const
{
return m_rootPaths;
}
std::shared_ptr<const SoftwareSystem> XsdAbstractModule::getSoftwareSystem() const
{
return m_parent.lock();
}
std::vector<FilePathFilter> XsdAbstractModule::getDerivedExcludeFilters() const
{
std::vector<FilePathFilter> excludeFilters = getExcludeFilters();
if (std::shared_ptr<const SoftwareSystem> parent = getSoftwareSystem())
{
utility::append(excludeFilters, parent->getExcludeFilters());
}
return excludeFilters;
}
std::vector<FilePathFilter> XsdAbstractModule::getDerivedIncludeFilters() const
{
std::vector<FilePathFilter> includeFilters = getIncludeFilters();
if (std::shared_ptr<const SoftwareSystem> parent = getSoftwareSystem())
{
utility::append(includeFilters, parent->getIncludeFilters());
}
return includeFilters;
}
bool XsdAbstractModule::init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
m_parent = parent;
if (element != nullptr)
{
{
const char* value = element->Attribute("name");
if (value != nullptr)
{
m_name = utility::decodeFromUtf8(value);
}
else
{
LOG_WARNING("Unable to parse \"name\" attribute of Sonargraph " + getXsdTypeName() + ".");
}
}
{
const TiXmlElement* descriptionElement = element->FirstChildElement("description");
if (descriptionElement != nullptr)
{
const char* text = descriptionElement->GetText();
if (text != nullptr)
{
m_description = utility::decodeFromUtf8(text);
}
}
}
for (const TiXmlElement* excludeElement : utility::getXmlChildElementsWithName(element, "exclude"))
{
const char* text = excludeElement->GetText();
if (text != nullptr)
{
m_excludeFilters.push_back(FilePathFilter(utility::decodeFromUtf8(text)));
}
}
for (const TiXmlElement* includeElement : utility::getXmlChildElementsWithName(element, "include"))
{
const char* text = includeElement->GetText();
if (text != nullptr)
{
m_includeFilters.push_back(FilePathFilter(utility::decodeFromUtf8(text)));
}
}
for (const TiXmlElement* rootPathElement : utility::getXmlChildElementsWithName(element, "rootPath"))
{
if (std::shared_ptr<XsdRootPath> rootPath = XsdRootPath::create(rootPathElement))
{
m_rootPaths.push_back(rootPath);
}
else
{
LOG_ERROR("Unable to parse \"rootPath\" element of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
return true;
}
return false;
}
}
@@ -1,62 +0,0 @@
#ifndef SONARGRAPH_XSD_ABSTRACT_MODULE_H
#define SONARGRAPH_XSD_ABSTRACT_MODULE_H
#include <set>
#include <string>
#include <vector>
#include "LanguageType.h"
#include "FilePathFilter.h"
class ApplicationSettings;
class IndexerCommand;
class SourceGroupSettings;
class TiXmlElement;
namespace Sonargraph
{
class XsdRootPath;
class SoftwareSystem;
class XsdAbstractModule
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<XsdAbstractModule> create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
virtual ~XsdAbstractModule() = default;
virtual LanguageType getSupportedLanguage() const = 0;
std::wstring getName() const;
std::wstring getDescription() const;
std::vector<FilePathFilter> getExcludeFilters() const;
std::vector<FilePathFilter> getIncludeFilters() const;
std::vector<std::shared_ptr<XsdRootPath>> getRootPaths() const;
virtual std::set<FilePath> getAllSourcePaths() const = 0;
virtual std::set<FilePath> getAllSourceFilePathsCanonical() const = 0;
virtual std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const = 0;
std::shared_ptr<const SoftwareSystem> getSoftwareSystem() const;
std::vector<FilePathFilter> getDerivedExcludeFilters() const;
std::vector<FilePathFilter> getDerivedIncludeFilters() const;
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const = 0;
protected:
XsdAbstractModule() = default;
bool init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
std::weak_ptr<SoftwareSystem> m_parent;
std::wstring m_name;
std::wstring m_description;
std::vector<FilePathFilter> m_excludeFilters;
std::vector<FilePathFilter> m_includeFilters;
std::vector<std::shared_ptr<XsdRootPath>> m_rootPaths;
};
}
#endif // SONARGRAPH_XSD_ABSTRACT_MODULE_H
@@ -1,42 +0,0 @@
#include "SonargraphXsdAbstractSystemExtension.h"
#include "tinyxml.h"
#include "logging.h"
#include "SonargraphXsdCppSystemSettings.h"
namespace Sonargraph
{
std::string XsdAbstractSystemExtension::getXsdTypeName()
{
return "xsdAbstractSystemExtension";
}
std::shared_ptr<XsdAbstractSystemExtension> XsdAbstractSystemExtension::create(const TiXmlElement* element)
{
if (std::shared_ptr<XsdCppSystemSettings> systemExtension = XsdCppSystemSettings::create(element))
{
return systemExtension;
}
return std::shared_ptr<XsdAbstractSystemExtension>();
}
bool XsdAbstractSystemExtension::init(const TiXmlElement* element)
{
if (element != nullptr)
{
const char* value = element->Attribute("language");
if (value != nullptr)
{
m_language = value;
}
else
{
LOG_WARNING("Unable to parse \"language\" attribute of Sonargraph " + getXsdTypeName() + ".");
}
return true;
}
return false;
}
}
@@ -1,27 +0,0 @@
#ifndef SONARGRAPH_XSD_ABSTRACT_SYSTEM_EXTENSION_H
#define SONARGRAPH_XSD_ABSTRACT_SYSTEM_EXTENSION_H
#include <memory>
#include <string>
class TiXmlElement;
namespace Sonargraph
{
class XsdAbstractSystemExtension
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<XsdAbstractSystemExtension> create(const TiXmlElement* element);
virtual ~XsdAbstractSystemExtension() = default;
protected:
XsdAbstractSystemExtension() = default;
bool init(const TiXmlElement* element);
std::string m_language;
};
}
#endif // SONARGRAPH_XSD_ABSTRACT_SYSTEM_EXTENSION_H
@@ -1,349 +0,0 @@
#include "SonargraphXsdCmakeJsonModule.h"
#include "tinyxml.h"
#include "IndexerCommandCxx.h"
#include "ApplicationSettings.h"
#include "LanguageType.h"
#include "SourceGroupSettings.h"
#include "SourceGroupSettingsCxxSonargraph.h"
#include "SourceGroupSettingsWithCppStandard.h"
#include "SourceGroupSettingsWithCStandard.h"
#include "FileSystem.h"
#include "logging.h"
#include "SonargraphSoftwareSystem.h"
#include "SonargraphXsdCppSystemSettings.h"
#include "utilitySonargraph.h"
#include "utility.h"
#include "utilityString.h"
#include "utilityXml.h"
#include "OrderedCache.h"
namespace Sonargraph
{
std::string XsdCmakeJsonModule::getXsdTypeName()
{
return "xsdCmakeJsonModule";
}
std::shared_ptr<XsdCmakeJsonModule> XsdCmakeJsonModule::create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<XsdCmakeJsonModule> module = std::shared_ptr<XsdCmakeJsonModule>(new XsdCmakeJsonModule());
if (module->init(element, parent))
{
return module;
}
}
return std::shared_ptr<XsdCmakeJsonModule>();
}
LanguageType XsdCmakeJsonModule::getSupportedLanguage() const
{
return LANGUAGE_CPP;
}
std::set<FilePath> XsdCmakeJsonModule::getAllSourcePaths() const
{
FilePath baseDirectory;
if (std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem())
{
baseDirectory = softwareSystem->getBaseDirectory();
}
std::set<FilePath> sourcePaths;
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
{
sourcePaths.insert(rootPath->getFilePath(baseDirectory));
}
for (std::shared_ptr<XsdRootPathWithFiles> rootPath : m_rootPathWithFiles)
{
sourcePaths.insert(rootPath->getFilePath(baseDirectory));
}
return sourcePaths;
}
std::set<FilePath> XsdCmakeJsonModule::getAllSourceFilePathsCanonical() const
{
FilePath baseDir;
if (std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem())
{
baseDir = softwareSystem->getBaseDirectory();
}
const std::set<FilePathFilter> excludeFilters = utility::toSet(getDerivedExcludeFilters());
const std::set<FilePathFilter> includeFilters = utility::toSet(getDerivedIncludeFilters());
std::set<FilePath> sourceFilePaths;
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
{
for (const XsdRootPathWithFiles::SourceFile& sourceFile : getIncludedSourceFilesForRootPath(rootPath, baseDir, excludeFilters, includeFilters))
{
sourceFilePaths.insert(sourceFile.getFilePath(baseDir.getConcatenated(rootPath->getName())));
}
}
for (std::shared_ptr<XsdRootPath> rootPath : m_rootPathWithFiles)
{
for (const XsdRootPathWithFiles::SourceFile& sourceFile : getIncludedSourceFilesForRootPath(rootPath, baseDir, excludeFilters, includeFilters))
{
sourceFilePaths.insert(sourceFile.getFilePath(baseDir.getConcatenated(rootPath->getName())));
}
}
return sourceFilePaths;
}
std::set<FilePath> XsdCmakeJsonModule::getAllCxxHeaderSearchPathsCanonical() const
{
std::set<Id> usedCompilerOptionSetIds;
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
{
if (std::shared_ptr<XsdRootPathWithFiles> rootPathWithFiles = std::dynamic_pointer_cast<XsdRootPathWithFiles>(rootPath))
{
for (const XsdRootPathWithFiles::SourceFile& sourceFile : rootPathWithFiles->getSourceFiles())
{
usedCompilerOptionSetIds.insert(sourceFile.compilerOptionSetId);
}
}
}
for (std::shared_ptr<XsdRootPathWithFiles> rootPath : m_rootPathWithFiles)
{
for (const XsdRootPathWithFiles::SourceFile& sourceFile : rootPath->getSourceFiles())
{
usedCompilerOptionSetIds.insert(sourceFile.compilerOptionSetId);
}
}
std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem();
if (!softwareSystem)
{
return std::set<FilePath>();
}
std::set<std::wstring> usedCompilerOptions;
for (Id compilerOptionSetId : usedCompilerOptionSetIds)
{
for (std::shared_ptr<const XsdCppSystemSettings> systemExtension :
softwareSystem->getSpecificSystemExtensions<XsdCppSystemSettings>()
)
{
if (systemExtension->hasCompilerOptionsForId(compilerOptionSetId))
{
utility::append(
usedCompilerOptions,
utility::toSet(systemExtension->getCompilerOptionsForId(compilerOptionSetId))
);
break;
}
}
}
// make sure that none of these prefixes is the prefix of a prefix that appears further down in the list
const std::vector<std::wstring> optionPrefixes = {
L"--include-directory=",
L"--include-directory",
L"-cxx-isystem",
L"-iquote",
L"-isystem-after",
L"-isystem",
L"-I"
};
std::set<FilePath> headerSearchPaths;
for (const std::wstring& compilerOption : usedCompilerOptions)
{
for (const std::wstring& optionPrefix : optionPrefixes)
{
if (utility::isPrefix(optionPrefix, compilerOption))
{
FilePath headerSearchPath(utility::trim(compilerOption.substr(optionPrefix.size())));
if (headerSearchPath.isAbsolute())
{
headerSearchPaths.insert(headerSearchPath);
}
else
{
headerSearchPaths.insert(softwareSystem->getBaseDirectory().getConcatenated(headerSearchPath));
}
break;
}
}
}
return headerSearchPaths;
}
std::vector<std::shared_ptr<IndexerCommand>> XsdCmakeJsonModule::getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const
{
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
std::set<FilePath> indexedHeaderPaths;
std::wstring languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic();
if (std::shared_ptr<const SourceGroupSettingsCxxSonargraph> sonargraphSettings =
std::dynamic_pointer_cast<const SourceGroupSettingsCxxSonargraph>(sourceGroupSettings))
{
indexedHeaderPaths = utility::toSet(sonargraphSettings->getIndexedHeaderPathsExpandedAndAbsolute());
languageStandard = sonargraphSettings->getCppStandard();
}
else
{
LOG_ERROR(L"Source group doesn't specify language standard. Falling back to \"" + languageStandard + L"\".");
LOG_ERROR(L"Source group doesn't specify any indexed header paths");
}
std::vector<std::wstring> compilerFlags;
compilerFlags.emplace_back(IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector<FilePath>()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector<FilePath>()));
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
{
if (std::shared_ptr<XsdRootPathWithFiles> rootPathWithFiles = std::dynamic_pointer_cast<XsdRootPathWithFiles>(rootPath))
{
utility::append(indexerCommands, getIndexerCommandsForRootPath(
rootPathWithFiles, indexedHeaderPaths, compilerFlags
));
}
}
for (std::shared_ptr<XsdRootPathWithFiles> rootPath : m_rootPathWithFiles)
{
utility::append(indexerCommands, getIndexerCommandsForRootPath(
rootPath, indexedHeaderPaths, compilerFlags
));
}
return indexerCommands;
}
bool XsdCmakeJsonModule::init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
if (!XsdAbstractModule::init(element, parent))
{
return false;
}
if (element != nullptr)
{
for (const TiXmlElement* rootPathWithFilesElement : utility::getXmlChildElementsWithName(element, "rootPathWithFiles"))
{
if (std::shared_ptr<XsdRootPathWithFiles> rootPath = XsdRootPathWithFiles::create(rootPathWithFilesElement))
{
m_rootPathWithFiles.push_back(rootPath);
}
else
{
LOG_ERROR("Unable to parse \"rootPathWithFiles\" element of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
return true;
}
return false;
}
std::vector<XsdRootPathWithFiles::SourceFile> XsdCmakeJsonModule::getIncludedSourceFilesForRootPath(
std::shared_ptr<XsdRootPath> rootPath,
const FilePath& baseDir,
const std::set<FilePathFilter>& excludeFilters,
const std::set<FilePathFilter>& includeFilters) const
{
std::vector<XsdRootPathWithFiles::SourceFile> sourceFiles;
if (std::shared_ptr<XsdRootPathWithFiles> rootPathWithFiles = std::dynamic_pointer_cast<XsdRootPathWithFiles>(rootPath))
{
for (const XsdRootPathWithFiles::SourceFile& sourceFile : rootPathWithFiles->getSourceFiles())
{
const FilePath sourceFilePath = sourceFile.getFilePath(baseDir).makeCanonical();
bool excludeMatches = false;
for (const FilePathFilter& excludeFilter : excludeFilters)
{
if (excludeFilter.isMatching(sourceFilePath))
{
excludeMatches = true;
break;
}
}
if (excludeMatches)
{
for (const FilePathFilter& includeFilter : includeFilters)
{
if (includeFilter.isMatching(sourceFilePath))
{
excludeMatches = false;
break;
}
}
}
if (!excludeMatches)
{
sourceFiles.push_back(sourceFile);
}
}
}
return sourceFiles;
}
std::vector<std::shared_ptr<IndexerCommand>> XsdCmakeJsonModule::getIndexerCommandsForRootPath(
std::shared_ptr<XsdRootPathWithFiles> rootPath,
const std::set<FilePath>& indexedHeaderPaths,
const std::vector<std::wstring>& compilerFlags) const
{
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
if (rootPath)
{
std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem();
if (!softwareSystem)
{
return std::vector<std::shared_ptr<IndexerCommand>>();
}
const FilePath baseDir = rootPath->getFilePath(softwareSystem->getBaseDirectory());
const std::set<FilePathFilter> excludeFilters = utility::toSet(getDerivedExcludeFilters());
const std::set<FilePathFilter> includeFilters = utility::toSet(getDerivedIncludeFilters());
OrderedCache<Id, std::vector<std::wstring>> compilerOptionCache([&](const Id& id) {
if (std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem())
{
for (std::shared_ptr<const XsdCppSystemSettings> systemExtension : softwareSystem->getSpecificSystemExtensions<XsdCppSystemSettings>())
{
if (systemExtension->hasCompilerOptionsForId(id))
{
return utility::concat(systemExtension->getCompilerOptionsForId(id), compilerFlags);
}
}
}
return compilerFlags;
});
for (const XsdRootPathWithFiles::SourceFile& sourceFile : getIncludedSourceFilesForRootPath(
rootPath, baseDir, excludeFilters, includeFilters)
)
{
const FilePath sourceFilePath = sourceFile.getFilePath(baseDir).makeCanonical();
indexerCommands.push_back(std::make_shared<IndexerCommandCxx>(
sourceFilePath,
utility::concat(indexedHeaderPaths, { sourceFilePath }),
excludeFilters,
includeFilters,
softwareSystem->getBaseDirectory(),
utility::concat(
compilerOptionCache.getValue(sourceFile.compilerOptionSetId),
sourceFilePath.wstr()
)
));
}
}
return indexerCommands;
}
}
@@ -1,43 +0,0 @@
#ifndef SONARGRAPH_XSD_CMAKE_JSON_MODULE_H
#define SONARGRAPH_XSD_CMAKE_JSON_MODULE_H
#include "SonargraphXsdAbstractModule.h"
#include "SonargraphXsdRootPathWithFiles.h"
namespace Sonargraph
{
class XsdCmakeJsonModule : public XsdAbstractModule
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<XsdCmakeJsonModule> create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
LanguageType getSupportedLanguage() const override;
std::set<FilePath> getAllSourcePaths() const override;
std::set<FilePath> getAllSourceFilePathsCanonical() const override;
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const override;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const override;
protected:
XsdCmakeJsonModule() = default;
bool init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
std::vector<XsdRootPathWithFiles::SourceFile> getIncludedSourceFilesForRootPath(
std::shared_ptr<XsdRootPath> rootPath,
const FilePath& baseDir,
const std::set<FilePathFilter>& excludeFilters,
const std::set<FilePathFilter>& includeFilters) const;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommandsForRootPath(
std::shared_ptr<XsdRootPathWithFiles> rootPath,
const std::set<FilePath>& indexedHeaderPaths,
const std::vector<std::wstring>& compilerFlags) const;
std::vector<std::shared_ptr<XsdRootPathWithFiles>> m_rootPathWithFiles;
};
}
#endif // SONARGRAPH_XSD_CMAKE_JSON_MODULE_H
@@ -1,296 +0,0 @@
#include "SonargraphXsdCppManualModule.h"
#include "tinyxml.h"
#include "ApplicationSettings.h"
#include "IndexerCommandCxx.h"
#include "FileSystem.h"
#include "logging.h"
#include "SonargraphSoftwareSystem.h"
#include "SourceGroupSettingsCxxSonargraph.h"
#include "utility.h"
#include "utilityFile.h"
#include "utilitySonargraph.h"
#include "utilityXml.h"
namespace Sonargraph
{
std::string XsdCppManualModule::getXsdTypeName()
{
return "xsdCppManualModule";
}
std::vector<std::wstring> XsdCppManualModule::getIncludeOptionPrefixes()
{
// make sure that none of these prefixes is the prefix of a prefix that appears further down in the list
return {
L"-I",
L"--include_directory=",
L"--sys_include="
};
}
std::shared_ptr<XsdCppManualModule> XsdCppManualModule::create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<XsdCppManualModule> module = std::shared_ptr<XsdCppManualModule>(new XsdCppManualModule());
if (module->init(element, parent))
{
return module;
}
}
return std::shared_ptr<XsdCppManualModule>();
}
LanguageType XsdCppManualModule::getSupportedLanguage() const
{
return LANGUAGE_CPP;
}
std::set<FilePath> XsdCppManualModule::getAllSourcePaths() const
{
FilePath baseDirectory;
if (std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem())
{
baseDirectory = softwareSystem->getBaseDirectory();
}
std::set<FilePath> sourcePaths;
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
{
sourcePaths.insert(rootPath->getFilePath(baseDirectory));
}
return sourcePaths;
}
std::set<FilePath> XsdCppManualModule::getAllSourceFilePathsCanonical() const
{
const std::vector<FilePathFilter> excludeFilters = getDerivedExcludeFilters();
const std::vector<FilePathFilter> includeFilters = getDerivedIncludeFilters();
std::set<FilePath> sourceFilePaths;
for (const FileInfo& fileInfo : FileSystem::getFileInfosFromPaths(utility::getTopLevelPaths(getAllSourcePaths()), m_sourceFileExtensions))
{
const FilePath sourceFilePath = fileInfo.path.getCanonical();
bool excludeMatches = false;
for (const FilePathFilter& excludeFilter : excludeFilters)
{
if (excludeFilter.isMatching(sourceFilePath))
{
excludeMatches = true;
break;
}
}
if (excludeMatches)
{
for (const FilePathFilter& includeFilter : includeFilters)
{
if (includeFilter.isMatching(sourceFilePath))
{
excludeMatches = false;
break;
}
}
}
if (!excludeMatches)
{
sourceFilePaths.insert(sourceFilePath);
}
}
return sourceFilePaths;
}
std::set<FilePath> XsdCppManualModule::getAllCxxHeaderSearchPathsCanonical() const
{
std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem();
if (!softwareSystem)
{
return std::set<FilePath>();
}
const std::vector<std::wstring> optionPrefixes = getIncludeOptionPrefixes();
const FilePath baseDir = softwareSystem->getBaseDirectory();
const FilePath baseIncludeDir = m_basePathForIncludes.isAbsolute() ? m_basePathForIncludes : baseDir.getConcatenated(m_basePathForIncludes);
std::set<FilePath> headerSearchPaths;
for (const std::wstring& compilerOption : m_moduleCompilerOptions)
{
for (const std::wstring& optionPrefix : optionPrefixes)
{
if (utility::isPrefix(optionPrefix, compilerOption))
{
FilePath headerSearchPath(utility::trim(compilerOption.substr(optionPrefix.size())));
if (headerSearchPath.isAbsolute())
{
headerSearchPaths.insert(headerSearchPath);
}
else
{
headerSearchPaths.insert(baseIncludeDir.getConcatenated(headerSearchPath));
}
break;
}
}
}
return headerSearchPaths;
}
std::vector<std::shared_ptr<IndexerCommand>> XsdCppManualModule::getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const
{
std::shared_ptr<const SoftwareSystem> softwareSystem = getSoftwareSystem();
if (!softwareSystem)
{
return std::vector<std::shared_ptr<IndexerCommand>>();
}
std::set<FilePath> indexedHeaderPaths;
std::wstring languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic();
if (std::shared_ptr<const SourceGroupSettingsCxxSonargraph> sonargraphSettings =
std::dynamic_pointer_cast<const SourceGroupSettingsCxxSonargraph>(sourceGroupSettings))
{
indexedHeaderPaths = utility::toSet(sonargraphSettings->getIndexedHeaderPathsExpandedAndAbsolute());
languageStandard = sonargraphSettings->getCppStandard();
}
else
{
LOG_ERROR(L"Source group doesn't specify language standard. Falling back to \"" + languageStandard + L"\".");
LOG_ERROR(L"Source group doesn't specify any indexed header paths");
}
const std::set<FilePathFilter> excludeFilters = utility::toSet(getDerivedExcludeFilters());
const std::set<FilePathFilter> includeFilters = utility::toSet(getDerivedIncludeFilters());
std::vector<std::wstring> compilerFlags;
{
const std::vector<std::wstring> optionPrefixes = getIncludeOptionPrefixes();
const FilePath baseIncludeDir = m_basePathForIncludes.isAbsolute() ? m_basePathForIncludes : softwareSystem->getBaseDirectory().getConcatenated(m_basePathForIncludes);
for (const std::wstring& compilerOption : m_moduleCompilerOptions)
{
bool isIncludeOption = false;
for (const std::wstring& optionPrefix : optionPrefixes)
{
if (utility::isPrefix(optionPrefix, compilerOption))
{
isIncludeOption = true;
compilerFlags.push_back(L"-isystem");
FilePath headerSearchPath(utility::trim(compilerOption.substr(optionPrefix.size())));
if (headerSearchPath.isAbsolute())
{
compilerFlags.push_back(headerSearchPath.wstr());
}
else
{
compilerFlags.push_back(baseIncludeDir.getConcatenated(headerSearchPath).wstr());
}
break;
}
}
if (!isIncludeOption)
{
compilerFlags.push_back(compilerOption);
}
}
}
compilerFlags.emplace_back(IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector<FilePath>()));
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector<FilePath>()));
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
for (const FilePath& sourceFilePath : getAllSourceFilePathsCanonical())
{
indexerCommands.push_back(std::make_shared<IndexerCommandCxx>(
sourceFilePath,
utility::concat(indexedHeaderPaths, { sourceFilePath }),
excludeFilters,
includeFilters,
softwareSystem->getBaseDirectory(),
utility::concat(compilerFlags, sourceFilePath.wstr())
));
}
return indexerCommands;
}
XsdCppManualModule::XsdCppManualModule()
: m_basePathForIncludes(L".")
, m_sourceFileExtensions({L".cpp"})
{
}
bool XsdCppManualModule::init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
if (!XsdAbstractModule::init(element, parent))
{
return false;
}
if (element != nullptr)
{
{
const TiXmlElement* basePathForIncludesElement = element->FirstChildElement("basePathForIncludes");
if (basePathForIncludesElement != nullptr)
{
const char* text = basePathForIncludesElement->GetText();
if (text != nullptr)
{
m_basePathForIncludes = FilePath(utility::decodeFromUtf8(text));
}
else
{
LOG_ERROR("Unable to parse \"basePathForIncludes\" element of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
}
{
const TiXmlElement* sourceFileExtensionsElement = element->FirstChildElement("sourceFileExtensions");
if (sourceFileExtensionsElement != nullptr)
{
const char* text = sourceFileExtensionsElement->GetText();
if (text != nullptr)
{
m_sourceFileExtensions.clear();
for (const std::wstring extension : utility::split<std::vector<std::wstring>>(utility::decodeFromUtf8(text), L","))
{
m_sourceFileExtensions.push_back(utility::trim(extension));
}
}
else
{
LOG_ERROR("Unable to parse \"sourceFileExtensions\" element of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
}
for (const TiXmlElement* moduleCompilerOptionsElement : utility::getXmlChildElementsWithName(element, "moduleCompilerOptions"))
{
const char* text = moduleCompilerOptionsElement->GetText();
if (text != nullptr)
{
for (const std::wstring& s : utility::splitToVector(utility::decodeFromUtf8(text), L' '))
{
m_moduleCompilerOptions.push_back(utility::trim(s));
}
}
}
return true;
}
return false;
}
}
@@ -1,35 +0,0 @@
#ifndef SONARGRAPH_XSD_CPP_MANUAL_MODULE_H
#define SONARGRAPH_XSD_CPP_MANUAL_MODULE_H
#include "SonargraphXsdAbstractModule.h"
#include "SonargraphXsdRootPathWithFiles.h"
namespace Sonargraph
{
class XsdCppManualModule : public XsdAbstractModule
{
public:
static std::string getXsdTypeName();
static std::vector<std::wstring> getIncludeOptionPrefixes();
static std::shared_ptr<XsdCppManualModule> create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
LanguageType getSupportedLanguage() const override;
std::set<FilePath> getAllSourcePaths() const override;
std::set<FilePath> getAllSourceFilePathsCanonical() const override;
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const override;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const override;
protected:
XsdCppManualModule();
bool init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
FilePath m_basePathForIncludes;
std::vector<std::wstring> m_sourceFileExtensions;
std::vector<std::wstring> m_moduleCompilerOptions;
};
}
#endif // SONARGRAPH_XSD_CPP_MANUAL_MODULE_H
@@ -1,85 +0,0 @@
#include "SonargraphXsdCppSystemSettings.h"
#include "tinyxml.h"
#include "utilitySonargraph.h"
#include "logging.h"
#include "utilityString.h"
#include "utilityXml.h"
namespace Sonargraph
{
std::string XsdCppSystemSettings::getXsdTypeName()
{
return "xsdCppSystemSettings";
}
std::shared_ptr<XsdCppSystemSettings> XsdCppSystemSettings::create(const TiXmlElement* element)
{
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<XsdCppSystemSettings> systemExtension = std::shared_ptr<XsdCppSystemSettings>(new XsdCppSystemSettings());
if (systemExtension->init(element))
{
return systemExtension;
}
}
return std::shared_ptr<XsdCppSystemSettings>();
}
bool XsdCppSystemSettings::hasCompilerOptionsForId(Id id) const
{
return m_compilerOptionSets.find(id) != m_compilerOptionSets.end();
}
std::vector<std::wstring> XsdCppSystemSettings::getCompilerOptionsForId(Id id) const
{
std::map<Id, std::vector<std::wstring>>::const_iterator it = m_compilerOptionSets.find(id);
if (it != m_compilerOptionSets.end())
{
return it->second;
}
return std::vector<std::wstring>();
}
bool XsdCppSystemSettings::init(const TiXmlElement* element)
{
XsdAbstractSystemExtension::init(element);
if (element != nullptr)
{
for (const TiXmlElement* compilerOptionSetElement : utility::getXmlChildElementsWithName(element, "compilerOptionSets"))
{
Id optionSetId = 0;
{
const char* value = compilerOptionSetElement->Attribute("id");
if (value != nullptr && atoi(value) >= 0)
{
optionSetId = atoi(value);
}
else
{
LOG_ERROR("Unable to parse \"id\" attribute of compilerOptionSets of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
for (const TiXmlElement* optionElement : utility::getXmlChildElementsWithName(compilerOptionSetElement, "option"))
{
const char* value = optionElement->GetText();
if (value != nullptr)
{
m_compilerOptionSets[optionSetId].push_back(utility::decodeFromUtf8(value));
}
else
{
LOG_ERROR("Unable to parse \"option\" attribute of compilerOptionSets of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
}
return true;
}
return false;
}
}
@@ -1,30 +0,0 @@
#ifndef SONARGRAPH_XSD_CPP_SYSTEM_SETTINGS_H
#define SONARGRAPH_XSD_CPP_SYSTEM_SETTINGS_H
#include <map>
#include <vector>
#include "SonargraphXsdAbstractSystemExtension.h"
#include "types.h"
namespace Sonargraph
{
class XsdCppSystemSettings : public XsdAbstractSystemExtension
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<XsdCppSystemSettings> create(const TiXmlElement* element);
bool hasCompilerOptionsForId(Id id) const;
std::vector<std::wstring> getCompilerOptionsForId(Id id) const;
protected:
XsdCppSystemSettings() = default;
bool init(const TiXmlElement* element);
private:
std::map<Id, std::vector<std::wstring>> m_compilerOptionSets;
};
}
#endif // SONARGRAPH_XSD_CPP_SYSTEM_SETTINGS_H
@@ -1,161 +0,0 @@
#include "SonargraphXsdJavaModule.h"
#include "tinyxml.h"
#include "FileSystem.h"
#include "IndexerCommandJava.h"
#include "LanguageType.h"
#include "logging.h"
#include "SonargraphSourceRootPath.h"
#include "SonargraphSoftwareSystem.h"
#include "SonargraphXsdRootPath.h"
#include "SourceGroupSettingsJavaSonargraph.h"
#include "utility.h"
#include "utilityFile.h"
#include "utilitySonargraph.h"
#include "utilityXml.h"
namespace Sonargraph
{
std::string XsdJavaModule::getXsdTypeName()
{
return "xsdJavaModule";
}
std::shared_ptr<XsdJavaModule> XsdJavaModule::create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<XsdJavaModule> module = std::shared_ptr<XsdJavaModule>(new XsdJavaModule());
if (module->init(element, parent))
{
return module;
}
}
return std::shared_ptr<XsdJavaModule>();
}
LanguageType XsdJavaModule::getSupportedLanguage() const
{
return LANGUAGE_JAVA;
}
std::set<FilePath> XsdJavaModule::getAllSourcePaths() const
{
const FilePath baseDirectory = getSoftwareSystem() ? getSoftwareSystem()->getBaseDirectory() : FilePath();
std::set<FilePath> sourcePaths;
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
{
sourcePaths.insert(rootPath->getFilePath(baseDirectory));
}
for (std::shared_ptr<SourceRootPath> rootPath : m_sourceRootPaths)
{
sourcePaths.insert(rootPath->getFilePath(baseDirectory));
}
return sourcePaths;
}
std::set<FilePath> XsdJavaModule::getAllSourceFilePathsCanonical() const
{
const std::vector<FilePathFilter> excludeFilters = getDerivedExcludeFilters();
const std::vector<FilePathFilter> includeFilters = getDerivedIncludeFilters();
std::set<FilePath> sourceFilePaths;
for (const FileInfo& fileInfo : FileSystem::getFileInfosFromPaths(utility::getTopLevelPaths(getAllSourcePaths()), { L".java" }))
{
const FilePath sourceFilePath = fileInfo.path.getCanonical();
bool excludeMatches = false;
for (const FilePathFilter& excludeFilter : excludeFilters)
{
if (excludeFilter.isMatching(sourceFilePath))
{
excludeMatches = true;
break;
}
}
if (excludeMatches)
{
for (const FilePathFilter& includeFilter : includeFilters)
{
if (includeFilter.isMatching(sourceFilePath))
{
excludeMatches = false;
break;
}
}
}
if (!excludeMatches)
{
sourceFilePaths.insert(sourceFilePath);
}
}
return sourceFilePaths;
}
std::set<FilePath> XsdJavaModule::getAllCxxHeaderSearchPathsCanonical() const
{
return std::set<FilePath>();
}
std::vector<std::shared_ptr<IndexerCommand>> XsdJavaModule::getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const
{
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
{
std::wstring languageStandard = SourceGroupSettingsWithJavaStandard::getDefaultJavaStandardStatic();
if (std::shared_ptr<const SourceGroupSettingsJavaSonargraph> settings =
std::dynamic_pointer_cast<const SourceGroupSettingsJavaSonargraph>(sourceGroupSettings))
{
languageStandard = settings->getJavaStandard();
}
else
{
LOG_ERROR(L"Source group doesn't specify language standard. Falling back to \"" + languageStandard + L"\".");
}
for (const FilePath& sourceFilePath : getAllSourceFilePathsCanonical())
{
indexerCommands.push_back(std::make_shared<IndexerCommandJava>(
sourceFilePath,
languageStandard,
std::vector<FilePath>() // the classpath is set later... TODO: fix this hack
));
}
}
return indexerCommands;
}
bool XsdJavaModule::init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent)
{
if (!XsdAbstractModule::init(element, parent))
{
return false;
}
if (element != nullptr)
{
for (const TiXmlElement* sourceRootPathElement : utility::getXmlChildElementsWithName(element, "sourceRootPath"))
{
if (std::shared_ptr<SourceRootPath> rootPath = SourceRootPath::create(sourceRootPathElement))
{
m_sourceRootPaths.push_back(rootPath);
}
else
{
LOG_ERROR("Unable to parse \"sourceRootPath\" element of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
return true;
}
return false;
}
}
@@ -1,33 +0,0 @@
#ifndef SONARGRAPH_XSD_JAVA_MODULE_H
#define SONARGRAPH_XSD_JAVA_MODULE_H
#include "SonargraphXsdAbstractModule.h"
namespace Sonargraph
{
class SourceRootPath;
class XsdJavaModule : public XsdAbstractModule
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<XsdJavaModule> create(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
LanguageType getSupportedLanguage() const override;
std::set<FilePath> getAllSourcePaths() const override;
std::set<FilePath> getAllSourceFilePathsCanonical() const override;
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const override;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
std::shared_ptr<const ApplicationSettings> appSettings) const override;
protected:
XsdJavaModule() = default;
bool init(const TiXmlElement* element, std::weak_ptr<SoftwareSystem> parent);
std::vector<std::shared_ptr<SourceRootPath>> m_sourceRootPaths;
};
}
#endif // SONARGRAPH_XSD_JAVA_MODULE_H
@@ -1,77 +0,0 @@
#include "SonargraphXsdRootPath.h"
#include "tinyxml.h"
#include "IndexerCommandJava.h"
#include "logging.h"
#include "SonargraphXsdAbstractModule.h"
#include "SonargraphXsdRootPathWithFiles.h"
#include "SonargraphXsdSourceRootPath.h"
#include "utilitySonargraph.h"
#include "utilityString.h"
#include "utilityXml.h"
namespace Sonargraph
{
std::string XsdRootPath::getXsdTypeName()
{
return "xsdRootPath";
}
std::shared_ptr<XsdRootPath> XsdRootPath::create(const TiXmlElement* element)
{
if (std::shared_ptr<XsdRootPathWithFiles> rootPath = XsdRootPathWithFiles::create(element))
{
return rootPath;
}
if (std::shared_ptr<XsdSourceRootPath> rootPath = XsdSourceRootPath::create(element))
{
return rootPath;
}
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<XsdRootPath> rootPath = std::shared_ptr<XsdRootPath>(new XsdRootPath());
if (rootPath->init(element))
{
return rootPath;
}
}
return std::shared_ptr<XsdRootPath>();
}
std::wstring XsdRootPath::getName() const
{
return m_name;
}
FilePath XsdRootPath::getFilePath(const FilePath& baseDirectory) const
{
FilePath filePath(getName());
if (filePath.isAbsolute())
{
return filePath;
}
return baseDirectory.getConcatenated(filePath);
}
bool XsdRootPath::init(const TiXmlElement* element)
{
if (element != nullptr)
{
const char* value = element->Attribute("name");
if (value != nullptr)
{
m_name = utility::decodeFromUtf8(value);
}
else
{
LOG_ERROR("Unable to parse \"name\" of Sonargraph " + getXsdTypeName() + ".");
return false;
}
return true;
}
return false;
}
}
@@ -1,36 +0,0 @@
#ifndef SONARGRAPH_XSD_ROOT_PATH_H
#define SONARGRAPH_XSD_ROOT_PATH_H
#include <memory>
#include <string>
#include <vector>
#include "FilePath.h"
class IndexerCommand;
class SonargraphAbstractModule;
class TiXmlElement;
namespace Sonargraph
{
class XsdRootPath
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<XsdRootPath> create(const TiXmlElement* element);
virtual ~XsdRootPath() = default;
std::wstring getName() const;
FilePath getFilePath(const FilePath& baseDirectory) const;
protected:
XsdRootPath() = default;
bool init(const TiXmlElement* element);
std::wstring m_name;
};
}
#endif // SONARGRAPH_XSD_ROOT_PATH_H
@@ -1,112 +0,0 @@
#include "SonargraphXsdRootPathWithFiles.h"
#include "tinyxml.h"
#include "utilitySonargraph.h"
#include "logging.h"
#include "utilityString.h"
#include "utilityXml.h"
namespace Sonargraph
{
XsdRootPathWithFiles::SourceFile::SourceFile(std::wstring fileName, Id compilerOptionSetId)
: fileName(fileName)
, compilerOptionSetId(compilerOptionSetId)
{
}
FilePath XsdRootPathWithFiles::SourceFile::getFilePath(const FilePath& baseDirectory) const
{
FilePath filePath(fileName);
if (filePath.isAbsolute())
{
return filePath;
}
return baseDirectory.getConcatenated(filePath).makeCanonical();
}
std::string XsdRootPathWithFiles::getXsdTypeName()
{
return "xsdRootPathWithFiles";
}
std::shared_ptr<XsdRootPathWithFiles> XsdRootPathWithFiles::create(const TiXmlElement* element)
{
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<XsdRootPathWithFiles> rootPath = std::shared_ptr<XsdRootPathWithFiles>(new XsdRootPathWithFiles());
if (rootPath->init(element))
{
return rootPath;
}
}
return std::shared_ptr<XsdRootPathWithFiles>();
}
std::vector<XsdRootPathWithFiles::SourceFile> XsdRootPathWithFiles::getSourceFiles() const
{
return m_sourceFiles;
}
std::vector<std::wstring> XsdRootPathWithFiles::getExcludedDirectories() const
{
return m_excludedDirectories;
}
bool XsdRootPathWithFiles::init(const TiXmlElement* element)
{
XsdRootPath::init(element);
if (element != nullptr)
{
for (const TiXmlElement* sourceFileElement : utility::getXmlChildElementsWithName(element, "sourceFile"))
{
std::wstring fileName;
{
const char* value = sourceFileElement->Attribute("fileName");
if (value != nullptr)
{
fileName = utility::decodeFromUtf8(value);
}
else
{
LOG_ERROR("Unable to parse \"fileName\" attribute of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
Id compilerOptionSetId;
{
int value;
if (sourceFileElement->QueryIntAttribute("compilerOptionSetId", &value) == TIXML_SUCCESS && value >= 0)
{
compilerOptionSetId = Id(value);
}
else
{
LOG_ERROR("Unable to parse \"compilerOptionSetId\" attribute of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
m_sourceFiles.push_back(SourceFile(fileName, compilerOptionSetId));
}
for (const TiXmlElement* excludedDirectoryElement : utility::getXmlChildElementsWithName(element, "excludedDirectory"))
{
const char* value = excludedDirectoryElement->Attribute("dir");
if (value != nullptr)
{
m_excludedDirectories.push_back(utility::decodeFromUtf8(value));
}
else
{
LOG_ERROR("Unable to parse \"dir\" attribute of Sonargraph " + getXsdTypeName() + ".");
return false;
}
}
return true;
}
return false;
}
}
@@ -1,39 +0,0 @@
#ifndef SONARGRAPH_XSD_ROOT_PATH_WITH_FILES_H
#define SONARGRAPH_XSD_ROOT_PATH_WITH_FILES_H
#include <memory>
#include "SonargraphXsdRootPath.h"
#include "types.h"
namespace Sonargraph
{
class XsdRootPathWithFiles : public XsdRootPath
{
public:
struct SourceFile
{
SourceFile(std::wstring fileName, Id compilerOptionSetId);
FilePath getFilePath(const FilePath& baseDirectory) const;
std::wstring fileName;
Id compilerOptionSetId;
};
static std::string getXsdTypeName();
static std::shared_ptr<XsdRootPathWithFiles> create(const TiXmlElement* element);
std::vector<SourceFile> getSourceFiles() const;
std::vector<std::wstring> getExcludedDirectories() const;
protected:
XsdRootPathWithFiles() = default;
bool init(const TiXmlElement* element);
std::vector<SourceFile> m_sourceFiles;
std::vector<std::wstring> m_excludedDirectories;
};
}
#endif // SONARGRAPH_XSD_ROOT_PATH_WITH_FILES_H
@@ -1,34 +0,0 @@
#include "SonargraphXsdSourceRootPath.h"
#include "tinyxml.h"
#include "utilitySonargraph.h"
#include "logging.h"
#include "utilityString.h"
#include "utilityXml.h"
namespace Sonargraph
{
std::string XsdSourceRootPath::getXsdTypeName()
{
return "xsdSourceRootPath";
}
std::shared_ptr<XsdSourceRootPath> XsdSourceRootPath::create(const TiXmlElement* element)
{
if (!utility::xmlElementHasAttribute(element, "xsi:type") || utility::sonargraphXmlElementIsType(element, getXsdTypeName()))
{
std::shared_ptr<XsdSourceRootPath> rootPath = std::shared_ptr<XsdSourceRootPath>(new XsdSourceRootPath());
if (rootPath->init(element))
{
return rootPath;
}
}
return std::shared_ptr<XsdSourceRootPath>();
}
bool XsdSourceRootPath::init(const TiXmlElement* element)
{
return XsdRootPath::init(element);
}
}
@@ -1,23 +0,0 @@
#ifndef SONARGRAPH_XSD_SOURCE_ROOT_PATH_H
#define SONARGRAPH_XSD_SOURCE_ROOT_PATH_H
#include <memory>
#include "SonargraphXsdRootPath.h"
#include "types.h"
namespace Sonargraph
{
class XsdSourceRootPath : public XsdRootPath
{
public:
static std::string getXsdTypeName();
static std::shared_ptr<XsdSourceRootPath> create(const TiXmlElement* element);
protected:
XsdSourceRootPath() = default;
bool init(const TiXmlElement* element);
};
}
#endif // SONARGRAPH_XSD_SOURCE_ROOT_PATH_H
@@ -1,12 +0,0 @@
#include "utilitySonargraph.h"
#include "tinyxml.h"
namespace utility
{
bool sonargraphXmlElementIsType(const TiXmlElement *element, const std::string& typeName)
{
const char* value = element->Attribute("xsi:type");
return (value != nullptr && value == "ns4:" + typeName);
}
}
@@ -1,13 +0,0 @@
#ifndef UTILITY_SONARGRAPH_H
#define UTILITY_SONARGRAPH_H
#include <string>
class TiXmlElement;
namespace utility
{
bool sonargraphXmlElementIsType(const TiXmlElement *element, const std::string& typeName);
}
#endif // UTILITY_SONARGRAPH_H