Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2014-07-07 16:22:46 -0400
committerIgor Fedorenko2014-07-08 00:54:43 -0400
commit2b6eace30686c8e2961d64a8b508aa231d0c9d61 (patch)
tree5df912e647a4d3bb584dcb10a5ce7dd91c8cc8cd /org.eclipse.m2e.core
parentdc8bf3bfa170f3197426d4e5ea2ce03fc03bc19c (diff)
downloadm2e-core-2b6eace30686c8e2961d64a8b508aa231d0c9d61.tar.gz
m2e-core-2b6eace30686c8e2961d64a8b508aa231d0c9d61.tar.xz
m2e-core-2b6eace30686c8e2961d64a8b508aa231d0c9d61.zip
438922 moved cli workspace resolver to a separate git repo
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java82
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java20
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java69
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java12
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java2
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java28
7 files changed, 125 insertions, 91 deletions
diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
index 266cd922..3bbd5870 100644
--- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF
@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.10.0",
org.eclipse.m2e.archetype.common;bundle-version="[1.6.0,1.7.0)",
org.eclipse.m2e.maven.indexer;bundle-version="[1.6.0,1.7.0)",
org.slf4j.api;bundle-version="1.6.2",
- com.google.guava;bundle-version="[14.0.1,16.0.0)"
+ com.google.guava;bundle-version="[14.0.1,16.0.0)",
+ org.eclipse.m2e.workspace.cli;bundle-version="0.1.0"
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Bundle-RequiredExecutionEnvironment: JavaSE-1.7,
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java
index efca3d27..cc101bae 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Bundles.java
@@ -11,15 +11,30 @@
package org.eclipse.m2e.core.internal;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
import org.osgi.framework.namespace.BundleNamespace;
import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.osgi.util.ManifestElement;
+
+import org.eclipse.m2e.core.internal.equinox.DevClassPathHelper;
/**
@@ -27,6 +42,8 @@ import org.osgi.framework.wiring.BundleWiring;
*/
public class Bundles {
+ private static final Logger log = LoggerFactory.getLogger(Bundles.class);
+
private static Bundle findDependencyBundle(Bundle bundle, String dependencyName, Set<Bundle> visited) {
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
if(bundleWiring == null) {
@@ -62,4 +79,69 @@ public class Bundles {
return bundleWiring.getClassLoader();
}
+ public static List<String> getClasspathEntries(Bundle bundle) {
+ log.debug("getClasspathEntries(Bundle={})", bundle.toString());
+ Set<String> cp = new LinkedHashSet<String>();
+ if(DevClassPathHelper.inDevelopmentMode()) {
+ cp.addAll(Arrays.asList(DevClassPathHelper.getDevClassPath(bundle.getSymbolicName())));
+ }
+ cp.addAll(Arrays.asList(parseBundleClasspath(bundle)));
+ List<String> entries = new ArrayList<>();
+ for(String cpe : cp) {
+ String entry;
+ if(".".equals(cpe)) {
+ entry = getNestedJarOrDir(bundle, "/");
+ } else {
+ entry = getNestedJarOrDir(bundle, cpe);
+ }
+
+ if(entry != null) {
+ log.debug("\tEntry:{}", entry);
+ entries.add(entry);
+ }
+ }
+ return entries;
+ }
+
+ private static String[] parseBundleClasspath(Bundle bundle) {
+ String[] result = new String[] {"."};
+ String header = bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH);
+ ManifestElement[] classpathEntries = null;
+ try {
+ classpathEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, header);
+ } catch(BundleException ex) {
+ log.warn("Could not parse bundle classpath of {}", bundle.toString(), ex);
+ }
+ if(classpathEntries != null) {
+ result = new String[classpathEntries.length];
+ for(int i = 0; i < classpathEntries.length; i++ ) {
+ result[i] = classpathEntries[i].getValue();
+ }
+ }
+ return result;
+ }
+
+ private static String getNestedJarOrDir(Bundle bundle, String cp) {
+ // try embeded entries first
+ URL url = bundle.getEntry(cp);
+ if(url != null) {
+ try {
+ return FileLocator.toFileURL(url).getFile();
+ } catch(IOException ex) {
+ log.warn("Could not get entry {} for bundle {}", new Object[] {cp, bundle.toString(), ex});
+ }
+ }
+
+ // in development mode entries can be absolute paths outside of bundle basedir
+ if(DevClassPathHelper.inDevelopmentMode()) {
+ File file = new File(cp);
+ if(file.exists() && file.isAbsolute()) {
+ return file.getAbsolutePath();
+ }
+ }
+
+ log.debug("Bundle {} does not have entry {}", bundle.toString(), cp);
+ return null;
+ }
+
}
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 214c8143..238af50a 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
@@ -23,6 +23,10 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
+
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration;
import org.eclipse.m2e.core.embedder.MavenRuntime;
@@ -38,6 +42,18 @@ import org.eclipse.m2e.core.project.IMavenProjectRegistry;
@SuppressWarnings("deprecation")
public abstract class AbstractMavenRuntime implements MavenRuntime {
+ private static final VersionRange SUPPORTED_VERSION;
+
+ static {
+ VersionRange supportedVersion;
+ try {
+ supportedVersion = VersionRange.createFromVersionSpec("[3.0,)");
+ } catch(InvalidVersionSpecificationException ex) {
+ supportedVersion = null;
+ }
+ SUPPORTED_VERSION = supportedVersion;
+ }
+
private static final IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot();
private static final IMavenProjectRegistry registry = MavenPlugin.getMavenProjectRegistry();
@@ -105,6 +121,10 @@ public abstract class AbstractMavenRuntime implements MavenRuntime {
return getName().hashCode();
}
+ protected boolean isSupportedVersion() {
+ return SUPPORTED_VERSION != null && SUPPORTED_VERSION.containsVersion(new DefaultArtifactVersion(getVersion()));
+ }
+
public abstract void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor)
throws CoreException;
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 505dba81..48d331f0 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
@@ -14,11 +14,8 @@ package org.eclipse.m2e.core.internal.launch;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
@@ -27,15 +24,12 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.osgi.util.ManifestElement;
import org.codehaus.plexus.util.IOUtil;
@@ -43,7 +37,6 @@ import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration;
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.equinox.DevClassPathHelper;
/**
@@ -149,67 +142,7 @@ public class MavenEmbeddedRuntime extends AbstractMavenRuntime {
}
private void addBundleClasspathEntries(Set<String> entries, Bundle bundle) {
- log.debug("addBundleClasspathEntries(Bundle={})", bundle.toString());
-
- Set<String> cp = new LinkedHashSet<String>();
- if(DevClassPathHelper.inDevelopmentMode()) {
- cp.addAll(Arrays.asList(DevClassPathHelper.getDevClassPath(bundle.getSymbolicName())));
- }
- cp.addAll(Arrays.asList(parseBundleClasspath(bundle)));
- for(String cpe : cp) {
- String entry;
- if(".".equals(cpe)) {
- entry = getNestedJarOrDir(bundle, "/");
- } else {
- entry = getNestedJarOrDir(bundle, cpe);
- }
-
- if(entry != null) {
- log.debug("\tEntry:{}", entry);
- entries.add(entry);
- }
- }
- }
-
- private String[] parseBundleClasspath(Bundle bundle) {
- String[] result = new String[] {"."};
- String header = bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH);
- ManifestElement[] classpathEntries = null;
- try {
- classpathEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, header);
- } catch(BundleException ex) {
- log.warn("Could not parse bundle classpath of {}", bundle.toString(), ex);
- }
- if(classpathEntries != null) {
- result = new String[classpathEntries.length];
- for(int i = 0; i < classpathEntries.length; i++ ) {
- result[i] = classpathEntries[i].getValue();
- }
- }
- return result;
- }
-
- private String getNestedJarOrDir(Bundle bundle, String cp) {
- // try embeded entries first
- URL url = bundle.getEntry(cp);
- if(url != null) {
- try {
- return FileLocator.toFileURL(url).getFile();
- } catch(IOException ex) {
- log.warn("Could not get entry {} for bundle {}", new Object[] {cp, bundle.toString(), ex});
- }
- }
-
- // in development mode entries can be absolute paths outside of bundle basedir
- if(DevClassPathHelper.inDevelopmentMode()) {
- File file = new File(cp);
- if(file.exists() && file.isAbsolute()) {
- return file.getAbsolutePath();
- }
- }
-
- log.debug("Bundle {} does not have entry {}", bundle.toString(), cp);
- return null;
+ entries.addAll(Bundles.getClasspathEntries(bundle));
}
private Bundle findMavenEmbedderBundle() {
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 bf2c54a9..b7fc27e2 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
@@ -49,6 +49,8 @@ public class MavenExternalRuntime extends AbstractMavenRuntime {
private final String location;
+ private transient String version;
+
public MavenExternalRuntime(String location) {
this.location = location;
}
@@ -63,7 +65,7 @@ public class MavenExternalRuntime extends AbstractMavenRuntime {
}
public boolean isAvailable() {
- return new File(location, "bin").exists() && getLauncherClasspath() != null; //$NON-NLS-1$
+ return new File(location, "bin").exists() && getLauncherClasspath() != null && isSupportedVersion(); //$NON-NLS-1$
}
public String getLocation() {
@@ -185,8 +187,14 @@ public class MavenExternalRuntime extends AbstractMavenRuntime {
return null;
}
- public String getVersion() {
+ public synchronized String getVersion() {
+ if(version == null) {
+ version = getVersion0();
+ }
+ return version;
+ }
+ private String getVersion0() {
class VersionHandler implements ConfigurationHandler {
File mavenCore;
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 7af14883..079b149d 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
@@ -77,7 +77,7 @@ public class MavenWorkspaceRuntime extends AbstractMavenRuntime {
}
public boolean isAvailable() {
- return getMavenDistribution() != null;
+ return getMavenDistribution() != null && isSupportedVersion();
}
protected IMavenProjectFacade getMavenDistribution() {
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java
index f837e3b6..a1988ff2 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java
@@ -11,12 +11,8 @@
package org.eclipse.m2e.core.internal.project;
-import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +34,7 @@ import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager;
import org.eclipse.m2e.core.project.IMavenProjectChangedListener;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenProjectChangedEvent;
+import org.eclipse.m2e.workspace.MutableWorkspaceState;
/**
@@ -56,7 +53,7 @@ public class WorkspaceStateWriter implements IMavenProjectChangedListener {
public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) {
try {
- Properties state = new Properties();
+ MutableWorkspaceState state = new MutableWorkspaceState();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
for(IMavenProjectFacade projectFacade : projectManager.getProjects()) {
@@ -73,8 +70,7 @@ public class WorkspaceStateWriter implements IMavenProjectChangedListener {
if(location != null) {
File pom = location.toFile();
if(pom.canRead()) {
- String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":pom::" + artifact.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$
- state.put(key, pom.getCanonicalPath());
+ state.putPom(pom, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
}
}
IResource outputLocation = root.findMember(projectFacade.getOutputLocation());
@@ -99,30 +95,24 @@ public class WorkspaceStateWriter implements IMavenProjectChangedListener {
if(classifier == null) {
classifier = "";
}
- String key = artifact.getGroupId()
- + ":" + artifact.getArtifactId() + ":" + extension + ":" + classifier + ":" + artifact.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- state.put(key, outputLocation.getLocation().toFile().getCanonicalPath());
+ state.putArtifact(outputLocation.getLocation().toFile(), artifact.getGroupId(), artifact.getArtifactId(),
+ extension, classifier, artifact.getVersion());
} else {
log.warn("Could not determine project {} main artifact extension.", project);
}
}
// assume test output location gets attached as classified=tests
IResource testOutputLocation = root.findMember(projectFacade.getTestOutputLocation());
- if(!"pom".equals(projectFacade.getPackaging()) && testOutputLocation != null && testOutputLocation.exists()) { //$NON-NLS-1$
- String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":jar:tests:" + artifact.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- state.put(key, testOutputLocation.getLocation().toFile().getCanonicalPath());
+ if(!"pom".equals(projectFacade.getPackaging()) && testOutputLocation != null && testOutputLocation.exists()) {
+ state.putArtifact(testOutputLocation.getLocation().toFile(), artifact.getGroupId(),
+ artifact.getArtifactId(), "jar", "tests", artifact.getVersion());
}
} catch(CoreException ex) {
log.error("Error writing workspace state file", ex);
}
}
- OutputStream buf = new BufferedOutputStream(new FileOutputStream(projectManager.getWorkspaceStateFile()));
- try {
- state.store(buf, null);
- } finally {
- buf.close();
- }
+ state.store(projectManager.getWorkspaceStateFile());
} catch(IOException ex) {
log.error("Error writing workspace state file", ex);
}

Back to the top