Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
logic: allow to specify custom Maven settings.xml file in project set…
Browse files Browse the repository at this point in the history
…tings (issue #794) (#847)
  • Loading branch information
mlangkabel authored Dec 11, 2019
1 parent d33a535 commit 3932bb1
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,45 @@ 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<const SourceGroupSettingsWithJavaMaven*>(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);
}

void SourceGroupSettingsWithJavaMaven::load(const ConfigManager* config, const std::string& key)
{
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());
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class SourceGroupSettingsWithJavaMaven: public SourceGroupSettingsComponent
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;

Expand All @@ -27,6 +31,7 @@ class SourceGroupSettingsWithJavaMaven: public SourceGroupSettingsComponent
private:
FilePath m_mavenProjectFilePath;
bool m_shouldIndexMavenTests = false;
FilePath m_mavenSettingsFilePath;
};

#endif // SOURCE_GROUP_SETTINGS_WITH_JAVA_MAVEN_H
2 changes: 2 additions & 0 deletions src/lib_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/lib_gui/qt/project_wizard/QtProjectWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

#if BUILD_JAVA_LANGUAGE_PACKAGE
# include "QtProjectWizardContentJavaStandard.h"
# include "QtProjectWizardContentPathSettingsMaven.h"
# include "QtProjectWizardContentPathSourceGradle.h"
# include "QtProjectWizardContentPathSourceMaven.h"
# include "QtProjectWizardContentPathsClassJava.h"
Expand Down Expand Up @@ -421,6 +422,8 @@ std::vector<QtSourceGroupWizardPage<SourceGroupSettingsJavaMaven>> getSourceGrou
WIZARD_CONTENT_CONTEXT_ALL);
page.addContentCreatorWithSettings<QtProjectWizardContentPathSourceMaven>(
WIZARD_CONTENT_CONTEXT_ALL);
page.addContentCreatorWithSettings<QtProjectWizardContentPathSettingsMaven>(
WIZARD_CONTENT_CONTEXT_ALL);
pages.push_back(page);
}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "QtProjectWizardContentPathSettingsMaven.h"

#include <QCheckBox>

//#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<SourceGroupSettingsJavaMaven> 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.<br />"
"<br />"
"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<SourceGroupSettings> QtProjectWizardContentPathSettingsMaven::getSourceGroupSettings()
{
return m_settings;
}
Original file line number Diff line number Diff line change
@@ -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<SourceGroupSettingsJavaMaven> settings, QtProjectWizardWindow* window);

// QtProjectWizardContent implementation
void populate(QGridLayout* layout, int& row) override;

void load() override;
void save() override;

private:
std::shared_ptr<SourceGroupSettings> getSourceGroupSettings() override;

std::shared_ptr<SourceGroupSettingsJavaMaven> m_settings;
};

#endif // QT_PROJECT_WIZARD_CONTENT_PATH_SETTINGS_MAVEN_H
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ std::vector<FilePath> QtProjectWizardContentPathSourceMaven::getFilePaths() cons
{
{
const FilePath mavenPath = ApplicationSettings::getInstance()->getMavenPath();
const FilePath mavenSettingsPath = m_settings->getMavenSettingsFilePathExpandedAndAbsolute();
const FilePath mavenProjectRoot =
m_settings->getMavenProjectFilePathExpandedAndAbsolute().getParentDirectory();

Expand All @@ -80,7 +81,8 @@ std::vector<FilePath> 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();
Expand Down
11 changes: 9 additions & 2 deletions src/lib_java/project/SourceGroupJavaMaven.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
Expand All @@ -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;
}
Expand All @@ -114,11 +119,13 @@ std::vector<FilePath> 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());
Expand Down
37 changes: 31 additions & 6 deletions src/lib_java/utility/utilityMaven.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,37 @@ std::wstring getErrorMessageFromMavenOutput(std::shared_ptr<const TextAccess> ma

return errorMessage;
}

std::string getMavenArgsString(const FilePath& settingsFilePath)
{
std::vector<std::string> 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<TextAccess> outputAccess = TextAccess::createFromString(
utility::executeProcessUntilNoOutput(
"\"" + mavenPath.str() + "\" generate-sources", projectDirectoryPath, 60000));
"\"" + mavenPath.str() + "\" " + getMavenArgsString(settingsFilePath) + "generate-sources",
projectDirectoryPath,
60000));

if (outputAccess->isEmpty())
{
Expand All @@ -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<TextAccess> 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));

Expand All @@ -127,6 +150,7 @@ bool mavenCopyDependencies(

std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath,
const FilePath& settingsFilePath,
const FilePath& projectDirectoryPath,
const FilePath& outputDirectoryPath,
bool addTestDirectories)
Expand All @@ -137,7 +161,8 @@ std::vector<FilePath> mavenGetAllDirectoriesFromEffectivePom(

std::shared_ptr<TextAccess> 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));

Expand Down
5 changes: 4 additions & 1 deletion src/lib_java/utility/utilityMaven.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilePath> mavenGetAllDirectoriesFromEffectivePom(
const FilePath& mavenPath,
const FilePath& settingsFilePath,
const FilePath& projectDirectoryPath,
const FilePath& outputDirectoryPath,
bool addTestDirectories);
Expand Down

0 comments on commit 3932bb1

Please sign in to comment.