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:
mlangkabel
2018-05-18 16:07:57 +02:00
parent e55ae5ba31
commit 7b735cfd17
164 changed files with 24770 additions and 1684 deletions
@@ -3,9 +3,11 @@
#include "project/SourceGroupJavaEmpty.h"
#include "project/SourceGroupJavaGradle.h"
#include "project/SourceGroupJavaMaven.h"
#include "project/SourceGroupJavaSonargraph.h"
#include "settings/SourceGroupSettingsJavaEmpty.h"
#include "settings/SourceGroupSettingsJavaGradle.h"
#include "settings/SourceGroupSettingsJavaMaven.h"
#include "settings/SourceGroupSettingsJavaSonargraph.h"
SourceGroupFactoryModuleJava::~SourceGroupFactoryModuleJava()
{
@@ -18,6 +20,7 @@ bool SourceGroupFactoryModuleJava::supports(SourceGroupType type) const
case SOURCE_GROUP_JAVA_EMPTY:
case SOURCE_GROUP_JAVA_GRADLE:
case SOURCE_GROUP_JAVA_MAVEN:
case SOURCE_GROUP_JAVA_SONARGRAPH:
return true;
default:
break;
@@ -40,5 +43,9 @@ std::shared_ptr<SourceGroup> SourceGroupFactoryModuleJava::createSourceGroup(std
{
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJavaMaven(javaSettings));
}
else if (std::shared_ptr<SourceGroupSettingsJavaSonargraph> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaSonargraph>(settings))
{
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJavaSonargraph(javaSettings));
}
return sourceGroup;
}
+25 -138
View File
@@ -1,34 +1,33 @@
#include "project/SourceGroupJava.h"
#include "component/view/DialogView.h"
#include "data/indexer/IndexerCommandJava.h"
#include "data/parser/java/JavaEnvironmentFactory.h"
#include "data/parser/java/JavaEnvironment.h"
#include "data/parser/java/JavaParser.h"
#include "settings/ApplicationSettings.h"
#include "settings/SourceGroupSettingsJava.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
#include "utility/ScopedFunctor.h"
#include "utility/utilityJava.h"
#include "utility/utilityString.h"
#include "Application.h"
#include "utility/file/FileManager.h"
#include "utility/logging/logging.h"
SourceGroupJava::SourceGroupJava()
std::set<FilePath> SourceGroupJava::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
{
}
SourceGroupJava::~SourceGroupJava()
{
}
bool SourceGroupJava::prepareIndexing()
{
if (!prepareJavaEnvironment())
std::set<FilePath> containedFilePaths;
const std::set<FilePath> allSourceFilePaths = getAllSourceFilePaths();
for (const FilePath& filePath : filePaths)
{
return false;
if (allSourceFilePaths.find(filePath) != allSourceFilePaths.end())
{
containedFilePaths.insert(filePath);
}
}
return true;
return containedFilePaths;
}
std::set<FilePath> SourceGroupJava::getAllSourceFilePaths() const
{
FileManager fileManager;
fileManager.update(
getAllSourcePaths(),
getSourceGroupSettingsJava()->getExcludeFiltersExpandedAndAbsolute(),
getSourceGroupSettingsJava()->getSourceExtensions()
);
return fileManager.getAllSourceFilePaths();
}
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands(const std::set<FilePath>& filesToIndex) const
@@ -36,16 +35,15 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
const std::string languageStandard = getSourceGroupSettingsJava()->getStandard();
std::vector<FilePath> classPath = getClassPath();
std::set<FilePath> indexedPaths = getIndexedPaths();
std::set<FilePathFilter> excludeFilters = getExcludeFilters();
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
for (const FilePath& sourcePath: getAllSourceFilePaths())
{
if (filesToIndex.find(sourcePath) != filesToIndex.end())
{
indexerCommands.push_back(
std::make_shared<IndexerCommandJava>(sourcePath, indexedPaths, excludeFilters, languageStandard, classPath));
indexerCommands.push_back(std::make_shared<IndexerCommandJava>(
sourcePath, languageStandard, classPath
));
}
}
@@ -62,36 +60,6 @@ std::shared_ptr<const SourceGroupSettings> SourceGroupJava::getSourceGroupSettin
return getSourceGroupSettingsJava();
}
bool SourceGroupJava::prepareJavaEnvironment()
{
const std::wstring errorString = utility::decodeFromUtf8(utility::prepareJavaEnvironment());
if (errorString.size() > 0)
{
LOG_ERROR(errorString);
MessageStatus(errorString, true, false).dispatch();
}
if (!JavaEnvironmentFactory::getInstance())
{
std::wstring dialogMessage =
L"Sourcetrail was unable to locate Java on this machine.\n"
"Please make sure to provide the correct Java Path in the preferences.";
if (!errorString.empty())
{
dialogMessage += L"\n\nError: " + errorString;
}
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
return false;
}
return true;
}
std::vector<FilePath> SourceGroupJava::getClassPath() const
{
LOG_INFO("Retrieving classpath for indexer commands");
@@ -99,84 +67,3 @@ std::vector<FilePath> SourceGroupJava::getClassPath() const
LOG_INFO("Found " + std::to_string(classPath.size()) + " paths for classpath.");
return classPath;
}
std::vector<FilePath> SourceGroupJava::doGetClassPath() const
{
std::vector<FilePath> classPath;
for (const FilePath& classpath : getSourceGroupSettingsJava()->getClasspathExpandedAndAbsolute())
{
if (classpath.exists())
{
LOG_INFO(L"Adding path to classpath: " + classpath.wstr());
classPath.push_back(classpath);
}
}
if (getSourceGroupSettingsJava()->getUseJreSystemLibrary())
{
for (const FilePath& systemLibraryPath : ApplicationSettings::getInstance()->getJreSystemLibraryPathsExpanded())
{
LOG_INFO(L"Adding JRE system library path to classpath: " + systemLibraryPath.wstr());
classPath.push_back(systemLibraryPath);
}
}
for (const FilePath& rootDirectory : fetchRootDirectories())
{
if (rootDirectory.exists())
{
LOG_INFO(L"Adding root directory to classpath: " + rootDirectory.wstr());
classPath.push_back(rootDirectory);
}
}
return classPath;
}
std::set<FilePath> SourceGroupJava::fetchRootDirectories() const
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Gathering Root\nDirectories");
ScopedFunctor dialogHider([&dialogView](){
dialogView->hideUnknownProgressDialog();
});
std::set<FilePath> rootDirectories;
std::shared_ptr<JavaEnvironment> javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment();
for (const FilePath& filePath: m_allSourceFilePaths)
{
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
std::string packageName = "";
javaEnvironment->callStaticStringMethod("com/sourcetrail/JavaIndexer", "getPackageName", packageName, textAccess->getText());
if (packageName.empty())
{
continue;
}
FilePath rootPath = filePath.getParentDirectory();
bool success = true;
const std::vector<std::string> packageNameParts = utility::splitToVector(packageName, ".");
for (std::vector<std::string>::const_reverse_iterator it = packageNameParts.rbegin(); it != packageNameParts.rend(); it++)
{
if (rootPath.fileName() != utility::decodeFromUtf8(*it))
{
success = false;
break;
}
rootPath = rootPath.getParentDirectory();
}
if (success)
{
rootDirectories.insert(rootPath);
}
}
return rootDirectories;
}
+7 -13
View File
@@ -12,25 +12,19 @@ class SourceGroupSettingsJava;
class SourceGroupJava: public SourceGroup
{
public:
SourceGroupJava();
virtual ~SourceGroupJava();
virtual bool prepareIndexing() override;
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& filesToIndex) const override;
protected:
virtual std::vector<FilePath> doGetClassPath() const;
std::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) const override;
std::set<FilePath> getAllSourceFilePaths() const override;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& filesToIndex) const override;
private:
virtual std::vector<FilePath> getAllSourcePaths() const = 0;
virtual std::vector<FilePath> doGetClassPath() const = 0;
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() = 0;
virtual std::shared_ptr<const SourceGroupSettingsJava> getSourceGroupSettingsJava() const = 0;
virtual std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;
virtual std::shared_ptr<const SourceGroupSettings> getSourceGroupSettings() const override;
bool prepareJavaEnvironment();
std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;
std::shared_ptr<const SourceGroupSettings> getSourceGroupSettings() const override;
std::vector<FilePath> getClassPath() const;
std::set<FilePath> fetchRootDirectories() const;
};
#endif // SOURCE_GROUP_JAVA_H
+14 -8
View File
@@ -1,19 +1,30 @@
#include "project/SourceGroupJavaEmpty.h"
#include "settings/SourceGroupSettingsJavaEmpty.h"
#include "utility/utilityJava.h"
SourceGroupJavaEmpty::SourceGroupJavaEmpty(std::shared_ptr<SourceGroupSettingsJavaEmpty> settings)
: m_settings(settings)
{
}
SourceGroupJavaEmpty::~SourceGroupJavaEmpty()
bool SourceGroupJavaEmpty::prepareIndexing()
{
if (!utility::prepareJavaEnvironmentAndDisplayOccurringErrors())
{
return false;
}
return true;
}
SourceGroupType SourceGroupJavaEmpty::getType() const
std::vector<FilePath> SourceGroupJavaEmpty::getAllSourcePaths() const
{
return SOURCE_GROUP_JAVA_EMPTY;
return m_settings->getSourcePathsExpandedAndAbsolute();
}
std::vector<FilePath> SourceGroupJavaEmpty::doGetClassPath() const
{
return utility::getClassPath(getSourceGroupSettingsJava(), getAllSourceFilePaths());
}
std::shared_ptr<SourceGroupSettingsJava> SourceGroupJavaEmpty::getSourceGroupSettingsJava()
@@ -25,8 +36,3 @@ std::shared_ptr<const SourceGroupSettingsJava> SourceGroupJavaEmpty::getSourceGr
{
return m_settings;
}
std::vector<FilePath> SourceGroupJavaEmpty::getAllSourcePaths() const
{
return m_settings->getSourcePathsExpandedAndAbsolute();
}
+5 -6
View File
@@ -12,14 +12,13 @@ class SourceGroupJavaEmpty: public SourceGroupJava
{
public:
SourceGroupJavaEmpty(std::shared_ptr<SourceGroupSettingsJavaEmpty> settings);
virtual ~SourceGroupJavaEmpty();
virtual SourceGroupType getType() const override;
bool prepareIndexing() override;
private:
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() override;
virtual std::shared_ptr<const SourceGroupSettingsJava> getSourceGroupSettingsJava() const override;
virtual std::vector<FilePath> getAllSourcePaths() const override;
std::vector<FilePath> getAllSourcePaths() const override;
std::vector<FilePath> doGetClassPath() const override;
std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() override;
std::shared_ptr<const SourceGroupSettingsJava> getSourceGroupSettingsJava() const override;
std::shared_ptr<SourceGroupSettingsJavaEmpty> m_settings;
};
+20 -29
View File
@@ -1,12 +1,12 @@
#include "project/SourceGroupJavaGradle.h"
#include "component/view/DialogView.h"
#include "settings/ApplicationSettings.h"
#include "settings/SourceGroupSettingsJavaGradle.h"
#include "utility/file/FileSystem.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/ScopedFunctor.h"
#include "utility/utility.h"
#include "utility/utilityGradle.h"
#include "utility/utilityJava.h"
#include "Application.h"
SourceGroupJavaGradle::SourceGroupJavaGradle(std::shared_ptr<SourceGroupSettingsJavaGradle> settings)
@@ -14,18 +14,9 @@ SourceGroupJavaGradle::SourceGroupJavaGradle(std::shared_ptr<SourceGroupSettings
{
}
SourceGroupJavaGradle::~SourceGroupJavaGradle()
{
}
SourceGroupType SourceGroupJavaGradle::getType() const
{
return SOURCE_GROUP_JAVA_GRADLE;
}
bool SourceGroupJavaGradle::prepareIndexing()
{
if (!SourceGroupJava::prepareIndexing())
if (!utility::prepareJavaEnvironmentAndDisplayOccurringErrors())
{
return false;
}
@@ -38,9 +29,25 @@ bool SourceGroupJavaGradle::prepareIndexing()
return true;
}
std::vector<FilePath> SourceGroupJavaGradle::getAllSourcePaths() const
{
std::vector<FilePath> sourcePaths;
if (m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists())
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Gradle\nFetching Source Directories");
const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::gradleGetAllSourceDirectories(projectRootPath, m_settings->getShouldIndexGradleTests());
dialogView->hideUnknownProgressDialog();
}
return sourcePaths;
}
std::vector<FilePath> SourceGroupJavaGradle::doGetClassPath() const
{
std::vector<FilePath> classPath = SourceGroupJava::doGetClassPath();
std::vector<FilePath> classPath = utility::getClassPath(getSourceGroupSettingsJava(), getAllSourceFilePaths());
if (m_settings->getGradleDependenciesDirectoryExpandedAndAbsolute().exists())
{
@@ -70,22 +77,6 @@ std::shared_ptr<const SourceGroupSettingsJava> SourceGroupJavaGradle::getSourceG
return m_settings;
}
std::vector<FilePath> SourceGroupJavaGradle::getAllSourcePaths() const
{
std::vector<FilePath> sourcePaths;
if (m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists())
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Gradle\nFetching Source Directories");
const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::gradleGetAllSourceDirectories(projectRootPath, m_settings->getShouldIndexGradleTests());
dialogView->hideUnknownProgressDialog();
}
return sourcePaths;
}
bool SourceGroupJavaGradle::prepareGradleData()
{
if (m_settings && m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists())
+7 -10
View File
@@ -4,24 +4,21 @@
#include <memory>
#include <vector>
#include "settings/SourceGroupSettingsJavaGradle.h"
#include "project/SourceGroupJava.h"
class SourceGroupSettingsJavaGradle;
class SourceGroupJavaGradle : public SourceGroupJava
{
public:
SourceGroupJavaGradle(std::shared_ptr<SourceGroupSettingsJavaGradle> settings);
virtual ~SourceGroupJavaGradle();
virtual SourceGroupType getType() const override;
virtual bool prepareIndexing() override;
protected:
virtual std::vector<FilePath> doGetClassPath() const override;
bool prepareIndexing() override;
private:
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() override;
virtual std::shared_ptr<const SourceGroupSettingsJava> getSourceGroupSettingsJava() const override;
virtual std::vector<FilePath> getAllSourcePaths() const override;
std::vector<FilePath> getAllSourcePaths() const override;
std::vector<FilePath> doGetClassPath() const override;
std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() override;
std::shared_ptr<const SourceGroupSettingsJava> getSourceGroupSettingsJava() const override;
bool prepareGradleData();
std::shared_ptr<SourceGroupSettingsJavaGradle> m_settings;
+21 -28
View File
@@ -2,10 +2,12 @@
#include "component/view/DialogView.h"
#include "settings/ApplicationSettings.h"
#include "settings/SourceGroupSettingsJavaMaven.h"
#include "utility/file/FileSystem.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/ScopedFunctor.h"
#include "utility/utility.h"
#include "utility/utilityJava.h"
#include "utility/utilityMaven.h"
#include "Application.h"
@@ -14,18 +16,9 @@ SourceGroupJavaMaven::SourceGroupJavaMaven(std::shared_ptr<SourceGroupSettingsJa
{
}
SourceGroupJavaMaven::~SourceGroupJavaMaven()
{
}
SourceGroupType SourceGroupJavaMaven::getType() const
{
return SOURCE_GROUP_JAVA_MAVEN;
}
bool SourceGroupJavaMaven::prepareIndexing()
{
if (!SourceGroupJava::prepareIndexing())
if (!utility::prepareJavaEnvironmentAndDisplayOccurringErrors())
{
return false;
}
@@ -38,9 +31,26 @@ bool SourceGroupJavaMaven::prepareIndexing()
return true;
}
std::vector<FilePath> SourceGroupJavaMaven::getAllSourcePaths() const
{
std::vector<FilePath> sourcePaths;
if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nFetching Source Directories");
const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath());
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(mavenPath, projectRootPath, m_settings->getShouldIndexMavenTests());
dialogView->hideUnknownProgressDialog();
}
return sourcePaths;
}
std::vector<FilePath> SourceGroupJavaMaven::doGetClassPath() const
{
std::vector<FilePath> classPath = SourceGroupJava::doGetClassPath();
std::vector<FilePath> classPath = utility::getClassPath(getSourceGroupSettingsJava(), getAllSourceFilePaths());
if (m_settings && m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute().exists())
{
@@ -70,23 +80,6 @@ std::shared_ptr<const SourceGroupSettingsJava> SourceGroupJavaMaven::getSourceGr
return m_settings;
}
std::vector<FilePath> SourceGroupJavaMaven::getAllSourcePaths() const
{
std::vector<FilePath> sourcePaths;
if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nFetching Source Directories");
const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath());
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(mavenPath, projectRootPath, m_settings->getShouldIndexMavenTests());
dialogView->hideUnknownProgressDialog();
}
return sourcePaths;
}
bool SourceGroupJavaMaven::prepareMavenData()
{
if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
+7 -10
View File
@@ -4,24 +4,21 @@
#include <memory>
#include <vector>
#include "settings/SourceGroupSettingsJavaMaven.h"
#include "project/SourceGroupJava.h"
class SourceGroupSettingsJavaMaven;
class SourceGroupJavaMaven: public SourceGroupJava
{
public:
SourceGroupJavaMaven(std::shared_ptr<SourceGroupSettingsJavaMaven> settings);
virtual ~SourceGroupJavaMaven();
virtual SourceGroupType getType() const override;
virtual bool prepareIndexing() override;
protected:
virtual std::vector<FilePath> doGetClassPath() const override;
bool prepareIndexing() override;
private:
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() override;
virtual std::shared_ptr<const SourceGroupSettingsJava> getSourceGroupSettingsJava() const override;
virtual std::vector<FilePath> getAllSourcePaths() const override;
std::vector<FilePath> getAllSourcePaths() const override;
std::vector<FilePath> doGetClassPath() const override;
std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() override;
std::shared_ptr<const SourceGroupSettingsJava> getSourceGroupSettingsJava() const override;
bool prepareMavenData();
std::shared_ptr<SourceGroupSettingsJavaMaven> m_settings;
@@ -0,0 +1,104 @@
#include "project/SourceGroupJavaSonargraph.h"
#include "data/indexer/IndexerCommandJava.h"
#include "settings/ApplicationSettings.h"
#include "settings/SourceGroupSettingsJavaSonargraph.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/sonargraph/SonargraphProject.h"
#include "utility/utilityJava.h"
#include "Application.h"
SourceGroupJavaSonargraph::SourceGroupJavaSonargraph(std::shared_ptr<SourceGroupSettingsJavaSonargraph> settings)
: m_settings(settings)
{
}
bool SourceGroupJavaSonargraph::prepareIndexing()
{
if (!utility::prepareJavaEnvironmentAndDisplayOccurringErrors())
{
return false;
}
FilePath sonargraphProjectPath = m_settings->getSonargraphProjectPathExpandedAndAbsolute();
if (!sonargraphProjectPath.empty() && !sonargraphProjectPath.exists())
{
MessageStatus(L"Can't refresh project. The referenced Sonargraph project does not exist anymore.").dispatch();
if (std::shared_ptr<Application> application = Application::getInstance())
{
if (application->hasGUI())
{
application->handleDialog(
L"Can't refresh project. The referenced Sonargraph project does not exist anymore: " + sonargraphProjectPath.wstr(),
{ L"Ok" }
);
}
}
return false;
}
return true;
}
std::set<FilePath> SourceGroupJavaSonargraph::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
{
if (std::shared_ptr<Sonargraph::Project> project = Sonargraph::Project::load(
m_settings->getSonargraphProjectPathExpandedAndAbsolute(), getLanguage()
))
{
return project->filterToContainedFilePaths(filePaths);
}
else
{
LOG_ERROR("Unable to load Sonargraph project to check the containment of file paths.");
}
return std::set<FilePath>();
}
std::set<FilePath> SourceGroupJavaSonargraph::getAllSourceFilePaths() const
{
if (std::shared_ptr<Sonargraph::Project> project = Sonargraph::Project::load(
m_settings->getSonargraphProjectPathExpandedAndAbsolute(), getLanguage()
))
{
// DONT CALL getIndexerCommands here because this would create an endless recursion due to hack...
return project->getAllSourceFilePathsCanonical();
}
return std::set<FilePath>();
}
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJavaSonargraph::getIndexerCommands(const std::set<FilePath>& filesToIndex) const
{
std::vector<std::shared_ptr<IndexerCommand>> indexerCommands;
if (std::shared_ptr<Sonargraph::Project> project = Sonargraph::Project::load(
m_settings->getSonargraphProjectPathExpandedAndAbsolute(), getLanguage()
))
{
indexerCommands = project->getIndexerCommands(m_settings, ApplicationSettings::getInstance());
}
if (!indexerCommands.empty())
{
const std::vector<FilePath> classPath = utility::getClassPath(m_settings, getAllSourceFilePaths()); // TODO: remove this hack once sourcegroup and sourcegroupsettings are merged
for (std::shared_ptr<IndexerCommand> indexerCommand : indexerCommands)
{
if (std::shared_ptr<IndexerCommandJava> javaIndexerCommand = std::dynamic_pointer_cast<IndexerCommandJava>(indexerCommand))
{
javaIndexerCommand->setClassPath(classPath);
}
}
}
return indexerCommands;
}
std::shared_ptr<SourceGroupSettings> SourceGroupJavaSonargraph::getSourceGroupSettings()
{
return m_settings;
}
std::shared_ptr<const SourceGroupSettings> SourceGroupJavaSonargraph::getSourceGroupSettings() const
{
return m_settings;
}
@@ -0,0 +1,29 @@
#ifndef SOURCE_GROUP_JAVA_SONARGRAPH_H
#define SOURCE_GROUP_JAVA_SONARGRAPH_H
#include <memory>
#include <set>
#include "project/SourceGroup.h"
class SourceGroupSettingsJavaSonargraph;
class SourceGroupJavaSonargraph
: public SourceGroup
{
public:
SourceGroupJavaSonargraph(std::shared_ptr<SourceGroupSettingsJavaSonargraph> settings);
bool prepareIndexing() override;
std::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) const override;
std::set<FilePath> getAllSourceFilePaths() const override;
std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(const std::set<FilePath>& filesToIndex) const override;
private:
std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;
std::shared_ptr<const SourceGroupSettings> getSourceGroupSettings() const override;
std::shared_ptr<SourceGroupSettingsJavaSonargraph> m_settings;
};
#endif // SOURCE_GROUP_JAVA_SONARGRAPH_H