logic: added project setup support for Sonargraph projects (Java and CMake-JSON modules supported)
* added classes for loading a Sonargraph project * added Sonargraph options to project setup wizard * added test for generating indexer commands from Sonargraph modules * fixed sqlite storage crashing in constructor when parent directory of provided path does not exist * removed unused FileRegister from Java indexing * removed unused info from IndexerCommandJava * refactored loading and saving of SourceGroupSettings * extracted sourcepaths settings to own class that can be re-used * merged CDB wizard contentents for source file and indexed paths * unified wizard content for sonargraph project path * removed include filters from default source groups * extracted generation of RefreshInfo from Project to RefreshInfoGenerator * added tests for RefreshInfoGenerator * added language and standard selection to sonargraph project setup * added auto-detection for indexed header paths of sonargraph cmake json modules * Sonargraph::Project can enable/disable support for specific modules * warn if sonargraph project contains no matching modules * indexed headers can be detected from sonargraph project
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utility.h"
|
||||
@@ -96,6 +97,17 @@ bool ConfigManager::getValue(const std::string& key, bool& value) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigManager::getValue(const std::string& key, FilePath& value) const
|
||||
{
|
||||
std::wstring valueString;
|
||||
if (getValue(key, valueString))
|
||||
{
|
||||
value = FilePath(valueString);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigManager::getValues(const std::string& key, std::vector<std::string>& values) const
|
||||
{
|
||||
std::pair <std::multimap<std::string, std::string>::const_iterator,
|
||||
@@ -178,6 +190,20 @@ bool ConfigManager::getValues(const std::string& key, std::vector<bool>& values)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ConfigManager::getValues(const std::string& key, std::vector<FilePath>& values) const
|
||||
{
|
||||
std::vector<std::wstring> valuesStringVector;
|
||||
if (getValues(key, valuesStringVector))
|
||||
{
|
||||
for (const std::wstring& valueString : valuesStringVector)
|
||||
{
|
||||
values.push_back(FilePath(valueString));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ConfigManager::setValue(const std::string& key, const std::string& value)
|
||||
{
|
||||
std::multimap<std::string, std::string>::iterator it = m_values.find(key);
|
||||
@@ -214,6 +240,11 @@ void ConfigManager::setValue(const std::string& key, const bool value)
|
||||
setValue(key, std::string(value ? "1" : "0"));
|
||||
}
|
||||
|
||||
void ConfigManager::setValue(const std::string& key, const FilePath& value)
|
||||
{
|
||||
setValue(key, value.wstr());
|
||||
}
|
||||
|
||||
void ConfigManager::setValues(const std::string& key, const std::vector<std::string>& values)
|
||||
{
|
||||
std::multimap<std::string, std::string>::iterator it = m_values.find(key);
|
||||
@@ -268,6 +299,16 @@ void ConfigManager::setValues(const std::string& key, const std::vector<bool>& v
|
||||
setValues(key, stringValues);
|
||||
}
|
||||
|
||||
void ConfigManager::setValues(const std::string& key, const std::vector<FilePath>& values)
|
||||
{
|
||||
std::vector<std::wstring> stringValues;
|
||||
for (const FilePath& p : values)
|
||||
{
|
||||
stringValues.push_back(p.wstr());
|
||||
}
|
||||
setValues(key, stringValues);
|
||||
}
|
||||
|
||||
void ConfigManager::removeValues(const std::string& key)
|
||||
{
|
||||
for (const std::string& sublevelKey: getSublevelKeys(key))
|
||||
@@ -304,20 +345,18 @@ std::vector<std::string> ConfigManager::getSublevelKeys(const std::string& key)
|
||||
|
||||
bool ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
|
||||
{
|
||||
std::string text = textAccess->getText();
|
||||
|
||||
TiXmlDocument doc;
|
||||
const char* pTest = doc.Parse(text.c_str(), 0, TIXML_ENCODING_UTF8);
|
||||
const char* pTest = doc.Parse(textAccess->getText().c_str(), 0, TIXML_ENCODING_UTF8);
|
||||
if (pTest != nullptr)
|
||||
{
|
||||
TiXmlHandle docHandle(&doc);
|
||||
TiXmlNode *rootNode = docHandle.FirstChild("config").ToNode();
|
||||
TiXmlNode* rootNode = docHandle.FirstChild("config").ToNode();
|
||||
if (rootNode == nullptr)
|
||||
{
|
||||
LOG_ERROR("No rootelement 'config' in the configfile");
|
||||
return false;
|
||||
}
|
||||
for (TiXmlNode *childNode = rootNode->FirstChild(); childNode; childNode = childNode->NextSibling())
|
||||
for (TiXmlNode* childNode = rootNode->FirstChild(); childNode; childNode = childNode->NextSibling())
|
||||
{
|
||||
parseSubtree(childNode, "");
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
class TextAccess;
|
||||
class TiXmlNode;
|
||||
class FilePath;
|
||||
|
||||
class ConfigManager
|
||||
{
|
||||
@@ -23,24 +24,34 @@ public:
|
||||
bool getValue(const std::string& key, int& value) const;
|
||||
bool getValue(const std::string& key, float& value) const;
|
||||
bool getValue(const std::string& key, bool& value) const;
|
||||
bool getValue(const std::string& key, FilePath& value) const;
|
||||
|
||||
template<typename T>
|
||||
T getValueOrDefault(const std::string& key, T defaultValue) const;
|
||||
|
||||
bool getValues(const std::string& key, std::vector<std::string>& values) const;
|
||||
bool getValues(const std::string& key, std::vector<std::wstring>& values) const;
|
||||
bool getValues(const std::string& key, std::vector<int>& values) const;
|
||||
bool getValues(const std::string& key, std::vector<float>& values) const;
|
||||
bool getValues(const std::string& key, std::vector<bool>& values) const;
|
||||
bool getValues(const std::string& key, std::vector<FilePath>& values) const;
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> getValuesOrDefaults(const std::string& key, std::vector<T> defaultValues) const;
|
||||
|
||||
void setValue(const std::string& key, const std::string& value);
|
||||
void setValue(const std::string& key, const std::wstring& value);
|
||||
void setValue(const std::string& key, const int value);
|
||||
void setValue(const std::string& key, const float value);
|
||||
void setValue(const std::string& key, const bool value);
|
||||
void setValue(const std::string& key, const FilePath& value);
|
||||
|
||||
void setValues(const std::string& key, const std::vector<std::string>& values);
|
||||
void setValues(const std::string& key, const std::vector<std::wstring>& values);
|
||||
void setValues(const std::string& key, const std::vector<int>& values);
|
||||
void setValues(const std::string& key, const std::vector<float>& values);
|
||||
void setValues(const std::string& key, const std::vector<bool>& values);
|
||||
void setValues(const std::string& key, const std::vector<FilePath>& values);
|
||||
|
||||
void removeValues(const std::string& key);
|
||||
|
||||
@@ -65,4 +76,26 @@ private:
|
||||
mutable bool m_warnOnEmptyKey;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T ConfigManager::getValueOrDefault(const std::string& key, T defaultValue) const
|
||||
{
|
||||
T value;
|
||||
if (getValue(key, value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::vector<T> ConfigManager::getValuesOrDefaults(const std::string& key, std::vector<T> defaultValues) const
|
||||
{
|
||||
std::vector<T> values;
|
||||
if (getValues(key, values))
|
||||
{
|
||||
return values;
|
||||
}
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
#endif // CONFIG_MANAGER_H
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef OPTIONAL_H
|
||||
#define OPTIONAL_H
|
||||
|
||||
template <typename T>
|
||||
class Optional
|
||||
{
|
||||
public:
|
||||
Optional();
|
||||
Optional(const T& value);
|
||||
|
||||
T& get();
|
||||
const T& get() const;
|
||||
|
||||
bool isPresent() const;
|
||||
|
||||
private:
|
||||
bool m_isPresent;
|
||||
T m_value;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
Optional<T>::Optional()
|
||||
: m_isPresent(false)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Optional<T>::Optional(const T& value)
|
||||
: m_isPresent(false)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& Optional<T>::get()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& Optional<T>::get() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Optional<T>::isPresent() const
|
||||
{
|
||||
return m_isPresent;
|
||||
}
|
||||
|
||||
#endif // OPTIONAL_H
|
||||
@@ -0,0 +1,89 @@
|
||||
#include "utility/sonargraph/SonargraphProject.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "utility/sonargraph/SonargraphSoftwareSystem.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/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::getAllSourcePaths() const
|
||||
{
|
||||
return m_softwareSystem->getAllSourcePaths();
|
||||
}
|
||||
|
||||
std::set<FilePath> Project::getAllSourceFilePathsCanonical() const
|
||||
{
|
||||
return m_softwareSystem->getAllSourceFilePathsCanonical();
|
||||
}
|
||||
|
||||
std::set<FilePath> Project::getAllCxxHeaderSearchPathsCanonical() const
|
||||
{
|
||||
return m_softwareSystem->getAllCxxHeaderSearchPathsCanonical();
|
||||
}
|
||||
|
||||
std::set<FilePath> Project::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
|
||||
{
|
||||
return m_softwareSystem->filterToContainedFilePaths(filePaths);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef SONARGRAPH_PROJECT_H
|
||||
#define SONARGRAPH_PROJECT_H
|
||||
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
// 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;
|
||||
enum LanguageType;
|
||||
|
||||
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> getAllSourcePaths() const;
|
||||
std::set<FilePath> getAllSourceFilePathsCanonical() const;
|
||||
std::set<FilePath> getAllCxxHeaderSearchPathsCanonical() const;
|
||||
std::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) 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
|
||||
@@ -0,0 +1,210 @@
|
||||
#include "utility/sonargraph/SonargraphSoftwareSystem.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "data/indexer/IndexerCommand.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/utilityXml.h"
|
||||
#include "utility/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::set<FilePath> SoftwareSystem::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
|
||||
{
|
||||
std::set<FilePath> containedFilePaths;
|
||||
for (std::shared_ptr<XsdAbstractModule> module : m_modules)
|
||||
{
|
||||
utility::append(containedFilePaths, module->filterToContainedFilePaths(filePaths));
|
||||
}
|
||||
return containedFilePaths;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#ifndef SONARGRAPH_SOFTWARE_SYSTEM_H
|
||||
#define SONARGRAPH_SOFTWARE_SYSTEM_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePathFilter.h"
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractModule.h"
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractSystemExtension.h"
|
||||
|
||||
class ApplicationSettings;
|
||||
class IndexerCommand;
|
||||
class SourceGroupSettings;
|
||||
class TiXmlElement;
|
||||
enum LanguageType;
|
||||
|
||||
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;
|
||||
std::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) 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
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "utility/sonargraph/SonargraphSourceRootPath.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "data/indexer/IndexerCommandJava.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractModule.h"
|
||||
#include "utility/sonargraph/SonargraphXsdRootPathWithFiles.h"
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef SONARGRAPH_SOURCE_ROOT_PATH_H
|
||||
#define SONARGRAPH_SOURCE_ROOT_PATH_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/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
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractModule.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/sonargraph/SonargraphXsdCmakeJsonModule.h"
|
||||
#include "utility/sonargraph/SonargraphXsdJavaModule.h"
|
||||
#include "utility/sonargraph/SonargraphXsdRootPath.h"
|
||||
#include "utility/sonargraph/SonargraphSoftwareSystem.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/utilityXml.h"
|
||||
#include "utility/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<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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#ifndef SONARGRAPH_XSD_ABSTRACT_MODULE_H
|
||||
#define SONARGRAPH_XSD_ABSTRACT_MODULE_H
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/FilePathFilter.h"
|
||||
|
||||
class ApplicationSettings;
|
||||
class IndexerCommand;
|
||||
class SourceGroupSettings;
|
||||
class TiXmlElement;
|
||||
enum LanguageType;
|
||||
|
||||
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;
|
||||
virtual std::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) 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
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractSystemExtension.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/sonargraph/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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#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
|
||||
@@ -0,0 +1,380 @@
|
||||
#include "utility/sonargraph/SonargraphXsdCmakeJsonModule.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "data/indexer/IndexerCommandCxxEmpty.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "settings/LanguageType.h"
|
||||
#include "settings/SourceGroupSettings.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/sonargraph/SonargraphSoftwareSystem.h"
|
||||
#include "utility/sonargraph/SonargraphXsdCppSystemSettings.h"
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/utilityXml.h"
|
||||
#include "utility/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::set<FilePath> XsdCmakeJsonModule::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
|
||||
{
|
||||
const std::set<FilePath> indexedPaths = getAllSourcePaths();
|
||||
const std::vector<FilePathFilter> excludeFilters = getDerivedExcludeFilters();
|
||||
const std::vector<FilePathFilter> includeFilters = getDerivedIncludeFilters();
|
||||
|
||||
std::set<FilePath> containedFilePaths;
|
||||
for (const FilePath& filePath : filePaths)
|
||||
{
|
||||
bool isInIndexedPaths = false;
|
||||
for (const FilePath& indexedPath : indexedPaths)
|
||||
{
|
||||
if (indexedPath == filePath || indexedPath.contains(filePath))
|
||||
{
|
||||
isInIndexedPaths = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isInIndexedPaths)
|
||||
{
|
||||
for (const FilePathFilter& excludeFilter : excludeFilters)
|
||||
{
|
||||
if (excludeFilter.isMatching(filePath))
|
||||
{
|
||||
isInIndexedPaths = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isInIndexedPaths)
|
||||
{
|
||||
for (const FilePathFilter& includeFilter : includeFilters)
|
||||
{
|
||||
if (includeFilter.isMatching(filePath))
|
||||
{
|
||||
isInIndexedPaths = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isInIndexedPaths)
|
||||
{
|
||||
containedFilePaths.insert(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
return containedFilePaths;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
for (std::shared_ptr<XsdRootPath> rootPath : getRootPaths())
|
||||
{
|
||||
if (std::shared_ptr<XsdRootPathWithFiles> rootPathWithFiles = std::dynamic_pointer_cast<XsdRootPathWithFiles>(rootPath))
|
||||
{
|
||||
utility::append(indexerCommands, getIndexerCommandsForRootPath(rootPathWithFiles, sourceGroupSettings, appSettings));
|
||||
}
|
||||
}
|
||||
|
||||
for (std::shared_ptr<XsdRootPathWithFiles> rootPath : m_rootPathWithFiles)
|
||||
{
|
||||
utility::append(indexerCommands, getIndexerCommandsForRootPath(rootPath, sourceGroupSettings, appSettings));
|
||||
}
|
||||
|
||||
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,
|
||||
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
|
||||
std::shared_ptr<const ApplicationSettings> appSettings) 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<FilePath> indexedPaths = softwareSystem->getAllSourcePaths();
|
||||
|
||||
const std::set<FilePathFilter> excludeFilters = utility::toSet(getDerivedExcludeFilters());
|
||||
const std::set<FilePathFilter> includeFilters = utility::toSet(getDerivedIncludeFilters());
|
||||
const std::string languageStandard = sourceGroupSettings->getStandard();
|
||||
const std::vector<FilePath> systemHeaderSearchPaths = utility::concat(
|
||||
(appSettings ? appSettings->getHeaderSearchPathsExpanded() : std::vector<FilePath>()),
|
||||
utility::toVector(indexedPaths)
|
||||
);
|
||||
const std::vector<FilePath> frameworkSearchPaths = (appSettings ? appSettings->getFrameworkSearchPathsExpanded() : std::vector<FilePath>());
|
||||
|
||||
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 systemExtension->getCompilerOptionsForId(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::vector<std::wstring>();
|
||||
});
|
||||
|
||||
for (const XsdRootPathWithFiles::SourceFile& sourceFile : getIncludedSourceFilesForRootPath(
|
||||
rootPath, baseDir, excludeFilters, includeFilters)
|
||||
)
|
||||
{
|
||||
indexerCommands.push_back(std::make_shared<IndexerCommandCxxEmpty>(
|
||||
sourceFile.getFilePath(baseDir).makeCanonical(),
|
||||
indexedPaths,
|
||||
excludeFilters,
|
||||
includeFilters,
|
||||
softwareSystem->getBaseDirectory(),
|
||||
systemHeaderSearchPaths,
|
||||
frameworkSearchPaths,
|
||||
compilerOptionCache.getValue(sourceFile.compilerOptionSetId),
|
||||
languageStandard
|
||||
));
|
||||
}
|
||||
}
|
||||
return indexerCommands;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef SONARGRAPH_XSD_CMAKE_JSON_MODULE_H
|
||||
#define SONARGRAPH_XSD_CMAKE_JSON_MODULE_H
|
||||
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractModule.h"
|
||||
#include "utility/sonargraph/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::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) 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,
|
||||
std::shared_ptr<const SourceGroupSettings> sourceGroupSettings,
|
||||
std::shared_ptr<const ApplicationSettings> appSettings) const;
|
||||
|
||||
std::vector<std::shared_ptr<XsdRootPathWithFiles>> m_rootPathWithFiles;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SONARGRAPH_XSD_CMAKE_JSON_MODULE_H
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "utility/sonargraph/SonargraphXsdCppSystemSettings.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef SONARGRAPH_XSD_CPP_SYSTEM_SETTINGS_H
|
||||
#define SONARGRAPH_XSD_CPP_SYSTEM_SETTINGS_H
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractSystemExtension.h"
|
||||
#include "utility/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
|
||||
@@ -0,0 +1,203 @@
|
||||
#include "utility/sonargraph/SonargraphXsdJavaModule.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "data/indexer/IndexerCommandJava.h"
|
||||
#include "settings/LanguageType.h"
|
||||
#include "settings/SourceGroupSettingsJavaSonargraph.h"
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/sonargraph/SonargraphSoftwareSystem.h"
|
||||
#include "utility/sonargraph/SonargraphSourceRootPath.h"
|
||||
#include "utility/sonargraph/SonargraphXsdRootPath.h"
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
#include "utility/utility.h"
|
||||
#include "utility/utilityFile.h"
|
||||
#include "utility/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::set<FilePath> XsdJavaModule::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
|
||||
{
|
||||
const std::set<FilePath> indexedPaths = getAllSourcePaths();
|
||||
const std::vector<FilePathFilter> excludeFilters = getDerivedExcludeFilters();
|
||||
const std::vector<FilePathFilter> includeFilters = getDerivedIncludeFilters();
|
||||
|
||||
std::set<FilePath> containedFilePaths;
|
||||
for (const FilePath& filePath : filePaths)
|
||||
{
|
||||
bool isInIndexedPaths = false;
|
||||
for (const FilePath& indexedPath : indexedPaths)
|
||||
{
|
||||
if (indexedPath == filePath || indexedPath.contains(filePath))
|
||||
{
|
||||
isInIndexedPaths = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isInIndexedPaths)
|
||||
{
|
||||
for (const FilePathFilter& excludeFilter : excludeFilters)
|
||||
{
|
||||
if (excludeFilter.isMatching(filePath))
|
||||
{
|
||||
isInIndexedPaths = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isInIndexedPaths)
|
||||
{
|
||||
for (const FilePathFilter& includeFilter : includeFilters)
|
||||
{
|
||||
if (includeFilter.isMatching(filePath))
|
||||
{
|
||||
isInIndexedPaths = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isInIndexedPaths)
|
||||
{
|
||||
containedFilePaths.insert(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
return containedFilePaths;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
{
|
||||
const std::string languageStandard = sourceGroupSettings->getStandard();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef SONARGRAPH_XSD_JAVA_MODULE_H
|
||||
#define SONARGRAPH_XSD_JAVA_MODULE_H
|
||||
|
||||
#include "utility/sonargraph/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::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) 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
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "utility/sonargraph/SonargraphXsdRootPath.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "data/indexer/IndexerCommandJava.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/sonargraph/SonargraphXsdAbstractModule.h"
|
||||
#include "utility/sonargraph/SonargraphXsdRootPathWithFiles.h"
|
||||
#include "utility/sonargraph/SonargraphXsdSourceRootPath.h"
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef SONARGRAPH_XSD_ROOT_PATH_H
|
||||
#define SONARGRAPH_XSD_ROOT_PATH_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/file/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
|
||||
@@ -0,0 +1,112 @@
|
||||
#include "utility/sonargraph/SonargraphXsdRootPathWithFiles.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef SONARGRAPH_XSD_ROOT_PATH_WITH_FILES_H
|
||||
#define SONARGRAPH_XSD_ROOT_PATH_WITH_FILES_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "utility/sonargraph/SonargraphXsdRootPath.h"
|
||||
#include "utility/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
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "utility/sonargraph/SonargraphXsdSourceRootPath.h"
|
||||
|
||||
#include "tinyxml/tinyxml.h"
|
||||
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utilityString.h"
|
||||
#include "utility/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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef SONARGRAPH_XSD_SOURCE_ROOT_PATH_H
|
||||
#define SONARGRAPH_XSD_SOURCE_ROOT_PATH_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "utility/sonargraph/SonargraphXsdRootPath.h"
|
||||
#include "utility/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
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "utility/sonargraph/utilitySonargraph.h"
|
||||
|
||||
#include "tinyxml/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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#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
|
||||
@@ -1,28 +1,28 @@
|
||||
#include "utility/utilityFile.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "utility/utility.h"
|
||||
|
||||
std::vector<FilePath> utility::getTopLevelPaths(const std::vector<FilePath>& paths)
|
||||
{
|
||||
return utility::getTopLevelPaths(utility::toSet(paths));
|
||||
}
|
||||
|
||||
std::vector<FilePath> utility::getTopLevelPaths(const std::set<FilePath>& paths)
|
||||
{
|
||||
// this works because the set contains the paths already in alphabetical order
|
||||
std::vector<FilePath> topLevelPaths;
|
||||
|
||||
FilePath lastPath;
|
||||
for (const FilePath& path : paths)
|
||||
{
|
||||
bool addPath = true;
|
||||
for (size_t i = 0; i < topLevelPaths.size(); i++)
|
||||
{
|
||||
if (topLevelPaths[i].contains(path))
|
||||
{
|
||||
addPath = false;
|
||||
break;
|
||||
}
|
||||
else if (path.contains(topLevelPaths[i]))
|
||||
{
|
||||
topLevelPaths.erase(topLevelPaths.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (addPath)
|
||||
if (lastPath.empty() || !lastPath.contains(path)) // don't add subdirectories of already added paths
|
||||
{
|
||||
lastPath = path;
|
||||
topLevelPaths.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
return topLevelPaths;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
#define UTILITY_FILE_H
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
class FilePath;
|
||||
|
||||
namespace utility
|
||||
{
|
||||
std::vector<FilePath> getTopLevelPaths(const std::vector<FilePath>& paths);
|
||||
std::vector<FilePath> getTopLevelPaths(const std::set<FilePath>& paths);
|
||||
}
|
||||
|
||||
#endif // UTILITY_FILE_H
|
||||
|
||||
@@ -6,6 +6,42 @@
|
||||
|
||||
namespace utility
|
||||
{
|
||||
bool xmlElementHasAttribute(const TiXmlElement* element, const std::string& attributeName)
|
||||
{
|
||||
return (element->Attribute(attributeName.c_str()) != nullptr);
|
||||
}
|
||||
|
||||
std::vector<const TiXmlElement*> getXmlChildElementsWithName(const TiXmlElement* parentElement, const std::string& elementName)
|
||||
{
|
||||
std::vector<const TiXmlElement*> elements;
|
||||
|
||||
const TiXmlElement* child = parentElement->FirstChildElement(elementName.c_str());
|
||||
|
||||
for (child; child; child = child->NextSiblingElement(elementName.c_str()))
|
||||
{
|
||||
elements.push_back(child);
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
std::vector<const TiXmlElement*> getXmlChildElementsWithAttribute(const TiXmlElement* parentElement, const std::string& attributeName, const std::string& attributeValue)
|
||||
{
|
||||
std::vector<const TiXmlElement*> elements;
|
||||
|
||||
const TiXmlElement* child = parentElement->FirstChildElement();
|
||||
|
||||
for (child; child; child = child->NextSiblingElement())
|
||||
{
|
||||
const char* value = child->Attribute(attributeName.c_str());
|
||||
if (value != nullptr && value == attributeValue)
|
||||
{
|
||||
elements.push_back(child);
|
||||
}
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
std::vector<std::string> getValuesOfAllXmlElementsOnPath(std::shared_ptr<TextAccess> textAccess, const std::vector<std::string>& tags)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,11 @@ class TiXmlElement;
|
||||
|
||||
namespace utility
|
||||
{
|
||||
bool xmlElementHasAttribute(const TiXmlElement* element, const std::string& attributeName);
|
||||
|
||||
std::vector<const TiXmlElement*> getXmlChildElementsWithName(const TiXmlElement* parentElement, const std::string& elementName);
|
||||
std::vector<const TiXmlElement*> getXmlChildElementsWithAttribute(const TiXmlElement* parentElement, const std::string& attributeName, const std::string& attributeValue);
|
||||
|
||||
std::vector<std::string> getValuesOfAllXmlElementsOnPath(std::shared_ptr<TextAccess> textAccess, const std::vector<std::string>& tags);
|
||||
std::vector<std::string> getValuesOfAllXmlTagsByName(std::shared_ptr<TextAccess> textAccess, const std::string& tag);
|
||||
std::vector<TiXmlElement*> getAllXmlTagsByName(TiXmlElement* root, const std::string& tag);
|
||||
|
||||
Reference in New Issue
Block a user