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:
@@ -16,11 +16,21 @@ add_files(
|
||||
data/parser/java/JavaEnvironmentFactory.cpp
|
||||
data/parser/java/JavaEnvironmentFactory.h
|
||||
|
||||
project/SourceGroupJava.cpp
|
||||
project/SourceGroupJava.h
|
||||
project/SourceGroupFactoryModuleJava.cpp
|
||||
project/SourceGroupFactoryModuleJava.h
|
||||
project/SourceGroupJava.cpp
|
||||
project/SourceGroupJava.h
|
||||
project/SourceGroupJavaEmpty.cpp
|
||||
project/SourceGroupJavaEmpty.h
|
||||
project/SourceGroupJavaGradle.cpp
|
||||
project/SourceGroupJavaGradle.h
|
||||
project/SourceGroupJavaMaven.cpp
|
||||
project/SourceGroupJavaMaven.h
|
||||
|
||||
utility/utilityJava.cpp
|
||||
utility/utilityJava.h
|
||||
utility/utilityGradle.cpp
|
||||
utility/utilityGradle.h
|
||||
utility/utilityMaven.cpp
|
||||
utility/utilityMaven.h
|
||||
)
|
||||
|
||||
@@ -22,6 +22,21 @@ bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string me
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string methodName, const std::string& arg1, const std::string& arg2, const std::string& arg3)
|
||||
{
|
||||
jclass javaClass = getJavaClass(className);
|
||||
jmethodID javaMethodId = getJavaStaticMethod(javaClass, methodName, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
if (javaMethodId != nullptr)
|
||||
{
|
||||
jstring jarg1 = m_env->NewStringUTF(arg1.c_str());
|
||||
jstring jarg2 = m_env->NewStringUTF(arg2.c_str());
|
||||
jstring jarg3 = m_env->NewStringUTF(arg3.c_str());
|
||||
m_env->CallStaticVoidMethod(javaClass, javaMethodId, jarg1, jarg2, jarg3);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string methodName, int arg1, std::string arg2, std::string arg3, std::string arg4, int arg5)
|
||||
{
|
||||
jclass javaClass = getJavaClass(className);
|
||||
@@ -39,11 +54,11 @@ bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string me
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JavaEnvironment::callStaticMethod(std::string className, std::string methodName, std::string& ret, std::string arg1)
|
||||
bool JavaEnvironment::callStaticStringMethod(std::string className, std::string methodName, std::string& ret, const std::string& arg1)
|
||||
{
|
||||
jclass javaClass = getJavaClass(className);
|
||||
jmethodID javaMethodId = getJavaStaticMethod(javaClass, methodName, "(Ljava/lang/String;)Ljava/lang/String;");
|
||||
if(javaMethodId != nullptr)
|
||||
jmethodID javaMethodId = getJavaStaticMethod(javaClass, methodName, "(Ljava/lang/String;)Ljava/lang/String;");
|
||||
if (javaMethodId != nullptr)
|
||||
{
|
||||
jstring jarg1 = m_env->NewStringUTF(arg1.c_str());
|
||||
jstring jret = (jstring)m_env->CallStaticObjectMethod(javaClass, javaMethodId, jarg1);
|
||||
@@ -58,6 +73,26 @@ bool JavaEnvironment::callStaticMethod(std::string className, std::string method
|
||||
return false;
|
||||
}
|
||||
|
||||
bool JavaEnvironment::callStaticStringMethod(std::string className, std::string methodName, std::string& ret, const std::string& arg1, const std::string& arg2)
|
||||
{
|
||||
jclass javaClass = getJavaClass(className);
|
||||
jmethodID javaMethodId = getJavaStaticMethod(javaClass, methodName, "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
|
||||
if (javaMethodId != nullptr)
|
||||
{
|
||||
jstring jarg1 = m_env->NewStringUTF(arg1.c_str());
|
||||
jstring jarg2 = m_env->NewStringUTF(arg2.c_str());
|
||||
jstring jret = (jstring)m_env->CallStaticObjectMethod(javaClass, javaMethodId, jarg1, jarg2);
|
||||
if (jret)
|
||||
{
|
||||
const char *buffer = m_env->GetStringUTFChars(jret, JNI_FALSE);
|
||||
ret = std::string(buffer);
|
||||
m_env->ReleaseStringUTFChars(jret, buffer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string JavaEnvironment::toStdString(jstring s)
|
||||
{
|
||||
const char *nativeString = m_env->GetStringUTFChars(s, 0);
|
||||
|
||||
@@ -33,8 +33,10 @@ public:
|
||||
|
||||
~JavaEnvironment();
|
||||
bool callStaticVoidMethod(std::string className, std::string methodName);
|
||||
bool callStaticVoidMethod(std::string className, std::string methodName, const std::string& arg1, const std::string& arg2, const std::string& arg3);
|
||||
bool callStaticVoidMethod(std::string className, std::string methodName, int arg1, std::string arg2, std::string arg3, std::string arg4, int arg5);
|
||||
bool callStaticMethod(std::string className, std::string methodName, std::string& ret, std::string arg1);
|
||||
bool callStaticStringMethod(std::string className, std::string methodName, std::string& ret, const std::string& arg1);
|
||||
bool callStaticStringMethod(std::string className, std::string methodName, std::string& ret, const std::string& arg1, const std::string& arg2);
|
||||
|
||||
std::string toStdString(jstring s);
|
||||
jstring toJString(std::string s);
|
||||
|
||||
@@ -11,65 +11,9 @@
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
#include "utility/utilityJava.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
std::vector<std::string> JavaParser::getRequiredJarNames()
|
||||
{
|
||||
std::vector<std::string> jarNames = {
|
||||
|
||||
"java-indexer.jar",
|
||||
"org.eclipse.core.commands-3.8.1.jar",
|
||||
"org.eclipse.core.contenttype-3.5.100.jar",
|
||||
"org.eclipse.core.expressions-3.5.100.jar",
|
||||
"org.eclipse.core.filesystem-1.6.1.jar",
|
||||
"org.eclipse.core.jobs-3.8.0.jar",
|
||||
"org.eclipse.core.resources-3.11.1.jar",
|
||||
"org.eclipse.core.runtime-3.12.0.jar",
|
||||
"org.eclipse.equinox.app-1.3.400.jar",
|
||||
"org.eclipse.equinox.common-3.8.0.jar",
|
||||
"org.eclipse.equinox.preferences-3.6.1.jar",
|
||||
"org.eclipse.equinox.registry-3.6.100.jar",
|
||||
"org.eclipse.jdt.core-3.12.3.jar",
|
||||
"org.eclipse.osgi-3.11.3.jar",
|
||||
"org.eclipse.text-3.6.0.jar"
|
||||
};
|
||||
return jarNames;
|
||||
}
|
||||
|
||||
std::string JavaParser::prepareJavaEnvironment()
|
||||
{
|
||||
std::string errorString;
|
||||
|
||||
if (!JavaEnvironmentFactory::getInstance())
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const std::string separator = ";";
|
||||
#else
|
||||
const std::string separator = ":";
|
||||
#endif
|
||||
|
||||
std::string classPath = "";
|
||||
{
|
||||
const std::vector<std::string> jarNames = getRequiredJarNames();
|
||||
for (size_t i = 0; i < jarNames.size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
classPath += separator;
|
||||
}
|
||||
classPath += ResourcePaths::getJavaPath().str() + jarNames[i];
|
||||
}
|
||||
}
|
||||
|
||||
JavaEnvironmentFactory::createInstance(
|
||||
classPath,
|
||||
errorString
|
||||
);
|
||||
}
|
||||
|
||||
return errorString;
|
||||
}
|
||||
|
||||
void JavaParser::clearCaches()
|
||||
{
|
||||
std::shared_ptr<JavaEnvironmentFactory> factory = JavaEnvironmentFactory::getInstance();
|
||||
@@ -90,7 +34,7 @@ JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<Fil
|
||||
: Parser(client)
|
||||
, m_id(s_nextParserId++)
|
||||
{
|
||||
const std::string errorString = prepareJavaEnvironment();
|
||||
const std::string errorString = utility::prepareJavaEnvironment();
|
||||
if (errorString.size() > 0)
|
||||
{
|
||||
LOG_ERROR(errorString);
|
||||
|
||||
@@ -32,9 +32,6 @@ class FileRegister;
|
||||
class JavaParser: public Parser
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> getRequiredJarNames();
|
||||
// returns: error message
|
||||
static std::string prepareJavaEnvironment();
|
||||
static void clearCaches();
|
||||
|
||||
JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,93 @@
|
||||
#include "utility/utilityGradle.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "data/parser/java/JavaEnvironment.h"
|
||||
#include "data/parser/java/JavaEnvironmentFactory.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
#include "utility/utilityJava.h"
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
void setJavaHomeVariableIfNotExists()
|
||||
{
|
||||
if (getenv("JAVA_HOME") == nullptr)
|
||||
{
|
||||
const FilePath javaPath(ApplicationSettings::getInstance()->getJavaPath());
|
||||
const FilePath javaHomePath = javaPath.parentDirectory().parentDirectory().parentDirectory();
|
||||
|
||||
LOG_WARNING("Environment variable \"JAVA_HOME\" not found on system. Setting value to \"" + javaHomePath.str() + "\" for this process.");
|
||||
|
||||
putenv(const_cast<char*>(("JAVA_HOME=" + javaHomePath.str()).c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace utility
|
||||
{
|
||||
bool gradleCopyDependencies(const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDependencies)
|
||||
{
|
||||
const std::string gradleInitScriptPath = ResourcePaths::getJavaPath().str() + "gradle/init.gradle";
|
||||
|
||||
setJavaHomeVariableIfNotExists();
|
||||
utility::prepareJavaEnvironment();
|
||||
|
||||
std::shared_ptr<JavaEnvironment> javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment();
|
||||
bool success = javaEnvironment->callStaticVoidMethod("com/sourcetrail/gradle/InfoRetriever", "copyCompileLibs", projectDirectoryPath.str(), gradleInitScriptPath, outputDirectoryPath.str());
|
||||
|
||||
if (success && addTestDependencies)
|
||||
{
|
||||
success = javaEnvironment->callStaticVoidMethod("com/sourcetrail/gradle/InfoRetriever", "copyTestCompileLibs", projectDirectoryPath.str(), gradleInitScriptPath, outputDirectoryPath.str());
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
std::vector<FilePath> gradleGetAllSourceDirectories(const FilePath& projectDirectoryPath, bool addTestDirectories)
|
||||
{
|
||||
const std::string gradleInitScriptPath = ResourcePaths::getJavaPath().str() + "gradle/init.gradle";
|
||||
|
||||
setJavaHomeVariableIfNotExists();
|
||||
utility::prepareJavaEnvironment();
|
||||
|
||||
std::set<std::string> uncheckedDirectories;
|
||||
{
|
||||
std::shared_ptr<JavaEnvironment> javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment();
|
||||
{
|
||||
std::string mainSrcDirs = "";
|
||||
javaEnvironment->callStaticStringMethod("com/sourcetrail/gradle/InfoRetriever", "getMainSrcDirs", mainSrcDirs, projectDirectoryPath.str(), gradleInitScriptPath);
|
||||
for (const std::string mainSrcDir : utility::splitToVector(mainSrcDirs, ";"))
|
||||
{
|
||||
uncheckedDirectories.insert(mainSrcDir);
|
||||
}
|
||||
}
|
||||
|
||||
if (addTestDirectories)
|
||||
{
|
||||
std::string testSrcDirs = "";
|
||||
javaEnvironment->callStaticStringMethod("com/sourcetrail/gradle/InfoRetriever", "getTestSrcDirs", testSrcDirs, projectDirectoryPath.str(), gradleInitScriptPath);
|
||||
for (const std::string testSrcDir : utility::splitToVector(testSrcDirs, ";"))
|
||||
{
|
||||
uncheckedDirectories.insert(testSrcDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<FilePath> directories;
|
||||
for (const std::string& uncheckedDirectory: uncheckedDirectories)
|
||||
{
|
||||
FilePath uncheckedDirectoryPath(uncheckedDirectory);
|
||||
if (uncheckedDirectoryPath.exists())
|
||||
{
|
||||
directories.push_back(uncheckedDirectoryPath);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO("Found " + std::to_string(directories.size()) + " of " + std::to_string(uncheckedDirectories.size()) + " directories on system.");
|
||||
|
||||
return directories;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef UTILITY_GRADLE_H
|
||||
#define UTILITY_GRADLE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
class FilePath;
|
||||
|
||||
namespace utility
|
||||
{
|
||||
bool gradleCopyDependencies(const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDependencies);
|
||||
std::vector<FilePath> gradleGetAllSourceDirectories(const FilePath& projectDirectoryPath, bool addTestDirectories);
|
||||
}
|
||||
|
||||
#endif // UTILITY_GRADLE_H
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "utility/utilityGradle.h"
|
||||
|
||||
#include "data/parser/java/JavaEnvironment.h"
|
||||
#include "data/parser/java/JavaEnvironmentFactory.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
namespace utility
|
||||
{
|
||||
std::vector<std::string> getRequiredJarNames()
|
||||
{
|
||||
std::vector<std::string> jarNames = {
|
||||
|
||||
"gradle-tooling-api-4.2.jar",
|
||||
"java-indexer.jar",
|
||||
"org.eclipse.core.commands-3.8.1.jar",
|
||||
"org.eclipse.core.contenttype-3.5.100.jar",
|
||||
"org.eclipse.core.expressions-3.5.100.jar",
|
||||
"org.eclipse.core.filesystem-1.6.1.jar",
|
||||
"org.eclipse.core.jobs-3.8.0.jar",
|
||||
"org.eclipse.core.resources-3.11.1.jar",
|
||||
"org.eclipse.core.runtime-3.12.0.jar",
|
||||
"org.eclipse.equinox.app-1.3.400.jar",
|
||||
"org.eclipse.equinox.common-3.8.0.jar",
|
||||
"org.eclipse.equinox.preferences-3.6.1.jar",
|
||||
"org.eclipse.equinox.registry-3.6.100.jar",
|
||||
"org.eclipse.jdt.core-3.12.3.jar",
|
||||
"org.eclipse.osgi-3.11.3.jar",
|
||||
"org.eclipse.text-3.6.0.jar",
|
||||
"slf4j-api-1.7.10.jar",
|
||||
"slf4j-simple-1.7.10.jar"
|
||||
};
|
||||
return jarNames;
|
||||
}
|
||||
|
||||
std::string prepareJavaEnvironment()
|
||||
{
|
||||
std::string errorString;
|
||||
|
||||
if (!JavaEnvironmentFactory::getInstance())
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const std::string separator = ";";
|
||||
#else
|
||||
const std::string separator = ":";
|
||||
#endif
|
||||
|
||||
std::string classPath = "";
|
||||
{
|
||||
const std::vector<std::string> jarNames = getRequiredJarNames();
|
||||
for (size_t i = 0; i < jarNames.size(); i++)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
classPath += separator;
|
||||
}
|
||||
classPath += ResourcePaths::getJavaPath().str() + "lib/" + jarNames[i];
|
||||
}
|
||||
}
|
||||
|
||||
JavaEnvironmentFactory::createInstance(
|
||||
classPath,
|
||||
errorString
|
||||
);
|
||||
}
|
||||
|
||||
return errorString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef UTILITY_JAVA_H
|
||||
#define UTILITY_JAVA_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class FilePath;
|
||||
|
||||
namespace utility
|
||||
{
|
||||
std::vector<std::string> getRequiredJarNames();
|
||||
std::string prepareJavaEnvironment();
|
||||
}
|
||||
|
||||
#endif // UTILITY_JAVA_H
|
||||
Reference in New Issue
Block a user