From 21c07cf5bfd3fd33dbe8f1a3765e1c8b2ad62969 Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Wed, 11 Dec 2019 14:00:20 +0100 Subject: [PATCH] logic: allow to specify custom Maven settings.xml file in project settings (issue #794) (#847) --- .../java/SourceGroupSettingsWithJavaMaven.cpp | 22 +++++++- .../java/SourceGroupSettingsWithJavaMaven.h | 5 ++ src/lib_gui/CMakeLists.txt | 2 + .../qt/project_wizard/QtProjectWizard.cpp | 3 ++ ...tProjectWizardContentPathSettingsMaven.cpp | 52 +++++++++++++++++++ .../QtProjectWizardContentPathSettingsMaven.h | 29 +++++++++++ .../QtProjectWizardContentPathSourceMaven.cpp | 4 +- src/lib_java/project/SourceGroupJavaMaven.cpp | 11 +++- src/lib_java/utility/utilityMaven.cpp | 37 ++++++++++--- src/lib_java/utility/utilityMaven.h | 5 +- 10 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.cpp create mode 100644 src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.h diff --git a/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.cpp b/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.cpp index afafe663..992e9419 100644 --- a/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.cpp +++ b/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.cpp @@ -35,13 +35,30 @@ void SourceGroupSettingsWithJavaMaven::setShouldIndexMavenTests(bool value) m_shouldIndexMavenTests = value; } +FilePath SourceGroupSettingsWithJavaMaven::getMavenSettingsFilePath() const +{ + return m_mavenSettingsFilePath; +} + +FilePath SourceGroupSettingsWithJavaMaven::getMavenSettingsFilePathExpandedAndAbsolute() const +{ + return utility::getExpandedAndAbsolutePath( + getMavenSettingsFilePath(), getProjectSettings()->getProjectDirectoryPath()); +} + +void SourceGroupSettingsWithJavaMaven::setMavenSettingsFilePath(const FilePath& path) +{ + m_mavenSettingsFilePath = path; +} + bool SourceGroupSettingsWithJavaMaven::equals(const SourceGroupSettingsBase* other) const { const SourceGroupSettingsWithJavaMaven* otherPtr = dynamic_cast(other); return ( - otherPtr && m_mavenProjectFilePath == otherPtr->m_mavenProjectFilePath && + otherPtr && m_mavenProjectFilePath == otherPtr->m_mavenProjectFilePath && otherPtr && + m_mavenSettingsFilePath == otherPtr->m_mavenSettingsFilePath && m_shouldIndexMavenTests == otherPtr->m_shouldIndexMavenTests); } @@ -49,11 +66,14 @@ void SourceGroupSettingsWithJavaMaven::load(const ConfigManager* config, const s { setMavenProjectFilePath( config->getValueOrDefault(key + "/maven/project_file_path", FilePath(L""))); + setMavenSettingsFilePath( + config->getValueOrDefault(key + "/maven/settings_file_path", FilePath(L""))); setShouldIndexMavenTests(config->getValueOrDefault(key + "/maven/should_index_tests", false)); } void SourceGroupSettingsWithJavaMaven::save(ConfigManager* config, const std::string& key) { config->setValue(key + "/maven/project_file_path", getMavenProjectFilePath().wstr()); + config->setValue(key + "/maven/settings_file_path", getMavenSettingsFilePath().wstr()); config->setValue(key + "/maven/should_index_tests", getShouldIndexMavenTests()); } diff --git a/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.h b/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.h index 6f411280..fdaba7ea 100644 --- a/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.h +++ b/src/lib/settings/source_group/component/java/SourceGroupSettingsWithJavaMaven.h @@ -18,6 +18,10 @@ public: bool getShouldIndexMavenTests() const; void setShouldIndexMavenTests(bool value); + FilePath getMavenSettingsFilePath() const; + FilePath getMavenSettingsFilePathExpandedAndAbsolute() const; + void setMavenSettingsFilePath(const FilePath& path); + protected: bool equals(const SourceGroupSettingsBase* other) const override; @@ -27,6 +31,7 @@ protected: private: FilePath m_mavenProjectFilePath; bool m_shouldIndexMavenTests = false; + FilePath m_mavenSettingsFilePath; }; #endif // SOURCE_GROUP_SETTINGS_WITH_JAVA_MAVEN_H diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index 7c6af071..0cabfae2 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -356,6 +356,8 @@ if (BUILD_JAVA_LANGUAGE_PACKAGE) add_files( LIB_GUI + qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.cpp + qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.h qt/project_wizard/content/path/QtProjectWizardContentPathSourceGradle.cpp qt/project_wizard/content/path/QtProjectWizardContentPathSourceGradle.h qt/project_wizard/content/path/QtProjectWizardContentPathSourceMaven.cpp diff --git a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp index c9e528e8..7964a900 100644 --- a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp +++ b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp @@ -60,6 +60,7 @@ #if BUILD_JAVA_LANGUAGE_PACKAGE # include "QtProjectWizardContentJavaStandard.h" +# include "QtProjectWizardContentPathSettingsMaven.h" # include "QtProjectWizardContentPathSourceGradle.h" # include "QtProjectWizardContentPathSourceMaven.h" # include "QtProjectWizardContentPathsClassJava.h" @@ -421,6 +422,8 @@ std::vector> getSourceGrou WIZARD_CONTENT_CONTEXT_ALL); page.addContentCreatorWithSettings( WIZARD_CONTENT_CONTEXT_ALL); + page.addContentCreatorWithSettings( + WIZARD_CONTENT_CONTEXT_ALL); pages.push_back(page); } { diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.cpp new file mode 100644 index 00000000..260d3058 --- /dev/null +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.cpp @@ -0,0 +1,52 @@ +#include "QtProjectWizardContentPathSettingsMaven.h" + +#include + +//#include "Application.h" +//#include "ApplicationSettings.h" +//#include "MessageStatus.h" +//#include "QtDialogView.h" +//#include "ScopedFunctor.h" +//#include "SourceGroupJavaMaven.h" +#include "SourceGroupSettingsJavaMaven.h" +//#include "logging.h" +//#include "utility.h" +//#include "utilityFile.h" +//#include "utilityMaven.h" + +QtProjectWizardContentPathSettingsMaven::QtProjectWizardContentPathSettingsMaven( + std::shared_ptr settings, QtProjectWizardWindow* window) + : QtProjectWizardContentPath(window), m_settings(settings) +{ + setTitleString("Maven Settings File (settings.xml)"); + setHelpString( + "If your project uses a custom Maven settings file, specify it here. " + "If you leave this option empty, the default Maven settings will be used.
" + "
" + "You can make use of environment variables with ${ENV_VAR}."); + setPlaceholderString("Use Default"); + setAllowEmpty(true); + setFileEndings({L".xml"}); +} + +void QtProjectWizardContentPathSettingsMaven::populate(QGridLayout* layout, int& row) +{ + QtProjectWizardContentPath::populate(layout, row); + m_picker->setPickDirectory(false); + m_picker->setFileFilter("Settings File (*.xml)"); +} + +void QtProjectWizardContentPathSettingsMaven::load() +{ + m_picker->setText(QString::fromStdWString(m_settings->getMavenSettingsFilePath().wstr())); +} + +void QtProjectWizardContentPathSettingsMaven::save() +{ + m_settings->setMavenSettingsFilePath(FilePath(m_picker->getText().toStdWString())); +} + +std::shared_ptr QtProjectWizardContentPathSettingsMaven::getSourceGroupSettings() +{ + return m_settings; +} diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.h b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.h new file mode 100644 index 00000000..72eeb94a --- /dev/null +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSettingsMaven.h @@ -0,0 +1,29 @@ +#ifndef QT_PROJECT_WIZARD_CONTENT_PATH_SETTINGS_MAVEN_H +#define QT_PROJECT_WIZARD_CONTENT_PATH_SETTINGS_MAVEN_H + +#include "QtProjectWizardContentPath.h" + +class QCheckBox; +class SourceGroupSettingsJavaMaven; + +class QtProjectWizardContentPathSettingsMaven: public QtProjectWizardContentPath +{ + Q_OBJECT + +public: + QtProjectWizardContentPathSettingsMaven( + std::shared_ptr settings, QtProjectWizardWindow* window); + + // QtProjectWizardContent implementation + void populate(QGridLayout* layout, int& row) override; + + void load() override; + void save() override; + +private: + std::shared_ptr getSourceGroupSettings() override; + + std::shared_ptr m_settings; +}; + +#endif // QT_PROJECT_WIZARD_CONTENT_PATH_SETTINGS_MAVEN_H diff --git a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSourceMaven.cpp b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSourceMaven.cpp index 8a6623bc..cfd2383a 100644 --- a/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSourceMaven.cpp +++ b/src/lib_gui/qt/project_wizard/content/path/QtProjectWizardContentPathSourceMaven.cpp @@ -61,6 +61,7 @@ std::vector QtProjectWizardContentPathSourceMaven::getFilePaths() cons { { const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath(); + const FilePath mavenSettingsPath = m_settings->getMavenSettingsFilePathExpandedAndAbsolute(); const FilePath mavenProjectRoot = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory(); @@ -80,7 +81,8 @@ std::vector QtProjectWizardContentPathSourceMaven::getFilePaths() cons dialogView->showUnknownProgressDialog( L"Preparing Project", L"Maven\nGenerating Source Files"); - const std::wstring errorMessage = utility::mavenGenerateSources(mavenPath, mavenProjectRoot); + const std::wstring errorMessage = utility::mavenGenerateSources( + mavenPath, mavenSettingsPath, mavenProjectRoot); if (!errorMessage.empty()) { MessageStatus(errorMessage, true, false).dispatch(); diff --git a/src/lib_java/project/SourceGroupJavaMaven.cpp b/src/lib_java/project/SourceGroupJavaMaven.cpp index 72ca9d3d..22ead0b4 100644 --- a/src/lib_java/project/SourceGroupJavaMaven.cpp +++ b/src/lib_java/project/SourceGroupJavaMaven.cpp @@ -73,6 +73,7 @@ bool SourceGroupJavaMaven::prepareMavenData() if (m_settings && m_settings->getMavenProjectFilePathExpandedAndAbsolute().exists()) { const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath(); + const FilePath mavenSettingsPath = m_settings->getMavenSettingsFilePathExpandedAndAbsolute(); const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory(); @@ -83,7 +84,8 @@ bool SourceGroupJavaMaven::prepareMavenData() ScopedFunctor dialogHider([&dialogView]() { dialogView->hideUnknownProgressDialog(); }); - const std::wstring errorMessage = utility::mavenGenerateSources(mavenPath, projectRootPath); + const std::wstring errorMessage = utility::mavenGenerateSources( + mavenPath, mavenSettingsPath, projectRootPath); if (!errorMessage.empty()) { MessageStatus(errorMessage, true, false).dispatch(); @@ -95,7 +97,10 @@ bool SourceGroupJavaMaven::prepareMavenData() L"Preparing Project", L"Maven\nExporting Dependencies"); bool success = utility::mavenCopyDependencies( - mavenPath, projectRootPath, m_settings->getMavenDependenciesDirectoryPath()); + mavenPath, + mavenSettingsPath, + projectRootPath, + m_settings->getMavenDependenciesDirectoryPath()); return success; } @@ -114,11 +119,13 @@ std::vector SourceGroupJavaMaven::doGetAllSourcePaths() const L"Preparing Project", L"Maven\nFetching Source Directories"); const FilePath mavenPath(ApplicationSettings::getInstance()->getMavenPath()); + const FilePath mavenSettingsPath = m_settings->getMavenSettingsFilePathExpandedAndAbsolute(); const FilePath projectRootPath = m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory(); sourcePaths = utility::mavenGetAllDirectoriesFromEffectivePom( mavenPath, + mavenSettingsPath, projectRootPath, m_settings->getMavenDependenciesDirectoryPath(), m_settings->getShouldIndexMavenTests()); diff --git a/src/lib_java/utility/utilityMaven.cpp b/src/lib_java/utility/utilityMaven.cpp index b169fae3..3652cf01 100644 --- a/src/lib_java/utility/utilityMaven.cpp +++ b/src/lib_java/utility/utilityMaven.cpp @@ -81,17 +81,37 @@ std::wstring getErrorMessageFromMavenOutput(std::shared_ptr ma return errorMessage; } + +std::string getMavenArgsString(const FilePath& settingsFilePath) +{ + std::vector args; + if (!settingsFilePath.empty() && settingsFilePath.exists()) + { + args.push_back("--settings \"" + settingsFilePath.str() + "\""); + } + std::string ret = ""; + for (const std::string& arg: args) + { + ret += arg + " "; + } + + return ret; +} + } // namespace namespace utility { -std::wstring mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath) +std::wstring mavenGenerateSources( + const FilePath& mavenPath, const FilePath& settingsFilePath, const FilePath& projectDirectoryPath) { utility::setJavaHomeVariableIfNotExists(); std::shared_ptr outputAccess = TextAccess::createFromString( utility::executeProcessUntilNoOutput( - "\"" + mavenPath.str() + "\" generate-sources", projectDirectoryPath, 60000)); + "\"" + mavenPath.str() + "\" " + getMavenArgsString(settingsFilePath) + "generate-sources", + projectDirectoryPath, + 60000)); if (outputAccess->isEmpty()) { @@ -103,14 +123,17 @@ std::wstring mavenGenerateSources(const FilePath& mavenPath, const FilePath& pro } bool mavenCopyDependencies( - const FilePath& mavenPath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath) + const FilePath& mavenPath, + const FilePath& settingsFilePath, + const FilePath& projectDirectoryPath, + const FilePath& outputDirectoryPath) { utility::setJavaHomeVariableIfNotExists(); std::shared_ptr outputAccess = TextAccess::createFromString( utility::executeProcessUntilNoOutput( - "\"" + mavenPath.str() + - "\" dependency:copy-dependencies -DoutputDirectory=" + outputDirectoryPath.str(), + "\"" + mavenPath.str() + "\" " + getMavenArgsString(settingsFilePath) + + "dependency:copy-dependencies -DoutputDirectory=" + outputDirectoryPath.str(), projectDirectoryPath, 60000)); @@ -127,6 +150,7 @@ bool mavenCopyDependencies( std::vector mavenGetAllDirectoriesFromEffectivePom( const FilePath& mavenPath, + const FilePath& settingsFilePath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDirectories) @@ -137,7 +161,8 @@ std::vector mavenGetAllDirectoriesFromEffectivePom( std::shared_ptr outputAccess = TextAccess::createFromString( utility::executeProcessUntilNoOutput( - "\"" + mavenPath.str() + "\" help:effective-pom -Doutput=\"" + outputPath.str(), + "\"" + mavenPath.str() + "\" " + getMavenArgsString(settingsFilePath) + + "help:effective-pom -Doutput=\"" + outputPath.str(), projectDirectoryPath, 60000)); diff --git a/src/lib_java/utility/utilityMaven.h b/src/lib_java/utility/utilityMaven.h index 59fab3d2..4f37973b 100644 --- a/src/lib_java/utility/utilityMaven.h +++ b/src/lib_java/utility/utilityMaven.h @@ -8,13 +8,16 @@ class FilePath; namespace utility { -std::wstring mavenGenerateSources(const FilePath& mavenPath, const FilePath& projectDirectoryPath); +std::wstring mavenGenerateSources( + const FilePath& mavenPath, const FilePath& settingsFilePath, const FilePath& projectDirectoryPath); bool mavenCopyDependencies( const FilePath& mavenPath, + const FilePath& settingsFilePath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath); std::vector mavenGetAllDirectoriesFromEffectivePom( const FilePath& mavenPath, + const FilePath& settingsFilePath, const FilePath& projectDirectoryPath, const FilePath& outputDirectoryPath, bool addTestDirectories);