Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2012-06-08 15:34:11 +0000
committerFred Bricon2013-01-16 22:26:57 +0000
commitc30ebdb14e18906e4ef1be233946669f3459155d (patch)
treecfca7bcfc724b5b58a840928a4fb1fb0031e7edf /org.eclipse.m2e.jdt
parent279c8cb44cb15ada20d06950eb2bd3f9bf47982e (diff)
downloadm2e-core-c30ebdb14e18906e4ef1be233946669f3459155d.tar.gz
m2e-core-c30ebdb14e18906e4ef1be233946669f3459155d.tar.xz
m2e-core-c30ebdb14e18906e4ef1be233946669f3459155d.zip
368230 : new API for Runtime classpath resolution
3rd party plugins can contribute IClassifierClasspathProvider implementations via the new classifierClasspathProvider extension point. These implementations should resolve the appropriate classpath (main or test) for a given classifier during classpath resolution of Launch configurations by the MavenRuntimeClasspathProvider. For instance, for the ejb "client" classifier, a dedicated classifierClasspathProvider extension would make available the EJB project classes to the main classpath, but not its test classes to the test classpath. It's recommended the implementations extend the AbstractClassifierClasspathProvider, as to provide better forward compatibility. Signed-off-by: Fred Bricon <fbricon@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.jdt')
-rw-r--r--org.eclipse.m2e.jdt/build.properties3
-rw-r--r--org.eclipse.m2e.jdt/plugin.properties4
-rw-r--r--org.eclipse.m2e.jdt/plugin.xml21
-rw-r--r--org.eclipse.m2e.jdt/schema/classifierClasspathProviders.exsd132
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java113
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClassifierClasspathProvider.java53
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IMavenClassifierManager.java34
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java14
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java123
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/BlankClassifierClasspathProvider.java66
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java49
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/NullClassifierClasspathProvider.java65
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/TestsClassifierClasspathProvider.java65
13 files changed, 704 insertions, 38 deletions
diff --git a/org.eclipse.m2e.jdt/build.properties b/org.eclipse.m2e.jdt/build.properties
index 8bded135..58b393be 100644
--- a/org.eclipse.m2e.jdt/build.properties
+++ b/org.eclipse.m2e.jdt/build.properties
@@ -14,7 +14,8 @@ bin.includes = META-INF/,\
plugin.properties,\
.,\
about.html,\
- lifecycle-mapping-metadata.xml
+ lifecycle-mapping-metadata.xml,\
+ schema/
jars.compile.order = .
source.. = src/
output.. = target/classes/
diff --git a/org.eclipse.m2e.jdt/plugin.properties b/org.eclipse.m2e.jdt/plugin.properties
index 97d642b6..446dd662 100644
--- a/org.eclipse.m2e.jdt/plugin.properties
+++ b/org.eclipse.m2e.jdt/plugin.properties
@@ -31,4 +31,6 @@ action.javadoc2.label = Open JavaDoc
action.javadoc3.label = Open JavaDoc
action.javadoc4.label = Open JavaDoc
lifecycleMapping.jar.name = Jar Lifecycle Mapping
-java.conversion.participant.name = Java project converter \ No newline at end of file
+java.conversion.participant.name = Java project converter
+
+extension-point.classifierClasspathProviders.name = Launch Configuration Classifier Classpath Providers
diff --git a/org.eclipse.m2e.jdt/plugin.xml b/org.eclipse.m2e.jdt/plugin.xml
index 698fd2b2..8511f676 100644
--- a/org.eclipse.m2e.jdt/plugin.xml
+++ b/org.eclipse.m2e.jdt/plugin.xml
@@ -8,6 +8,8 @@
-->
<?eclipse version="3.2"?>
<plugin>
+ <extension-point id="classifierClasspathProviders" name="%extension-point.classifierClasspathProviders.name" schema="schema/classifierClasspathProviders.exsd"/>
+
<extension
point="org.eclipse.m2e.core.lifecycleMappings">
<lifecycleMapping
@@ -372,5 +374,24 @@
compatiblePackagings="jar"
/>
</extension>
+ <extension
+ point="org.eclipse.m2e.jdt.classifierClasspathProviders">
+ <classifierClasspathProvider
+ class="org.eclipse.m2e.jdt.internal.launch.BlankClassifierClasspathProvider"
+ id="org.eclipse.m2e.jdt.mainClassifierClasspathProvider"
+ name="Main Classifier Classpath Provider">
+ </classifierClasspathProvider>
+ <classifierClasspathProvider
+ class="org.eclipse.m2e.jdt.internal.launch.NullClassifierClasspathProvider"
+ id="org.eclipse.m2e.jdt.nullClassifierClasspathProvider"
+ name="Null Classifier Classpath Provider">
+ </classifierClasspathProvider>
+ <classifierClasspathProvider
+ class="org.eclipse.m2e.jdt.internal.launch.TestsClassifierClasspathProvider"
+ id="org.eclipse.m2e.jdt.testsClassifierClasspathProvider"
+ name="Tests Classifier Classpath Provider">
+ </classifierClasspathProvider>
+ </extension>
+
</plugin>
diff --git a/org.eclipse.m2e.jdt/schema/classifierClasspathProviders.exsd b/org.eclipse.m2e.jdt/schema/classifierClasspathProviders.exsd
new file mode 100644
index 00000000..1611bdd5
--- /dev/null
+++ b/org.eclipse.m2e.jdt/schema/classifierClasspathProviders.exsd
@@ -0,0 +1,132 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.m2e.jdt" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.m2e.jdt" id="classifierClasspathProviders" name="org.eclipse.m2e.jdt.classifierClasspathProviders"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <choice>
+ <element ref="classifierClasspathProvider"/>
+ </choice>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="classifierClasspathProvider">
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Unique classifier classpath provider Id
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.m2e.jdt.IClassifierClasspathProvider"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ Translatable name of this classifier classpath provider. Ex. &quot;EJB client classpath provider&quot;
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 1.3
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2012 Red Hat, 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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java
new file mode 100644
index 00000000..def45c31
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.JavaRuntime;
+
+import org.apache.maven.model.Build;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
+
+/**
+ * Base class for {@link IClassifierClasspathProvider} implementations.
+ *
+ * @author Fred Bricon
+ * @since 1.3
+ */
+public abstract class AbstractClassifierClasspathProvider implements IClassifierClasspathProvider, IExecutableExtension {
+
+ private static final String ATTR_ID = "id";
+
+ private static final String ATTR_NAME = "name";
+
+ private String id;
+
+ private String name;
+
+ /**
+ * @throws CoreException
+ */
+ public void setTestClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ }
+
+ /**
+ * @throws CoreException
+ */
+ public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ }
+
+ /**
+ * Adds test classes folder to the runtime classpath.
+ */
+ protected void addTestFolder(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ Build build = mavenProjectFacade.getMavenProject(monitor).getBuild();
+ final Set<IPath> allTestClasses = new LinkedHashSet<IPath>();
+ allTestClasses.add(mavenProjectFacade.getProjectRelativePath(build.getTestOutputDirectory()));
+ addFolders(runtimeClasspath, mavenProjectFacade.getProject(), allTestClasses);
+ }
+
+ /**
+ * Adds main classes folder to the runtime classpath.
+ */
+ protected void addMainFolder(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ Build build = mavenProjectFacade.getMavenProject(monitor).getBuild();
+ final Set<IPath> allClasses = new LinkedHashSet<IPath>();
+ allClasses.add(mavenProjectFacade.getProjectRelativePath(build.getOutputDirectory()));
+ addFolders(runtimeClasspath, mavenProjectFacade.getProject(), allClasses);
+ }
+
+ /**
+ * Adds a {@link Set} of folder {@link IPath} to the runtime classpath.
+ */
+ protected void addFolders(Set<IRuntimeClasspathEntry> runtimeClasspath, IProject project, Set<IPath> folders) {
+ for(IPath folder : folders) {
+ IResource member = project.findMember(folder); // only returns existing members
+ if(member instanceof IFolder) { // must exist and be a folder
+ runtimeClasspath.add(JavaRuntime.newArchiveRuntimeClasspathEntry(member.getFullPath()));
+ }
+ }
+ }
+
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) {
+ this.id = config.getAttribute(ATTR_ID);
+ this.name = config.getAttribute(ATTR_NAME);
+ }
+
+ public String toString() {
+ return getName();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClassifierClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClassifierClasspathProvider.java
new file mode 100644
index 00000000..781f2f68
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClassifierClasspathProvider.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
+
+/**
+ * Configures Runtime Classpath for Launch configuration of a given workspace project, depending on its classifier.
+ *
+ * @author Fred Bricon
+ * @since 1.3
+ */
+public interface IClassifierClasspathProvider {
+
+ /**
+ * Checks if this provider applies to the given project / classifier combo.
+ */
+ boolean applies(IMavenProjectFacade mavenProjectFacade, String classifier);
+
+ /**
+ * @return the classifier key this provider applies to. Can be <code>null</code>.
+ */
+ String getClassifier();
+
+ /**
+ * Configures the test classpath of the given project
+ */
+ void setTestClasspath(Set<IRuntimeClasspathEntry> testClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException;
+
+ /**
+ * Configures the runtime classpath of the given project.
+ */
+ void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException;
+
+}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IMavenClassifierManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IMavenClassifierManager.java
new file mode 100644
index 00000000..58151cf1
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IMavenClassifierManager.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+
+
+/**
+ * IMavenClassifierManager
+ *
+ * @author Fred Bricon
+ * @since 1.3
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public interface IMavenClassifierManager {
+
+ /**
+ * @param mavenProjectFacade
+ * @param classifier
+ * @return
+ */
+ IClassifierClasspathProvider getClassifierClasspathProvider(IMavenProjectFacade mavenProjectFacade, String classifier);
+
+}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java
index df77b35f..a360b9f1 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java
@@ -44,6 +44,7 @@ import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.index.IndexManager;
import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager;
import org.eclipse.m2e.jdt.internal.BuildPathManager;
+import org.eclipse.m2e.jdt.internal.MavenClassifierManager;
import org.eclipse.m2e.jdt.internal.Messages;
import org.eclipse.m2e.jdt.internal.launch.MavenLaunchConfigurationListener;
@@ -62,6 +63,8 @@ public class MavenJdtPlugin extends AbstractUIPlugin {
BuildPathManager buildpathManager;
+ IMavenClassifierManager mavenClassifierManager;
+
/**
* @noreference see class javadoc
*/
@@ -122,6 +125,8 @@ public class MavenJdtPlugin extends AbstractUIPlugin {
this.launchConfigurationListener = new MavenLaunchConfigurationListener();
DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(launchConfigurationListener);
projectManager.addMavenProjectChangedListener(launchConfigurationListener);
+
+ this.mavenClassifierManager = new MavenClassifierManager();
}
/**
@@ -139,6 +144,7 @@ public class MavenJdtPlugin extends AbstractUIPlugin {
this.buildpathManager = null;
this.launchConfigurationListener = null;
+ this.mavenClassifierManager = null;
}
public static MavenJdtPlugin getDefault() {
@@ -148,4 +154,12 @@ public class MavenJdtPlugin extends AbstractUIPlugin {
public IClasspathManager getBuildpathManager() {
return buildpathManager;
}
+
+ /**
+ * @return Returns the mavenClassifierManager.
+ */
+ public IMavenClassifierManager getMavenClassifierManager() {
+ return this.mavenClassifierManager;
+ }
+
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java
new file mode 100644
index 00000000..af64b820
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 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.jdt.internal;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.jdt.AbstractClassifierClasspathProvider;
+import org.eclipse.m2e.jdt.IClassifierClasspathProvider;
+import org.eclipse.m2e.jdt.IMavenClassifierManager;
+
+
+/**
+ * MavenClassifierManager
+ *
+ * @author Fred Bricon
+ */
+public class MavenClassifierManager implements IMavenClassifierManager {
+
+ private static final String EXTENSION_CLASSIFIER_CLASSPATH_PROVIDERS = "org.eclipse.m2e.jdt.classifierClasspathProviders";
+
+ private static final Logger log = LoggerFactory.getLogger(MavenClassifierManager.class);
+
+ private static final IClassifierClasspathProvider NO_OP_CLASSIFIER_CLASSPATH_PROVIDER = new AbstractClassifierClasspathProvider() {
+
+ public String getClassifier() {
+ return "(__ignore_classifier__)";
+ }
+
+ public boolean applies(IMavenProjectFacade mavenProjectFacade, String classifier) {
+ return false;
+ }
+
+ public String toString() {
+ return "No-Op Classifier Classpath Provider";
+ }
+ };
+
+ private Map<String, List<IClassifierClasspathProvider>> classifierClasspathProvidersMap;
+
+ public IClassifierClasspathProvider getClassifierClasspathProvider(IMavenProjectFacade project, String classifier) {
+ List<IClassifierClasspathProvider> allProviders = getClassifierClasspathProviders(classifier);
+ List<IClassifierClasspathProvider> compatibleProviders = new ArrayList<IClassifierClasspathProvider>();
+
+ if(allProviders != null) {
+ for(IClassifierClasspathProvider p : allProviders) {
+ if(p.applies(project, classifier)) {
+ compatibleProviders.add(p);
+ }
+ }
+ }
+
+ switch(compatibleProviders.size()) {
+ case 0:
+ //nothing here
+ break;
+ case 1:
+ return compatibleProviders.get(0);
+ default:
+ //TODO display/log error message
+ }
+ return NO_OP_CLASSIFIER_CLASSPATH_PROVIDER;
+ }
+
+ protected List<IClassifierClasspathProvider> getClassifierClasspathProviders(String classifier) {
+ if(classifierClasspathProvidersMap == null) {
+ classifierClasspathProvidersMap = readExtensions();
+ }
+ return classifierClasspathProvidersMap.get(classifier);
+ }
+
+ protected static synchronized Map<String, List<IClassifierClasspathProvider>> readExtensions() {
+ Map<String, List<IClassifierClasspathProvider>> map = new HashMap<String, List<IClassifierClasspathProvider>>();
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint ccpExtensionPoint = registry.getExtensionPoint(EXTENSION_CLASSIFIER_CLASSPATH_PROVIDERS);
+ if(ccpExtensionPoint != null) {
+ IExtension[] ccpExtensions = ccpExtensionPoint.getExtensions();
+ for(IExtension extension : ccpExtensions) {
+ for(IConfigurationElement element : extension.getConfigurationElements()) {
+ IClassifierClasspathProvider classifierClasspathProvider = null;
+ try {
+ classifierClasspathProvider = (IClassifierClasspathProvider) element.createExecutableExtension("class");
+ String classifier = classifierClasspathProvider.getClassifier();
+ List<IClassifierClasspathProvider> providers = map.get(classifier);
+ if(providers == null) {
+ providers = new ArrayList<IClassifierClasspathProvider>(1);
+ map.put(classifier, providers);
+ }
+ providers.add(classifierClasspathProvider);
+ } catch(CoreException ex) {
+ log.debug("Can not instanciate IClassifierClasspathProvider", ex);
+ }
+ }
+ }
+ }
+
+ return map;
+ }
+
+}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/BlankClassifierClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/BlankClassifierClasspathProvider.java
new file mode 100644
index 00000000..15496043
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/BlankClassifierClasspathProvider.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat, 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt.internal.launch;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.jdt.AbstractClassifierClasspathProvider;
+
+
+/**
+ * Classpath provider for the blank (i.e. empty String) classifier, corresponding to the main project for which the
+ * Launch configuration applies.
+ *
+ * @author Fred Bricon
+ * @since 1.3
+ */
+public class BlankClassifierClasspathProvider extends AbstractClassifierClasspathProvider {
+
+ /**
+ * This provider applies to the mavenProjectFacade if the classifier is blank.
+ */
+ public boolean applies(IMavenProjectFacade mavenProjectFacade, String classifier) {
+ return getClassifier().equals(classifier);
+ }
+
+ /**
+ * @return an empty String
+ */
+ public String getClassifier() {
+ return "";
+ }
+
+ /**
+ * Adds the main classes folder to the runtime classpath.
+ */
+ @Override
+ public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ addMainFolder(runtimeClasspath, mavenProjectFacade, monitor);
+ }
+
+ /**
+ * Adds the test classes folder followed by the main classes one to the runtime classpath.
+ */
+ @Override
+ public void setTestClasspath(Set<IRuntimeClasspathEntry> testClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ addTestFolder(testClasspath, mavenProjectFacade, monitor);
+ addMainFolder(testClasspath, mavenProjectFacade, monitor);
+ }
+
+}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java
index 9516ba11..0fadec17 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java
@@ -18,7 +18,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
@@ -45,14 +44,14 @@ import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.StandardClasspathProvider;
import org.eclipse.osgi.util.NLS;
-import org.apache.maven.model.Build;
-
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
import org.eclipse.m2e.core.project.ResolverConfiguration;
+import org.eclipse.m2e.jdt.IClassifierClasspathProvider;
import org.eclipse.m2e.jdt.IClasspathManager;
+import org.eclipse.m2e.jdt.IMavenClassifierManager;
import org.eclipse.m2e.jdt.MavenJdtPlugin;
import org.eclipse.m2e.jdt.internal.MavenClasspathHelpers;
import org.eclipse.m2e.jdt.internal.Messages;
@@ -208,28 +207,26 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
return;
}
- final Set<IPath> allClasses = new LinkedHashSet<IPath>();
- final Set<IPath> allTestClasses = new LinkedHashSet<IPath>();
-
- Build build = projectFacade.getMavenProject(monitor).getBuild();
- allClasses.add(projectFacade.getProjectRelativePath(build.getOutputDirectory()));
- allTestClasses.add(projectFacade.getProjectRelativePath(build.getTestOutputDirectory()));
-
IJavaProject javaProject = JavaCore.create(project);
boolean projectResolved = false;
+
for(IClasspathEntry entry : javaProject.getRawClasspath()) {
IRuntimeClasspathEntry rce = null;
switch(entry.getEntryKind()) {
case IClasspathEntry.CPE_SOURCE:
if(!projectResolved) {
- if(IClasspathManager.CLASSPATH_TEST == scope && isTestClassifier(classifier)) {
- // ECLIPSE-19: test classes come infront on the rest
- addFolders(resolved, project, allTestClasses);
- }
- if(isMainClassifier(classifier)) {
- addFolders(resolved, project, allClasses);
+
+ IMavenClassifierManager mavenClassifierManager = MavenJdtPlugin.getDefault().getMavenClassifierManager();
+ IClassifierClasspathProvider classifierClasspathProvider = mavenClassifierManager
+ .getClassifierClasspathProvider(projectFacade, classifier);
+
+ if(IClasspathManager.CLASSPATH_TEST == scope) {
+ classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor);
+ } else {
+ classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor);
}
+
projectResolved = true;
}
break;
@@ -276,26 +273,6 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
}
}
- private boolean isMainClassifier(String classifier) {
- return THIS_PROJECT_CLASSIFIER.equals(classifier) // main project
- || classifier == null; // default classifier
- }
-
- private boolean isTestClassifier(String classifier) {
- return THIS_PROJECT_CLASSIFIER.equals(classifier) // main project
- || TESTS_PROJECT_CLASSIFIER.equals(classifier) // tests classifier
- || classifier != null; // unknown classifier
- }
-
- private void addFolders(Set<IRuntimeClasspathEntry> resolved, IProject project, Set<IPath> folders) {
- for(IPath folder : folders) {
- IResource member = project.findMember(folder); // only returns existing members
- if(member instanceof IFolder) { // must exist and be a folder
- resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(member.getFullPath()));
- }
- }
- }
-
public static boolean isSupportedType(String id) {
return supportedTypes.contains(id);
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/NullClassifierClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/NullClassifierClasspathProvider.java
new file mode 100644
index 00000000..3fb27ee5
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/NullClassifierClasspathProvider.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat, 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt.internal.launch;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.jdt.AbstractClassifierClasspathProvider;
+
+
+/**
+ * Classpath provider for the <code>null</code> classifier. This provider adds the main classes folder to the runtime
+ * classpath for both Runtime and Test launch configurations.
+ *
+ * @author Fred Bricon
+ * @since 1.3
+ */
+public class NullClassifierClasspathProvider extends AbstractClassifierClasspathProvider {
+
+ /**
+ * This provider applies to the mavenProjectFacade if the classifier is <code>null</code>.
+ */
+ public boolean applies(IMavenProjectFacade mavenProjectFacade, String classifier) {
+ return classifier == null;
+ }
+
+ /**
+ * @return <code>null</code>
+ */
+ public String getClassifier() {
+ return null;
+ }
+
+ /**
+ * Adds the main classes folder to the runtime classpath.
+ */
+ @Override
+ public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ addMainFolder(runtimeClasspath, mavenProjectFacade, monitor);
+ }
+
+ /**
+ * Adds the main classes folder to the test classpath.
+ */
+ @Override
+ public void setTestClasspath(Set<IRuntimeClasspathEntry> testClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ setRuntimeClasspath(testClasspath, mavenProjectFacade, monitor);
+ }
+
+}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/TestsClassifierClasspathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/TestsClassifierClasspathProvider.java
new file mode 100644
index 00000000..fd2972ae
--- /dev/null
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/TestsClassifierClasspathProvider.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat, 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:
+ * Red Hat, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.jdt.internal.launch;
+
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+
+import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.jdt.AbstractClassifierClasspathProvider;
+
+
+/**
+ * Classpath provider for the <code>tests</code> classifier. This provider adds the test classes folder to the runtime
+ * classpath for both Runtime and Test launch configurations.
+ *
+ * @author Fred Bricon
+ * @since 1.3
+ */
+public class TestsClassifierClasspathProvider extends AbstractClassifierClasspathProvider {
+
+ /**
+ * This provider applies to the mavenProjectFacade if the classifier is <code>tests</code>.
+ */
+ public boolean applies(IMavenProjectFacade mavenProjectFacade, String classifier) {
+ return getClassifier().equals(classifier);
+ }
+
+ /**
+ * @return the <code>tests</code> String.
+ */
+ public String getClassifier() {
+ return "tests";
+ }
+
+ /**
+ * Adds the test classes folder to the runtime classpath.
+ */
+ @Override
+ public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ addTestFolder(runtimeClasspath, mavenProjectFacade, monitor);
+ }
+
+ /**
+ * Adds the test classes folder to the test classpath.
+ */
+ @Override
+ public void setTestClasspath(Set<IRuntimeClasspathEntry> testClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ addTestFolder(testClasspath, mavenProjectFacade, monitor);
+ }
+
+}

Back to the top