Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Tanasenko2017-07-10 11:29:10 -0400
committerAnton Tanasenko2017-07-11 09:01:30 -0400
commit2cdd96ced02638222ea906c7bb844031c65c05ce (patch)
tree89243ca8724a9ccbec12ebcd10ed5518f81a3fb3 /org.eclipse.m2e.jdt
parent6e42ba9d02a67bbf36b30331d71d414d4d3942c0 (diff)
downloadm2e-core-2cdd96ced02638222ea906c7bb844031c65c05ce.tar.gz
m2e-core-2cdd96ced02638222ea906c7bb844031c65c05ce.tar.xz
m2e-core-2cdd96ced02638222ea906c7bb844031c65c05ce.zip
Bug 519467 - Mechanism to map classifiers to files during workspace
resolution Change-Id: Ie94ac27054b9ab9326f2e03e12e32419b68dfbfb Signed-off-by: Anton Tanasenko <atg.sleepless@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.jdt')
-rw-r--r--org.eclipse.m2e.jdt/plugin.xml10
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java55
-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
4 files changed, 55 insertions, 140 deletions
diff --git a/org.eclipse.m2e.jdt/plugin.xml b/org.eclipse.m2e.jdt/plugin.xml
index d29c4e11..ed5a287b 100644
--- a/org.eclipse.m2e.jdt/plugin.xml
+++ b/org.eclipse.m2e.jdt/plugin.xml
@@ -88,15 +88,5 @@
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/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java
index af64b820..ae264732 100644
--- 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
@@ -12,21 +12,31 @@
package org.eclipse.m2e.jdt.internal;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
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.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
+import org.eclipse.m2e.core.project.IWorkspaceClassifierResolver;
import org.eclipse.m2e.jdt.AbstractClassifierClasspathProvider;
import org.eclipse.m2e.jdt.IClassifierClasspathProvider;
import org.eclipse.m2e.jdt.IMavenClassifierManager;
@@ -58,6 +68,37 @@ public class MavenClassifierManager implements IMavenClassifierManager {
}
};
+ private static class WorkspaceClassifierResolverDelegatingProvider extends AbstractClassifierClasspathProvider {
+
+ private IPath path;
+
+ public WorkspaceClassifierResolverDelegatingProvider(IPath path) {
+ this.path = path;
+ }
+
+ public String getClassifier() {
+ return "(__ignore_classifier__)";
+ }
+
+ public boolean applies(IMavenProjectFacade mavenProjectFacade, String classifier) {
+ return false;
+ }
+
+ public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath,
+ IMavenProjectFacade mavenProjectFacade, IProgressMonitor monitor) {
+ addFolders(runtimeClasspath, mavenProjectFacade.getProject(), Collections.singleton(path));
+ }
+
+ public void setTestClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) {
+ setRuntimeClasspath(runtimeClasspath, mavenProjectFacade, monitor);
+ }
+
+ public String toString() {
+ return "Delegates to IWorkspaceClassifierResolver";
+ }
+ };
+
private Map<String, List<IClassifierClasspathProvider>> classifierClasspathProvidersMap;
public IClassifierClasspathProvider getClassifierClasspathProvider(IMavenProjectFacade project, String classifier) {
@@ -81,6 +122,20 @@ public class MavenClassifierManager implements IMavenClassifierManager {
default:
//TODO display/log error message
}
+
+ IWorkspaceClassifierResolver resolver = MavenPlugin.getWorkspaceClassifierResolverManager().getResolver();
+ IPath resolvedPath = resolver.resolveClassifier(project, classifier);
+ if(resolvedPath != null) {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource res = root.findMember(resolvedPath);
+ if(res.getProject().equals(project.getProject())) {
+ IPath projectRelativePath = res.getProjectRelativePath();
+ return new WorkspaceClassifierResolverDelegatingProvider(projectRelativePath);
+ }
+ log.error("Project {} classifier {} resolved to wrong project at {}", project.getProject().getName(), classifier,
+ res.toString());
+ }
+
return NO_OP_CLASSIFIER_CLASSPATH_PROVIDER;
}
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
deleted file mode 100644
index 3fb27ee5..00000000
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/NullClassifierClasspathProvider.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * 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
deleted file mode 100644
index fd2972ae..00000000
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/TestsClassifierClasspathProvider.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * 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