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
+93
View File
@@ -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;
}
}
+14
View File
@@ -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
+68
View File
@@ -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;
}
}
+15
View File
@@ -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