src: applied clang-format

This commit is contained in:
mlangkabel
2019-11-18 17:07:20 +01:00
parent 52058d9947
commit 078feca004
1100 changed files with 21382 additions and 20822 deletions
+1 -3
View File
@@ -4,7 +4,5 @@
std::vector<std::shared_ptr<IndexerBase>> LanguagePackageJava::instantiateSupportedIndexers() const
{
return {
std::make_shared<IndexerJava>()
};
return {std::make_shared<IndexerJava>()};
}
+2 -2
View File
@@ -3,10 +3,10 @@
#include "LanguagePackage.h"
class LanguagePackageJava : public LanguagePackage
class LanguagePackageJava: public LanguagePackage
{
public:
virtual std::vector<std::shared_ptr<IndexerBase>> instantiateSupportedIndexers() const;
};
#endif // LANGUAGE_PACKAGE_JAVA_H
#endif // LANGUAGE_PACKAGE_JAVA_H
@@ -13,11 +13,8 @@ IndexerCommandType IndexerCommandJava::getStaticIndexerCommandType()
IndexerCommandJava::IndexerCommandJava(
const FilePath& sourceFilePath,
const std::wstring& languageStandard,
const std::vector<FilePath>& classPath
)
: IndexerCommand(sourceFilePath)
, m_languageStandard(languageStandard)
, m_classPath(classPath)
const std::vector<FilePath>& classPath)
: IndexerCommand(sourceFilePath), m_languageStandard(languageStandard), m_classPath(classPath)
{
}
@@ -30,7 +27,7 @@ size_t IndexerCommandJava::getByteSize(size_t stringSize) const
{
size_t size = IndexerCommand::getByteSize(stringSize);
for (const FilePath& i : m_classPath)
for (const FilePath& i: m_classPath)
{
size += stringSize + utility::encodeToUtf8(i.wstr()).size();
}
@@ -59,7 +56,7 @@ QJsonObject IndexerCommandJava::doSerialize() const
{
QJsonArray classPathArray;
for (const FilePath& classPath : m_classPath)
for (const FilePath& classPath: m_classPath)
{
classPathArray.append(QString::fromStdWString(classPath.wstr()));
}
@@ -8,8 +8,7 @@
class FilePath;
class FilePathFilter;
class IndexerCommandJava
: public IndexerCommand
class IndexerCommandJava: public IndexerCommand
{
public:
static IndexerCommandType getStaticIndexerCommandType();
@@ -35,4 +34,4 @@ private:
std::vector<FilePath> m_classPath;
};
#endif // INDEXER_COMMAND_JAVA_H
#endif // INDEXER_COMMAND_JAVA_H
+2 -2
View File
@@ -10,7 +10,7 @@ IndexerJava::~IndexerJava()
void IndexerJava::doIndex(
std::shared_ptr<IndexerCommandJava> indexerCommand,
std::shared_ptr<ParserClientImpl> parserClient,
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo
){
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo)
{
JavaParser(parserClient, m_indexerStateInfo).buildIndex(indexerCommand);
}
+2 -3
View File
@@ -6,8 +6,7 @@
struct IndexerStateInfo;
class IndexerJava
: public Indexer<IndexerCommandJava>
class IndexerJava: public Indexer<IndexerCommandJava>
{
public:
virtual ~IndexerJava();
@@ -19,4 +18,4 @@ private:
std::shared_ptr<IndexerStateInfo> m_indexerStateInfo) override;
};
#endif // INDEXER_JAVA_H
#endif // INDEXER_JAVA_H
@@ -2,8 +2,8 @@
#include <jni.h>
#include "logging.h"
#include "JavaEnvironmentFactory.h"
#include "logging.h"
JavaEnvironment::~JavaEnvironment()
{
@@ -14,7 +14,7 @@ bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string me
{
jclass javaClass = getJavaClass(className);
jmethodID javaMethodId = getJavaStaticMethod(javaClass, methodName, "()V");
if(javaMethodId != nullptr)
if (javaMethodId != nullptr)
{
m_env->CallStaticVoidMethod(javaClass, javaMethodId);
return true;
@@ -22,10 +22,16 @@ 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)
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");
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());
@@ -37,11 +43,22 @@ bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string me
return false;
}
bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string methodName, int arg1, std::string arg2, std::string arg3, std::string arg4, std::string arg5, int arg6)
bool JavaEnvironment::callStaticVoidMethod(
std::string className,
std::string methodName,
int arg1,
std::string arg2,
std::string arg3,
std::string arg4,
std::string arg5,
int arg6)
{
jclass javaClass = getJavaClass(className);
jmethodID javaMethodId = getJavaStaticMethod(javaClass, methodName, "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
if(javaMethodId != nullptr)
jmethodID javaMethodId = getJavaStaticMethod(
javaClass,
methodName,
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
if (javaMethodId != nullptr)
{
jint jarg1 = arg1;
jstring jarg2 = m_env->NewStringUTF(arg2.c_str());
@@ -49,23 +66,26 @@ bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string me
jstring jarg4 = m_env->NewStringUTF(arg4.c_str());
jstring jarg5 = m_env->NewStringUTF(arg5.c_str());
jint jarg6 = arg6;
m_env->CallStaticVoidMethod(javaClass, javaMethodId, jarg1, jarg2, jarg3, jarg4, jarg5, jarg6);
m_env->CallStaticVoidMethod(
javaClass, javaMethodId, jarg1, jarg2, jarg3, jarg4, jarg5, jarg6);
return true;
}
return false;
}
bool JavaEnvironment::callStaticStringMethod(std::string className, std::string methodName, std::string& ret, const 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;");
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);
if (jret)
{
const char *buffer = m_env->GetStringUTFChars(jret, JNI_FALSE);
const char* buffer = m_env->GetStringUTFChars(jret, JNI_FALSE);
ret = std::string(buffer);
m_env->ReleaseStringUTFChars(jret, buffer);
return true;
@@ -74,10 +94,16 @@ bool JavaEnvironment::callStaticStringMethod(std::string className, std::string
return false;
}
bool JavaEnvironment::callStaticStringMethod(std::string className, std::string methodName, std::string& ret, const std::string& arg1, const std::string& arg2)
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;");
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());
@@ -85,7 +111,7 @@ bool JavaEnvironment::callStaticStringMethod(std::string className, std::string
jstring jret = (jstring)m_env->CallStaticObjectMethod(javaClass, javaMethodId, jarg1, jarg2);
if (jret)
{
const char *buffer = m_env->GetStringUTFChars(jret, JNI_FALSE);
const char* buffer = m_env->GetStringUTFChars(jret, JNI_FALSE);
ret = std::string(buffer);
m_env->ReleaseStringUTFChars(jret, buffer);
return true;
@@ -96,7 +122,7 @@ bool JavaEnvironment::callStaticStringMethod(std::string className, std::string
std::string JavaEnvironment::toStdString(jstring s)
{
const char *nativeString = m_env->GetStringUTFChars(s, 0);
const char* nativeString = m_env->GetStringUTFChars(s, 0);
std::string ret = nativeString;
m_env->ReleaseStringUTFChars(s, nativeString);
return ret;
@@ -131,12 +157,10 @@ void JavaEnvironment::registerNativeMethods(std::string className, std::vector<N
LOG_ERROR("class \"" + className + "\" not found while registering native methods");
}
delete [] jniMethods;
delete[] jniMethods;
}
JavaEnvironment::JavaEnvironment(JavaVM* jvm, JNIEnv* env)
: m_jvm(jvm)
, m_env(env)
JavaEnvironment::JavaEnvironment(JavaVM* jvm, JNIEnv* env): m_jvm(jvm), m_env(env)
{
JavaEnvironmentFactory::getInstance()->registerEnvironment();
}
@@ -144,11 +168,11 @@ JavaEnvironment::JavaEnvironment(JavaVM* jvm, JNIEnv* env)
jclass JavaEnvironment::getJavaClass(const std::string& className)
{
jclass javaClass = m_env->FindClass(className.c_str());
if(javaClass == nullptr)
if (javaClass == nullptr)
{
LOG_ERROR("class " + className + " not found in JVM environment");
jthrowable exc = m_env->ExceptionOccurred();
if(exc)
if (exc)
{
m_env->ExceptionDescribe();
m_env->ExceptionClear();
@@ -157,17 +181,20 @@ jclass JavaEnvironment::getJavaClass(const std::string& className)
return javaClass;
}
jmethodID JavaEnvironment::getJavaStaticMethod(const std::string& className, const std::string& methodName, const std::string& methodSignature)
jmethodID JavaEnvironment::getJavaStaticMethod(
const std::string& className, const std::string& methodName, const std::string& methodSignature)
{
return getJavaStaticMethod(getJavaClass(className), methodName, methodSignature);
}
jmethodID JavaEnvironment::getJavaStaticMethod(jclass javaClass, const std::string& methodName, const std::string& methodSignature)
jmethodID JavaEnvironment::getJavaStaticMethod(
jclass javaClass, const std::string& methodName, const std::string& methodSignature)
{
if(javaClass != nullptr)
if (javaClass != nullptr)
{
jmethodID javaMethodId = m_env->GetStaticMethodID(javaClass, methodName.c_str(), methodSignature.c_str());
if(javaMethodId == nullptr)
jmethodID javaMethodId = m_env->GetStaticMethodID(
javaClass, methodName.c_str(), methodSignature.c_str());
if (javaMethodId == nullptr)
{
LOG_ERROR("method " + methodName + methodSignature + " not found in JVM environment");
}
+35 -11
View File
@@ -11,13 +11,13 @@ struct JNIEnv_;
typedef JNIEnv_ JNIEnv;
class _jclass;
typedef _jclass *jclass;
typedef _jclass* jclass;
class _jstring;
typedef _jstring *jstring;
typedef _jstring* jstring;
struct _jmethodID;
typedef struct _jmethodID *jmethodID;
typedef struct _jmethodID* jmethodID;
class JavaEnvironmentFactory;
@@ -28,30 +28,54 @@ public:
{
std::string name;
std::string signature;
void *function;
void* function;
};
~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, std::string arg5, int arg6);
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);
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,
std::string arg5,
int arg6);
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);
void registerNativeMethods(std::string className, std::vector<NativeMethod> methods);
private:
friend class JavaEnvironmentFactory;
JavaEnvironment(JavaVM* jvm, JNIEnv* env);
jclass getJavaClass(const std::string& className);
jmethodID getJavaStaticMethod(const std::string& className, const std::string& methodName, const std::string& methodSignature);
jmethodID getJavaStaticMethod(jclass javaClass, const std::string& methodName, const std::string& methodSignature);
jmethodID getJavaStaticMethod(
const std::string& className,
const std::string& methodName,
const std::string& methodSignature);
jmethodID getJavaStaticMethod(
jclass javaClass, const std::string& methodName, const std::string& methodSignature);
JavaVM* m_jvm;
JNIEnv* m_env;
};
#endif // JAVA_ENVIRONMENT_H
#endif // JAVA_ENVIRONMENT_H
@@ -4,8 +4,8 @@
#include <jni.h>
#include "JavaEnvironment.h"
#include "ApplicationSettings.h"
#include "JavaEnvironment.h"
#include "logging.h"
#include "utilityLibrary.h"
#include "utilityWindows.h"
@@ -22,12 +22,13 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string&
{
LOG_ERROR("java classpath cannot be changed!");
// todo: implement destroying the old factory instance and create a new one.
// may be not so easy... there can only be one java env per process (which can never be destroyed) -.-
// may be not so easy... there can only be one java env per process (which can never be
// destroyed) -.-
return;
}
}
std::function<jint (JavaVM**, void**, void*)> createInstanceFunction;
std::function<jint(JavaVM**, void**, void*)> createInstanceFunction;
const FilePath javaPath = ApplicationSettings::getInstance()->getJavaPath();
if (javaPath.empty())
@@ -37,10 +38,7 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string&
}
createInstanceFunction = utility::loadFunctionFromLibrary<jint, JavaVM**, void**, void*>(
javaPath,
"JNI_CreateJavaVM",
errorString
);
javaPath, "JNI_CreateJavaVM", errorString);
if (!createInstanceFunction && !errorString.empty())
{
@@ -51,52 +49,54 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string&
const int optionCount = 2;
JavaVM* jvm = nullptr; // Pointer to the JVM (Java Virtual Machine)
JNIEnv* env = nullptr; // Pointer to native interface
JavaVM* jvm = nullptr; // Pointer to the JVM (Java Virtual Machine)
JNIEnv* env = nullptr; // Pointer to native interface
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[optionCount]; // JVM invocation options
JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[optionCount]; // JVM invocation options
std::string classPathOption = "-Djava.class.path=" + classPath;
options[0].optionString = const_cast<char*>(classPathOption.c_str());
options[1].optionString = const_cast<char*>("-Xms64m");
// use these options to enable profiling in VisualVM
//options[2].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote");
//options[3].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote.port=9010");
//options[4].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote.local.only=false");
//options[5].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote.authenticate=false");
//options[6].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote.ssl=false");
// options[2].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote");
// options[3].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote.port=9010");
// options[4].optionString =
// const_cast<char*>("-Dcom.sun.management.jmxremote.local.only=false"); options[5].optionString
// = const_cast<char*>("-Dcom.sun.management.jmxremote.authenticate=false"); options[6].optionString
// = const_cast<char*>("-Dcom.sun.management.jmxremote.ssl=false");
vm_args.version = JNI_VERSION_1_8;
vm_args.nOptions = optionCount;
vm_args.options = options;
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail
jint rc = createInstanceFunction(&jvm, (void**)&env, &vm_args);
delete [] options;
delete[] options;
if (rc != JNI_OK)
{
if(rc == JNI_EVERSION)
if (rc == JNI_EVERSION)
{
errorString = "JVM is oudated and doesn't meet requirements";
}
else if(rc == JNI_ENOMEM)
else if (rc == JNI_ENOMEM)
{
errorString = "not enough memory for JVM";
}
else if(rc == JNI_EINVAL)
else if (rc == JNI_EINVAL)
{
errorString = "invalid argument for launching JVM";
}
else if(rc == JNI_EEXIST)
else if (rc == JNI_EEXIST)
{
errorString = "the process can only launch one JVM an not more";
}
else
{
errorString = "could not create the JVM instance (error code " + std::to_string(rc) + ")";
errorString = "could not create the JVM instance (error code " + std::to_string(rc) +
")";
}
}
else
@@ -113,7 +113,7 @@ std::shared_ptr<JavaEnvironmentFactory> JavaEnvironmentFactory::getInstance()
JavaEnvironmentFactory::~JavaEnvironmentFactory()
{
// todo: what if there are threads running using the jvm?? log something!
// todo: what if there are threads running using the jvm?? log something!
m_jvm->DestroyJavaVM();
}
@@ -126,7 +126,8 @@ std::shared_ptr<JavaEnvironment> JavaEnvironmentFactory::createEnvironment()
{
std::lock_guard<std::mutex> lock(m_threadIdToEnvAndUserCountMutex);
std::map<std::thread::id, std::pair<JNIEnv*, int>>::const_iterator it = m_threadIdToEnvAndUserCount.find(currentThreadId);
std::map<std::thread::id, std::pair<JNIEnv*, int>>::const_iterator it =
m_threadIdToEnvAndUserCount.find(currentThreadId);
if (it != m_threadIdToEnvAndUserCount.end())
{
env = it->second.first;
@@ -134,7 +135,8 @@ std::shared_ptr<JavaEnvironment> JavaEnvironmentFactory::createEnvironment()
else
{
m_jvm->AttachCurrentThread((void**)&env, NULL);
m_threadIdToEnvAndUserCount.insert(std::make_pair(currentThreadId, std::make_pair(env, 0)));
m_threadIdToEnvAndUserCount.insert(
std::make_pair(currentThreadId, std::make_pair(env, 0)));
}
}
@@ -145,17 +147,15 @@ std::shared_ptr<JavaEnvironmentFactory> JavaEnvironmentFactory::s_instance;
std::string JavaEnvironmentFactory::s_classPath;
JavaEnvironmentFactory::JavaEnvironmentFactory(JavaVM* jvm)
: m_jvm(jvm)
{
}
JavaEnvironmentFactory::JavaEnvironmentFactory(JavaVM* jvm): m_jvm(jvm) {}
void JavaEnvironmentFactory::registerEnvironment()
{
std::thread::id currentThreadId = std::this_thread::get_id();
{
std::lock_guard<std::mutex> lock(m_threadIdToEnvAndUserCountMutex);
std::map<std::thread::id, std::pair<JNIEnv*, int>>::iterator it = m_threadIdToEnvAndUserCount.find(currentThreadId);
std::map<std::thread::id, std::pair<JNIEnv*, int>>::iterator it =
m_threadIdToEnvAndUserCount.find(currentThreadId);
if (it != m_threadIdToEnvAndUserCount.end())
{
it->second.second++;
@@ -172,12 +172,13 @@ void JavaEnvironmentFactory::unregisterEnvironment()
std::thread::id currentThreadId = std::this_thread::get_id();
{
std::lock_guard<std::mutex> lock(m_threadIdToEnvAndUserCountMutex);
std::map<std::thread::id, std::pair<JNIEnv*, int>>::iterator it = m_threadIdToEnvAndUserCount.find(currentThreadId);
std::map<std::thread::id, std::pair<JNIEnv*, int>>::iterator it =
m_threadIdToEnvAndUserCount.find(currentThreadId);
if (it != m_threadIdToEnvAndUserCount.end())
{
it->second.second--;
if (it->second.second == 0)
{ // TODO: currently this happens quite often. do something about that.
{ // TODO: currently this happens quite often. do something about that.
m_jvm->DetachCurrentThread();
m_threadIdToEnvAndUserCount.erase(it);
}
@@ -188,5 +189,3 @@ void JavaEnvironmentFactory::unregisterEnvironment()
}
}
}
@@ -41,4 +41,4 @@ private:
std::mutex m_threadIdToEnvAndUserCountMutex;
};
#endif // JAVA_ENVIRONMENT_FACTORY_H
#endif // JAVA_ENVIRONMENT_FACTORY_H
+135 -82
View File
@@ -22,19 +22,14 @@ void JavaParser::clearCaches()
std::shared_ptr<JavaEnvironment> environment = factory->createEnvironment();
if (environment)
{
environment->callStaticVoidMethod(
"com/sourcetrail/JavaIndexer",
"clearCaches"
);
environment->callStaticVoidMethod("com/sourcetrail/JavaIndexer", "clearCaches");
}
}
}
JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<IndexerStateInfo> indexerStateInfo)
: Parser(client)
, m_indexerStateInfo(indexerStateInfo)
, m_id(s_nextParserId++)
, m_currentFileId(0)
JavaParser::JavaParser(
std::shared_ptr<ParserClient> client, std::shared_ptr<IndexerStateInfo> indexerStateInfo)
: Parser(client), m_indexerStateInfo(indexerStateInfo), m_id(s_nextParserId++), m_currentFileId(0)
{
const std::string errorString = utility::prepareJavaEnvironment();
if (!errorString.empty())
@@ -49,19 +44,37 @@ JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<Ind
std::vector<JavaEnvironment::NativeMethod> methods;
methods.push_back({ "getInterrupted", "(I)Z", (void*)&JavaParser::GetInterrupted });
methods.push_back({ "logInfo", "(ILjava/lang/String;)V", (void*)&JavaParser::LogInfo });
methods.push_back({ "logWarning", "(ILjava/lang/String;)V", (void*)&JavaParser::LogWarning });
methods.push_back({ "logError", "(ILjava/lang/String;)V", (void*)&JavaParser::LogError });
methods.push_back({ "recordSymbol", "(ILjava/lang/String;III)V", (void*)&JavaParser::RecordSymbol });
methods.push_back({ "recordSymbolWithLocation", "(ILjava/lang/String;IIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocation });
methods.push_back({ "recordSymbolWithLocationAndScope", "(ILjava/lang/String;IIIIIIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocationAndScope });
methods.push_back({ "recordSymbolWithLocationAndScopeAndSignature", "(ILjava/lang/String;IIIIIIIIIIIIIII)V", (void*)&JavaParser::RecordSymbolWithLocationAndScopeAndSignature });
methods.push_back({ "recordReference", "(IILjava/lang/String;Ljava/lang/String;IIII)V", (void*)&JavaParser::RecordReference });
methods.push_back({ "recordQualifierLocation", "(ILjava/lang/String;IIII)V", (void*)&JavaParser::RecordQualifierLocation });
methods.push_back({ "recordLocalSymbol", "(ILjava/lang/String;IIII)V", (void*)&JavaParser::RecordLocalSymbol });
methods.push_back({ "recordComment", "(IIIII)V", (void*)&JavaParser::RecordComment });
methods.push_back({ "recordError", "(ILjava/lang/String;IIIIII)V", (void*)&JavaParser::RecordError });
methods.push_back({"getInterrupted", "(I)Z", (void*)&JavaParser::GetInterrupted});
methods.push_back({"logInfo", "(ILjava/lang/String;)V", (void*)&JavaParser::LogInfo});
methods.push_back({"logWarning", "(ILjava/lang/String;)V", (void*)&JavaParser::LogWarning});
methods.push_back({"logError", "(ILjava/lang/String;)V", (void*)&JavaParser::LogError});
methods.push_back(
{"recordSymbol", "(ILjava/lang/String;III)V", (void*)&JavaParser::RecordSymbol});
methods.push_back(
{"recordSymbolWithLocation",
"(ILjava/lang/String;IIIIIII)V",
(void*)&JavaParser::RecordSymbolWithLocation});
methods.push_back(
{"recordSymbolWithLocationAndScope",
"(ILjava/lang/String;IIIIIIIIIII)V",
(void*)&JavaParser::RecordSymbolWithLocationAndScope});
methods.push_back(
{"recordSymbolWithLocationAndScopeAndSignature",
"(ILjava/lang/String;IIIIIIIIIIIIIII)V",
(void*)&JavaParser::RecordSymbolWithLocationAndScopeAndSignature});
methods.push_back(
{"recordReference",
"(IILjava/lang/String;Ljava/lang/String;IIII)V",
(void*)&JavaParser::RecordReference});
methods.push_back(
{"recordQualifierLocation",
"(ILjava/lang/String;IIII)V",
(void*)&JavaParser::RecordQualifierLocation});
methods.push_back(
{"recordLocalSymbol", "(ILjava/lang/String;IIII)V", (void*)&JavaParser::RecordLocalSymbol});
methods.push_back({"recordComment", "(IIIII)V", (void*)&JavaParser::RecordComment});
methods.push_back(
{"recordError", "(ILjava/lang/String;IIIIII)V", (void*)&JavaParser::RecordError});
m_javaEnvironment->registerNativeMethods("com/sourcetrail/JavaIndexer", methods);
}
@@ -85,7 +98,11 @@ void JavaParser::buildIndex(std::shared_ptr<IndexerCommandJava> indexerCommand)
classPath += path.str() + ";";
}
buildIndex(indexerCommand->getSourceFilePath(), indexerCommand->getLanguageStandard(), classPath, TextAccess::createFromFile(indexerCommand->getSourceFilePath()));
buildIndex(
indexerCommand->getSourceFilePath(),
indexerCommand->getLanguageStandard(),
classPath,
TextAccess::createFromFile(indexerCommand->getSourceFilePath()));
}
void JavaParser::buildIndex(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess)
@@ -109,7 +126,9 @@ void JavaParser::buildIndex(
std::string fileContent = utility::replace(textAccess->getText(), "\t", " ");
int verbose = ApplicationSettings::getInstance()->getLoggingEnabled() &&
ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled() ? 1 : 0;
ApplicationSettings::getInstance()->getVerboseIndexerLoggingEnabled()
? 1
: 0;
m_javaEnvironment->callStaticVoidMethod(
"com/sourcetrail/JavaIndexer",
@@ -119,8 +138,7 @@ void JavaParser::buildIndex(
fileContent,
utility::encodeToUtf8(languageStandard),
classPath,
verbose
);
verbose);
}
}
@@ -131,14 +149,6 @@ std::map<int, JavaParser*> JavaParser::s_parsers;
std::mutex JavaParser::s_parsersMutex;
// definition of native methods
bool JavaParser::doGetInterrupted()
@@ -161,10 +171,7 @@ void JavaParser::doLogError(jstring jError)
LOG_ERROR_STREAM_BARE(<< "Indexer - " << m_javaEnvironment->toStdString(jError));
}
void JavaParser::doRecordSymbol(
jstring jSymbolName, jint jSymbolKind,
jint jAccess, jint jDefinitionKind
)
void JavaParser::doRecordSymbol(jstring jSymbolName, jint jSymbolKind, jint jAccess, jint jDefinitionKind)
{
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
@@ -173,93 +180,140 @@ void JavaParser::doRecordSymbol(
}
void JavaParser::doRecordSymbolWithLocation(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint jAccess, jint jDefinitionKind
)
jstring jSymbolName,
jint jSymbolKind,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn,
jint jAccess,
jint jDefinitionKind)
{
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::TOKEN);
m_client->recordLocation(
symbolId,
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn),
ParseLocationType::TOKEN);
m_client->recordAccessKind(symbolId, intToAccessKind(jAccess));
m_client->recordDefinitionKind(symbolId, intToDefinitionKind(jDefinitionKind));
}
void JavaParser::doRecordSymbolWithLocationAndScope(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint scopeBeginLine, jint scopeBeginColumn, jint scopeEndLine, jint scopeEndColumn,
jint jAccess, jint jDefinitionKind
)
jstring jSymbolName,
jint jSymbolKind,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn,
jint scopeBeginLine,
jint scopeBeginColumn,
jint scopeEndLine,
jint scopeEndColumn,
jint jAccess,
jint jDefinitionKind)
{
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn), ParseLocationType::SCOPE);
m_client->recordLocation(
symbolId,
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn),
ParseLocationType::TOKEN);
m_client->recordLocation(
symbolId,
ParseLocation(m_currentFileId, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn),
ParseLocationType::SCOPE);
m_client->recordAccessKind(symbolId, intToAccessKind(jAccess));
m_client->recordDefinitionKind(symbolId, intToDefinitionKind(jDefinitionKind));
}
void JavaParser::doRecordSymbolWithLocationAndScopeAndSignature(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint scopeBeginLine, jint scopeBeginColumn, jint scopeEndLine, jint scopeEndColumn,
jint signatureBeginLine, jint signatureBeginColumn, jint signatureEndLine, jint signatureEndColumn,
jint jAccess, jint jDefinitionKind
)
jstring jSymbolName,
jint jSymbolKind,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn,
jint scopeBeginLine,
jint scopeBeginColumn,
jint scopeEndLine,
jint scopeEndColumn,
jint signatureBeginLine,
jint signatureBeginColumn,
jint signatureEndLine,
jint signatureEndColumn,
jint jAccess,
jint jDefinitionKind)
{
Id symbolId = getOrCreateSymbolId(jSymbolName);
m_client->recordSymbolKind(symbolId, intToSymbolKind(jSymbolKind));
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn), ParseLocationType::SCOPE);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, signatureBeginLine, signatureBeginColumn, signatureEndLine, signatureEndColumn), ParseLocationType::SIGNATURE);
m_client->recordLocation(
symbolId,
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn),
ParseLocationType::TOKEN);
m_client->recordLocation(
symbolId,
ParseLocation(m_currentFileId, scopeBeginLine, scopeBeginColumn, scopeEndLine, scopeEndColumn),
ParseLocationType::SCOPE);
m_client->recordLocation(
symbolId,
ParseLocation(
m_currentFileId, signatureBeginLine, signatureBeginColumn, signatureEndLine, signatureEndColumn),
ParseLocationType::SIGNATURE);
m_client->recordAccessKind(symbolId, intToAccessKind(jAccess));
m_client->recordDefinitionKind(symbolId, intToDefinitionKind(jDefinitionKind));
}
void JavaParser::doRecordReference(
jint jReferenceKind, jstring jReferencedName, jstring jContextName,
jint beginLine, jint beginColumn, jint endLine, jint endColumn
)
jint jReferenceKind,
jstring jReferencedName,
jstring jContextName,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn)
{
m_client->recordReference(
intToReferenceKind(jReferenceKind),
getOrCreateSymbolId(jReferencedName),
getOrCreateSymbolId(jContextName),
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn)
);
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn));
}
void JavaParser::doRecordQualifierLocation(
jstring jQualifierName,
jint beginLine, jint beginColumn, jint endLine, jint endColumn
)
jstring jQualifierName, jint beginLine, jint beginColumn, jint endLine, jint endColumn)
{
Id symbolId = getOrCreateSymbolId(jQualifierName);
m_client->recordLocation(symbolId, ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn), ParseLocationType::QUALIFIER);
m_client->recordLocation(
symbolId,
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn),
ParseLocationType::QUALIFIER);
}
void JavaParser::doRecordLocalSymbol(jstring jSymbolName, jint beginLine, jint beginColumn, jint endLine, jint endColumn)
void JavaParser::doRecordLocalSymbol(
jstring jSymbolName, jint beginLine, jint beginColumn, jint endLine, jint endColumn)
{
m_client->recordLocalSymbol(
NameHierarchy::deserialize(utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName))).getQualifiedName(),
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn)
);
NameHierarchy::deserialize(
utility::decodeFromUtf8(m_javaEnvironment->toStdString(jSymbolName)))
.getQualifiedName(),
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn));
}
void JavaParser::doRecordComment(
jint beginLine, jint beginColumn, jint endLine, jint endColumn
)
void JavaParser::doRecordComment(jint beginLine, jint beginColumn, jint endLine, jint endColumn)
{
m_client->recordComment(
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn)
);
ParseLocation(m_currentFileId, beginLine, beginColumn, endLine, endColumn));
}
void JavaParser::doRecordError(
jstring jMessage, jint jFatal, jint jIndexed,
jint beginLine, jint beginColumn, jint endLine, jint endColumn
)
jstring jMessage,
jint jFatal,
jint jIndexed,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn)
{
bool fatal = jFatal;
bool indexed = jIndexed;
@@ -269,8 +323,7 @@ void JavaParser::doRecordError(
fatal,
indexed,
FilePath(),
ParseLocation(m_currentFileId, beginLine, beginColumn)
);
ParseLocation(m_currentFileId, beginLine, beginColumn));
}
Id JavaParser::getOrCreateSymbolId(jstring jSymbolName)
+181 -84
View File
@@ -9,8 +9,8 @@
#include "IndexerCommandJava.h"
#include "IndexerStateInfo.h"
#include "JavaEnvironment.h"
#include "logging.h"
#include "Parser.h"
#include "logging.h"
#include "types.h"
struct JNIEnv_;
@@ -26,7 +26,7 @@ typedef int jint;
#endif
class _jstring;
typedef _jstring *jstring;
typedef _jstring* jstring;
class FilePath;
class TextAccess;
@@ -57,17 +57,33 @@ private:
#define MAKE_PARAMS_4(t1, t2, t3, t4) , t1 arg1, t2 arg2, t3 arg3, t4 arg4
#define MAKE_PARAMS_5(t1, t2, t3, t4, t5) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5
#define MAKE_PARAMS_6(t1, t2, t3, t4, t5, t6) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6
#define MAKE_PARAMS_7(t1, t2, t3, t4, t5, t6, t7) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7
#define MAKE_PARAMS_8(t1, t2, t3, t4, t5, t6, t7, t8) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8
#define MAKE_PARAMS_9(t1, t2, t3, t4, t5, t6, t7, t8, t9) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9
#define MAKE_PARAMS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10
#define MAKE_PARAMS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11
#define MAKE_PARAMS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12
#define MAKE_PARAMS_13(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13
#define MAKE_PARAMS_14(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13, t14 arg14
#define MAKE_PARAMS_15(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13, t14 arg14, t15 arg15
#define MAKE_PARAMS_16(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) , t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, t11 arg11, t12 arg12, t13 arg13, t14 arg14, t15 arg15, t16 arg16
//.. add as many MAKE_PARAMS_* as required
#define MAKE_PARAMS_7(t1, t2, t3, t4, t5, t6, t7) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7
#define MAKE_PARAMS_8(t1, t2, t3, t4, t5, t6, t7, t8) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8
#define MAKE_PARAMS_9(t1, t2, t3, t4, t5, t6, t7, t8, t9) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9
#define MAKE_PARAMS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10
#define MAKE_PARAMS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, \
t11 arg11
#define MAKE_PARAMS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, \
t11 arg11, t12 arg12
#define MAKE_PARAMS_13(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, \
t11 arg11, t12 arg12, t13 arg13
#define MAKE_PARAMS_14(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, \
t11 arg11, t12 arg12, t13 arg13, t14 arg14
#define MAKE_PARAMS_15(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, \
t11 arg11, t12 arg12, t13 arg13, t14 arg14, t15 arg15
#define MAKE_PARAMS_16(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) \
, t1 arg1, t2 arg2, t3 arg3, t4 arg4, t5 arg5, t6 arg6, t7 arg7, t8 arg8, t9 arg9, t10 arg10, \
t11 arg11, t12 arg12, t13 arg13, t14 arg14, t15 arg15, t16 arg16
//.. add as many MAKE_PARAMS_* as required
#define MAKE_ARGS_0()
#define MAKE_ARGS_1() arg1
@@ -82,76 +98,94 @@ private:
#define MAKE_ARGS_10() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10
#define MAKE_ARGS_11() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11
#define MAKE_ARGS_12() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12
#define MAKE_ARGS_13() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13
#define MAKE_ARGS_14() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14
#define MAKE_ARGS_15() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15
#define MAKE_ARGS_16() arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16
//.. add as many MAKE_ARGS_* as there are MAKE_PARAMS_*
#define MAKE_ARGS_13() \
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13
#define MAKE_ARGS_14() \
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14
#define MAKE_ARGS_15() \
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15
#define MAKE_ARGS_16() \
arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, \
arg15, arg16
//.. add as many MAKE_ARGS_* as there are MAKE_PARAMS_*
#define DEF_RELAYING_METHOD_0(NAME) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_0(), MAKE_ARGS_0())
#define DEF_RELAYING_METHOD_0(NAME) DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_0(), MAKE_ARGS_0())
#define DEF_RELAYING_METHOD_1(NAME, t1) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_1(t1), MAKE_ARGS_1())
#define DEF_RELAYING_METHOD_1(NAME, t1) DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_1(t1), MAKE_ARGS_1())
#define DEF_RELAYING_METHOD_2(NAME, t1, t2) \
#define DEF_RELAYING_METHOD_2(NAME, t1, t2) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_2(t1, t2), MAKE_ARGS_2())
#define DEF_RELAYING_METHOD_3(NAME, t1, t2, t3) \
#define DEF_RELAYING_METHOD_3(NAME, t1, t2, t3) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_3(t1, t2, t3), MAKE_ARGS_3())
#define DEF_RELAYING_METHOD_4(NAME, t1, t2, t3, t4) \
#define DEF_RELAYING_METHOD_4(NAME, t1, t2, t3, t4) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_4(t1, t2, t3, t4), MAKE_ARGS_4())
#define DEF_RELAYING_METHOD_5(NAME, t1, t2, t3, t4, t5) \
#define DEF_RELAYING_METHOD_5(NAME, t1, t2, t3, t4, t5) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_5(t1, t2, t3, t4, t5), MAKE_ARGS_5())
#define DEF_RELAYING_METHOD_6(NAME, t1, t2, t3, t4, t5, t6) \
#define DEF_RELAYING_METHOD_6(NAME, t1, t2, t3, t4, t5, t6) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_6(t1, t2, t3, t4, t5, t6), MAKE_ARGS_6())
#define DEF_RELAYING_METHOD_7(NAME, t1, t2, t3, t4, t5, t6, t7) \
#define DEF_RELAYING_METHOD_7(NAME, t1, t2, t3, t4, t5, t6, t7) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_7(t1, t2, t3, t4, t5, t6, t7), MAKE_ARGS_7())
#define DEF_RELAYING_METHOD_8(NAME, t1, t2, t3, t4, t5, t6, t7, t8) \
#define DEF_RELAYING_METHOD_8(NAME, t1, t2, t3, t4, t5, t6, t7, t8) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_8(t1, t2, t3, t4, t5, t6, t7, t8), MAKE_ARGS_8())
#define DEF_RELAYING_METHOD_9(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
#define DEF_RELAYING_METHOD_9(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_9(t1, t2, t3, t4, t5, t6, t7, t8, t9), MAKE_ARGS_9())
#define DEF_RELAYING_METHOD_10(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10), MAKE_ARGS_10())
#define DEF_RELAYING_METHOD_10(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) \
DEF_RELAYING_METHOD( \
NAME, MAKE_PARAMS_10(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10), MAKE_ARGS_10())
#define DEF_RELAYING_METHOD_11(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11), MAKE_ARGS_11())
#define DEF_RELAYING_METHOD_11(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11) \
DEF_RELAYING_METHOD( \
NAME, MAKE_PARAMS_11(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11), MAKE_ARGS_11())
#define DEF_RELAYING_METHOD_12(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12), MAKE_ARGS_12())
#define DEF_RELAYING_METHOD_12(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12) \
DEF_RELAYING_METHOD( \
NAME, MAKE_PARAMS_12(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12), MAKE_ARGS_12())
#define DEF_RELAYING_METHOD_13(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_13(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13), MAKE_ARGS_13())
#define DEF_RELAYING_METHOD_13(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13) \
DEF_RELAYING_METHOD( \
NAME, MAKE_PARAMS_13(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13), MAKE_ARGS_13())
#define DEF_RELAYING_METHOD_14(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_14(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14), MAKE_ARGS_14())
#define DEF_RELAYING_METHOD_14(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14) \
DEF_RELAYING_METHOD( \
NAME, \
MAKE_PARAMS_14(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14), \
MAKE_ARGS_14())
#define DEF_RELAYING_METHOD_15(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_15(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15), MAKE_ARGS_15())
#define DEF_RELAYING_METHOD_15( \
NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15) \
DEF_RELAYING_METHOD( \
NAME, \
MAKE_PARAMS_15(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15), \
MAKE_ARGS_15())
#define DEF_RELAYING_METHOD_16(NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) \
DEF_RELAYING_METHOD(NAME, MAKE_PARAMS_16(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16), MAKE_ARGS_16())
#define DEF_RELAYING_METHOD_16( \
NAME, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16) \
DEF_RELAYING_METHOD( \
NAME, \
MAKE_PARAMS_16(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16), \
MAKE_ARGS_16())
#define DEF_RELAYING_METHOD(NAME, PARAMETERS, ARGUMENTS) \
static void NAME(JNIEnv *env, jobject objectOrClass, jint parserId PARAMETERS) \
{ \
std::map<int, JavaParser*>::iterator it = s_parsers.find(int(parserId)); \
if (it != s_parsers.end()) \
{ \
it->second->do##NAME(ARGUMENTS); \
} \
else \
{ \
LOG_ERROR("parser with id " + std::to_string(parserId) + " not found"); \
} \
#define DEF_RELAYING_METHOD(NAME, PARAMETERS, ARGUMENTS) \
static void NAME(JNIEnv* env, jobject objectOrClass, jint parserId PARAMETERS) \
{ \
std::map<int, JavaParser*>::iterator it = s_parsers.find(int(parserId)); \
if (it != s_parsers.end()) \
{ \
it->second->do##NAME(ARGUMENTS); \
} \
else \
{ \
LOG_ERROR("parser with id " + std::to_string(parserId) + " not found"); \
} \
}
DEF_RELAYING_METHOD_1(LogInfo, jstring)
@@ -159,15 +193,45 @@ private:
DEF_RELAYING_METHOD_1(LogError, jstring)
DEF_RELAYING_METHOD_4(RecordSymbol, jstring, jint, jint, jint)
DEF_RELAYING_METHOD_8(RecordSymbolWithLocation, jstring, jint, jint, jint, jint, jint, jint, jint)
DEF_RELAYING_METHOD_12(RecordSymbolWithLocationAndScope, jstring, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint)
DEF_RELAYING_METHOD_16(RecordSymbolWithLocationAndScopeAndSignature, jstring, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint)
DEF_RELAYING_METHOD_12(
RecordSymbolWithLocationAndScope,
jstring,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint)
DEF_RELAYING_METHOD_16(
RecordSymbolWithLocationAndScopeAndSignature,
jstring,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint,
jint)
DEF_RELAYING_METHOD_7(RecordReference, jint, jstring, jstring, jint, jint, jint, jint)
DEF_RELAYING_METHOD_5(RecordQualifierLocation, jstring, jint, jint, jint, jint)
DEF_RELAYING_METHOD_5(RecordLocalSymbol, jstring, jint, jint, jint, jint)
DEF_RELAYING_METHOD_4(RecordComment, jint, jint, jint, jint)
DEF_RELAYING_METHOD_7(RecordError, jstring, jint, jint, jint, jint, jint, jint)
static bool GetInterrupted(JNIEnv *env, jobject objectOrClass, jint parserId)
static bool GetInterrupted(JNIEnv* env, jobject objectOrClass, jint parserId)
{
std::map<int, JavaParser*>::iterator it = s_parsers.find(int(parserId));
if (it != s_parsers.end())
@@ -187,7 +251,6 @@ private:
static std::mutex s_parsersMutex;
bool doGetInterrupted();
void doLogInfo(jstring jInfo);
@@ -196,37 +259,71 @@ private:
void doLogError(jstring jError);
void doRecordSymbol(
jstring jSymbolName, jint jSymbolKind,
jint jAccess, jint jDefinitionKind
);
void doRecordSymbol(jstring jSymbolName, jint jSymbolKind, jint jAccess, jint jDefinitionKind);
void doRecordSymbolWithLocation(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint jAccess, jint jDefinitionKind
);
jstring jSymbolName,
jint jSymbolKind,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn,
jint jAccess,
jint jDefinitionKind);
void doRecordSymbolWithLocationAndScope(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint scopeBeginLine, jint scopeBeginColumn, jint scopeEndLine, jint scopeEndColumn,
jint jAccess, jint jDefinitionKind
);
jstring jSymbolName,
jint jSymbolKind,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn,
jint scopeBeginLine,
jint scopeBeginColumn,
jint scopeEndLine,
jint scopeEndColumn,
jint jAccess,
jint jDefinitionKind);
void doRecordSymbolWithLocationAndScopeAndSignature(
jstring jSymbolName, jint jSymbolKind,
jint beginLine, jint beginColumn, jint endLine, jint endColumn,
jint scopeBeginLine, jint scopeBeginColumn, jint scopeEndLine, jint scopeEndColumn,
jint signatureBeginLine, jint signatureBeginColumn, jint signatureEndLine, jint signatureEndColumn,
jint jAccess, jint jDefinitionKind
);
jstring jSymbolName,
jint jSymbolKind,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn,
jint scopeBeginLine,
jint scopeBeginColumn,
jint scopeEndLine,
jint scopeEndColumn,
jint signatureBeginLine,
jint signatureBeginColumn,
jint signatureEndLine,
jint signatureEndColumn,
jint jAccess,
jint jDefinitionKind);
void doRecordReference(jint jReferenceKind, jstring jReferencedName, jstring jContextName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordQualifierLocation(jstring jQualifierName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordLocalSymbol(jstring jSymbolName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordReference(
jint jReferenceKind,
jstring jReferencedName,
jstring jContextName,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn);
void doRecordQualifierLocation(
jstring jQualifierName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordLocalSymbol(
jstring jSymbolName, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordComment(jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordError(jstring jMessage, jint jFatal, jint jIndexed, jint beginLine, jint beginColumn, jint endLine, jint endColumn);
void doRecordError(
jstring jMessage,
jint jFatal,
jint jIndexed,
jint beginLine,
jint beginColumn,
jint endLine,
jint endColumn);
Id getOrCreateSymbolId(jstring jSymbolName);
@@ -240,4 +337,4 @@ private:
std::map<std::string, Id> m_symbolNameToIdMap;
};
#endif // JAVA_PARSER_H
#endif // JAVA_PARSER_H
@@ -21,18 +21,24 @@ bool SourceGroupFactoryModuleJava::supports(SourceGroupType type) const
return false;
}
std::shared_ptr<SourceGroup> SourceGroupFactoryModuleJava::createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) const
std::shared_ptr<SourceGroup> SourceGroupFactoryModuleJava::createSourceGroup(
std::shared_ptr<SourceGroupSettings> settings) const
{
std::shared_ptr<SourceGroup> sourceGroup;
if (std::shared_ptr<SourceGroupSettingsJavaEmpty> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaEmpty>(settings))
if (std::shared_ptr<SourceGroupSettingsJavaEmpty> javaSettings =
std::dynamic_pointer_cast<SourceGroupSettingsJavaEmpty>(settings))
{
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJavaEmpty(javaSettings));
}
else if (std::shared_ptr<SourceGroupSettingsJavaGradle> javaSettings = std::dynamic_pointer_cast<SourceGroupSettingsJavaGradle>(settings))
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))
else if (
std::shared_ptr<SourceGroupSettingsJavaMaven> javaSettings =
std::dynamic_pointer_cast<SourceGroupSettingsJavaMaven>(settings))
{
sourceGroup = std::shared_ptr<SourceGroup>(new SourceGroupJavaMaven(javaSettings));
}
@@ -7,7 +7,8 @@ class SourceGroupFactoryModuleJava: public SourceGroupFactoryModule
{
public:
bool supports(SourceGroupType type) const override;
std::shared_ptr<SourceGroup> createSourceGroup(std::shared_ptr<SourceGroupSettings> settings) const override;
std::shared_ptr<SourceGroup> createSourceGroup(
std::shared_ptr<SourceGroupSettings> settings) const override;
};
#endif // SOURCE_GROUP_FACTORY_MODULE_JAVA_H
#endif // SOURCE_GROUP_FACTORY_MODULE_JAVA_H
+14 -12
View File
@@ -1,19 +1,19 @@
#include "SourceGroupJava.h"
#include "IndexerCommandJava.h"
#include "FileManager.h"
#include "logging.h"
#include "IndexerCommandJava.h"
#include "RefreshInfo.h"
#include "SourceGroupSettings.h"
#include "SourceGroupSettingsWithExcludeFilters.h"
#include "SourceGroupSettingsWithJavaStandard.h"
#include "SourceGroupSettingsWithSourceExtensions.h"
#include "logging.h"
std::set<FilePath> SourceGroupJava::filterToContainedFilePaths(const std::set<FilePath>& filePaths) const
{
std::set<FilePath> containedFilePaths;
const std::set<FilePath> allSourceFilePaths = getAllSourceFilePaths();
for (const FilePath& filePath : filePaths)
for (const FilePath& filePath: filePaths)
{
if (allSourceFilePaths.find(filePath) != allSourceFilePaths.end())
{
@@ -28,16 +28,19 @@ std::set<FilePath> SourceGroupJava::getAllSourceFilePaths() const
FileManager fileManager;
fileManager.update(
getAllSourcePaths(),
dynamic_cast<const SourceGroupSettingsWithExcludeFilters*>(getSourceGroupSettings().get())->getExcludeFiltersExpandedAndAbsolute(),
dynamic_cast<const SourceGroupSettingsWithSourceExtensions*>(getSourceGroupSettings().get())->getSourceExtensions()
);
dynamic_cast<const SourceGroupSettingsWithExcludeFilters*>(getSourceGroupSettings().get())
->getExcludeFiltersExpandedAndAbsolute(),
dynamic_cast<const SourceGroupSettingsWithSourceExtensions*>(getSourceGroupSettings().get())
->getSourceExtensions());
return fileManager.getAllSourceFilePaths();
}
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands(const RefreshInfo& info) const
std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands(
const RefreshInfo& info) const
{
const std::wstring languageStandard =
dynamic_cast<const SourceGroupSettingsWithJavaStandard*>(getSourceGroupSettings().get())->getJavaStandard();
const std::wstring languageStandard = dynamic_cast<const SourceGroupSettingsWithJavaStandard*>(
getSourceGroupSettings().get())
->getJavaStandard();
std::vector<FilePath> classPath = getClassPath();
@@ -46,9 +49,8 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
{
if (info.filesToIndex.find(sourcePath) != info.filesToIndex.end())
{
indexerCommands.push_back(std::make_shared<IndexerCommandJava>(
sourcePath, languageStandard, classPath
));
indexerCommands.push_back(
std::make_shared<IndexerCommandJava>(sourcePath, languageStandard, classPath));
}
}
+2 -3
View File
@@ -7,8 +7,7 @@
#include "SourceGroup.h"
class SourceGroupJava
: public SourceGroup
class SourceGroupJava: public SourceGroup
{
public:
std::set<FilePath> filterToContainedFilePaths(const std::set<FilePath>& filePaths) const override;
@@ -22,4 +21,4 @@ private:
std::vector<FilePath> getClassPath() const;
};
#endif // SOURCE_GROUP_JAVA_H
#endif // SOURCE_GROUP_JAVA_H
@@ -25,7 +25,9 @@ std::vector<FilePath> SourceGroupJavaEmpty::getAllSourcePaths() const
std::vector<FilePath> SourceGroupJavaEmpty::doGetClassPath() const
{
return utility::getClassPath(
m_settings->getClasspathExpandedAndAbsolute(), m_settings->getUseJreSystemLibrary(), getAllSourceFilePaths());
m_settings->getClasspathExpandedAndAbsolute(),
m_settings->getUseJreSystemLibrary(),
getAllSourceFilePaths());
}
std::shared_ptr<SourceGroupSettings> SourceGroupJavaEmpty::getSourceGroupSettings()
+2 -3
View File
@@ -8,8 +8,7 @@
class SourceGroupSettingsJavaEmpty;
class SourceGroupJavaEmpty
: public SourceGroupJava
class SourceGroupJavaEmpty: public SourceGroupJava
{
public:
SourceGroupJavaEmpty(std::shared_ptr<SourceGroupSettingsJavaEmpty> settings);
@@ -24,4 +23,4 @@ private:
std::shared_ptr<SourceGroupSettingsJavaEmpty> m_settings;
};
#endif // SOURCE_GROUP_JAVA_EMPTY_H
#endif // SOURCE_GROUP_JAVA_EMPTY_H
+20 -18
View File
@@ -3,9 +3,9 @@
#include "Application.h"
#include "DialogView.h"
#include "FileSystem.h"
#include "logging.h"
#include "SourceGroupSettingsJavaGradle.h"
#include "ScopedFunctor.h"
#include "SourceGroupSettingsJavaGradle.h"
#include "logging.h"
#include "utility.h"
#include "utilityGradle.h"
#include "utilityJava.h"
@@ -43,11 +43,9 @@ std::vector<FilePath> SourceGroupJavaGradle::doGetClassPath() const
if (m_settings->getGradleDependenciesDirectoryPath().exists())
{
std::vector<FilePath> gradleJarPaths = FileSystem::getFilePathsFromDirectory(
m_settings->getGradleDependenciesDirectoryPath(),
{ L".jar" }
);
m_settings->getGradleDependenciesDirectoryPath(), {L".jar"});
for (const FilePath& gradleJarPath : gradleJarPaths)
for (const FilePath& gradleJarPath: gradleJarPaths)
{
LOG_INFO(L"Adding jar to classpath: " + gradleJarPath.wstr());
}
@@ -72,21 +70,21 @@ bool SourceGroupJavaGradle::prepareGradleData()
{
if (m_settings && m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists())
{
const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory();
const FilePath projectRootPath =
m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory();
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP);
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(
DialogView::UseCase::PROJECT_SETUP);
ScopedFunctor dialogHider([&dialogView]() {
dialogView->hideUnknownProgressDialog();
});
ScopedFunctor dialogHider([&dialogView]() { dialogView->hideUnknownProgressDialog(); });
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Gradle\nExporting Dependencies");
dialogView->showUnknownProgressDialog(
L"Preparing Project", L"Gradle\nExporting Dependencies");
bool success = utility::gradleCopyDependencies(
projectRootPath,
m_settings->getGradleDependenciesDirectoryPath(),
m_settings->getShouldIndexGradleTests()
);
m_settings->getShouldIndexGradleTests());
return success;
}
@@ -99,11 +97,15 @@ std::vector<FilePath> SourceGroupJavaGradle::doGetAllSourcePaths() const
std::vector<FilePath> sourcePaths;
if (m_settings->getGradleProjectFilePathExpandedAndAbsolute().exists())
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP);
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Gradle\nFetching Source Directories");
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(
DialogView::UseCase::PROJECT_SETUP);
dialogView->showUnknownProgressDialog(
L"Preparing Project", L"Gradle\nFetching Source Directories");
const FilePath projectRootPath = m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::gradleGetAllSourceDirectories(projectRootPath, m_settings->getShouldIndexGradleTests());
const FilePath projectRootPath =
m_settings->getGradleProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::gradleGetAllSourceDirectories(
projectRootPath, m_settings->getShouldIndexGradleTests());
dialogView->hideUnknownProgressDialog();
}
+2 -3
View File
@@ -9,8 +9,7 @@
class SourceGroupSettingsJavaGradle;
class SourceGroupJavaGradle
: public SourceGroupJava
class SourceGroupJavaGradle: public SourceGroupJava
{
public:
SourceGroupJavaGradle(std::shared_ptr<SourceGroupSettingsJavaGradle> settings);
@@ -28,4 +27,4 @@ private:
mutable SingleValueCache<std::vector<FilePath>> m_allSourcePathsCache;
};
#endif // SOURCE_GROUP_JAVA_GRADLE_H
#endif // SOURCE_GROUP_JAVA_GRADLE_H
+20 -19
View File
@@ -4,10 +4,10 @@
#include "ApplicationSettings.h"
#include "DialogView.h"
#include "FileSystem.h"
#include "logging.h"
#include "MessageStatus.h"
#include "ScopedFunctor.h"
#include "SourceGroupSettingsJavaMaven.h"
#include "logging.h"
#include "utility.h"
#include "utilityJava.h"
#include "utilityMaven.h"
@@ -45,11 +45,9 @@ std::vector<FilePath> SourceGroupJavaMaven::doGetClassPath() const
if (m_settings && m_settings->getMavenDependenciesDirectoryPath().exists())
{
std::vector<FilePath> mavenJarPaths = FileSystem::getFilePathsFromDirectory(
m_settings->getMavenDependenciesDirectoryPath(),
{ L".jar" }
);
m_settings->getMavenDependenciesDirectoryPath(), {L".jar"});
for (const FilePath& mavenJarPath : mavenJarPaths)
for (const FilePath& mavenJarPath: mavenJarPaths)
{
LOG_INFO(L"Adding jar to classpath: " + mavenJarPath.wstr());
}
@@ -75,14 +73,15 @@ bool SourceGroupJavaMaven::prepareMavenData()
if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
{
const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath();
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
const FilePath projectRootPath =
m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP);
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nGenerating Source Files");
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(
DialogView::UseCase::PROJECT_SETUP);
dialogView->showUnknownProgressDialog(
L"Preparing Project", L"Maven\nGenerating Source Files");
ScopedFunctor dialogHider([&dialogView](){
dialogView->hideUnknownProgressDialog();
});
ScopedFunctor dialogHider([&dialogView]() { dialogView->hideUnknownProgressDialog(); });
const std::wstring errorMessage = utility::mavenGenerateSources(mavenPath, projectRootPath);
if (!errorMessage.empty())
@@ -92,11 +91,11 @@ bool SourceGroupJavaMaven::prepareMavenData()
return false;
}
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nExporting Dependencies");
dialogView->showUnknownProgressDialog(
L"Preparing Project", L"Maven\nExporting Dependencies");
bool success = utility::mavenCopyDependencies(
mavenPath, projectRootPath, m_settings->getMavenDependenciesDirectoryPath()
);
mavenPath, projectRootPath, m_settings->getMavenDependenciesDirectoryPath());
return success;
}
@@ -109,18 +108,20 @@ std::vector<FilePath> SourceGroupJavaMaven::doGetAllSourcePaths() const
std::vector<FilePath> sourcePaths;
if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists())
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP);
dialogView->showUnknownProgressDialog(L"Preparing Project", L"Maven\nFetching Source Directories");
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(
DialogView::UseCase::PROJECT_SETUP);
dialogView->showUnknownProgressDialog(
L"Preparing Project", L"Maven\nFetching Source Directories");
const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath());
const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
const FilePath projectRootPath =
m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(
mavenPath,
projectRootPath,
m_settings->getMavenDependenciesDirectoryPath(),
m_settings->getShouldIndexMavenTests()
);
m_settings->getShouldIndexMavenTests());
dialogView->hideUnknownProgressDialog();
}
+1 -1
View File
@@ -27,4 +27,4 @@ private:
mutable SingleValueCache<std::vector<FilePath>> m_allSourcePathsCache;
};
#endif // SOURCE_GROUP_JAVA_MAVEN_H
#endif // SOURCE_GROUP_JAVA_MAVEN_H
+111 -107
View File
@@ -6,124 +6,128 @@
#include "ApplicationSettings.h"
#include "JavaEnvironment.h"
#include "JavaEnvironmentFactory.h"
#include "logging.h"
#include "MessageStatus.h"
#include "ResourcePaths.h"
#include "logging.h"
#include "utilityJava.h"
#include "utilityString.h"
namespace utility
{
bool gradleCopyDependencies(const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDependencies)
bool gradleCopyDependencies(
const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDependencies)
{
const FilePath gradleInitScriptPath = ResourcePaths::getJavaPath().concatenate(
L"gradle/init.gradle");
utility::setJavaHomeVariableIfNotExists();
utility::prepareJavaEnvironment();
std::shared_ptr<JavaEnvironment> javaEnvironment =
JavaEnvironmentFactory::getInstance()->createEnvironment();
bool success = javaEnvironment->callStaticVoidMethod(
"com/sourcetrail/gradle/InfoRetriever",
"copyCompileLibs",
utility::encodeToUtf8(projectDirectoryPath.wstr()),
utility::encodeToUtf8(gradleInitScriptPath.wstr()),
utility::encodeToUtf8(outputDirectoryPath.wstr()));
if (success && addTestDependencies)
{
const FilePath gradleInitScriptPath = ResourcePaths::getJavaPath().concatenate(L"gradle/init.gradle");
utility::setJavaHomeVariableIfNotExists();
utility::prepareJavaEnvironment();
std::shared_ptr<JavaEnvironment> javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment();
bool success = javaEnvironment->callStaticVoidMethod(
success = javaEnvironment->callStaticVoidMethod(
"com/sourcetrail/gradle/InfoRetriever",
"copyCompileLibs",
"copyTestCompileLibs",
utility::encodeToUtf8(projectDirectoryPath.wstr()),
utility::encodeToUtf8(gradleInitScriptPath.wstr()),
utility::encodeToUtf8(outputDirectoryPath.wstr())
);
if (success && addTestDependencies)
{
success = javaEnvironment->callStaticVoidMethod(
"com/sourcetrail/gradle/InfoRetriever",
"copyTestCompileLibs",
utility::encodeToUtf8(projectDirectoryPath.wstr()),
utility::encodeToUtf8(gradleInitScriptPath.wstr()),
utility::encodeToUtf8(outputDirectoryPath.wstr())
);
}
return success;
utility::encodeToUtf8(outputDirectoryPath.wstr()));
}
std::vector<FilePath> gradleGetAllSourceDirectories(const FilePath& projectDirectoryPath, bool addTestDirectories)
{
const FilePath gradleInitScriptPath = ResourcePaths::getJavaPath().concatenate(L"gradle/init.gradle");
utility::setJavaHomeVariableIfNotExists();
utility::prepareJavaEnvironment();
std::set<std::wstring> uncheckedDirectories;
{
std::shared_ptr<JavaEnvironment> javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment();
{
std::string output = "";
javaEnvironment->callStaticStringMethod(
"com/sourcetrail/gradle/InfoRetriever",
"getMainSrcDirs",
output,
utility::encodeToUtf8(projectDirectoryPath.wstr()),
utility::encodeToUtf8(gradleInitScriptPath.wstr())
);
if (utility::isPrefix<std::string>("[ERROR]", utility::trim(output)))
{
// TODO: move error handling to caller of this function
const std::wstring dialogMessage =
L"The following error occurred while executing a Gradle command:\n\n" +
utility::decodeFromUtf8(utility::replace(output, "\r\n", "\n"));
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
return std::vector<FilePath>();
}
for (const std::string mainSrcDir : utility::splitToVector(output, ";"))
{
uncheckedDirectories.insert(utility::decodeFromUtf8(mainSrcDir));
}
}
if (addTestDirectories)
{
std::string output = "";
javaEnvironment->callStaticStringMethod(
"com/sourcetrail/gradle/InfoRetriever",
"getTestSrcDirs",
output,
utility::encodeToUtf8(projectDirectoryPath.wstr()),
utility::encodeToUtf8(gradleInitScriptPath.wstr())
);
if (utility::isPrefix<std::string>("[ERROR]", utility::trim(output)))
{
// TODO: move error handling to caller of this function
const std::wstring dialogMessage =
L"The following error occurred while executing a Gradle command:\n\n" +
utility::decodeFromUtf8(utility::replace(output, "\r\n", "\n"));
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
return std::vector<FilePath>();
}
for (const std::string testSrcDir : utility::splitToVector(output, ";"))
{
uncheckedDirectories.insert(utility::decodeFromUtf8(testSrcDir));
}
}
}
std::vector<FilePath> directories;
for (const std::wstring& 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;
}
return success;
}
std::vector<FilePath> gradleGetAllSourceDirectories(
const FilePath& projectDirectoryPath, bool addTestDirectories)
{
const FilePath gradleInitScriptPath = ResourcePaths::getJavaPath().concatenate(
L"gradle/init.gradle");
utility::setJavaHomeVariableIfNotExists();
utility::prepareJavaEnvironment();
std::set<std::wstring> uncheckedDirectories;
{
std::shared_ptr<JavaEnvironment> javaEnvironment =
JavaEnvironmentFactory::getInstance()->createEnvironment();
{
std::string output = "";
javaEnvironment->callStaticStringMethod(
"com/sourcetrail/gradle/InfoRetriever",
"getMainSrcDirs",
output,
utility::encodeToUtf8(projectDirectoryPath.wstr()),
utility::encodeToUtf8(gradleInitScriptPath.wstr()));
if (utility::isPrefix<std::string>("[ERROR]", utility::trim(output)))
{
// TODO: move error handling to caller of this function
const std::wstring dialogMessage =
L"The following error occurred while executing a Gradle command:\n\n" +
utility::decodeFromUtf8(utility::replace(output, "\r\n", "\n"));
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
return std::vector<FilePath>();
}
for (const std::string mainSrcDir: utility::splitToVector(output, ";"))
{
uncheckedDirectories.insert(utility::decodeFromUtf8(mainSrcDir));
}
}
if (addTestDirectories)
{
std::string output = "";
javaEnvironment->callStaticStringMethod(
"com/sourcetrail/gradle/InfoRetriever",
"getTestSrcDirs",
output,
utility::encodeToUtf8(projectDirectoryPath.wstr()),
utility::encodeToUtf8(gradleInitScriptPath.wstr()));
if (utility::isPrefix<std::string>("[ERROR]", utility::trim(output)))
{
// TODO: move error handling to caller of this function
const std::wstring dialogMessage =
L"The following error occurred while executing a Gradle command:\n\n" +
utility::decodeFromUtf8(utility::replace(output, "\r\n", "\n"));
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
return std::vector<FilePath>();
}
for (const std::string testSrcDir: utility::splitToVector(output, ";"))
{
uncheckedDirectories.insert(utility::decodeFromUtf8(testSrcDir));
}
}
}
std::vector<FilePath> directories;
for (const std::wstring& 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;
}
} // namespace utility
+8 -4
View File
@@ -7,8 +7,12 @@ class FilePath;
namespace utility
{
bool gradleCopyDependencies(const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDependencies);
std::vector<FilePath> gradleGetAllSourceDirectories(const FilePath& projectDirectoryPath, bool addTestDirectories);
}
bool gradleCopyDependencies(
const FilePath& projectDirectoryPath,
const FilePath& outputDirectoryPath,
bool addTestDependencies);
std::vector<FilePath> gradleGetAllSourceDirectories(
const FilePath& projectDirectoryPath, bool addTestDirectories);
} // namespace utility
#endif // UTILITY_GRADLE_H
#endif // UTILITY_GRADLE_H
+149 -143
View File
@@ -1,198 +1,204 @@
#include "utilityGradle.h"
#include "Application.h"
#include "ApplicationSettings.h"
#include "DialogView.h"
#include "JavaEnvironment.h"
#include "JavaEnvironmentFactory.h"
#include "SourceGroupSettingsWithClasspath.h"
#include "ApplicationSettings.h"
#include "logging.h"
#include "MessageStatus.h"
#include "TextAccess.h"
#include "ResourcePaths.h"
#include "ScopedFunctor.h"
#include "SourceGroupSettingsWithClasspath.h"
#include "TextAccess.h"
#include "logging.h"
#include "utilityString.h"
#include "Application.h"
namespace utility
{
std::vector<std::wstring> getRequiredJarNames()
{
return {
L"gradle-tooling-api-4.2.jar",
L"java-indexer.jar",
L"org.eclipse.core.commands-3.9.200.jar",
L"org.eclipse.core.contenttype-3.7.200.jar",
L"org.eclipse.core.expressions-3.6.200.jar",
L"org.eclipse.core.filesystem-1.7.200.jar",
L"org.eclipse.core.jobs-3.10.200.jar",
L"org.eclipse.core.resources-3.13.200.jar",
L"org.eclipse.core.runtime-3.15.100.jar",
L"org.eclipse.equinox.app-1.4.0.jar",
L"org.eclipse.equinox.common-3.10.200.jar",
L"org.eclipse.equinox.preferences-3.7.200.jar",
L"org.eclipse.equinox.registry-3.8.200.jar",
L"org.eclipse.jdt.core-3.13.102.jar",
L"org.eclipse.osgi-3.13.200.jar",
L"org.eclipse.text-3.8.0.jar",
L"slf4j-api-1.7.10.jar",
L"slf4j-simple-1.7.10.jar"
};
}
std::vector<std::wstring> getRequiredJarNames()
{
return {
L"gradle-tooling-api-4.2.jar",
L"java-indexer.jar",
L"org.eclipse.core.commands-3.9.200.jar",
L"org.eclipse.core.contenttype-3.7.200.jar",
L"org.eclipse.core.expressions-3.6.200.jar",
L"org.eclipse.core.filesystem-1.7.200.jar",
L"org.eclipse.core.jobs-3.10.200.jar",
L"org.eclipse.core.resources-3.13.200.jar",
L"org.eclipse.core.runtime-3.15.100.jar",
L"org.eclipse.equinox.app-1.4.0.jar",
L"org.eclipse.equinox.common-3.10.200.jar",
L"org.eclipse.equinox.preferences-3.7.200.jar",
L"org.eclipse.equinox.registry-3.8.200.jar",
L"org.eclipse.jdt.core-3.13.102.jar",
L"org.eclipse.osgi-3.13.200.jar",
L"org.eclipse.text-3.8.0.jar",
L"slf4j-api-1.7.10.jar",
L"slf4j-simple-1.7.10.jar"};
}
std::string prepareJavaEnvironment()
{
std::string errorString;
std::string prepareJavaEnvironment()
{
std::string errorString;
if (!JavaEnvironmentFactory::getInstance())
{
if (!JavaEnvironmentFactory::getInstance())
{
#ifdef _WIN32
const std::string separator = ";";
const std::string separator = ";";
#else
const std::string separator = ":";
const std::string separator = ":";
#endif
std::string classPath = "";
std::string classPath = "";
{
const std::vector<std::wstring> jarNames = getRequiredJarNames();
for (size_t i = 0; i < jarNames.size(); i++)
{
const std::vector<std::wstring> jarNames = getRequiredJarNames();
for (size_t i = 0; i < jarNames.size(); i++)
if (i != 0)
{
if (i != 0)
{
classPath += separator;
}
classPath += ResourcePaths::getJavaPath().concatenate(L"lib/" + jarNames[i]).str();
classPath += separator;
}
classPath += ResourcePaths::getJavaPath().concatenate(L"lib/" + jarNames[i]).str();
}
JavaEnvironmentFactory::createInstance(
classPath,
errorString
);
}
return errorString;
JavaEnvironmentFactory::createInstance(classPath, errorString);
}
bool prepareJavaEnvironmentAndDisplayOccurringErrors()
return errorString;
}
bool prepareJavaEnvironmentAndDisplayOccurringErrors()
{
const std::wstring errorString = utility::decodeFromUtf8(utility::prepareJavaEnvironment());
if (!errorString.empty())
{
const std::wstring errorString = utility::decodeFromUtf8(utility::prepareJavaEnvironment());
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())
{
LOG_ERROR(errorString);
MessageStatus(errorString, true, false).dispatch();
dialogMessage += L"\n\nError: " + errorString;
}
if (!JavaEnvironmentFactory::getInstance())
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::UseCase::PROJECT_SETUP);
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())
{
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.";
continue;
}
if (!errorString.empty())
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))
{
dialogMessage += L"\n\nError: " + errorString;
success = false;
break;
}
MessageStatus(dialogMessage, true, false).dispatch();
rootPath = rootPath.getParentDirectory();
}
Application::getInstance()->handleDialog(dialogMessage);
return false;
if (success)
{
rootDirectories.insert(rootPath);
}
return true;
}
std::set<FilePath> fetchRootDirectories(const std::set<FilePath>& sourceFilePaths)
return rootDirectories;
}
std::vector<FilePath> getClassPath(
const std::vector<FilePath>& classpathItems,
bool useJreSystemLibrary,
const std::set<FilePath>& sourceFilePaths)
{
std::vector<FilePath> classPath;
for (const FilePath& classpath: classpathItems)
{
std::shared_ptr<DialogView> dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::PROJECT_SETUP);
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)
if (classpath.exists())
{
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);
}
LOG_INFO(L"Adding path to classpath: " + classpath.wstr());
classPath.push_back(classpath);
}
return rootDirectories;
}
std::vector<FilePath> getClassPath(const std::vector<FilePath>& classpathItems, bool useJreSystemLibrary, const std::set<FilePath>& sourceFilePaths)
if (useJreSystemLibrary)
{
std::vector<FilePath> classPath;
for (const FilePath& classpath : classpathItems)
for (const FilePath& systemLibraryPath:
ApplicationSettings::getInstance()->getJreSystemLibraryPathsExpanded())
{
if (classpath.exists())
{
LOG_INFO(L"Adding path to classpath: " + classpath.wstr());
classPath.push_back(classpath);
}
LOG_INFO(L"Adding JRE system library path to classpath: " + systemLibraryPath.wstr());
classPath.push_back(systemLibraryPath);
}
if (useJreSystemLibrary)
{
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;
}
void setJavaHomeVariableIfNotExists()
for (const FilePath& rootDirectory: utility::fetchRootDirectories(sourceFilePaths))
{
if (getenv("JAVA_HOME") == nullptr)
if (rootDirectory.exists())
{
const FilePath javaPath = ApplicationSettings::getInstance()->getJavaPath();
const FilePath javaHomePath = javaPath.getParentDirectory().getParentDirectory().getParentDirectory();
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()));
LOG_INFO(L"Adding root directory to classpath: " + rootDirectory.wstr());
classPath.push_back(rootDirectory);
}
}
return classPath;
}
void setJavaHomeVariableIfNotExists()
{
if (getenv("JAVA_HOME") == nullptr)
{
const FilePath javaPath = ApplicationSettings::getInstance()->getJavaPath();
const FilePath javaHomePath =
javaPath.getParentDirectory().getParentDirectory().getParentDirectory();
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
+12 -12
View File
@@ -1,8 +1,8 @@
#ifndef UTILITY_JAVA_H
#define UTILITY_JAVA_H
#include <string>
#include <set>
#include <string>
#include <vector>
class FilePath;
@@ -10,15 +10,15 @@ 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(
const std::vector<FilePath>& classpathItems,
bool useJreSystemLibrary,
const std::set<FilePath>& sourceFilePaths);
void setJavaHomeVariableIfNotExists();
}
std::vector<std::wstring> getRequiredJarNames();
std::string prepareJavaEnvironment();
bool prepareJavaEnvironmentAndDisplayOccurringErrors();
std::set<FilePath> fetchRootDirectories(const std::set<FilePath>& sourceFilePaths);
std::vector<FilePath> getClassPath(
const std::vector<FilePath>& classpathItems,
bool useJreSystemLibrary,
const std::set<FilePath>& sourceFilePaths);
void setJavaHomeVariableIfNotExists();
} // namespace utility
#endif // UTILITY_JAVA_H
#endif // UTILITY_JAVA_H
+173 -142
View File
@@ -5,9 +5,9 @@
#include "Application.h"
#include "ApplicationSettings.h"
#include "FilePath.h"
#include "logging.h"
#include "MessageStatus.h"
#include "TextAccess.h"
#include "logging.h"
#include "utility.h"
#include "utilityApp.h"
#include "utilityJava.h"
@@ -16,174 +16,205 @@
namespace
{
void fetchDirectories(
std::vector<FilePath>& pathList, std::shared_ptr<TextAccess> xmlAccess,
const std::vector<std::string>& tags,
const FilePath& toAppend = FilePath())
void fetchDirectories(
std::vector<FilePath>& pathList,
std::shared_ptr<TextAccess> xmlAccess,
const std::vector<std::string>& tags,
const FilePath& toAppend = FilePath())
{
{
std::string tagString = "";
for (size_t i = 0; i < tags.size(); i++)
{
std::string tagString = "";
for (size_t i = 0; i < tags.size(); i++)
if (i != 0)
{
if (i != 0)
{
tagString += " -> ";
}
tagString += tags[i];
tagString += " -> ";
}
LOG_INFO("Fetching source directories in \"" + tagString + "\".");
}
std::vector<std::string> fetchedDirectories = utility::getValuesOfAllXmlElementsOnPath(
xmlAccess, tags
);
LOG_INFO("Found " + std::to_string(fetchedDirectories.size()) + " source directories.");
for (const std::string& fetchedDirectory: fetchedDirectories)
{
FilePath path(fetchedDirectory);
if (!toAppend.empty())
{
path.concatenate(toAppend);
}
pathList.push_back(path);
LOG_INFO(L"Found directory \"" + path.wstr() + L"\".");
tagString += tags[i];
}
LOG_INFO("Fetching source directories in \"" + tagString + "\".");
}
std::wstring getErrorMessageFromMavenOutput(std::shared_ptr<const TextAccess> mavenOutput)
std::vector<std::string> fetchedDirectories = utility::getValuesOfAllXmlElementsOnPath(
xmlAccess, tags);
LOG_INFO("Found " + std::to_string(fetchedDirectories.size()) + " source directories.");
for (const std::string& fetchedDirectory: fetchedDirectories)
{
const std::string errorPrefix = "[ERROR]";
const std::string fatalPrefix = "[FATAL]";
std::wstring errorMessage;
for (const std::string& line : mavenOutput->getAllLines())
FilePath path(fetchedDirectory);
if (!toAppend.empty())
{
const std::string trimmedLine = utility::trim(line);
if (utility::isPrefix<std::string>(errorPrefix, trimmedLine))
{
errorMessage += utility::decodeFromUtf8(utility::trim(trimmedLine.substr(errorPrefix.size())) + "\n");
}
else if (utility::isPrefix<std::string>(fatalPrefix, trimmedLine))
{
errorMessage += utility::decodeFromUtf8(trimmedLine + "\n");
}
path.concatenate(toAppend);
}
if (!errorMessage.empty())
{
errorMessage = L"The following error occurred while executing a Maven command:\n\n" + errorMessage;
}
return errorMessage;
pathList.push_back(path);
LOG_INFO(L"Found directory \"" + path.wstr() + L"\".");
}
}
std::wstring getErrorMessageFromMavenOutput(std::shared_ptr<const TextAccess> mavenOutput)
{
const std::string errorPrefix = "[ERROR]";
const std::string fatalPrefix = "[FATAL]";
std::wstring errorMessage;
for (const std::string& line: mavenOutput->getAllLines())
{
const std::string trimmedLine = utility::trim(line);
if (utility::isPrefix<std::string>(errorPrefix, trimmedLine))
{
errorMessage += utility::decodeFromUtf8(
utility::trim(trimmedLine.substr(errorPrefix.size())) + "\n");
}
else if (utility::isPrefix<std::string>(fatalPrefix, trimmedLine))
{
errorMessage += utility::decodeFromUtf8(trimmedLine + "\n");
}
}
if (!errorMessage.empty())
{
errorMessage = L"The following error occurred while executing a Maven command:\n\n" +
errorMessage;
}
return errorMessage;
}
} // namespace
namespace utility
{
std::wstring mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath)
std::wstring mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath)
{
utility::setJavaHomeVariableIfNotExists();
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(
utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" generate-sources", projectDirectoryPath, 60000));
if (outputAccess->isEmpty())
{
utility::setJavaHomeVariableIfNotExists();
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" generate-sources",
projectDirectoryPath,
60000
));
if (outputAccess->isEmpty())
{
return L"Sourcetrail was unable to locate Maven on this machine.\n"
"Please make sure to provide the correct Maven Path in the preferences.";
}
return getErrorMessageFromMavenOutput(outputAccess);
return L"Sourcetrail was unable to locate Maven on this machine.\n"
"Please make sure to provide the correct Maven Path in the preferences.";
}
bool mavenCopyDependencies(const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath)
{
utility::setJavaHomeVariableIfNotExists();
return getErrorMessageFromMavenOutput(outputAccess);
}
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" dependency:copy-dependencies -DoutputDirectory=" + outputDirectoryPath.str(),
bool mavenCopyDependencies(
const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath)
{
utility::setJavaHomeVariableIfNotExists();
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(
utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() +
"\" dependency:copy-dependencies -DoutputDirectory=" + outputDirectoryPath.str(),
projectDirectoryPath,
60000
));
60000));
const std::wstring errorMessage = getErrorMessageFromMavenOutput(outputAccess);
if (!errorMessage.empty())
{
MessageStatus(errorMessage, true, false).dispatch();
Application::getInstance()->handleDialog(errorMessage);
return false;
}
return !outputAccess->isEmpty();
const std::wstring errorMessage = getErrorMessageFromMavenOutput(outputAccess);
if (!errorMessage.empty())
{
MessageStatus(errorMessage, true, false).dispatch();
Application::getInstance()->handleDialog(errorMessage);
return false;
}
std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDirectories)
{
utility::setJavaHomeVariableIfNotExists();
return !outputAccess->isEmpty();
}
FilePath outputPath = outputDirectoryPath.getConcatenated(FilePath("/effective-pom.xml"));
std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath,
const FilePath& projectDirectoryPath,
const FilePath& outputDirectoryPath,
bool addTestDirectories)
{
utility::setJavaHomeVariableIfNotExists();
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(utility::executeProcessUntilNoOutput(
FilePath outputPath = outputDirectoryPath.getConcatenated(FilePath("/effective-pom.xml"));
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(
utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" help:effective-pom -Doutput=\"" + outputPath.str(),
projectDirectoryPath,
60000
));
60000));
const std::wstring errorMessage = getErrorMessageFromMavenOutput(outputAccess);
if (!errorMessage.empty())
{
MessageStatus(errorMessage, true, false).dispatch();
Application::getInstance()->handleDialog(errorMessage);
return {};
}
else if (!outputPath.exists())
{
LOG_ERROR("Maven effective-pom didn't generate an output file: " + outputPath.str());
return {};
}
std::shared_ptr<TextAccess> xmlAccess = TextAccess::createFromFile(outputPath);
std::vector<FilePath> uncheckedDirectories;
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("project", "build", "sourceDirectory"));
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("projects", "project", "build", "sourceDirectory"));
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("project", "build", "directory"), FilePath(L"generated-sources"));
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("projects", "project", "build", "directory"), FilePath(L"generated-sources"));
if (addTestDirectories)
{
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("project", "build", "testSourceDirectory"));
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("projects", "project", "build", "testSourceDirectory"));
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("project", "build", "directory"), FilePath(L"generated-test-sources"));
fetchDirectories(uncheckedDirectories, xmlAccess,
utility::createVectorFromElements<std::string>("projects", "project", "build", "directory"), FilePath(L"generated-test-sources"));
}
std::vector<FilePath> directories;
for (const FilePath& uncheckedDirectory: uncheckedDirectories)
{
if (uncheckedDirectory.exists())
{
directories.push_back(uncheckedDirectory);
}
}
LOG_INFO("Found " + std::to_string(directories.size()) + " of " + std::to_string(uncheckedDirectories.size()) + " directories on system.");
return directories;
const std::wstring errorMessage = getErrorMessageFromMavenOutput(outputAccess);
if (!errorMessage.empty())
{
MessageStatus(errorMessage, true, false).dispatch();
Application::getInstance()->handleDialog(errorMessage);
return {};
}
else if (!outputPath.exists())
{
LOG_ERROR("Maven effective-pom didn't generate an output file: " + outputPath.str());
return {};
}
std::shared_ptr<TextAccess> xmlAccess = TextAccess::createFromFile(outputPath);
std::vector<FilePath> uncheckedDirectories;
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>("project", "build", "sourceDirectory"));
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>(
"projects", "project", "build", "sourceDirectory"));
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>("project", "build", "directory"),
FilePath(L"generated-sources"));
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>("projects", "project", "build", "directory"),
FilePath(L"generated-sources"));
if (addTestDirectories)
{
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>(
"project", "build", "testSourceDirectory"));
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>(
"projects", "project", "build", "testSourceDirectory"));
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>("project", "build", "directory"),
FilePath(L"generated-test-sources"));
fetchDirectories(
uncheckedDirectories,
xmlAccess,
utility::createVectorFromElements<std::string>(
"projects", "project", "build", "directory"),
FilePath(L"generated-test-sources"));
}
std::vector<FilePath> directories;
for (const FilePath& uncheckedDirectory: uncheckedDirectories)
{
if (uncheckedDirectory.exists())
{
directories.push_back(uncheckedDirectory);
}
}
LOG_INFO(
"Found " + std::to_string(directories.size()) + " of " +
std::to_string(uncheckedDirectories.size()) + " directories on system.");
return directories;
}
} // namespace utility
+12 -7
View File
@@ -8,11 +8,16 @@ class FilePath;
namespace utility
{
std::wstring mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath);
bool mavenCopyDependencies(
const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath);
std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDirectories);
}
std::wstring mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath);
bool mavenCopyDependencies(
const FilePath& mavenPath,
const FilePath& projectDirectoryPath,
const FilePath& outputDirectoryPath);
std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath,
const FilePath& projectDirectoryPath,
const FilePath& outputDirectoryPath,
bool addTestDirectories);
} // namespace utility
#endif // UTILITY_MAVEN_H
#endif // UTILITY_MAVEN_H