selectedFile,
- File defaultFile) {
- Link link = new Link(composite, SWT.NONE);
- link.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- link.setText(text);
- link.setToolTipText(tooltip);
- link.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
- File file = Optional.ofNullable(selectedFile.get()).map(File::new).orElse(defaultFile);
- if(file != null) {
- openEditor(file);
- }
- }));
- return link;
+ /**
+ * @param composite
+ * @param mavenSettingsPreferencePage_globalPreferences
+ */
+ private void createHeading(Composite composite, String caption, boolean sep) {
+ if(sep) {
+ Label lblSpace = new Label(composite, SWT.NONE);
+ GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 4, 1);
+ gridData.heightHint = 20;
+ lblSpace.setLayoutData(gridData);
+ }
+
+ Label lblCaption = new Label(composite, SWT.NONE);
+ lblCaption.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 4, 1));
+ lblCaption.setText(caption);
+
+ Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
+ GridData gd_separator = new GridData(SWT.FILL, SWT.TOP, true, false, 4, 1);
+ gd_separator.heightHint = 10;
+ separator.setLayoutData(gd_separator);
}
- private Text createFileSelectionWidgets(Composite composite, String selectedFile, File defaultFile) {
+
+
+ private Text createFileSelectionWidgets(Composite composite, String label, String selectedFile, File defaultFile) {
+ Label lbSetting = new Label(composite, SWT.NONE);
+ lbSetting.setLayoutData(new GridData(SWT.LEFT, SWT.LEFT, false, false, 1, 1));
+ lbSetting.setText(label);
+
Text fileText = new Text(composite, SWT.BORDER);
fileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
if(defaultFile != null) {
@@ -266,16 +293,23 @@ private Text createFileSelectionWidgets(Composite composite, String selectedFile
});
Button browseButton = new Button(composite, SWT.NONE);
- browseButton.setLayoutData(new GridData(SWT.FILL, SWT.RIGHT, false, false, 1, 1));
- browseButton.setText(Messages.MavenSettingsPreferencePage_settingsBrowseButton_text);
+ browseButton.setLayoutData(new GridData(SWT.LEFT, SWT.LEFT, false, false, 1, 1));
+ browseButton.setText(Messages.MavenSettingsPreferencePage_btnBrowse_text);
+ browseButton.setToolTipText(Messages.MavenSettingsPreferencePage_btnBrowse_tooltip);
browseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> browseSettingsAction(fileText)));
- return fileText;
- }
- private void updateLink(Link link, String path, File defaultFile, String activeText, String inactiveText) {
- File file = path != null ? new File(path) : defaultFile;
- boolean active = file != null && file.canRead();
- link.setText(active ? activeText : inactiveText);
+ Button editButton = new Button(composite, SWT.NONE);
+ editButton.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, false, false, 1, 1));
+ editButton.setText(Messages.MavenSettingsPreferencePage_btnEdit_text);
+ editButton.setToolTipText(Messages.MavenSettingsPreferencePage_btnEdit_tooltip);
+ editButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
+ final String path = fileText.getText();
+ final File file = (path.isBlank()) ? defaultFile : new File(path);
+ if(file != null) {
+ openEditor(file);
+ }
+ }));
+ return fileText;
}
protected void updateLocalRepository() {
@@ -295,6 +329,7 @@ protected void updateLocalRepository() {
}
}
+
protected void checkSettings() {
setErrorMessage(null);
setMessage(null);
@@ -302,22 +337,18 @@ protected void checkSettings() {
// NB: enable/disable links regardless of validation errors
String globalSettings = getGlobalSettings();
- updateLink(globalSettingsLink, globalSettings, null, Messages.MavenSettingsPreferencePage_globalSettingslink2,
- Messages.MavenSettingsPreferencePage_globalSettingslink1);
-
+ String globalToolchains = getGlobalToolchains();
String userSettings = getUserSettings();
- updateLink(userSettingsLink, userSettings, SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE,
- Messages.MavenSettingsPreferencePage_userSettingslink2, Messages.MavenSettingsPreferencePage_userSettingslink1);
-
String userToolchains = getUserToolchains();
- updateLink(userToolchainsLink, userToolchains, MavenCli.DEFAULT_USER_TOOLCHAINS_FILE,
- Messages.MavenSettingsPreferencePage_userToolchainslink2,
- Messages.MavenSettingsPreferencePage_userToolchainslink1);
setMessage(null);
checkSettings(globalSettings, Messages.MavenSettingsPreferencePage_error_globalSettingsMissing,
l -> maven.validateSettings(l).stream().map(SettingsProblem::getMessage),
Messages.MavenSettingsPreferencePage_error_globalSettingsParse);
+ checkSettings(globalToolchains, Messages.MavenSettingsPreferencePage_error_globalToolchainsMissing,
+ l -> IMavenToolbox.of(maven).validateToolchains(l).stream().map(Problem::getMessage),
+ Messages.MavenSettingsPreferencePage_error_globalToolchainsParse);
+
checkSettings(userSettings, Messages.MavenSettingsPreferencePage_error_userSettingsMissing,
l -> maven.validateSettings(l).stream().map(SettingsProblem::getMessage),
Messages.MavenSettingsPreferencePage_error_userSettingsParse);
@@ -343,10 +374,8 @@ void openEditor(File file) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
-
- IEditorDescriptor desc = workbench.getEditorRegistry().getDefaultEditor("settings.xml"); //$NON-NLS-1$
-
- IEditorInput input = new FileStoreEditorInput(EFS.getLocalFileSystem().fromLocalFile(file));
+ IEditorDescriptor desc = workbench.getEditorRegistry().getDefaultEditor(file.getName()); //$NON-NLS-1$
+ IEditorInput input = new FileStoreEditorInput(EFS.getLocalFileSystem().fromLocalFile(file.getAbsoluteFile()));
try {
IEditorPart editor = IDE.openEditor(page, input, desc.getId());
if(editor == null) {
@@ -363,6 +392,29 @@ void openEditor(File file) {
}
}
+ private File getDefaultGlobalSettingsFile() {
+ return this.getRuntimeBasedFile("conf/settings.xml");
+ }
+
+ private File getDefaultGlobalToolchainsFile() {
+ return this.getRuntimeBasedFile("conf/toolchains.xml");
+ }
+
+ /**
+ * Calcuate relative path of an file to the configured maven runtime.
+ *
+ * @param relativePath the expected relative path.
+ * @return null
if the runtime has no accessible location e.g. EMBEDDED.
+ */
+ private File getRuntimeBasedFile(String relativePath) {
+ final AbstractMavenRuntime runtime = this.runtimeManager.getRuntime(MavenRuntimeManagerImpl.DEFAULT);
+ final String location = runtime.getLocation();
+ if(null != location && !location.isBlank() && runtime.isEditable()) {
+ return new File(location, relativePath);
+ }
+ return null;
+ }
+
private String getUserSettings() {
return getSettings(userSettingsText);
}
@@ -375,6 +427,10 @@ private String getGlobalSettings() {
return getSettings(globalSettingsText);
}
+ private String getGlobalToolchains() {
+ return getSettings(globalToolchainsText);
+ }
+
private String getSettings(Text settings) {
String location = settings.getText().trim();
return location.length() > 0 ? location : null;
@@ -392,4 +448,12 @@ protected void browseSettingsAction(Text settings) {
checkSettings();
}
}
+
+ protected void updateGlobalSettingsDefaultFiles() {
+ this.globalSettingsText
+ .setMessage(Optional.ofNullable(this.getDefaultGlobalSettingsFile()).map(File::getAbsolutePath).orElse(""));
+
+ this.globalToolchainsText
+ .setMessage(Optional.ofNullable(this.getDefaultGlobalToolchainsFile()).map(File::getAbsolutePath).orElse(""));
+ }
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/CoreSupplier.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/CoreSupplier.java
new file mode 100644
index 0000000000..dc456b0751
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/CoreSupplier.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Georg Tsakumagos and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Georg Tsakumagos - initial declaration
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.embedder;
+
+import org.eclipse.core.runtime.CoreException;
+
+
+/**
+ * Represents a supplier of results that throws a {@link CoreException}
+ *
+ * There is no requirement that a new or distinct result be returned each time the supplier is invoked.
+ *
+ * This is a functional interface whose functional method is {@link #get()}.
+ *
+ * @param the type of results supplied by this supplier
+ * @since 2.1.0
+ * @author Georg Tsakumagos
+ */
+@FunctionalInterface
+public interface CoreSupplier {
+
+ /**
+ * Gets a result.
+ *
+ * @return a result
+ * @throws CoreException If something went wrong.
+ */
+ T get() throws CoreException;
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java
index 4858b3cc92..397e951896 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java
@@ -51,6 +51,10 @@ public interface IMavenConfiguration {
//settable for embedded maven
void setGlobalSettingsFile(String absolutePath) throws CoreException;
+ String getGlobalToolchainsFile();
+
+ void setGlobalToolchainsFile(String absolutePath) throws CoreException;
+
String getUserSettingsFile();
void setUserSettingsFile(String absolutePath) throws CoreException;
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
index edf5cb23a2..0ce802f0d0 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java
@@ -208,6 +208,9 @@ static MavenExecutionRequest createExecutionRequest(IMavenConfiguration mavenCon
updateSettingsFiles(request, settingsLocations);
//and settings are actually derived from IMavenConfiguration
File userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
+ if(mavenConfiguration.getGlobalToolchainsFile() != null) {
+ request.setGlobalToolchainsFile(new File(mavenConfiguration.getGlobalToolchainsFile()));
+ }
if(mavenConfiguration.getUserToolchainsFile() != null) {
userToolchainsFile = new File(mavenConfiguration.getUserToolchainsFile());
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
index e58327cc3d..f45a510388 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java
@@ -127,6 +127,7 @@
import org.apache.maven.settings.building.SettingsBuilder;
import org.apache.maven.settings.building.SettingsBuildingException;
import org.apache.maven.settings.building.SettingsBuildingRequest;
+import org.apache.maven.settings.building.SettingsBuildingResult;
import org.apache.maven.settings.building.SettingsProblem;
import org.apache.maven.settings.building.SettingsProblem.Severity;
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
@@ -310,7 +311,8 @@ public List validateSettings(String settings) {
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
request.setUserSettingsFile(settingsFile);
try {
- lookup(SettingsBuilder.class).build(request);
+ SettingsBuildingResult result = lookup(SettingsBuilder.class).build(request);
+ problems.addAll(result.getProblems());
} catch(SettingsBuildingException ex) {
problems.addAll(ex.getProblems());
} catch(CoreException ex) {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java
index d9d5d479fb..8f778d80ec 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java
@@ -100,6 +100,11 @@ public String getGlobalSettingsFile() {
return getStringPreference(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE, null);
}
+ @Override
+ public String getGlobalToolchainsFile() {
+ return getStringPreference(MavenPreferenceConstants.P_GLOBAL_TOOLCHAINS_FILE, null);
+ }
+
@Override
public String getUserSettingsFile() {
return getStringPreference(MavenPreferenceConstants.P_USER_SETTINGS_FILE, null);
@@ -157,6 +162,11 @@ public void setGlobalSettingsFile(String globalSettingsFile) throws CoreExceptio
setSettingsFile(globalSettingsFile, MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE);
}
+ @Override
+ public void setGlobalToolchainsFile(String globalToolchainsFile) throws CoreException {
+ setSettingsFile(globalToolchainsFile, MavenPreferenceConstants.P_GLOBAL_TOOLCHAINS_FILE);
+ }
+
@Override
public void setUserToolchainsFile(String settingsFile) throws CoreException {
setSettingsFile(settingsFile, MavenPreferenceConstants.P_USER_TOOLCHAINS_FILE);
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java
index f5d1297ef8..7ace01f635 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java
@@ -58,6 +58,9 @@ public interface MavenPreferenceConstants {
/** String */
String P_GLOBAL_SETTINGS_FILE = PREFIX + "globalSettingsFile"; //$NON-NLS-1$
+ /** String */
+ String P_GLOBAL_TOOLCHAINS_FILE = PREFIX + "globalToolchainsFile"; //$NON-NLS-1$
+
/** String */
String P_USER_SETTINGS_FILE = PREFIX + "userSettingsFile"; //$NON-NLS-1$
diff --git a/org.eclipse.m2e.launching/META-INF/MANIFEST.MF b/org.eclipse.m2e.launching/META-INF/MANIFEST.MF
index 523d712280..9d3d8c5799 100644
--- a/org.eclipse.m2e.launching/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.launching/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.m2e.launching;singleton:=true
-Bundle-Version: 2.0.601.qualifier
+Bundle-Version: 2.0.602.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.27.0,4.0.0)",
org.eclipse.core.variables,
diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java
index 3fad7104e1..4d20cf620a 100644
--- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java
+++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java
@@ -58,11 +58,13 @@
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.cli.CLIManager;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.eclipse.m2e.actions.MavenLaunchConstants;
import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.CoreSupplier;
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime;
@@ -113,6 +115,40 @@ public MavenLaunchDelegate() {
allowAdvancedSourcelookup();
}
+ /**
+ * Appends file based configuration key if not already set.
+ *
+ * @param name The name of the setting.
+ * @param arg The argument without dash. Must not be null
.
+ * @param sb The target. Must not be null
.
+ * @param goals The configured goals. Used to override settings.
+ * @param substitute true
, if variables in settings should be substituted.
+ * @param source Source for the settings. Must not be null
.
+ * @throws CoreException If something went wrong.
+ * @throws IllegalArgumentException If the configured file does not exists.
+ */
+ private void appendFileSetting(String name, String arg, StringBuilder sb, String goals, boolean substitute,
+ CoreSupplier source) throws CoreException, IllegalArgumentException {
+ final String key = "-" + arg + " ";
+ if(!goals.contains(key) && 0 >= sb.indexOf(key)) {
+ String setting = source.get();
+
+ if(substitute && null != setting) {
+ setting = LaunchingUtils.substituteVar(setting);
+ }
+
+ if(null != setting && !setting.isBlank()) {
+ final File file = new File(setting.trim());
+ if(file.exists()) {
+ sb.append(" "); //$NON-NLS-1$
+ sb.append(key).append(quote(file.getAbsolutePath()));
+ } else {
+ throw new IllegalArgumentException("invalid path for " + name + ": " + file.getAbsolutePath());
+ }
+ }
+ }
+ }
+
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
@@ -433,7 +469,7 @@ private void getProperties(StringBuilder sb, ILaunchConfiguration configuration)
try {
String profiles = configuration.getAttribute(ATTR_PROFILES, (String) null);
if(profiles != null && profiles.trim().length() > 0) {
- sb.append(" -P").append(profiles.replaceAll("\\s+", ",")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ sb.append(" -P").append(profiles.replaceAll("\\s+", ",")); ////$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
} catch(CoreException ex) {
log.error("Exception while getting configuration attribute " + ATTR_PROFILES, ex);
@@ -494,28 +530,19 @@ private void getPreferences(StringBuilder sb, ILaunchConfiguration configuration
"Unexpected value for" + MavenLaunchConstants.ATTR_COLOR + ": " + colors);
};
sb.append(" -Dstyle.color=" + enableColor);
-
- if(!goals.contains("-gs ")) { //$NON-NLS-1$
- String globalSettings = launchSupport.getSettings();
- if(globalSettings != null && !globalSettings.trim().isEmpty() && !new File(globalSettings.trim()).exists()) {
- globalSettings = null;
- }
- if(globalSettings != null && !globalSettings.trim().isEmpty()) {
- sb.append(" -gs ").append(quote(globalSettings)); //$NON-NLS-1$
- }
- }
-
- String settings = configuration.getAttribute(MavenLaunchConstants.ATTR_USER_SETTINGS, (String) null);
- settings = LaunchingUtils.substituteVar(settings);
- if(settings == null || settings.trim().isEmpty()) {
- settings = mavenConfiguration.getUserSettingsFile();
- if(settings != null && !settings.trim().isEmpty() && !new File(settings.trim()).exists()) {
- settings = null;
- }
- }
- if(settings != null && !settings.trim().isEmpty()) {
- sb.append(" -s ").append(quote(settings)); //$NON-NLS-1$
- }
+ this.appendFileSetting("global settings", CLIManager.ALTERNATE_GLOBAL_SETTINGS, sb, goals, false, //$NON-NLS-1$
+ mavenConfiguration::getGlobalSettingsFile);
+ this.appendFileSetting("global settings", CLIManager.ALTERNATE_GLOBAL_SETTINGS, sb, goals, false, //$NON-NLS-1$
+ launchSupport::getSettings); //$NON-NLS-2$
+ this.appendFileSetting("global toolchains", CLIManager.ALTERNATE_GLOBAL_TOOLCHAINS, sb, goals, false, //$NON-NLS-1$
+ mavenConfiguration::getGlobalToolchainsFile); //$NON-NLS-2$
+
+ this.appendFileSetting("user settings", String.valueOf(CLIManager.ALTERNATE_USER_SETTINGS), sb, goals, false, //$NON-NLS-1$ //$NON-NLS-2$
+ () -> configuration.getAttribute(MavenLaunchConstants.ATTR_USER_SETTINGS, (String) null));
+ this.appendFileSetting("user settings", String.valueOf(CLIManager.ALTERNATE_USER_SETTINGS), sb, goals, false, //$NON-NLS-1$
+ mavenConfiguration::getUserSettingsFile); //$NON-NLS-2$
+ this.appendFileSetting("user toolchains", String.valueOf(CLIManager.ALTERNATE_USER_TOOLCHAINS), sb, goals, false, //$NON-NLS-1$
+ mavenConfiguration::getUserToolchainsFile); //$NON-NLS-2$
// boolean b = preferenceStore.getBoolean(MavenPreferenceConstants.P_CHECK_LATEST_PLUGIN_VERSION);
// sb.append(" -D").append(MavenPreferenceConstants.P_CHECK_LATEST_PLUGIN_VERSION).append("=").append(b);