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
+2
View File
@@ -24,6 +24,8 @@ add_files(
project/SourceGroupJavaGradle.h
project/SourceGroupJavaMaven.cpp
project/SourceGroupJavaMaven.h
project/SourceGroupJavaSonargraph.cpp
project/SourceGroupJavaSonargraph.h
utility/utilityJava.cpp
utility/utilityJava.h
@@ -9,21 +9,15 @@ IndexerCommandType IndexerCommandJava::getStaticIndexerCommandType()
IndexerCommandJava::IndexerCommandJava(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePathFilter>& excludeFilters,
const std::string& languageStandard,
const std::vector<FilePath>& classPath
)
: IndexerCommand(sourceFilePath, indexedPaths, excludeFilters)
: IndexerCommand(sourceFilePath)
, m_languageStandard(languageStandard)
, m_classPath(classPath)
{
}
IndexerCommandJava::~IndexerCommandJava()
{
}
IndexerCommandType IndexerCommandJava::getIndexerCommandType() const
{
return getStaticIndexerCommandType();
@@ -33,7 +27,7 @@ size_t IndexerCommandJava::getByteSize(size_t stringSize) const
{
size_t size = IndexerCommand::getByteSize(stringSize);
for (auto& i : m_classPath)
for (const FilePath& i : m_classPath)
{
size += stringSize + utility::encodeToUtf8(i.wstr()).size();
}
@@ -46,6 +40,11 @@ std::string IndexerCommandJava::getLanguageStandard() const
return m_languageStandard;
}
void IndexerCommandJava::setClassPath(std::vector<FilePath> classPath)
{
m_classPath = classPath;
}
std::vector<FilePath> IndexerCommandJava::getClassPath() const
{
return m_classPath;
@@ -6,6 +6,7 @@
#include "data/indexer/IndexerCommand.h"
class FilePath;
class FilePathFilter;
class IndexerCommandJava
: public IndexerCommand
@@ -15,17 +16,15 @@ public:
IndexerCommandJava(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePathFilter>& excludeFilters,
const std::string& languageStandard,
const std::vector<FilePath>& classPath);
virtual ~IndexerCommandJava();
virtual IndexerCommandType getIndexerCommandType() const override;
virtual size_t getByteSize(size_t stringSize) const override;
std::string getLanguageStandard() const;
void setClassPath(std::vector<FilePath> classPath);
std::vector<FilePath> getClassPath() const;
private:
@@ -0,0 +1,52 @@
#include "data/indexer/IndexerCommandJava.h"
#include "utility/utilityString.h"
IndexerCommandType IndexerCommandJava::getStaticIndexerCommandType()
{
return INDEXER_COMMAND_JAVA;
}
IndexerCommandJava::IndexerCommandJava(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePathFilter>& excludeFilters,
const std::string& languageStandard,
const std::vector<FilePath>& classPath
)
: IndexerCommand(sourceFilePath, indexedPaths, excludeFilters)
, m_languageStandard(languageStandard)
, m_classPath(classPath)
{
}
IndexerCommandJava::~IndexerCommandJava()
{
}
IndexerCommandType IndexerCommandJava::getIndexerCommandType() const
{
return getStaticIndexerCommandType();
}
size_t IndexerCommandJava::getByteSize(size_t stringSize) const
{
size_t size = IndexerCommand::getByteSize(stringSize);
for (auto& i : m_classPath)
{
size += stringSize + utility::encodeToUtf8(i.wstr()).size();
}
return size;
}
std::string IndexerCommandJava::getLanguageStandard() const
{
return m_languageStandard;
}
std::vector<FilePath> IndexerCommandJava::getClassPath() const
{
return m_classPath;
}
@@ -0,0 +1,36 @@
#ifndef INDEXER_COMMAND_JAVA_H
#define INDEXER_COMMAND_JAVA_H
#include <vector>
#include "data/indexer/IndexerCommand.h"
class FilePath;
class IndexerCommandJava
: public IndexerCommand
{
public:
static IndexerCommandType getStaticIndexerCommandType();
IndexerCommandJava(
const FilePath& sourceFilePath,
const std::set<FilePath>& indexedPaths,
const std::set<FilePathFilter>& excludeFilters,
const std::string& languageStandard,
const std::vector<FilePath>& classPath);
virtual ~IndexerCommandJava();
virtual IndexerCommandType getIndexerCommandType() const override;
virtual size_t getByteSize(size_t stringSize) const override;
std::string getLanguageStandard() const;
std::vector<FilePath> getClassPath() const;
private:
const std::string m_languageStandard;
std::vector<FilePath> m_classPath;
};
#endif // INDEXER_COMMAND_JAVA_H
+2 -5
View File
@@ -3,20 +3,17 @@
#include "data/indexer/IndexerCommandJava.h"
#include "data/parser/ParserClientImpl.h"
#include "data/parser/java/JavaParser.h"
#include "utility/file/FileRegister.h"
IndexerJava::~IndexerJava()
{
JavaParser::clearCaches();
}
std::shared_ptr<IntermediateStorage> IndexerJava::doIndex(
std::shared_ptr<IndexerCommandJava> indexerCommand,
std::shared_ptr<FileRegister> fileRegister)
std::shared_ptr<IntermediateStorage> IndexerJava::doIndex(std::shared_ptr<IndexerCommandJava> indexerCommand)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient, fileRegister);
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
parserClient->setStorage(storage);
+1 -3
View File
@@ -11,9 +11,7 @@ class IndexerJava: public Indexer<IndexerCommandJava>
public:
virtual ~IndexerJava();
virtual std::shared_ptr<IntermediateStorage> doIndex(
std::shared_ptr<IndexerCommandJava> indexerCommand,
std::shared_ptr<FileRegister> fileRegister);
virtual std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<IndexerCommandJava> indexerCommand);
};
#endif // INDEXER_JAVA_H
+1 -1
View File
@@ -30,7 +30,7 @@ void JavaParser::clearCaches()
}
}
JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
JavaParser::JavaParser(std::shared_ptr<ParserClient> client)
: Parser(client)
, m_id(s_nextParserId++)
{
+1 -2
View File
@@ -27,14 +27,13 @@ class _jstring;
typedef _jstring *jstring;
class FilePath;
class FileRegister;
class JavaParser: public Parser
{
public:
static void clearCaches();
JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
JavaParser(std::shared_ptr<ParserClient> client);
~JavaParser();
void buildIndex(std::shared_ptr<IndexerCommandJava> indexerCommand);
@@ -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
+119
View File
@@ -1,8 +1,17 @@
#include "utility/utilityGradle.h"
#include "component/view/DialogView.h"
#include "data/parser/java/JavaEnvironment.h"
#include "data/parser/java/JavaEnvironmentFactory.h"
#include "settings/SourceGroupSettingsWithClasspath.h"
#include "settings/ApplicationSettings.h"
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
#include "utility/ResourcePaths.h"
#include "utility/ScopedFunctor.h"
#include "utility/utilityString.h"
#include "Application.h"
namespace utility
{
@@ -63,4 +72,114 @@ namespace utility
return errorString;
}
bool prepareJavaEnvironmentAndDisplayOccurringErrors()
{
const std::wstring errorString = utility::decodeFromUtf8(utility::prepareJavaEnvironment());
if (!errorString.empty())
{
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::set<FilePath> fetchRootDirectories(const std::set<FilePath>& sourceFilePaths)
{
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 : sourceFilePaths)
{
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;
}
std::vector<FilePath> getClassPath(std::shared_ptr<const SourceGroupSettingsWithClasspath> settings, const std::set<FilePath>& sourceFilePaths)
{
std::vector<FilePath> classPath;
for (const FilePath& classpath : settings->getClasspathExpandedAndAbsolute())
{
if (classpath.exists())
{
LOG_INFO(L"Adding path to classpath: " + classpath.wstr());
classPath.push_back(classpath);
}
}
if (settings->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 : utility::fetchRootDirectories(sourceFilePaths))
{
if (rootDirectory.exists())
{
LOG_INFO(L"Adding root directory to classpath: " + rootDirectory.wstr());
classPath.push_back(rootDirectory);
}
}
return classPath;
}
}
+7
View File
@@ -2,14 +2,21 @@
#define UTILITY_JAVA_H
#include <string>
#include <set>
#include <vector>
class FilePath;
class SourceGroupSettingsWithClasspath;
namespace utility
{
std::vector<std::wstring> getRequiredJarNames();
std::string prepareJavaEnvironment();
bool prepareJavaEnvironmentAndDisplayOccurringErrors();
std::set<FilePath> fetchRootDirectories(const std::set<FilePath>& sourceFilePaths);
std::vector<FilePath> getClassPath(
std::shared_ptr<const SourceGroupSettingsWithClasspath> settings,
const std::set<FilePath>& sourceFilePaths);
}
#endif // UTILITY_JAVA_H