Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason van Zyl2013-05-02 01:19:02 -0400
committerJason van Zyl2013-05-02 01:19:02 -0400
commit784ec22a9361bef020777cb8c11433b31c027bc2 (patch)
tree446a93bba0cb73fef353c6fdddbac7e6ba61c8d0
parent6395f4980834edff03cea30ed9ab734616026337 (diff)
downloadm2e-core-784ec22a9361bef020777cb8c11433b31c027bc2.tar.gz
m2e-core-784ec22a9361bef020777cb8c11433b31c027bc2.tar.xz
m2e-core-784ec22a9361bef020777cb8c11433b31c027bc2.zip
o start of a small rework of the runtime system to allow for multiple workspace runtimes
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java35
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java4
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java170
4 files changed, 187 insertions, 24 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 6d178186..f317d39a 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
@@ -32,6 +32,7 @@ import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants;
* Maven runtime manager
*
* @author Eugene Kuleshov
+ * @author Jason van Zyl
*/
public class MavenRuntimeManager {
@@ -49,8 +50,6 @@ public class MavenRuntimeManager {
private MavenRuntime embeddedRuntime;
- private MavenRuntime workspaceRuntime;
-
private MavenRuntime defaultRuntime;
public MavenRuntimeManager() {
@@ -64,10 +63,15 @@ public class MavenRuntimeManager {
public void setEmbeddedRuntime(MavenRuntime embeddedRuntime) {
this.embeddedRuntime = embeddedRuntime;
+ runtimes.put(embeddedRuntime.getLocation(), embeddedRuntime);
+ }
+
+ public void addWorkspaceRuntime(MavenRuntime workspaceRuntime) {
+ runtimes.put(workspaceRuntime.getLocation(), workspaceRuntime);
}
public void setWorkspaceRuntime(MavenRuntime workspaceRuntime) {
- this.workspaceRuntime = workspaceRuntime;
+ addWorkspaceRuntime(workspaceRuntime);
}
public MavenRuntime getDefaultRuntime() {
@@ -81,30 +85,18 @@ public class MavenRuntimeManager {
if(location == null || location.length() == 0 || DEFAULT.equals(location)) {
return getDefaultRuntime();
}
- if(EMBEDDED.equals(location)) {
- return embeddedRuntime;
- }
- if(WORKSPACE.equals(location)) {
- return workspaceRuntime;
- }
+
return runtimes.get(location);
}
public List<MavenRuntime> getMavenRuntimes() {
- ArrayList<MavenRuntime> runtimes = new ArrayList<MavenRuntime>();
-
- runtimes.add(embeddedRuntime);
-
- if(workspaceRuntime != null && workspaceRuntime.isAvailable()) {
- runtimes.add(workspaceRuntime);
- }
-
- for(MavenRuntime runtime : this.runtimes.values()) {
- if(runtime.isAvailable()) {
- runtimes.add(runtime);
+ List<MavenRuntime> mavenRuntimes = new ArrayList<MavenRuntime>();
+ for(MavenRuntime mavenRuntime : runtimes.values()) {
+ if(mavenRuntime.isAvailable()) {
+ mavenRuntimes.add(mavenRuntime);
}
}
- return runtimes;
+ return mavenRuntimes;
}
public void reset() {
@@ -140,7 +132,6 @@ public class MavenRuntimeManager {
}
private void initRuntimes() {
- runtimes.clear();
defaultRuntime = null;
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
index 99b3cd90..73a2f561 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java
@@ -61,6 +61,7 @@ import org.eclipse.m2e.core.internal.archetype.ArchetypeManager;
import org.eclipse.m2e.core.internal.embedder.MavenEmbeddedRuntime;
import org.eclipse.m2e.core.internal.embedder.MavenImpl;
import org.eclipse.m2e.core.internal.embedder.MavenWorkspaceRuntime;
+import org.eclipse.m2e.core.internal.embedder.TeslaWorkspaceRuntime;
import org.eclipse.m2e.core.internal.index.IndexManager;
import org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager;
import org.eclipse.m2e.core.internal.index.nexus.IndexesExtensionReader;
@@ -219,7 +220,8 @@ public class MavenPluginActivator extends Plugin {
this.runtimeManager = new MavenRuntimeManager();
this.runtimeManager.setEmbeddedRuntime(new MavenEmbeddedRuntime(getBundleContext()));
- this.runtimeManager.setWorkspaceRuntime(new MavenWorkspaceRuntime(projectManager));
+ this.runtimeManager.addWorkspaceRuntime(new MavenWorkspaceRuntime(projectManager));
+ this.runtimeManager.addWorkspaceRuntime(new TeslaWorkspaceRuntime(projectManager));
this.configurationManager = new ProjectConfigurationManager(maven, managerImpl, modelManager, mavenMarkerManager,
mavenConfiguration);
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 85c138c2..e90a807b 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
@@ -140,7 +140,7 @@ public class MavenWorkspaceRuntime implements MavenRuntime {
}
public String toString() {
- return "Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
public String 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
new file mode 100644
index 00000000..eb4ea3c5
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * 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.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
+ */
+public class TeslaWorkspaceRuntime implements MavenRuntime {
+
+ 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$
+
+ 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;
+ }
+
+ public boolean isAvailable() {
+ return getMavenDistribution() != null;
+ }
+
+ 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;
+ }
+
+ 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 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