logic: reduce access to filesystem while indexing

* use canonical filepath cache in cxx indexer
* made constructors of FilePath explicit
* use FilePath at more places instead of string
* forward declares FilePath wherever possible
This commit is contained in:
malte_langkabel
2017-05-04 10:55:16 +02:00
parent 55d3f9c189
commit 054b8fab17
156 changed files with 656 additions and 444 deletions
@@ -4,7 +4,8 @@
#include <vector>
#include "data/indexer/IndexerCommand.h"
#include "utility/file/FilePath.h"
class FilePath;
class IndexerCommandJava
: public IndexerCommand
+3 -4
View File
@@ -14,7 +14,6 @@
JavaParser::JavaParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileRegister> fileRegister)
: Parser(client)
, m_id(s_nextParserId++)
, m_currentFilePath("")
{
std::shared_ptr<JavaEnvironmentFactory> factory = JavaEnvironmentFactory::getInstance();
if (factory)
@@ -56,7 +55,7 @@ void JavaParser::buildIndex(std::shared_ptr<IndexerCommandJava> indexerCommand)
classPath += path.str() + ";";
}
buildIndex(indexerCommand->getSourceFilePath(), classPath, TextAccess::createFromFile(indexerCommand->getSourceFilePath().str()));
buildIndex(indexerCommand->getSourceFilePath(), classPath, TextAccess::createFromFile(indexerCommand->getSourceFilePath()));
}
void JavaParser::buildIndex(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess)
@@ -68,7 +67,7 @@ void JavaParser::buildIndex(const FilePath& sourceFilePath, const std::string& c
{
if (m_javaEnvironment)
{
m_currentFilePath = sourceFilePath.str();
m_currentFilePath = sourceFilePath;
m_client->onFileParsed(FileSystem::getFileInfoForPath(sourceFilePath));
@@ -82,7 +81,7 @@ void JavaParser::buildIndex(const FilePath& sourceFilePath, const std::string& c
"com/sourcetrail/JavaIndexer",
"processFile",
m_id,
m_currentFilePath,
m_currentFilePath.str(),
fileContent,
classPath,
verbose
+3 -1
View File
@@ -7,6 +7,7 @@
#include "data/indexer/IndexerCommandJava.h"
#include "data/parser/Parser.h"
#include "data/parser/java/JavaEnvironment.h"
#include "utility/file/FilePath.h"
#include "utility/logging/logging.h"
struct JNIEnv_;
@@ -24,6 +25,7 @@ typedef int jint;
class _jstring;
typedef _jstring *jstring;
class FilePath;
class FileRegister;
class JavaParser: public Parser
@@ -171,7 +173,7 @@ private:
std::shared_ptr<JavaEnvironment> m_javaEnvironment;
const int m_id;
std::string m_currentFilePath;
FilePath m_currentFilePath;
};
#endif // JAVA_PARSER_H
+12 -12
View File
@@ -114,14 +114,14 @@ bool SourceGroupJava::prepareJavaEnvironment()
const std::string separator = ":";
#endif
JavaEnvironmentFactory::createInstance(
ResourcePaths::getJavaPath() + "guava-18.0.jar" + separator +
ResourcePaths::getJavaPath() + "java-indexer.jar" + separator +
ResourcePaths::getJavaPath() + "javaparser-core.jar" + separator +
ResourcePaths::getJavaPath() + "javaslang-2.0.3.jar" + separator +
ResourcePaths::getJavaPath() + "javassist-3.19.0-GA.jar" + separator +
ResourcePaths::getJavaPath() + "java-symbol-solver-core.jar" + separator +
ResourcePaths::getJavaPath() + "java-symbol-solver-logic.jar" + separator +
ResourcePaths::getJavaPath() + "java-symbol-solver-model.jar",
ResourcePaths::getJavaPath().str() + "guava-18.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 +
ResourcePaths::getJavaPath().str() + "javassist-3.19.0-GA.jar" + separator +
ResourcePaths::getJavaPath().str() + "java-symbol-solver-core.jar" + separator +
ResourcePaths::getJavaPath().str() + "java-symbol-solver-logic.jar" + separator +
ResourcePaths::getJavaPath().str() + "java-symbol-solver-model.jar",
errorString
);
}
@@ -205,12 +205,12 @@ std::vector<FilePath> SourceGroupJava::getClassPath()
if (m_settings->getAbsoluteMavenDependenciesDirectory().exists())
{
const std::vector<std::string> dependencies = FileSystem::getFileNamesFromDirectory(
m_settings->getAbsoluteMavenDependenciesDirectory().str(),
m_settings->getAbsoluteMavenDependenciesDirectory(),
utility::createVectorFromElements<std::string>(".jar")
);
for (const std::string& dependency: dependencies)
{
classPath.push_back(dependency);
classPath.push_back(FilePath(dependency));
}
}
@@ -218,7 +218,7 @@ std::vector<FilePath> SourceGroupJava::getClassPath()
{
if (rootDirectory.exists())
{
classPath.push_back(rootDirectory.str());
classPath.push_back(rootDirectory);
}
}
@@ -239,7 +239,7 @@ std::set<FilePath> SourceGroupJava::fetchRootDirectories()
std::shared_ptr<JavaEnvironment> javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment();
for (FilePath filePath: m_allSourceFilePaths)
{
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath.str());
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromFile(filePath);
std::string packageName = "";
javaEnvironment->callStaticMethod("com/sourcetrail/JavaIndexer", "getPackageName", packageName, textAccess->getText());
+5 -4
View File
@@ -1,5 +1,6 @@
#include "utility/utilityMaven.h"
#include "utility/file/FilePath.h"
#include "utility/text/TextAccess.h"
#include "utility/utilityApp.h"
#include "utility/utilityString.h"
@@ -61,12 +62,12 @@ namespace utility
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("project", "build", "directory")))
{
uncheckedDirectories.push_back(FilePath(value).concat("generated-sources"));
uncheckedDirectories.push_back(FilePath(value).concat(FilePath("generated-sources")));
}
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("projects", "project", "build", "directory")))
{
uncheckedDirectories.push_back(FilePath(value).concat("generated-sources"));
uncheckedDirectories.push_back(FilePath(value).concat(FilePath("generated-sources")));
}
if (addTestDirectories)
@@ -82,12 +83,12 @@ namespace utility
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("project", "build", "directory")))
{
uncheckedDirectories.push_back(FilePath(value).concat("generated-test-sources"));
uncheckedDirectories.push_back(FilePath(value).concat(FilePath("generated-test-sources")));
}
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("projects", "project", "build", "directory")))
{
uncheckedDirectories.push_back(FilePath(value).concat("generated-test-sources"));
uncheckedDirectories.push_back(FilePath(value).concat(FilePath("generated-test-sources")));
}
}
+3 -1
View File
@@ -1,7 +1,9 @@
#ifndef UTILITY_MAVEN_H
#define UTILITY_MAVEN_H
#include "utility/file/FilePath.h"
#include <vector>
class FilePath;
namespace utility
{