Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason van Zyl2013-05-12 21:18:08 +0000
committerJason van Zyl2013-05-12 21:18:08 +0000
commit8fdd1de5cf50a068e4439a489b2e40e5021aad79 (patch)
treef932b8eb907a6d1df783a2bd286461bcd720f3a4
parent9a9db64704687ac601d54626dd84db5a2d387bfc (diff)
downloadm2e-core-8fdd1de5cf50a068e4439a489b2e40e5021aad79.tar.gz
m2e-core-8fdd1de5cf50a068e4439a489b2e40e5021aad79.tar.xz
m2e-core-8fdd1de5cf50a068e4439a489b2e40e5021aad79.zip
o deprecate setWorkspaceRuntime and encourage people to use addWorkspaceRuntime as there are at least two variants of a Maven runtime now: standard Maven flavour and Tesla flavourruntime
o create an AbstractWorkspaceRuntime which can be shared by the existing MavenWorkspaceRuntime and the new TeslaWorkspaceRuntime
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java4
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java177
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java118
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java144
4 files changed, 202 insertions, 241 deletions
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 f317d39a..28335f3a 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
@@ -70,6 +70,10 @@ public class MavenRuntimeManager {
runtimes.put(workspaceRuntime.getLocation(), workspaceRuntime);
}
+ /**
+ * @deprecated use {@link addWorkspaceRuntime(runtime)}
+ */
+ @Deprecated
public void setWorkspaceRuntime(MavenRuntime workspaceRuntime) {
addWorkspaceRuntime(workspaceRuntime);
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java
new file mode 100644
index 00000000..8d78b61f
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * 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.embedder;
+
+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.MavenRuntime;
+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
+ *
+ * @author Eugene Kuleshov
+ * @author Igor Fedorenko
+ * @author Jason van Zyl
+ */
+public abstract class AbstractWorkspaceRuntime implements MavenRuntime {
+
+ 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);
+ //
+ // 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/embedder/MavenWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java
index e90a807b..5c92c2ad 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java
@@ -11,23 +11,8 @@
package org.eclipse.m2e.core.internal.embedder;
-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.MavenRuntime;
import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
-import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
@@ -37,118 +22,31 @@ import org.eclipse.m2e.core.project.IMavenProjectRegistry;
* @author Eugene Kuleshov
* @author Igor Fedorenko
*/
-public class MavenWorkspaceRuntime implements MavenRuntime {
+public class MavenWorkspaceRuntime extends AbstractWorkspaceRuntime {
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 MavenWorkspaceRuntime(IMavenProjectRegistry projectManager) {
- this.projectManager = projectManager;
- }
-
- public String getLocation() {
- return MavenRuntimeManager.WORKSPACE;
- }
-
- public String getSettings() {
- return null;
- }
-
- public boolean isEditable() {
- return false;
- }
-
- public boolean isAvailable() {
- return getMavenDistribution() != null;
+ super(projectManager);
}
- private IMavenProjectFacade getMavenDistribution() {
- try {
- VersionRange range = VersionRange.createFromVersionSpec(MAVEN_DISTRIBUTION.getVersion());
- for(IMavenProjectFacade facade : projectManager.getProjects()) {
- ArtifactKey artifactKey = facade.getArtifactKey();
- if(MAVEN_DISTRIBUTION.getGroupId().equals(artifactKey.getGroupId()) //
- && MAVEN_DISTRIBUTION.getArtifactId().equals(artifactKey.getArtifactId())//
- && range.containsVersion(new DefaultArtifactVersion(artifactKey.getVersion()))) {
- return facade;
- }
- }
- } catch(InvalidVersionSpecificationException e) {
- // can't happen
- }
- return null;
+ protected ArtifactKey getDistributionArtifactKey() {
+ return MAVEN_DISTRIBUTION;
}
- public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor)
- throws CoreException {
- IMavenProjectFacade maven = getMavenDistribution();
- if(maven != null) {
- MavenProject mavenProject = maven.getMavenProject(monitor);
-
- collector.setMainType(MAVEN_EXECUTOR_CLASS, PLEXUS_CLASSWORLD_NAME);
-
- collector.addRealm(PLEXUS_CLASSWORLD_NAME);
-
- 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);
- }
- }
-
- // XXX throw something at the caller!
+ protected String getMainClass() {
+ return MAVEN_EXECUTOR_CLASS;
}
- private 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 getLocation() {
+ return MavenRuntimeManager.WORKSPACE;
}
public String toString() {
return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
- public String getVersion() {
- IMavenProjectFacade maven = getMavenDistribution();
- if(maven != null) {
- return maven.getArtifactKey().getVersion();
- }
- return MAVEN_DISTRIBUTION.getVersion();
- }
-
}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java
index eb4ea3c5..9ebf0561 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2013 Sonatype, Inc., Jason van Zyl
* 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
@@ -7,164 +7,46 @@
*
* Contributors:
* Sonatype, Inc. - initial API and implementation
+ * Jason van Zyl - extension to account for Tesla
*******************************************************************************/
package org.eclipse.m2e.core.internal.embedder;
-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.MavenRuntime;
-import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
/**
- * Maven 3.0-SNAPSHOT runtime loaded from the Eclipse Workspace
+ * Tesla runtime loaded from the Eclipse Workspace
*
* @author Eugene Kuleshov
* @author Igor Fedorenko
+ * @author Jason van Zyl
*/
-public class TeslaWorkspaceRuntime implements MavenRuntime {
+public class TeslaWorkspaceRuntime extends AbstractWorkspaceRuntime {
private static final ArtifactKey TESLA_DISTRIBUTION = new ArtifactKey(
- "io.tesla.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$
+ "io.tesla.maven", "apache-maven", "[3.1,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
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 TeslaWorkspaceRuntime(IMavenProjectRegistry projectManager) {
- this.projectManager = projectManager;
- }
-
- public String getLocation() {
- return "TESLA_WORKSPACE";
- }
-
- public String getSettings() {
- return null;
- }
-
- public boolean isEditable() {
- return false;
+ super(projectManager);
}
- public boolean isAvailable() {
- return getMavenDistribution() != null;
+ protected ArtifactKey getDistributionArtifactKey() {
+ return TESLA_DISTRIBUTION;
}
- private IMavenProjectFacade getMavenDistribution() {
- try {
- VersionRange range = VersionRange.createFromVersionSpec(TESLA_DISTRIBUTION.getVersion());
- for(IMavenProjectFacade facade : projectManager.getProjects()) {
- ArtifactKey artifactKey = facade.getArtifactKey();
- if(TESLA_DISTRIBUTION.getGroupId().equals(artifactKey.getGroupId()) //
- && TESLA_DISTRIBUTION.getArtifactId().equals(artifactKey.getArtifactId())//
- && range.containsVersion(new DefaultArtifactVersion(artifactKey.getVersion()))) {
- return facade;
- }
- }
- } catch(InvalidVersionSpecificationException e) {
- // can't happen
- }
- return null;
+ protected String getMainClass() {
+ return MAVEN_EXECUTOR_CLASS;
}
- 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(MAVEN_EXECUTOR_CLASS, PLEXUS_CLASSWORLD_NAME);
- collector.addRealm(PLEXUS_CLASSWORLD_NAME);
- //
- // plexus.core is the current realm, and now we want the add the SLF4J loggging configuration.
- //
- for(IMavenProjectFacade facade : projectManager.getProjects()) {
- ArtifactKey artifactKey = facade.getArtifactKey();
- if(TESLA_DISTRIBUTION.getGroupId().equals(artifactKey.getGroupId()) //
- && TESLA_DISTRIBUTION.getArtifactId().equals(artifactKey.getArtifactId())) {
- collector.addArchiveEntry(new File(facade.getPomFile().getParentFile(), "src/conf/logging").getAbsolutePath());
- }
- }
- collector.addArchiveEntry("/Users/jvanzyl/js/tesla/maven/apache-maven/src/conf/logging");
- 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);
- }
- }
-
- // XXX throw something at the caller!
- }
-
- private 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 getLocation() {
+ return "TESLA_WORKSPACE";
}
public String toString() {
return "Tesla Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
-
- public String getVersion() {
- IMavenProjectFacade maven = getMavenDistribution();
- if(maven != null) {
- return maven.getArtifactKey().getVersion();
- }
- return TESLA_DISTRIBUTION.getVersion();
- }
-
}

Back to the top