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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user