Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2014-04-18 23:29:50 -0400
committerIgor Fedorenko2014-04-20 19:04:43 -0400
commitf68db7860dd0d0c7b03349e0dc550733a01844fa (patch)
treefae654514ea87b2b7798f224ff5158804f7e592a
parent150c457edc53494dd4d48bb72454f998e08473e7 (diff)
downloadm2e-core-f68db7860dd0d0c7b03349e0dc550733a01844fa.tar.gz
m2e-core-f68db7860dd0d0c7b03349e0dc550733a01844fa.tar.xz
m2e-core-f68db7860dd0d0c7b03349e0dc550733a01844fa.zip
432436 ability to add/edit/use customized workspace runtimes
Change-Id: I6eab67cb7ce7791ee912606fe5754e8402e40721 Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java5
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties7
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java73
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java34
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java11
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java179
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/DefaultWorkspaceRuntime.java34
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java6
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java11
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java140
-rw-r--r--org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenRuntimeSelector.java17
11 files changed, 293 insertions, 224 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
index d6a84ce7..f13b8b6a 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
@@ -930,6 +930,11 @@ public class Messages extends NLS {
public static String MavenInstallationsPreferencePage_tblclmnName_text;
public static String MavenInstallationsPreferencePage_tblclmnDetails_text;
+ public static String MavenInstallationWizardPage_btnExternal_text;
+ public static String MavenInstallationWizardPage_btnExternal_text_1;
+ public static String MavenInstallationWizardPage_btnEmbedded_text;
+ public static String MavenInstallationWizardPage_btnWorkspace_text;
+ public static String MavenInstallationWizardPage_lblInstallationType_text;
static {
// initialize resource bundle
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
index 4bca224e..cb06d805 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
@@ -1,5 +1,5 @@
#Eclipse modern messages class
-#Sat Apr 19 00:39:56 MSK 2014
+#Sat Apr 19 06:12:29 MSK 2014
AddDependencyAction_error_msg=Can't add dependency to {0}
AddDependencyAction_error_title=Add Dependency
AddDependencyAction_searchDialog_title=Add Dependency
@@ -169,6 +169,11 @@ MavenInstallFileArtifactWizardPage_title=Install file in local repository
MavenInstallFileWizard_error=Execution error
MavenInstallFileWizard_job=Installing artifact
MavenInstallFileWizard_title=Install artifact
+MavenInstallationWizardPage_btnEmbedded_text=Embedded
+MavenInstallationWizardPage_btnExternal_text=External
+MavenInstallationWizardPage_btnExternal_text_1=External
+MavenInstallationWizardPage_btnWorkspace_text=Workspace
+MavenInstallationWizardPage_lblInstallationType_text=Installation type\:
MavenInstallationsPreferencePage_btnAdd=&Add...
MavenInstallationsPreferencePage_btnEdit=&Edit...
MavenInstallationsPreferencePage_btnGlobalBrowse=&Browse...
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java
index 90ba6cc2..2cfcd5de 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java
@@ -37,6 +37,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DirectoryDialog;
@@ -49,6 +50,7 @@ import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime;
import org.eclipse.m2e.core.internal.launch.ClasspathEntry;
import org.eclipse.m2e.core.internal.launch.MavenExternalRuntime;
+import org.eclipse.m2e.core.internal.launch.MavenWorkspaceRuntime;
import org.eclipse.m2e.core.internal.launch.ProjectClasspathEntry;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.ui.internal.Messages;
@@ -76,6 +78,12 @@ public class MavenInstallationWizardPage extends WizardPage {
private AbstractMavenRuntime original;
+ private Button btnExternal;
+
+ private Button btnWorkspace;
+
+ private Button btnDirectory;
+
class TreeContentProvider implements ITreeContentProvider {
public void dispose() {
@@ -144,6 +152,27 @@ public class MavenInstallationWizardPage extends WizardPage {
setControl(container);
container.setLayout(new GridLayout(3, false));
+ Label lblInstallationType = new Label(container, SWT.NONE);
+ lblInstallationType.setText(Messages.MavenInstallationWizardPage_lblInstallationType_text);
+
+ Composite composite = new Composite(container, SWT.NONE);
+ RowLayout rl_composite = new RowLayout(SWT.HORIZONTAL);
+ rl_composite.fill = true;
+ composite.setLayout(rl_composite);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
+
+ btnExternal = new Button(composite, SWT.RADIO);
+ btnExternal.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ changeRuntimeTypeAction();
+ }
+ });
+ btnExternal.setText(Messages.MavenInstallationWizardPage_btnExternal_text_1);
+
+ btnWorkspace = new Button(composite, SWT.RADIO);
+ btnWorkspace.setText(Messages.MavenInstallationWizardPage_btnWorkspace_text);
+
Label lblInstallationLocation = new Label(container, SWT.NONE);
lblInstallationLocation.setText(Messages.ExternalInstallPage_lblInstallationLocation_text);
@@ -155,7 +184,7 @@ public class MavenInstallationWizardPage extends WizardPage {
});
location.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- Button btnDirectory = new Button(container, SWT.NONE);
+ btnDirectory = new Button(container, SWT.NONE);
btnDirectory.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
@@ -166,7 +195,6 @@ public class MavenInstallationWizardPage extends WizardPage {
btnDirectory.setText(Messages.ExternalInstallPage_btnDirectory_text);
Label lblInstallationName = new Label(container, SWT.NONE);
- lblInstallationName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblInstallationName.setText(Messages.ExternalInstallPage_lblInstallationName_text);
name = new Text(container, SWT.BORDER);
@@ -243,17 +271,33 @@ public class MavenInstallationWizardPage extends WizardPage {
btnRestoreDefault.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));
btnRestoreDefault.setText(Messages.ExternalInstallPage_btnRestoreDefault_text);
- if(original != null) {
+ if(original instanceof MavenExternalRuntime) {
+ btnExternal.setSelection(true);
location.setText(original.getLocation());
if(!original.isLegacy()) {
name.setText(original.getName());
}
}
+ if(original instanceof MavenWorkspaceRuntime) {
+ btnWorkspace.setSelection(true);
+ name.setText(original.getName());
+ } else {
+ btnWorkspace.setEnabled(new MavenWorkspaceRuntime("test").isAvailable()); //$NON-NLS-1$
+ }
+ if(original == null) {
+ btnExternal.setSelection(true);
+ }
updateButtonsState();
updateStatus();
}
+ protected void changeRuntimeTypeAction() {
+ location.setEnabled(btnExternal.getSelection());
+ btnDirectory.setEnabled(btnExternal.getSelection());
+ updateStatus();
+ }
+
protected void moveExtensionAction(int offset) {
int from = extensions.indexOf(getSelectedElement());
int to = Math.min(extensions.size() - 1, Math.max(0, from + offset));
@@ -343,14 +387,16 @@ public class MavenInstallationWizardPage extends WizardPage {
protected void updateStatus() {
setPageComplete(false);
- if(location.getText().trim().isEmpty()) {
- setMessage("Enter the home directory of the Maven Installation");
- return;
- }
+ if(btnExternal.getSelection()) {
+ if(location.getText().trim().isEmpty()) {
+ setMessage("Enter the home directory of the Maven Installation");
+ return;
+ }
- if(!isValidMavenInstall(location.getText())) {
- setErrorMessage("Target is not a Maven Home");
- return;
+ if(!isValidMavenInstall(location.getText())) {
+ setErrorMessage("Target is not a Maven Home");
+ return;
+ }
}
if(name.getText().trim().isEmpty()) {
@@ -365,7 +411,12 @@ public class MavenInstallationWizardPage extends WizardPage {
}
public AbstractMavenRuntime getResult() {
- MavenExternalRuntime runtime = new MavenExternalRuntime(name.getText(), location.getText());
+ AbstractMavenRuntime runtime;
+ if(btnExternal.getSelection()) {
+ runtime = new MavenExternalRuntime(name.getText(), location.getText());
+ } else {
+ runtime = new MavenWorkspaceRuntime(name.getText());
+ }
runtime.setExtensions(extensions);
return runtime;
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java
index 0eb8df36..6fa3dead 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java
@@ -26,9 +26,9 @@ import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.m2e.core.internal.IMavenConstants;
-import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime;
import org.eclipse.m2e.core.internal.launch.ClasspathEntry;
+import org.eclipse.m2e.core.internal.launch.DefaultWorkspaceRuntime;
import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime;
import org.eclipse.m2e.core.internal.launch.MavenExternalRuntime;
import org.eclipse.m2e.core.internal.launch.MavenWorkspaceRuntime;
@@ -49,6 +49,8 @@ public class MavenRuntimeManager {
public static final String WORKSPACE = "WORKSPACE"; //$NON-NLS-1$
+ private static final String EXTERNAL = "EXTERNAL"; //$NON-NLS-1$
+
private final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
private final IPreferencesService preferenceStore;
@@ -75,14 +77,10 @@ public class MavenRuntimeManager {
public MavenRuntime getDefaultRuntime() {
String selected = preferenceStore.get(MavenPreferenceConstants.P_DEFAULT_RUNTIME, null, preferencesLookup);
if(selected == null) {
- return getEmbeddedRuntime();
+ return new MavenEmbeddedRuntime();
}
MavenRuntime runtime = getRuntimeByName(selected);
- return runtime != null && runtime.isAvailable() ? runtime : getEmbeddedRuntime();
- }
-
- private MavenEmbeddedRuntime getEmbeddedRuntime() {
- return new MavenEmbeddedRuntime(MavenPluginActivator.getDefault().getBundle());
+ return runtime != null && runtime.isAvailable() ? runtime : new MavenEmbeddedRuntime();
}
/**
@@ -154,6 +152,7 @@ public class MavenRuntimeManager {
sb.append(runtime.getName());
if(!impl.isLegacy()) {
Preferences runtimeNode = getRuntimePreferences(runtime.getName(), true);
+ runtimeNode.put("type", getRuntimeType(runtime));
runtimeNode.put("location", runtime.getLocation());
String extensions = encodeClasspath(impl.getExtensions());
if(extensions != null) {
@@ -178,6 +177,15 @@ public class MavenRuntimeManager {
}
}
+ private String getRuntimeType(MavenRuntime runtime) {
+ if(runtime instanceof MavenExternalRuntime) {
+ return EXTERNAL;
+ } else if(runtime instanceof MavenWorkspaceRuntime) {
+ return WORKSPACE;
+ }
+ throw new IllegalArgumentException();
+ }
+
private Preferences getRuntimePreferences(String name, boolean create) {
Preferences runtimesNode = preferencesLookup[0].node(MavenPreferenceConstants.P_RUNTIMES_NODE);
try {
@@ -220,8 +228,8 @@ public class MavenRuntimeManager {
private Map<String, AbstractMavenRuntime> getRuntimes() {
Map<String, AbstractMavenRuntime> runtimes = new LinkedHashMap<String, AbstractMavenRuntime>();
- runtimes.put(EMBEDDED, getEmbeddedRuntime());
- runtimes.put(WORKSPACE, new MavenWorkspaceRuntime(MavenPluginActivator.getDefault().getMavenProjectManager()));
+ runtimes.put(EMBEDDED, new MavenEmbeddedRuntime());
+ runtimes.put(WORKSPACE, new DefaultWorkspaceRuntime());
String runtimesPreference = preferenceStore.get(MavenPreferenceConstants.P_RUNTIMES, null, preferencesLookup);
if(runtimesPreference != null && runtimesPreference.length() > 0) {
@@ -242,7 +250,13 @@ public class MavenRuntimeManager {
private AbstractMavenRuntime createRuntime(String name, Preferences preferences) {
String location = preferences.get("location", null);
- MavenExternalRuntime runtime = new MavenExternalRuntime(name, location);
+ String type = preferences.get("type", EXTERNAL);
+ AbstractMavenRuntime runtime;
+ if(WORKSPACE.equals(type)) {
+ runtime = new MavenWorkspaceRuntime(name);
+ } else {
+ runtime = new MavenExternalRuntime(name, location);
+ }
runtime.setExtensions(decodeClasspath(preferences.get("extensions", null)));
return runtime;
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java
index 2f9d5e89..7d6742c5 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java
@@ -94,4 +94,15 @@ public abstract class AbstractMavenRuntime implements MavenRuntime {
collector.addProjectEntry(facade);
}
+ public boolean equals(Object o) {
+ if(o != null && getClass().equals(o.getClass())) {
+ return getName().equals(((AbstractMavenRuntime) o).getName());
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java
deleted file mode 100644
index 1c592add..00000000
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Sonatype, Inc. - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.m2e.core.internal.launch;
-
-import java.io.File;
-import java.util.Set;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.apache.maven.artifact.Artifact;
-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.project.MavenProject;
-
-import org.eclipse.m2e.core.embedder.ArtifactKey;
-import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration;
-import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
-import org.eclipse.m2e.core.project.IMavenProjectFacade;
-import org.eclipse.m2e.core.project.IMavenProjectRegistry;
-
-
-/**
- * Maven 3.x runtime loaded from the Eclipse Workspace
- *
- * @author Eugene Kuleshov
- * @author Igor Fedorenko
- * @author Jason van Zyl
- */
-public abstract class AbstractWorkspaceRuntime extends AbstractMavenRuntime {
-
- private static final ArtifactKey MAVEN_DISTRIBUTION = new ArtifactKey(
- "org.apache.maven", "apache-maven", "[3.0,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- private static final ArtifactKey PLEXUS_CLASSWORLDS = new ArtifactKey(
- "org.codehaus.plexus", "plexus-classworlds", null, null); //$NON-NLS-1$ //$NON-NLS-2$
-
- private static final String MAVEN_EXECUTOR_CLASS = "org.apache.maven.cli.MavenCli"; //$NON-NLS-1$
-
- private static final String PLEXUS_CLASSWORLD_NAME = "plexus.core"; //$NON-NLS-1$
-
- private IMavenProjectRegistry projectManager;
-
- public AbstractWorkspaceRuntime(IMavenProjectRegistry projectManager) {
- this.projectManager = projectManager;
- }
-
- protected abstract ArtifactKey getDistributionArtifactKey();
-
- protected abstract String getMainClass();
-
- public String getLocation() {
- return MavenRuntimeManager.WORKSPACE;
- }
-
- public String getSettings() {
- return null;
- }
-
- public boolean isEditable() {
- return false;
- }
-
- public boolean isAvailable() {
- return getMavenDistribution() != null;
- }
-
- protected IMavenProjectFacade getMavenDistribution() {
- try {
- VersionRange range = VersionRange.createFromVersionSpec(getDistributionArtifactKey().getVersion());
- for(IMavenProjectFacade facade : projectManager.getProjects()) {
- ArtifactKey artifactKey = facade.getArtifactKey();
- if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) //
- && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())//
- && range.containsVersion(new DefaultArtifactVersion(artifactKey.getVersion()))) {
- return facade;
- }
- }
- } catch(InvalidVersionSpecificationException e) {
- // can't happen
- }
- return null;
- }
-
- public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor)
- throws CoreException {
- IMavenProjectFacade maven = getMavenDistribution();
- if(maven != null) {
- MavenProject mavenProject = maven.getMavenProject(monitor);
- //
- // main is org.apache.maven.cli.MavenCli from plexus.core
- //
- // set maven.home default ${user.home}/m2
- //
- // [plexus.core]
- // optionally ${maven.home}/lib/ext/*.jar
- // load ${maven.home}/lib/*.jar
- // load ${maven.home}/conf/logging
- //
- collector.setMainType(getMainClass(), PLEXUS_CLASSWORLD_NAME);
- collector.addRealm(PLEXUS_CLASSWORLD_NAME);
-
- collectExtensions(collector, monitor);
-
- //
- // plexus.core is the current realm, and now we want the add the SLF4J loggging configuration if
- // we have a verion>3.1.x Maven-like runtime
- //
- for(IMavenProjectFacade facade : projectManager.getProjects()) {
- ArtifactKey artifactKey = facade.getArtifactKey();
- if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) //
- && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())) {
- File loggingConfigurationDirectory = new File(facade.getPomFile().getParentFile(), "src/conf/logging");
- if(loggingConfigurationDirectory.exists()) {
- collector.addArchiveEntry(loggingConfigurationDirectory.getAbsolutePath());
- }
- }
- }
- Set<Artifact> artifacts = mavenProject.getArtifacts();
- Artifact launcherArtifact = null;
-
- for(Artifact artifact : artifacts) {
- if(Artifact.SCOPE_TEST.equals(artifact.getScope())) {
- continue;
- }
-
- if(PLEXUS_CLASSWORLDS.getGroupId().equals(artifact.getGroupId())
- && PLEXUS_CLASSWORLDS.getArtifactId().equals(artifact.getArtifactId())) {
- launcherArtifact = artifact;
- continue;
- }
-
- addArtifact(collector, artifact);
- }
-
- if(launcherArtifact != null) {
- collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM);
- addArtifact(collector, launcherArtifact);
- }
- }
- }
-
- public String toString() {
- return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected void addArtifact(IMavenLauncherConfiguration collector, Artifact artifact) throws CoreException {
- IMavenProjectFacade facade = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(),
- artifact.getVersion());
-
- if(facade != null) {
- collector.addProjectEntry(facade);
- } else {
- File file = artifact.getFile();
- if(file != null) {
- collector.addArchiveEntry(file.getAbsolutePath());
- }
- }
- }
-
- public String getVersion() {
- IMavenProjectFacade maven = getMavenDistribution();
- if(maven != null) {
- return maven.getArtifactKey().getVersion();
- }
- return getDistributionArtifactKey().getVersion();
- }
-
-}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/DefaultWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/DefaultWorkspaceRuntime.java
new file mode 100644
index 00000000..57d2ef4b
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/DefaultWorkspaceRuntime.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Takari, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Takari, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.internal.launch;
+
+import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
+
+
+/**
+ * @since 1.5
+ */
+public class DefaultWorkspaceRuntime extends MavenWorkspaceRuntime {
+
+ public DefaultWorkspaceRuntime() {
+ super(MavenRuntimeManager.WORKSPACE);
+ }
+
+ public boolean isEditable() {
+ return false;
+ }
+
+ public String toString() {
+ return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java
index 5f820a46..695add45 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java
@@ -42,6 +42,7 @@ import org.codehaus.plexus.util.IOUtil;
import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration;
import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
import org.eclipse.m2e.core.internal.Bundles;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.Messages;
import org.eclipse.m2e.core.internal.e44.DevClassPathHelper;
@@ -70,11 +71,10 @@ public class MavenEmbeddedRuntime extends AbstractMavenRuntime {
private static volatile String mavenVersion;
- private Bundle m2eCore;
+ private static final Bundle m2eCore = MavenPluginActivator.getDefault().getBundle();
- public MavenEmbeddedRuntime(Bundle m2eCore) {
+ public MavenEmbeddedRuntime() {
super(MavenRuntimeManager.EMBEDDED);
- this.m2eCore = m2eCore;
}
public boolean isEditable() {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java
index 88f4c5a9..80583c03 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java
@@ -154,17 +154,6 @@ public class MavenExternalRuntime extends AbstractMavenRuntime {
// XXX show error dialog and fail launch
}
- public boolean equals(Object o) {
- if(o instanceof MavenExternalRuntime) {
- return getName().equals(((MavenExternalRuntime) o).getName());
- }
- return false;
- }
-
- public int hashCode() {
- return getName().hashCode();
- }
-
public String toString() {
return "External" + " " + location + " (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java
index 346f0c13..d98c60bb 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java
@@ -11,26 +11,49 @@
package org.eclipse.m2e.core.internal.launch;
+import java.io.File;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import org.apache.maven.artifact.Artifact;
+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.project.MavenProject;
+
+import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
+import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration;
import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
/**
- * Maven 3.0-SNAPSHOT runtime loaded from the Eclipse Workspace
+ * Maven 3.x runtime loaded from the Eclipse Workspace
*
* @author Eugene Kuleshov
* @author Igor Fedorenko
+ * @author Jason van Zyl
*/
-public class MavenWorkspaceRuntime extends AbstractWorkspaceRuntime {
+public class MavenWorkspaceRuntime extends AbstractMavenRuntime {
private static final ArtifactKey MAVEN_DISTRIBUTION = new ArtifactKey(
"org.apache.maven", "apache-maven", "[3.0,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ private static final ArtifactKey PLEXUS_CLASSWORLDS = new ArtifactKey(
+ "org.codehaus.plexus", "plexus-classworlds", null, null); //$NON-NLS-1$ //$NON-NLS-2$
+
private static final String MAVEN_EXECUTOR_CLASS = "org.apache.maven.cli.MavenCli"; //$NON-NLS-1$
- public MavenWorkspaceRuntime(IMavenProjectRegistry projectManager) {
- super(projectManager);
+ private static final String PLEXUS_CLASSWORLD_NAME = "plexus.core"; //$NON-NLS-1$
+
+ private static final IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
+
+ public MavenWorkspaceRuntime(String name) {
+ super(name);
}
protected ArtifactKey getDistributionArtifactKey() {
@@ -45,8 +68,117 @@ public class MavenWorkspaceRuntime extends AbstractWorkspaceRuntime {
return MavenRuntimeManager.WORKSPACE;
}
+ public String getSettings() {
+ return null;
+ }
+
+ public boolean isEditable() {
+ return true;
+ }
+
+ public boolean isAvailable() {
+ return getMavenDistribution() != null;
+ }
+
+ protected IMavenProjectFacade getMavenDistribution() {
+ try {
+ VersionRange range = VersionRange.createFromVersionSpec(getDistributionArtifactKey().getVersion());
+ for(IMavenProjectFacade facade : projectManager.getProjects()) {
+ ArtifactKey artifactKey = facade.getArtifactKey();
+ if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) //
+ && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())//
+ && range.containsVersion(new DefaultArtifactVersion(artifactKey.getVersion()))) {
+ return facade;
+ }
+ }
+ } catch(InvalidVersionSpecificationException e) {
+ // can't happen
+ }
+ return null;
+ }
+
+ public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor)
+ throws CoreException {
+ IMavenProjectFacade maven = getMavenDistribution();
+ if(maven != null) {
+ MavenProject mavenProject = maven.getMavenProject(monitor);
+ //
+ // main is org.apache.maven.cli.MavenCli from plexus.core
+ //
+ // set maven.home default ${user.home}/m2
+ //
+ // [plexus.core]
+ // optionally ${maven.home}/lib/ext/*.jar
+ // load ${maven.home}/lib/*.jar
+ // load ${maven.home}/conf/logging
+ //
+ collector.setMainType(getMainClass(), PLEXUS_CLASSWORLD_NAME);
+ collector.addRealm(PLEXUS_CLASSWORLD_NAME);
+
+ collectExtensions(collector, monitor);
+
+ //
+ // plexus.core is the current realm, and now we want the add the SLF4J loggging configuration if
+ // we have a verion>3.1.x Maven-like runtime
+ //
+ for(IMavenProjectFacade facade : projectManager.getProjects()) {
+ ArtifactKey artifactKey = facade.getArtifactKey();
+ if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) //
+ && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())) {
+ File loggingConfigurationDirectory = new File(facade.getPomFile().getParentFile(), "src/conf/logging");
+ if(loggingConfigurationDirectory.exists()) {
+ collector.addArchiveEntry(loggingConfigurationDirectory.getAbsolutePath());
+ }
+ }
+ }
+ Set<Artifact> artifacts = mavenProject.getArtifacts();
+ Artifact launcherArtifact = null;
+
+ for(Artifact artifact : artifacts) {
+ if(Artifact.SCOPE_TEST.equals(artifact.getScope())) {
+ continue;
+ }
+
+ if(PLEXUS_CLASSWORLDS.getGroupId().equals(artifact.getGroupId())
+ && PLEXUS_CLASSWORLDS.getArtifactId().equals(artifact.getArtifactId())) {
+ launcherArtifact = artifact;
+ continue;
+ }
+
+ addArtifact(collector, artifact);
+ }
+
+ if(launcherArtifact != null) {
+ collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM);
+ addArtifact(collector, launcherArtifact);
+ }
+ }
+ }
+
public String toString() {
return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
+ protected void addArtifact(IMavenLauncherConfiguration collector, Artifact artifact) throws CoreException {
+ IMavenProjectFacade facade = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion());
+
+ if(facade != null) {
+ collector.addProjectEntry(facade);
+ } else {
+ File file = artifact.getFile();
+ if(file != null) {
+ collector.addArchiveEntry(file.getAbsolutePath());
+ }
+ }
+ }
+
+ public String getVersion() {
+ IMavenProjectFacade maven = getMavenDistribution();
+ if(maven != null) {
+ return maven.getArtifactKey().getVersion();
+ }
+ return getDistributionArtifactKey().getVersion();
+ }
+
}
diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenRuntimeSelector.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenRuntimeSelector.java
index fe8aafc1..297944f9 100644
--- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenRuntimeSelector.java
+++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenRuntimeSelector.java
@@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
@@ -24,6 +25,7 @@ import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -50,7 +52,9 @@ public class MavenRuntimeSelector extends Composite {
ComboViewer runtimeComboViewer;
- private static final MavenRuntimeManager runtimeManager = MavenPlugin.getMavenRuntimeManager();
+ private static MavenRuntimeManager getRuntimeManager() {
+ return MavenPlugin.getMavenRuntimeManager();
+ }
public MavenRuntimeSelector(final Composite mainComposite) {
super(mainComposite, SWT.NONE);
@@ -115,14 +119,17 @@ public class MavenRuntimeSelector extends Composite {
configureRuntimesButton.setText(org.eclipse.m2e.internal.launch.Messages.MavenLaunchMainTab_btnConfigure);
configureRuntimesButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- PreferencesUtil.createPreferenceDialogOn(mainComposite.getShell(),
- "org.eclipse.m2e.core.preferences.MavenInstallationsPreferencePage", null, null).open(); //$NON-NLS-1$
- setInput();
+ PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(mainComposite.getShell(),
+ "org.eclipse.m2e.core.preferences.MavenInstallationsPreferencePage", null, null); //$NON-NLS-1$
+ if(dialog.open() == Window.OK) {
+ setInput();
+ }
}
});
}
protected void setInput() {
+ MavenRuntimeManager runtimeManager = getRuntimeManager();
runtimeComboViewer.setInput(runtimeManager.getMavenRuntimes());
runtimeComboViewer.setSelection(new StructuredSelection(runtimeManager.getDefaultRuntime()));
}
@@ -147,7 +154,7 @@ public class MavenRuntimeSelector extends Composite {
} catch(CoreException ex) {
// TODO log
}
- MavenRuntime runtime = runtimeManager.getRuntimeByName(name);
+ MavenRuntime runtime = getRuntimeManager().getRuntimeByName(name);
if(runtime != null) {
setSelectRuntime(runtime);
}

Back to the top