logic: added Gradle project setup (issue #379)

* added implementation for Gradle project setup (icon is still missing)
* refactored project loading/saving and SourceGroupSettings
* removed long deprecated Cxx UseSourcePathsForHeaderSearch option

fortune cookie message = There is true and sincere friendship between you and your friends.
This commit is contained in:
mlangkabel
2017-10-02 18:43:59 +02:00
parent 72ae4d5695
commit e604d24c40
83 changed files with 3518 additions and 1182 deletions
@@ -1,6 +1,11 @@
#include "project/SourceGroupFactoryModuleJava.h"
#include "project/SourceGroupJava.h"
#include "project/SourceGroupJavaEmpty.h"
#include "project/SourceGroupJavaGradle.h"
#include "project/SourceGroupJavaMaven.h"
#include "settings/SourceGroupSettingsJavaEmpty.h"
#include "settings/SourceGroupSettingsJavaGradle.h"
#include "settings/SourceGroupSettingsJavaMaven.h"
SourceGroupFactoryModuleJava::~SourceGroupFactoryModuleJava()
{
@@ -11,6 +16,7 @@ bool SourceGroupFactoryModuleJava::supports(SourceGroupType type) const
switch (type)
{
case SOURCE_GROUP_JAVA_EMPTY:
case SOURCE_GROUP_JAVA_GRADLE:
case SOURCE_GROUP_JAVA_MAVEN:
return true;
default:
@@ -22,9 +28,17 @@ bool SourceGroupFactoryModuleJava::supports(SourceGroupType type) const
std::shared_ptr<SourceGroup> SourceGroupFactoryModuleJava::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings)
{
std::shared_ptr<SourceGroup> sourceGroup;
if (std::shared_ptr<SourceGroupSettingsJava> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJava>(settings))
if (std::shared_ptr<SourceGroupSettingsJavaEmpty> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaEmpty>(settings))
{
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJava(javaSettings));
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJavaEmpty(javaSettings));
}
else if (std::shared_ptr<SourceGroupSettingsJavaGradle> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaGradle>(settings))
{
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJavaGradle(javaSettings));
}
else if (std::shared_ptr<SourceGroupSettingsJavaMaven> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaMaven>(settings))
{
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJavaMaven(javaSettings));
}
return sourceGroup;
}
+22 -108
View File
@@ -6,18 +6,14 @@
#include "data/parser/java/JavaEnvironment.h"
#include "data/parser/java/JavaParser.h"
#include "settings/ApplicationSettings.h"
#include "utility/file/FileManager.h"
#include "utility/file/FileSystem.h"
#include "settings/SourceGroupSettingsJava.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
#include "utility/ScopedFunctor.h"
#include "utility/utility.h"
#include "utility/utilityMaven.h"
#include "utility/utilityString.h"
#include "utility/utilityJava.h"
#include "Application.h"
SourceGroupJava::SourceGroupJava(std::shared_ptr<SourceGroupSettingsJava> settings)
: m_settings(settings)
SourceGroupJava::SourceGroupJava()
{
}
@@ -25,58 +21,22 @@ SourceGroupJava::~SourceGroupJava()
{
}
SourceGroupType SourceGroupJava::getType() const
{
return m_settings->getType();
}
bool SourceGroupJava::prepareIndexing()
{
if (!prepareJavaEnvironment())
{
return false;
}
if (!prepareMavenData())
{
return false;
}
return true;
}
void SourceGroupJava::fetchAllSourceFilePaths()
{
std::vector<FilePath> sourcePaths;
if (m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog("Preparing Project", "Maven\nFetching Source Directories");
const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath());
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().parentDirectory();
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(mavenPath, projectRootPath, m_settings->getShouldIndexMavenTests());
dialogView->hideUnknownProgressDialog();
}
else
{
sourcePaths = m_settings->getSourcePathsExpandedAndAbsolute();
}
m_sourceFilePathsToIndex.clear();
FileManager fileManager;
fileManager.update(sourcePaths, m_settings->getExcludePathsExpandedAndAbsolute(), m_settings->getSourceExtensions());
m_allSourceFilePaths = fileManager.getAllSourceFilePaths();
}
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands(
std::set<FilePath>* filesToIndex, bool fullRefresh)
{
std::vector<FilePath> classPath = getClassPath();
std::set<FilePath> indexedPaths;
for (const FilePath& p: m_settings->getSourcePathsExpandedAndAbsolute())
for (const FilePath& p: getSourceGroupSettings()->getSourcePathsExpandedAndAbsolute())
{
if (p.exists())
{
@@ -85,7 +45,7 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
}
std::set<FilePath> excludedPaths;
for (const FilePath& p: m_settings->getExcludePathsExpandedAndAbsolute())
for (const FilePath& p: getSourceGroupSettings()->getExcludePathsExpandedAndAbsolute())
{
if (p.exists())
{
@@ -110,9 +70,14 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
return indexerCommands;
}
std::shared_ptr<SourceGroupSettings> SourceGroupJava::getSourceGroupSettings()
{
return getSourceGroupSettingsJava();
}
bool SourceGroupJava::prepareJavaEnvironment()
{
const std::string errorString = JavaParser::prepareJavaEnvironment();
const std::string errorString = utility::prepareJavaEnvironment();
if (errorString.size() > 0)
{
@@ -139,55 +104,20 @@ bool SourceGroupJava::prepareJavaEnvironment()
return true;
}
bool SourceGroupJava::prepareMavenData()
{
if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
{
const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath();
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().parentDirectory();
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog("Preparing Project", "Maven\nGenerating Source Files");
ScopedFunctor dialogHider([&dialogView](){
dialogView->hideUnknownProgressDialog();
});
bool success = utility::mavenGenerateSources(mavenPath, projectRootPath);
if (!success)
{
const std::string dialogMessage =
"Sourcetrail was unable to locate Maven on this machine.\n"
"Please make sure to provide the correct Maven Path in the preferences.";
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
}
if (success)
{
dialogView->showUnknownProgressDialog("Preparing Project", "Maven\nExporting Dependencies");
success = utility::mavenCopyDependencies(
mavenPath, projectRootPath, m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute()
);
}
return success;
}
return true;
}
std::vector<FilePath> SourceGroupJava::getClassPath()
{
LOG_INFO("Retrieving classpath for indexer commands");
std::vector<FilePath> classPath = doGetClassPath();
LOG_INFO("Found " + std::to_string(classPath.size()) + " paths for classpath.");
return classPath;
}
std::vector<FilePath> SourceGroupJava::doGetClassPath()
{
std::vector<FilePath> classPath;
for (const FilePath& classpath: m_settings->getClasspathExpandedAndAbsolute())
for (const FilePath& classpath : getSourceGroupSettingsJava()->getClasspathExpandedAndAbsolute())
{
if (classpath.exists())
{
@@ -196,31 +126,16 @@ std::vector<FilePath> SourceGroupJava::getClassPath()
}
}
if (m_settings->getUseJreSystemLibrary())
if (getSourceGroupSettingsJava()->getUseJreSystemLibrary())
{
for (const FilePath& systemLibraryPath: ApplicationSettings::getInstance()->getJreSystemLibraryPathsExpanded())
for (const FilePath& systemLibraryPath : ApplicationSettings::getInstance()->getJreSystemLibraryPathsExpanded())
{
LOG_INFO("Adding JRE system library path to classpath: " + systemLibraryPath.str());
classPath.push_back(systemLibraryPath);
}
}
if (m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute().exists())
{
std::vector<FilePath> mavenJarPaths = FileSystem::getFilePathsFromDirectory(
m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute(),
utility::createVectorFromElements<std::string>(".jar")
);
for (const FilePath& mavenJarPath: mavenJarPaths)
{
LOG_INFO("Adding jar to classpath: " + mavenJarPath.str());
}
utility::append(classPath, mavenJarPaths);
}
for (const FilePath& rootDirectory: fetchRootDirectories())
for (const FilePath& rootDirectory : fetchRootDirectories())
{
if (rootDirectory.exists())
{
@@ -228,7 +143,6 @@ std::vector<FilePath> SourceGroupJava::getClassPath()
classPath.push_back(rootDirectory);
}
}
LOG_INFO("Found " + std::to_string(classPath.size()) + " paths for classpath.");
return classPath;
}
@@ -250,7 +164,7 @@ std::set<FilePath> SourceGroupJava::fetchRootDirectories()
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
std::string packageName = "";
javaEnvironment->callStaticMethod("com/sourcetrail/JavaIndexer", "getPackageName", packageName, textAccess->getText());
javaEnvironment->callStaticStringMethod("com/sourcetrail/JavaIndexer", "getPackageName", packageName, textAccess->getText());
if (packageName.empty())
{
+10 -9
View File
@@ -3,33 +3,34 @@
#include <memory>
#include <set>
#include <vector>
#include "settings/SourceGroupSettingsJava.h"
#include "project/SourceGroup.h"
class SourceGroupSettingsJava;
class SourceGroupJava: public SourceGroup
{
public:
SourceGroupJava(std::shared_ptr<SourceGroupSettingsJava> settings);
SourceGroupJava();
virtual ~SourceGroupJava();
virtual SourceGroupType getType() const;
virtual bool prepareIndexing();
virtual void fetchAllSourceFilePaths();
virtual std::vector<std::shared_ptr<IndexerCommand>> getIndexerCommands(
std::set<FilePath>* filesToIndex, bool fullRefresh);
protected:
virtual std::vector<FilePath> doGetClassPath();
private:
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava() = 0;
virtual std::shared_ptr<SourceGroupSettings> getSourceGroupSettings();
bool prepareJavaEnvironment();
bool prepareMavenData();
std::vector<FilePath> getClassPath();
std::set<FilePath> fetchRootDirectories();
std::shared_ptr<SourceGroupSettingsJava> m_settings;
};
#endif // SOURCE_GROUP_JAVA_H
@@ -0,0 +1,27 @@
#include "project/SourceGroupJavaEmpty.h"
#include "settings/SourceGroupSettingsJavaEmpty.h"
SourceGroupJavaEmpty::SourceGroupJavaEmpty(std::shared_ptr<SourceGroupSettingsJavaEmpty> settings)
: m_settings(settings)
{
}
SourceGroupJavaEmpty::~SourceGroupJavaEmpty()
{
}
SourceGroupType SourceGroupJavaEmpty::getType() const
{
return SOURCE_GROUP_JAVA_EMPTY;
}
std::shared_ptr<SourceGroupSettingsJava> SourceGroupJavaEmpty::getSourceGroupSettingsJava()
{
return m_settings;
}
std::vector<FilePath> SourceGroupJavaEmpty::getAllSourcePaths() const
{
return m_settings->getSourcePathsExpandedAndAbsolute();
}
@@ -0,0 +1,26 @@
#ifndef SOURCE_GROUP_JAVA_EMPTY_H
#define SOURCE_GROUP_JAVA_EMPTY_H
#include <memory>
#include <vector>
#include "project/SourceGroupJava.h"
class SourceGroupSettingsJavaEmpty;
class SourceGroupJavaEmpty: public SourceGroupJava
{
public:
SourceGroupJavaEmpty(std::shared_ptr<SourceGroupSettingsJavaEmpty> settings);
virtual ~SourceGroupJavaEmpty();
virtual SourceGroupType getType() const;
private:
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava();
virtual std::vector<FilePath> getAllSourcePaths() const;
std::shared_ptr<SourceGroupSettingsJavaEmpty> m_settings;
};
#endif // SOURCE_GROUP_JAVA_EMPTY_H
@@ -0,0 +1,108 @@
#include "project/SourceGroupJavaGradle.h"
#include "component/view/DialogView.h"
#include "settings/ApplicationSettings.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 "Application.h"
SourceGroupJavaGradle::SourceGroupJavaGradle(std::shared_ptr<SourceGroupSettingsJavaGradle> settings)
: m_settings(settings)
{
}
SourceGroupJavaGradle::~SourceGroupJavaGradle()
{
}
SourceGroupType SourceGroupJavaGradle::getType() const
{
return SOURCE_GROUP_JAVA_GRADLE;
}
bool SourceGroupJavaGradle::prepareIndexing()
{
if (!SourceGroupJava::prepareIndexing())
{
return false;
}
if (!prepareGradleData())
{
return false;
}
return true;
}
std::vector<FilePath> SourceGroupJavaGradle::doGetClassPath()
{
std::vector<FilePath> classPath = SourceGroupJava::doGetClassPath();
if (m_settings->getGradleDependenciesDirectoryExpandedAndAbsolute().exists())
{
std::vector<FilePath> gradleJarPaths = FileSystem::getFilePathsFromDirectory(
m_settings->getGradleDependenciesDirectoryExpandedAndAbsolute(),
{".jar"}
);
for (const FilePath& gradleJarPath : gradleJarPaths)
{
LOG_INFO("Adding jar to classpath: " + gradleJarPath.str());
}
utility::append(classPath, gradleJarPaths);
}
return classPath;
}
std::shared_ptr<SourceGroupSettingsJava> SourceGroupJavaGradle::getSourceGroupSettingsJava()
{
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("Preparing Project", "Gradle\nFetching Source Directories");
const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().parentDirectory();
sourcePaths = utility::gradleGetAllSourceDirectories(projectRootPath, m_settings->getShouldIndexGradleTests());
dialogView->hideUnknownProgressDialog();
}
return sourcePaths;
}
bool SourceGroupJavaGradle::prepareGradleData()
{
if (m_settings && m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists())
{
const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().parentDirectory();
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
ScopedFunctor dialogHider([&dialogView]() {
dialogView->hideUnknownProgressDialog();
});
dialogView->showUnknownProgressDialog("Preparing Project", "Gradle\nExporting Dependencies");
bool success = utility::gradleCopyDependencies(
projectRootPath,
m_settings->getGradleDependenciesDirectoryExpandedAndAbsolute(),
m_settings->getShouldIndexGradleTests()
);
return success;
}
return true;
}
@@ -0,0 +1,29 @@
#ifndef SOURCE_GROUP_JAVA_GRADLE_H
#define SOURCE_GROUP_JAVA_GRADLE_H
#include <memory>
#include <vector>
#include "settings/SourceGroupSettingsJavaGradle.h"
#include "project/SourceGroupJava.h"
class SourceGroupJavaGradle : public SourceGroupJava
{
public:
SourceGroupJavaGradle(std::shared_ptr<SourceGroupSettingsJavaGradle> settings);
virtual ~SourceGroupJavaGradle();
virtual SourceGroupType getType() const;
virtual bool prepareIndexing();
protected:
virtual std::vector<FilePath> doGetClassPath();
private:
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava();
virtual std::vector<FilePath> getAllSourcePaths() const;
bool prepareGradleData();
std::shared_ptr<SourceGroupSettingsJavaGradle> m_settings;
};
#endif // SOURCE_GROUP_JAVA_GRADLE_H
@@ -0,0 +1,124 @@
#include "project/SourceGroupJavaMaven.h"
#include "component/view/DialogView.h"
#include "settings/ApplicationSettings.h"
#include "utility/file/FileSystem.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/ScopedFunctor.h"
#include "utility/utility.h"
#include "utility/utilityMaven.h"
#include "Application.h"
SourceGroupJavaMaven::SourceGroupJavaMaven(std::shared_ptr<SourceGroupSettingsJavaMaven> settings)
: m_settings(settings)
{
}
SourceGroupJavaMaven::~SourceGroupJavaMaven()
{
}
SourceGroupType SourceGroupJavaMaven::getType() const
{
return SOURCE_GROUP_JAVA_MAVEN;
}
bool SourceGroupJavaMaven::prepareIndexing()
{
if (!SourceGroupJava::prepareIndexing())
{
return false;
}
if (!prepareMavenData())
{
return false;
}
return true;
}
std::vector<FilePath> SourceGroupJavaMaven::doGetClassPath()
{
std::vector<FilePath> classPath = SourceGroupJava::doGetClassPath();
if (m_settings && m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute().exists())
{
std::vector<FilePath> mavenJarPaths = FileSystem::getFilePathsFromDirectory(
m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute(),
utility::createVectorFromElements<std::string>(".jar")
);
for (const FilePath& mavenJarPath : mavenJarPaths)
{
LOG_INFO("Adding jar to classpath: " + mavenJarPath.str());
}
utility::append(classPath, mavenJarPaths);
}
return classPath;
}
std::shared_ptr<SourceGroupSettingsJava> SourceGroupJavaMaven::getSourceGroupSettingsJava()
{
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("Preparing Project", "Maven\nFetching Source Directories");
const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath());
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().parentDirectory();
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(mavenPath, projectRootPath, m_settings->getShouldIndexMavenTests());
dialogView->hideUnknownProgressDialog();
}
return sourcePaths;
}
bool SourceGroupJavaMaven::prepareMavenData()
{
if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
{
const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath();
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().parentDirectory();
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView();
dialogView->showUnknownProgressDialog("Preparing Project", "Maven\nGenerating Source Files");
ScopedFunctor dialogHider([&dialogView](){
dialogView->hideUnknownProgressDialog();
});
bool success = utility::mavenGenerateSources(mavenPath, projectRootPath);
if (!success)
{
const std::string dialogMessage =
"Sourcetrail was unable to locate Maven on this machine.\n"
"Please make sure to provide the correct Maven Path in the preferences.";
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
}
if (success)
{
dialogView->showUnknownProgressDialog("Preparing Project", "Maven\nExporting Dependencies");
success = utility::mavenCopyDependencies(
mavenPath, projectRootPath, m_settings->getMavenDependenciesDirectoryExpandedAndAbsolute()
);
}
return success;
}
return true;
}
@@ -0,0 +1,29 @@
#ifndef SOURCE_GROUP_JAVA_MAVEN_H
#define SOURCE_GROUP_JAVA_MAVEN_H
#include <memory>
#include <vector>
#include "settings/SourceGroupSettingsJavaMaven.h"
#include "project/SourceGroupJava.h"
class SourceGroupJavaMaven: public SourceGroupJava
{
public:
SourceGroupJavaMaven(std::shared_ptr<SourceGroupSettingsJavaMaven> settings);
virtual ~SourceGroupJavaMaven();
virtual SourceGroupType getType() const;
virtual bool prepareIndexing();
protected:
virtual std::vector<FilePath> doGetClassPath();
private:
virtual std::shared_ptr<SourceGroupSettingsJava> getSourceGroupSettingsJava();
virtual std::vector<FilePath> getAllSourcePaths() const;
bool prepareMavenData();
std::shared_ptr<SourceGroupSettingsJavaMaven> m_settings;
};
#endif // SOURCE_GROUP_JAVA_MAVEN_H