logic: maven project setup

* added option to create a Coati project from a Maven POM file
* show list of indexed file paths in maven project setup
* use FileManager to detect indexed files in project setup (except cdb)
* added Maven path to preferences window and added path detectors.
* fixed: QtDialogView::hideStatusDialog now also hides loader in status bar.
* refactored ProjectType

fortune cookie message = If you continually give, you will continually have.
This commit is contained in:
malte_langkabel
2017-03-08 14:55:42 +01:00
parent d6f3099981
commit 3cbe83f9e6
83 changed files with 1502 additions and 545 deletions
+3
View File
@@ -16,6 +16,9 @@ add_files(
data/parser/java/JavaEnvironmentFactory.cpp
data/parser/java/JavaEnvironmentFactory.h
utility/utilityMaven.cpp
utility/utilityMaven.h
JavaProject.cpp
JavaProject.h
ProjectFactoryModuleJava.cpp
+73 -12
View File
@@ -5,14 +5,20 @@
#include "data/parser/java/JavaEnvironmentFactory.h"
#include "data/parser/java/JavaEnvironment.h"
#include "utility/file/FileRegister.h"
#include "utility/text/TextAccess.h"
#include "utility/file/FileSystem.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/text/TextAccess.h"
#include "utility/ResourcePaths.h"
#include "utility/utilityMaven.h"
#include "utility/utilityString.h"
#include "Application.h"
#include "settings/ApplicationSettings.h"
#include "utility/tracing.h"
#include "utility/ScopedFunctor.h"
JavaProject::JavaProject(
std::shared_ptr<JavaProjectSettings> projectSettings, StorageAccessProxy* storageAccessProxy, DialogView* dialogView
std::shared_ptr<JavaProjectSettings> projectSettings, StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView
)
: Project(storageAccessProxy, dialogView)
, m_projectSettings(projectSettings)
@@ -67,17 +73,52 @@ bool JavaProject::prepareIndexing()
if (!JavaEnvironmentFactory::getInstance())
{
std::string dialogMessage =
"Coati was unable to locate Java on this machine.\nPlease make sure to provide the correct Java Path in the preferences.";
"Coati was unable to locate Java on this machine.\n"
"Please make sure to provide the correct Java Path in the preferences.";
if (errorString.size() > 0)
{
dialogMessage += "\n\nError: " + errorString;
}
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
return false;
}
if (m_projectSettings->getAbsoluteMavenProjectFilePath().exists())
{
const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath();
const FilePath projectRootPath = m_projectSettings->getAbsoluteMavenProjectFilePath().parentDirectory();
ScopedFunctor dialogHider([this](){
getDialogView()->hideStatusDialog();
});
getDialogView()->showStatusDialog("Preparing Project", "Maven\nGenerating Source Files");
bool success = utility::mavenGenerateSources(
mavenPath, projectRootPath
);
if (!success)
{
const std::string dialogMessage =
"Coati was unable to locate Maven on this machine.\n"
"Please make sure to provide the correct Maven Path in the preferences.";
MessageStatus(dialogMessage, true, false).dispatch();
Application::getInstance()->handleDialog(dialogMessage);
return false;
}
getDialogView()->showStatusDialog("Preparing Project", "Maven\nExporting Dependencies");
utility::mavenCopyDependencies(
mavenPath, projectRootPath, m_projectSettings->getAbsoluteMavenDependenciesDirectory()
);
}
return true;
}
@@ -85,7 +126,7 @@ std::vector<std::shared_ptr<IndexerCommand>> JavaProject::getIndexerCommands()
{
std::vector<FilePath> classPath;
for (FilePath p: m_projectSettings->getAbsoluteClasspaths())
for (const FilePath& p: m_projectSettings->getAbsoluteClasspaths())
{
if (p.exists())
{
@@ -93,6 +134,18 @@ std::vector<std::shared_ptr<IndexerCommand>> JavaProject::getIndexerCommands()
}
}
if (m_projectSettings->getAbsoluteMavenDependenciesDirectory().exists())
{
const std::vector<std::string> dependencies = FileSystem::getFileNamesFromDirectory(
m_projectSettings->getAbsoluteMavenDependenciesDirectory().str(),
std::vector<std::string>(1, ".jar")
);
for (const std::string& dependency: dependencies)
{
classPath.push_back(dependency);
}
}
if (!m_rootDirectories)
{
getDialogView()->showStatusDialog("Preparing Project", "Gathering Root\nDirectories");
@@ -135,10 +188,23 @@ std::vector<std::shared_ptr<IndexerCommand>> JavaProject::getIndexerCommands()
return indexerCommands;
}
void JavaProject::updateFileManager(FileManager& fileManager)
{
std::vector<FilePath> sourcePaths = m_projectSettings->getAbsoluteSourcePaths();
std::vector<FilePath> sourcePaths;
if (m_projectSettings->getAbsoluteMavenProjectFilePath().exists())
{
getDialogView()->showStatusDialog("Preparing Project", "Maven\nFetching Source Directories");
const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath());
const FilePath projectRootPath = m_projectSettings->getAbsoluteMavenProjectFilePath().parentDirectory();
sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom(mavenPath, projectRootPath, m_projectSettings->getShouldIndexMavenTests());
getDialogView()->hideStatusDialog();
}
else
{
sourcePaths = m_projectSettings->getAbsoluteSourcePaths();
}
std::vector<FilePath> headerPaths = sourcePaths;
std::vector<std::string> sourceExtensions = m_projectSettings->getSourceExtensions();
std::vector<FilePath> excludePaths = m_projectSettings->getAbsoluteExcludePaths();
@@ -151,12 +217,7 @@ void JavaProject::fetchRootDirectories()
m_rootDirectories = std::make_shared<std::set<FilePath>>();
FileManager fileManager;
fileManager.setPaths(
m_projectSettings->getAbsoluteSourcePaths(),
std::vector<FilePath>(),
m_projectSettings->getAbsoluteExcludePaths(),
m_projectSettings->getSourceExtensions()
);
updateFileManager(fileManager);
FileManager::FileSets fileSets = fileManager.fetchFilePaths(std::vector<FileInfo>());
std::shared_ptr<JavaEnvironment> javaEnvironment = JavaEnvironmentFactory::getInstance()->createEnvironment();
+1 -1
View File
@@ -12,7 +12,7 @@ public:
JavaProject(
std::shared_ptr<JavaProjectSettings> projectSettings,
StorageAccessProxy* storageAccessProxy,
DialogView* dialogView
std::shared_ptr<DialogView> dialogView
);
virtual ~JavaProject();
+1 -1
View File
@@ -13,7 +13,7 @@ LanguageType ProjectFactoryModuleJava::getLanguage() const
}
std::shared_ptr<Project> ProjectFactoryModuleJava::createProject(
const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView
const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView
)
{
return std::shared_ptr<JavaProject>(new JavaProject(
+1 -1
View File
@@ -10,7 +10,7 @@ public:
virtual LanguageType getLanguage() const;
virtual std::shared_ptr<Project> createProject(
const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, DialogView* dialogView
const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy, std::shared_ptr<DialogView> dialogView
);
};
+104
View File
@@ -0,0 +1,104 @@
#include "utility/utilityMaven.h"
#include "utility/text/TextAccess.h"
#include "utility/utilityApp.h"
#include "utility/utilityString.h"
#include "utility/utilityXml.h"
#include "utility/utility.h"
namespace utility
{
bool mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath)
{
const std::string output = utility::executeProcess(
mavenPath.str() + " generate-sources",
projectDirectoryPath.str()
);
return !output.empty();
}
bool mavenCopyDependencies(const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath)
{
const std::string output = utility::executeProcess(
mavenPath.str() + " dependency:copy-dependencies -DoutputDirectory=" + outputDirectoryPath.str(),
projectDirectoryPath.str()
);
return !output.empty();
}
std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(const FilePath& mavenPath, const FilePath& projectDirectoryPath, bool addTestDirectories)
{
std::shared_ptr<TextAccess> outputAccess = TextAccess::createFromString(utility::executeProcess(
mavenPath.str() + " help:effective-pom",
projectDirectoryPath.str()
));
std::string xmlContent = "";
for (std::string line: outputAccess->getAllLines())
{
const std::string trimmedLine = utility::trim(line);
if (!trimmedLine.empty() && trimmedLine.front() == '<')
{
xmlContent.append(line);
}
}
std::shared_ptr<TextAccess> xmlAccess = TextAccess::createFromString(xmlContent);
std::vector<FilePath> directories;
std::vector<FilePath> uncheckedDirectories;
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("project", "build", "sourceDirectory")))
{
uncheckedDirectories.push_back(FilePath(value));
}
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("projects", "project", "build", "sourceDirectory")))
{
uncheckedDirectories.push_back(FilePath(value));
}
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("project", "build", "directory")))
{
uncheckedDirectories.push_back(FilePath(value).concat("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"));
}
if (addTestDirectories)
{
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("project", "build", "testSourceDirectory")))
{
uncheckedDirectories.push_back(FilePath(value));
}
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("projects", "project", "build", "testSourceDirectory")))
{
uncheckedDirectories.push_back(FilePath(value));
}
for (std::string value: utility::getValuesOfAllXmlElementsOnPath(xmlAccess, utility::createVectorFromElements<std::string>("project", "build", "directory")))
{
uncheckedDirectories.push_back(FilePath(value).concat("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"));
}
}
for (const FilePath& uncheckedDirectory: uncheckedDirectories)
{
if (uncheckedDirectory.exists())
{
directories.push_back(uncheckedDirectory);
}
}
return directories;
}
}
+13
View File
@@ -0,0 +1,13 @@
#ifndef UTILITY_MAVEN_H
#define UTILITY_MAVEN_H
#include "utility/file/FilePath.h"
namespace utility
{
bool 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, bool addTestDirectories);
}
#endif // UTILITY_MAVEN_H