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
+2
View File
@@ -1,6 +1,8 @@
#ifndef UNDO_REDO_VIEW_H
#define UNDO_REDO_VIEW_H
#include <vector>
#include "component/view/View.h"
#include <vector>
+13 -36
View File
@@ -4,11 +4,10 @@
#include <memory>
#include "data/indexer/IndexerBase.h"
#include "data/parser/ParserClientImpl.h"
#include "utility/file/FileRegister.h"
#include "data/indexer/IndexerCommand.h"
#include "utility/logging/logging.h"
template <typename IndexerCommandType, typename ParserType>
template <typename IndexerCommandType>
class Indexer
: public IndexerBase
{
@@ -20,21 +19,25 @@ public:
virtual std::shared_ptr<IntermediateStorage> index(
std::shared_ptr<IndexerCommand> indexerCommand,
std::shared_ptr<FileRegister> fileRegister);
virtual std::shared_ptr<IntermediateStorage> doIndex(
std::shared_ptr<IndexerCommandType> indexerCommand,
std::shared_ptr<FileRegister> fileRegister) = 0;
};
template <typename IndexerCommandType, typename ParserType>
Indexer<IndexerCommandType, ParserType>::~Indexer()
template <typename IndexerCommandType>
Indexer<IndexerCommandType>::~Indexer()
{
}
template <typename IndexerCommandType, typename ParserType>
std::string Indexer<IndexerCommandType, ParserType>::getKindString() const
template <typename IndexerCommandType>
std::string Indexer<IndexerCommandType>::getKindString() const
{
return IndexerCommandType::getIndexerKindString();
}
template <typename IndexerCommandType, typename ParserType>
std::shared_ptr<IntermediateStorage> Indexer<IndexerCommandType, ParserType>::index(
template <typename IndexerCommandType>
std::shared_ptr<IntermediateStorage> Indexer<IndexerCommandType>::index(
std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister)
{
std::shared_ptr<IndexerCommandType> castedCommand = std::dynamic_pointer_cast<IndexerCommandType>(indexerCommand);
@@ -46,33 +49,7 @@ std::shared_ptr<IntermediateStorage> Indexer<IndexerCommandType, ParserType>::in
return std::shared_ptr<IntermediateStorage>();
}
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<ParserType> parser = std::make_shared<ParserType>(parserClient, fileRegister);
std::shared_ptr<IntermediateStorage> storage = std::make_shared<IntermediateStorage>();
parserClient->setStorage(storage);
parser->buildIndex(castedCommand);
parserClient->resetStorage();
if (parserClient->hasFatalErrors() || indexerCommand->preprocessorOnly())
{
storage->setAllFilesIncomplete();
}
else
{
storage->setFilesWithErrorsIncomplete();
fileRegister->markIndexingFilesIndexed();
}
if (interrupted())
{
return std::shared_ptr<IntermediateStorage>();
}
return storage;
return doIndex(castedCommand, fileRegister);
}
#endif // INDEXER_H
+3 -3
View File
@@ -2,11 +2,11 @@
#define INDEXER_BASE_H
#include <memory>
#include "data/indexer/IndexerCommand.h"
#include "data/IntermediateStorage.h"
#include <string>
class FileRegister;
class IndexerCommand;
class IntermediateStorage;
class IndexerBase
{
@@ -1,5 +1,8 @@
#include "data/indexer/IndexerComposite.h"
#include "data/indexer/IndexerCommand.h"
#include "utility/logging/logging.h"
#include "data/IntermediateStorage.h"
IndexerComposite::~IndexerComposite()
{
+1
View File
@@ -8,6 +8,7 @@ add_files(
data/indexer/IndexerCommandCxxCdb.h
data/indexer/IndexerCommandCxxManual.cpp
data/indexer/IndexerCommandCxxManual.h
data/indexer/IndexerCxx.h
data/indexer/IndexerFactoryModuleCxxCdb.cpp
data/indexer/IndexerFactoryModuleCxxCdb.h
data/indexer/IndexerFactoryModuleCxxManual.cpp
+60
View File
@@ -0,0 +1,60 @@
#ifndef INDEXER_CXX_H
#define INDEXER_CXX_H
#include <memory>
#include "data/indexer/Indexer.h"
#include "data/parser/ParserClientImpl.h"
#include "utility/file/FileRegister.h"
template <typename IndexerCommandType, typename ParserType>
class IndexerCxx: public Indexer<IndexerCommandType>
{
public:
virtual ~IndexerCxx();
virtual std::shared_ptr<IntermediateStorage> doIndex(
std::shared_ptr<IndexerCommandType> indexerCommand,
std::shared_ptr<FileRegister> fileRegister);
};
template <typename IndexerCommandType, typename ParserType>
IndexerCxx<IndexerCommandType, ParserType>::~IndexerCxx()
{
}
template <typename IndexerCommandType, typename ParserType>
std::shared_ptr<IntermediateStorage> IndexerCxx<IndexerCommandType, ParserType>::doIndex(
std::shared_ptr<IndexerCommandType> indexerCommand,
std::shared_ptr<FileRegister> fileRegister)
{
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
std::shared_ptr<ParserType> parser = std::make_shared<ParserType>(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;
}
#endif // INDEXER_CXX_H
@@ -1,6 +1,6 @@
#include "data/indexer/IndexerFactoryModuleCxxCdb.h"
#include "data/indexer/Indexer.h"
#include "data/indexer/IndexerCxx.h"
#include "data/indexer/IndexerCommandCxxCdb.h"
#include "data/parser/cxx/CxxParser.h"
@@ -10,5 +10,5 @@ IndexerFactoryModuleCxxCdb::~IndexerFactoryModuleCxxCdb()
std::shared_ptr<IndexerBase> IndexerFactoryModuleCxxCdb::createIndexer()
{
return std::make_shared<Indexer<IndexerCommandCxxCdb, CxxParser>>();
return std::make_shared<IndexerCxx<IndexerCommandCxxCdb, CxxParser>>();
}
@@ -1,6 +1,6 @@
#include "data/indexer/IndexerFactoryModuleCxxManual.h"
#include "data/indexer/Indexer.h"
#include "data/indexer/IndexerCxx.h"
#include "data/indexer/IndexerCommandCxxManual.h"
#include "data/parser/cxx/CxxParser.h"
@@ -10,5 +10,5 @@ IndexerFactoryModuleCxxManual::~IndexerFactoryModuleCxxManual()
std::shared_ptr<IndexerBase> IndexerFactoryModuleCxxManual::createIndexer()
{
return std::make_shared<Indexer<IndexerCommandCxxManual, CxxParser>>();
return std::make_shared<IndexerCxx<IndexerCommandCxxManual, CxxParser>>();
}
+2
View File
@@ -6,6 +6,8 @@ add_files(
data/indexer/IndexerCommandJava.h
data/indexer/IndexerFactoryModuleJava.cpp
data/indexer/IndexerFactoryModuleJava.h
data/indexer/IndexerJava.cpp
data/indexer/IndexerJava.h
data/parser/java/JavaParser.cpp
data/parser/java/JavaParser.h
@@ -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();
+1
View File
@@ -108,6 +108,7 @@ std::vector<std::shared_ptr<IndexerCommand>> SourceGroupJava::getIndexerCommands
bool SourceGroupJava::prepareJavaEnvironment()
{
const std::string errorString = JavaParser::prepareJavaEnvironment();
if (errorString.size() > 0)
{
LOG_ERROR(errorString);
+1 -1
View File
@@ -817,7 +817,7 @@ private:
const std::string separator = ":";
#endif
JavaEnvironmentFactory::createInstance(
"../app/data/java/guava-18.0.jar" + separator +
"../app/data/java/guava-21.0.jar" + separator +
"../app/data/java/java-indexer.jar" + separator +
"../app/data/java/javaparser-core.jar" + separator +
"../app/data/java/javaslang-2.0.3.jar" + separator +