Skip to content

Commit

Permalink
Support variables in Maven Installations
Browse files Browse the repository at this point in the history
Currently maven installations only support a fixed path but for certain
setups it would be desirable to use a variable.

This adds support for specify a variable in the path for an external
installation.

Fix #1372
  • Loading branch information
laeubi committed Aug 15, 2023
1 parent 8c4961d commit 82a43fa
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ If you want to switch back to an older runtime you currently need to modify you

![grafik](https://github.com/eclipse-m2e/m2e-core/assets/1331477/ef04e7f4-e36b-4bbc-a4d3-ff92e6a5f9f4)

### Support for variables in maven installations

In the preferences for maven installations one can now specify variables for maven location.

## 2.3.0

* 📅 Release Date: 23th May 2023
Expand Down
5 changes: 3 additions & 2 deletions org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.m2e.core.ui;singleton:=true
Bundle-Version: 2.0.6.qualifier
Bundle-Version: 2.4.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Expand Down Expand Up @@ -42,7 +42,8 @@ Require-Bundle: org.eclipse.m2e.core;bundle-version="[2.0.0,3.0.0)",
org.eclipse.jface.text,
org.eclipse.core.filebuffers,
org.eclipse.ui,
org.eclipse.ui.navigator
org.eclipse.ui.navigator,
org.eclipse.debug.ui
Import-Package: org.eclipse.compare.rangedifferencer,
org.eclipse.ltk.core.refactoring,
org.slf4j;version="[1.7.0,3.0.0)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ public class Messages extends NLS {

public static String ExternalInstallPage_btnDirectory_text;

public static String ExternalInstallPage_btnVariables_text;

public static String ExternalInstallPage_lblInstallationLibraries_text;

public static String ExternalInstallPage_btnRestoreDefault_text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ EnableNatureAction_job_enable=Enabling Maven Dependency Management
EnableNatureAction_wizard_shell=Create new POM
ExternalInstallPage_btnAddProject_text=Project...
ExternalInstallPage_btnDirectory_text=Directory...
ExternalInstallPage_btnVariables_text=&Variables...
ExternalInstallPage_btnDown_text=Down
ExternalInstallPage_btnRemove_text=Remove
ExternalInstallPage_btnRestoreDefault_text=Restore Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Set;

import org.eclipse.core.resources.IProject;
import org.eclipse.debug.ui.StringVariableSelectionDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredSelection;
Expand Down Expand Up @@ -189,11 +190,24 @@ public void createControl(Composite parent) {
location.addModifyListener(e -> updateStatus());
location.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

btnDirectory = new Button(container, SWT.NONE);
Composite btnComposite = new Composite(container, SWT.NONE);
btnComposite.setLayout((new GridLayout(2, true)));
btnDirectory = new Button(btnComposite, SWT.NONE);
btnDirectory.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> selectLocationAction()));
btnDirectory.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btnDirectory.setText(Messages.ExternalInstallPage_btnDirectory_text);

Button variablesButton = new Button(btnComposite, SWT.NONE);
variablesButton.setText(Messages.ExternalInstallPage_btnVariables_text);
variablesButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
dialog.open();
String variable = dialog.getVariableExpression();
if(variable != null) {
location.setText(location.getText() + variable);
}
}));

Label lblInstallationName = new Label(container, SWT.NONE);
lblInstallationName.setText(Messages.ExternalInstallPage_lblInstallationName_text);

Expand Down Expand Up @@ -353,10 +367,6 @@ private boolean isValidMavenInstall(String dir) {
if(dir == null || dir.length() == 0) {
return false;
}
File selectedDir = new File(dir);
if(!selectedDir.isDirectory()) {
return false;
}
return new MavenExternalRuntime(dir).isAvailable();
}

Expand Down
3 changes: 2 additions & 1 deletion org.eclipse.m2e.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.m2e.maven.runtime;bundle-version="[3.8.6,4.0.0)",
org.eclipse.m2e.workspace.cli;bundle-version="0.1.0",
org.eclipse.core.runtime;bundle-version="3.12.0",
org.eclipse.core.resources;bundle-version="3.9.0",
org.eclipse.core.filesystem;bundle-version="1.7.700"
org.eclipse.core.filesystem;bundle-version="1.7.700",
org.eclipse.core.variables
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.m2e.core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;

import org.codehaus.plexus.classworlds.ClassWorldException;
import org.codehaus.plexus.classworlds.launcher.ConfigurationException;
Expand Down Expand Up @@ -71,16 +73,22 @@ public boolean isEditable() {

@Override
public boolean isAvailable() {
return new File(location, "bin").exists() && getLauncherClasspath() != null && isSupportedVersion(); //$NON-NLS-1$
return new File(getLocation(), "bin").exists() && getLauncherClasspath() != null && isSupportedVersion(); //$NON-NLS-1$
}

@Override
public String getLocation() {
IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
try {
return manager.performStringSubstitution(location);
} catch(CoreException ex) {
//if we can't parse the location we need to return the unparsed raw value...
}
return location;
}

private File getLauncherConfigurationFile() {
return new File(location, "bin/m2.conf"); //$NON-NLS-1$
return new File(getLocation(), "bin/m2.conf"); //$NON-NLS-1$
}

@Override
Expand Down Expand Up @@ -140,7 +148,7 @@ public void setAppMain(String mainClassName, String mainRealmName) {

Properties properties = new Properties();
copyProperties(properties, System.getProperties());
properties.put(PROPERTY_MAVEN_HOME, location);
properties.put(PROPERTY_MAVEN_HOME, getLocation());

ConfigurationParser parser = new ConfigurationParser(handler, properties);

Expand All @@ -158,7 +166,7 @@ public void setAppMain(String mainClassName, String mainRealmName) {

@Override
public String toString() {
return location + ' ' + getVersion();
return getLocation() + ' ' + getVersion();
}

private static class ExceptionWrapper extends RuntimeException {
Expand All @@ -170,7 +178,7 @@ public ExceptionWrapper(Exception cause) {
}

private String getLauncherClasspath() {
File mavenHome = new File(location);
File mavenHome = new File(getLocation());
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(mavenHome);
ds.setIncludes(new String[] {"core/boot/classworlds*.jar", // 2.0.4 //$NON-NLS-1$
Expand Down Expand Up @@ -255,7 +263,7 @@ public void setAppMain(String mainClassName, String mainRealmName) {

Properties properties = new Properties();
copyProperties(properties, System.getProperties());
properties.put(PROPERTY_MAVEN_HOME, location);
properties.put(PROPERTY_MAVEN_HOME, getLocation());

try (FileInputStream is = new FileInputStream(getLauncherConfigurationFile())) {
new ConfigurationParser(handler, properties).parse(is);
Expand Down

0 comments on commit 82a43fa

Please sign in to comment.