logic: fix update of Java indexer to new version of Java dependencies

* reapplied previous reverts
* added cache for TypeSolvers in Java code
This commit is contained in:
malte_langkabel
2017-05-10 17:54:21 +02:00
parent f9a6c1ac09
commit 8a92453d60
39 changed files with 231 additions and 70 deletions
@@ -1,8 +1,6 @@
#include "data/indexer/IndexerFactoryModuleJava.h"
#include "data/indexer/Indexer.h"
#include "data/indexer/IndexerCommandJava.h"
#include "data/parser/java/JavaParser.h"
#include "data/indexer/IndexerJava.h"
IndexerFactoryModuleJava::~IndexerFactoryModuleJava()
{
@@ -10,5 +8,5 @@ IndexerFactoryModuleJava::~IndexerFactoryModuleJava()
std::shared_ptr<IndexerBase> IndexerFactoryModuleJava::createIndexer()
{
return std::make_shared<Indexer<IndexerCommandJava, JavaParser>>();
return std::make_shared<IndexerJava>();
}
+44
View File
@@ -0,0 +1,44 @@
#include "data/indexer/IndexerJava.h"
#include "data/indexer/IndexerCommandJava.h"
#include "data/parser/ParserClientImpl.h"
#include "data/parser/java/JavaParser.h"
#include "utility/file/FileRegister.h"
IndexerJava::~IndexerJava()
{
JavaParser::clearCaches();
}
std::shared_ptr<IntermediateStorage> IndexerJava::doIndex(
std::shared_ptr<IndexerCommandJava> indexerCommand,
std::shared_ptr<FileRegister> fileRegister)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient, fileRegister);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
parserClient->setStorage(storage);
parser->buildIndex(indexerCommand);
parserClient->resetStorage();
if (parserClient->hasFatalErrors() || indexerCommand->preprocessorOnly())
{
storage->setAllFilesIncomplete();
}
else
{
storage->setFilesWithErrorsIncomplete();
fileRegister->markIndexingFilesIndexed();
}
if (interrupted())
{
return std::shared_ptr<IntermediateStorage>();
}
return storage;
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef INDEXER_JAVA_H
#define INDEXER_JAVA_H
#include <memory>
#include "data/indexer/IndexerCommandJava.h"
#include "data/indexer/Indexer.h"
class IndexerJava: public Indexer<IndexerCommandJava>
{
public:
virtual ~IndexerJava();
virtual std::shared_ptr<IntermediateStorage> doIndex(
std::shared_ptr<IndexerCommandJava> indexerCommand,
std::shared_ptr<FileRegister> fileRegister);
};
#endif // INDEXER_JAVA_H
@@ -10,6 +10,18 @@ JavaEnvironment::~JavaEnvironment()
JavaEnvironmentFactory::getInstance()->unregisterEnvironment();
}
bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string methodName)
{
jclass javaClass = getJavaClass(className);
jmethodID javaMethodId = getJavaStaticMethod(javaClass, methodName, "()V");
if(javaMethodId != nullptr)
{
m_env->CallStaticVoidMethod(javaClass, javaMethodId);
return true;
}
return false;
}
bool JavaEnvironment::callStaticVoidMethod(std::string className, std::string methodName, int arg1, std::string arg2, std::string arg3, std::string arg4, int arg5)
{
jclass javaClass = getJavaClass(className);
@@ -32,6 +32,7 @@ public:
};
~JavaEnvironment();
bool callStaticVoidMethod(std::string className, std::string methodName);
bool callStaticVoidMethod(std::string className, std::string methodName, int arg1, std::string arg2, std::string arg3, std::string arg4, int arg5);
bool callStaticMethod(std::string className, std::string methodName, std::string& ret, std::string arg1);
@@ -28,7 +28,6 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string&
}
std::function<jint (JavaVM**, void**, void*)> createInstanceFunction;
const FilePath javaPath(ApplicationSettings::getInstance()->getJavaPath());
createInstanceFunction = utility::loadFunctionFromLibrary<jint, JavaVM**, void**, void*>(
javaPath,
+17 -1
View File
@@ -26,7 +26,7 @@ std::string JavaParser::prepareJavaEnvironment()
const std::string separator = ":";
#endif
JavaEnvironmentFactory::createInstance(
ResourcePaths::getJavaPath().str() + "guava-18.0.jar" + separator +
ResourcePaths::getJavaPath().str() + "guava-21.0.jar" + separator +
ResourcePaths::getJavaPath().str() + "java-indexer.jar" + separator +
ResourcePaths::getJavaPath().str() + "javaparser-core.jar" + separator +
ResourcePaths::getJavaPath().str() + "javaslang-2.0.3.jar" + separator +
@@ -41,6 +41,22 @@ std::string JavaParser::prepareJavaEnvironment()
return errorString;
}
void JavaParser::clearCaches()
{
std::shared_ptr<JavaEnvironmentFactory> factory = JavaEnvironmentFactory::getInstance();
if (factory)
{
std::shared_ptr<JavaEnvironment> environment = factory->createEnvironment();
if (environment)
{
environment->callStaticVoidMethod(
"com/sourcetrail/JavaIndexer",
"clearCaches"
);
}
}
}
JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: Parser(client)
, m_id(s_nextParserId++)
@@ -33,6 +33,7 @@ class JavaParser: public Parser
public:
// returns: error message
static std::string prepareJavaEnvironment();
static void clearCaches();
JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister);
~JavaParser();