Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2018-01-20 17:45:21 -0500
committerTill Brychcy2018-01-30 13:06:39 -0500
commit10c35e04ef11ff5f20bcd0cec36f30306f57b1be (patch)
treebefc653fcc2c3f5ce33c4ea85e073542467799f4 /org.eclipse.m2e.jdt
parent08675dbd2ee5d0c6bde68ca1516f968ec820cf16 (diff)
downloadm2e-core-10c35e04ef11ff5f20bcd0cec36f30306f57b1be.tar.gz
m2e-core-10c35e04ef11ff5f20bcd0cec36f30306f57b1be.tar.xz
m2e-core-10c35e04ef11ff5f20bcd0cec36f30306f57b1be.zip
Bug 529398 - Support Java 9 in MavenRuntimeClasspathProvider
Change-Id: If851da08ad369f55b637462cdc7ee7d34bec4ed2 Signed-off-by: Till Brychcy <register.eclipse@brychcy.de>
Diffstat (limited to 'org.eclipse.m2e.jdt')
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java47
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClassifierClasspathProvider.java20
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/InternalModuleSupport.java53
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClassifierManager.java8
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ModuleSupport.java55
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/BlankClassifierClasspathProvider.java10
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenRuntimeClasspathProvider.java57
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java2
8 files changed, 218 insertions, 34 deletions
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
index def45c31..ee3a1ea7 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/AbstractClassifierClasspathProvider.java
@@ -23,11 +23,11 @@ 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;
+import org.eclipse.m2e.jdt.internal.ModuleSupport;
/**
@@ -36,7 +36,8 @@ import org.eclipse.m2e.core.project.IMavenProjectFacade;
* @author Fred Bricon
* @since 1.3
*/
-public abstract class AbstractClassifierClasspathProvider implements IClassifierClasspathProvider, IExecutableExtension {
+public abstract class AbstractClassifierClasspathProvider
+ implements IClassifierClasspathProvider, IExecutableExtension {
private static final String ATTR_ID = "id";
@@ -48,48 +49,78 @@ public abstract class AbstractClassifierClasspathProvider implements IClassifier
/**
* @throws CoreException
+ * @deprecated replaced by
+ * {@link IClassifierClasspathProvider#setTestClasspath(Set, IMavenProjectFacade, IProgressMonitor, int)}
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
public void setTestClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
IProgressMonitor monitor) throws CoreException {
}
/**
* @throws CoreException
+ * @deprecated replaced by
+ * {@link IClassifierClasspathProvider#setRuntimeClasspath(Set, IMavenProjectFacade, IProgressMonitor, int)}
*/
+ @SuppressWarnings("deprecation")
+ @Deprecated
public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
IProgressMonitor monitor) throws CoreException {
}
+ @Deprecated
+ protected void addTestFolder(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ addTestFolder(runtimeClasspath, mavenProjectFacade, monitor, IRuntimeClasspathEntry.USER_CLASSES);
+ }
+
+ @Deprecated
+ protected void addMainFolder(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor) throws CoreException {
+ addMainFolder(runtimeClasspath, mavenProjectFacade, monitor, IRuntimeClasspathEntry.USER_CLASSES);
+ }
+
+ @Deprecated
+ protected void addFolders(Set<IRuntimeClasspathEntry> runtimeClasspath, IProject project, Set<IPath> folders) {
+ addFolders(runtimeClasspath, project, folders, IRuntimeClasspathEntry.USER_CLASSES);
+ }
+
/**
* Adds test classes folder to the runtime classpath.
+ *
+ * @param requiredModules
*/
protected void addTestFolder(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
- IProgressMonitor monitor) throws CoreException {
+ IProgressMonitor monitor, int classpathProperty) 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);
+ addFolders(runtimeClasspath, mavenProjectFacade.getProject(), allTestClasses, classpathProperty);
}
/**
* Adds main classes folder to the runtime classpath.
+ *
+ * @param classpathProperty
*/
protected void addMainFolder(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
- IProgressMonitor monitor) throws CoreException {
+ IProgressMonitor monitor, int classpathProperty) 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);
+ addFolders(runtimeClasspath, mavenProjectFacade.getProject(), allClasses, classpathProperty);
}
/**
* Adds a {@link Set} of folder {@link IPath} to the runtime classpath.
*/
- protected void addFolders(Set<IRuntimeClasspathEntry> runtimeClasspath, IProject project, Set<IPath> folders) {
+ protected void addFolders(Set<IRuntimeClasspathEntry> runtimeClasspath, IProject project, Set<IPath> folders,
+ int classpathProperty) {
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()));
+ runtimeClasspath.add(ModuleSupport.createRuntimeClasspathEntry((IFolder) member, classpathProperty, project));
}
}
}
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
index 781f2f68..06a79e99 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClassifierClasspathProvider.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/IClassifierClasspathProvider.java
@@ -40,6 +40,8 @@ public interface IClassifierClasspathProvider {
/**
* Configures the test classpath of the given project
+ *
+ * @deprecated replaced by {@link #setTestClasspath(Set, IMavenProjectFacade, IProgressMonitor, int)}
*/
void setTestClasspath(Set<IRuntimeClasspathEntry> testClasspath, IMavenProjectFacade mavenProjectFacade,
IProgressMonitor monitor) throws CoreException;
@@ -47,7 +49,25 @@ public interface IClassifierClasspathProvider {
/**
* Configures the runtime classpath of the given project.
*/
+ default void setTestClasspath(Set<IRuntimeClasspathEntry> testClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor, int classpathProperty) throws CoreException {
+ setTestClasspath(testClasspath, mavenProjectFacade, monitor);
+ }
+
+ /**
+ * Configures the runtime classpath of the given project.
+ *
+ * @deprecated replaced by {@link #setRuntimeClasspath(Set, IMavenProjectFacade, IProgressMonitor, int)}.
+ */
void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
IProgressMonitor monitor) throws CoreException;
+ /**
+ * Configures the runtime classpath of the given project.
+ */
+ default void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
+ IProgressMonitor monitor, int classpathProperty) throws CoreException {
+ setRuntimeClasspath(runtimeClasspath, mavenProjectFacade, monitor);
+ }
+
}
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/InternalModuleSupport.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/InternalModuleSupport.java
index 5b740236..b5c2f73c 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/InternalModuleSupport.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/InternalModuleSupport.java
@@ -13,6 +13,7 @@ package org.eclipse.m2e.jdt.internal;
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -21,12 +22,15 @@ import java.util.zip.ZipFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
@@ -37,6 +41,9 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.env.AutomaticModuleNaming;
import org.eclipse.jdt.internal.compiler.env.IModule;
import org.eclipse.jdt.internal.core.AbstractModule;
+import org.eclipse.jdt.internal.launching.RuntimeClasspathEntry;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.JavaRuntime;
import org.apache.maven.project.MavenProject;
@@ -59,6 +66,12 @@ class InternalModuleSupport {
private static final Logger log = LoggerFactory.getLogger(InternalModuleSupport.class);
/**
+ * This is a copy of the constant of org.eclipse.jdt.launching.IRuntimeClasspathEntry.PATCH_MODULE. Having this copy
+ * allows to compile and run with 4.7.1a
+ */
+ private static final int PATCH_MODULE = 6;
+
+ /**
* Sets <code>module</code flag to <code>true</code> to classpath dependencies declared in module-info.java
*
* @param facade a Maven facade project
@@ -159,4 +172,44 @@ class InternalModuleSupport {
return new String(moduleName);
}
+ public static int determineModularClasspathProperty(IClasspathEntry entry) {
+ return Arrays.stream(entry.getExtraAttributes())
+ .anyMatch(p -> p.getName().equals(IClasspathAttribute.MODULE) && "true".equals(p.getValue()))
+ ? IRuntimeClasspathEntry.MODULE_PATH
+ : IRuntimeClasspathEntry.CLASS_PATH;
+ }
+
+ public static IRuntimeClasspathEntry createRuntimeClasspathEntry(IFolder folder, int classpathProperty,
+ IProject project) {
+ if(classpathProperty == IRuntimeClasspathEntry.MODULE_PATH && !folder.exists(new Path("module-info.class"))) {
+ classpathProperty = PATCH_MODULE;
+ }
+ IRuntimeClasspathEntry newArchiveRuntimeClasspathEntry = JavaRuntime
+ .newArchiveRuntimeClasspathEntry(folder.getFullPath(), classpathProperty);
+ if(classpathProperty == PATCH_MODULE) {
+ ((RuntimeClasspathEntry) newArchiveRuntimeClasspathEntry).setJavaProject(JavaCore.create(project));
+ }
+ return newArchiveRuntimeClasspathEntry;
+ }
+
+ public static int determineClasspathPropertyForMainProject(boolean isModularConfiguration, IJavaProject javaProject) {
+ if(!isModularConfiguration) {
+ return IRuntimeClasspathEntry.USER_CLASSES;
+ } else if(!JavaRuntime.isModularProject(javaProject)) {
+ return IRuntimeClasspathEntry.CLASS_PATH;
+ } else {
+ return IRuntimeClasspathEntry.MODULE_PATH;
+ }
+ }
+
+ public static boolean isModularConfiguration(ILaunchConfiguration configuration) {
+ return JavaRuntime.isModularConfiguration(configuration);
+ }
+
+ public static IRuntimeClasspathEntry newModularProjectRuntimeClasspathEntry(IJavaProject javaProject) {
+ return JavaRuntime.newProjectRuntimeClasspathEntry(javaProject,
+ JavaRuntime.isModularProject(javaProject) ? IRuntimeClasspathEntry.MODULE_PATH
+ : IRuntimeClasspathEntry.CLASS_PATH);
+ }
+
}
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 ae264732..dbb4fecd 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
@@ -85,13 +85,13 @@ public class MavenClassifierManager implements IMavenClassifierManager {
}
public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath,
- IMavenProjectFacade mavenProjectFacade, IProgressMonitor monitor) {
- addFolders(runtimeClasspath, mavenProjectFacade.getProject(), Collections.singleton(path));
+ IMavenProjectFacade mavenProjectFacade, IProgressMonitor monitor, int classpathProperty) {
+ addFolders(runtimeClasspath, mavenProjectFacade.getProject(), Collections.singleton(path), classpathProperty);
}
public void setTestClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
- IProgressMonitor monitor) {
- setRuntimeClasspath(runtimeClasspath, mavenProjectFacade, monitor);
+ IProgressMonitor monitor, int classpathProperty) {
+ setRuntimeClasspath(runtimeClasspath, mavenProjectFacade, monitor, classpathProperty);
}
public String toString() {
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ModuleSupport.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ModuleSupport.java
index 6e8dbb58..33672823 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ModuleSupport.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/ModuleSupport.java
@@ -11,8 +11,15 @@
package org.eclipse.m2e.jdt.internal;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.jdt.IClasspathDescriptor;
@@ -28,18 +35,28 @@ public class ModuleSupport {
static final boolean IS_MODULE_SUPPORT_AVAILABLE;
+ static final boolean IS_PATCH_MODULE_SUPPORT_AVAILABLE;
+
static {
boolean isModuleSupportAvailable = false;
+ boolean isPatchModuleSupportAvailable = false;
try {
Class.forName("org.eclipse.jdt.core.IModuleDescription");
isModuleSupportAvailable = true;
+ try {
+ IRuntimeClasspathEntry.class.getDeclaredField("PATCH_MODULE");
+ isPatchModuleSupportAvailable = true;
+ } catch(NoSuchFieldException | SecurityException ignored) {
+ }
} catch(ClassNotFoundException ignored) {
}
+
IS_MODULE_SUPPORT_AVAILABLE = isModuleSupportAvailable;
+ IS_PATCH_MODULE_SUPPORT_AVAILABLE = isPatchModuleSupportAvailable;
}
/**
- * Sets <code>module</code flag to <code>true</code> to classpath dependencies declared in module-info.java
+ * Sets <code>module</code> flag to <code>true</code> to classpath dependencies declared in module-info.java
*
* @param facade a Maven facade project
* @param classpath a classpath descriptor
@@ -52,4 +69,40 @@ public class ModuleSupport {
}
InternalModuleSupport.configureClasspath(facade, classpath, monitor);
}
+
+ public static int determineModularClasspathProperty(IClasspathEntry entry) {
+ if(!IS_PATCH_MODULE_SUPPORT_AVAILABLE) {
+ return IRuntimeClasspathEntry.USER_CLASSES;
+ }
+ return InternalModuleSupport.determineModularClasspathProperty(entry);
+ }
+
+ public static IRuntimeClasspathEntry createRuntimeClasspathEntry(IFolder folder, int classpathProperty,
+ IProject project) {
+ if(!IS_PATCH_MODULE_SUPPORT_AVAILABLE) {
+ return JavaRuntime.newArchiveRuntimeClasspathEntry(folder.getFullPath());
+ }
+ return InternalModuleSupport.createRuntimeClasspathEntry(folder, classpathProperty, project);
+ }
+
+ public static int determineClasspathPropertyForMainProject(boolean isModularConfiguration, IJavaProject javaProject) {
+ if(!IS_PATCH_MODULE_SUPPORT_AVAILABLE) {
+ return IRuntimeClasspathEntry.USER_CLASSES;
+ }
+ return InternalModuleSupport.determineClasspathPropertyForMainProject(isModularConfiguration, javaProject);
+ }
+
+ public static boolean isModularConfiguration(ILaunchConfiguration configuration) {
+ if(!IS_PATCH_MODULE_SUPPORT_AVAILABLE) {
+ return false;
+ }
+ return InternalModuleSupport.isModularConfiguration(configuration);
+ }
+
+ public static IRuntimeClasspathEntry newModularProjectRuntimeClasspathEntry(IJavaProject javaProject) {
+ if(!IS_PATCH_MODULE_SUPPORT_AVAILABLE) {
+ return JavaRuntime.newProjectRuntimeClasspathEntry(javaProject);
+ }
+ return InternalModuleSupport.newModularProjectRuntimeClasspathEntry(javaProject);
+ }
}
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
index 15496043..1bd51f53 100644
--- 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
@@ -49,8 +49,8 @@ public class BlankClassifierClasspathProvider extends AbstractClassifierClasspat
*/
@Override
public void setRuntimeClasspath(Set<IRuntimeClasspathEntry> runtimeClasspath, IMavenProjectFacade mavenProjectFacade,
- IProgressMonitor monitor) throws CoreException {
- addMainFolder(runtimeClasspath, mavenProjectFacade, monitor);
+ IProgressMonitor monitor, int classpathProperty) throws CoreException {
+ addMainFolder(runtimeClasspath, mavenProjectFacade, monitor, classpathProperty);
}
/**
@@ -58,9 +58,9 @@ public class BlankClassifierClasspathProvider extends AbstractClassifierClasspat
*/
@Override
public void setTestClasspath(Set<IRuntimeClasspathEntry> testClasspath, IMavenProjectFacade mavenProjectFacade,
- IProgressMonitor monitor) throws CoreException {
- addTestFolder(testClasspath, mavenProjectFacade, monitor);
- addMainFolder(testClasspath, mavenProjectFacade, monitor);
+ IProgressMonitor monitor, int classpathProperty) throws CoreException {
+ addTestFolder(testClasspath, mavenProjectFacade, monitor, classpathProperty);
+ addMainFolder(testClasspath, mavenProjectFacade, monitor, classpathProperty);
}
}
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 d93af4f9..c15b88d4 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
@@ -57,6 +57,7 @@ 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;
+import org.eclipse.m2e.jdt.internal.ModuleSupport;
public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
@@ -87,13 +88,19 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
public IRuntimeClasspathEntry[] computeUnresolvedClasspath(final ILaunchConfiguration configuration)
throws CoreException {
+ boolean isModular = ModuleSupport.isModularConfiguration(configuration);
boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
if(useDefault) {
IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(configuration);
- IRuntimeClasspathEntry projectEntry = JavaRuntime.newProjectRuntimeClasspathEntry(javaProject);
- IRuntimeClasspathEntry mavenEntry = JavaRuntime.newRuntimeContainerClasspathEntry(new Path(
- IClasspathManager.CONTAINER_ID), IRuntimeClasspathEntry.USER_CLASSES);
+ IRuntimeClasspathEntry projectEntry;
+ if(isModular) {
+ projectEntry = ModuleSupport.newModularProjectRuntimeClasspathEntry(javaProject);
+ } else {
+ projectEntry = JavaRuntime.newProjectRuntimeClasspathEntry(javaProject);
+ }
+ IRuntimeClasspathEntry mavenEntry = JavaRuntime.newRuntimeContainerClasspathEntry(
+ new Path(IClasspathManager.CONTAINER_ID), IRuntimeClasspathEntry.USER_CLASSES);
if(jreEntry == null) {
return new IRuntimeClasspathEntry[] {projectEntry, mavenEntry};
@@ -101,6 +108,17 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
return new IRuntimeClasspathEntry[] {jreEntry, projectEntry, mavenEntry};
}
+ // recover persisted classpath
+ if(isModular) {
+ IRuntimeClasspathEntry[] runtimeModulePaths = recoverRuntimePath(configuration,
+ IJavaLaunchConfigurationConstants.ATTR_MODULEPATH);
+ IRuntimeClasspathEntry[] runtimeClasspaths = recoverRuntimePath(configuration,
+ IJavaLaunchConfigurationConstants.ATTR_CLASSPATH);
+ IRuntimeClasspathEntry[] result = Arrays.copyOf(runtimeModulePaths,
+ runtimeModulePaths.length + runtimeClasspaths.length);
+ System.arraycopy(runtimeClasspaths, 0, result, runtimeModulePaths.length, runtimeClasspaths.length);
+ return result;
+ }
return recoverRuntimePath(configuration, IJavaLaunchConfigurationConstants.ATTR_CLASSPATH);
}
@@ -118,16 +136,19 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
IRuntimeClasspathEntry[] resolveClasspath0(IRuntimeClasspathEntry[] entries, ILaunchConfiguration configuration,
IProgressMonitor monitor) throws CoreException {
+ IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
+
+ boolean isModularConfiguration = JavaRuntime.isModularConfiguration(configuration);
int scope = getArtifactScope(configuration);
Set<IRuntimeClasspathEntry> all = new LinkedHashSet<IRuntimeClasspathEntry>(entries.length);
for(IRuntimeClasspathEntry entry : entries) {
if(entry.getType() == IRuntimeClasspathEntry.CONTAINER
&& MavenClasspathHelpers.isMaven2ClasspathContainer(entry.getPath())) {
- addMavenClasspathEntries(all, entry, configuration, scope, monitor);
+ addMavenClasspathEntries(all, entry, configuration, scope, monitor, isModularConfiguration);
} else if(entry.getType() == IRuntimeClasspathEntry.PROJECT) {
- IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
if(javaProject.getPath().equals(entry.getPath())) {
- addProjectEntries(all, entry.getPath(), scope, THIS_PROJECT_CLASSIFIER, configuration, monitor);
+ addProjectEntries(all, entry.getPath(), scope, THIS_PROJECT_CLASSIFIER, configuration, monitor,
+ ModuleSupport.determineClasspathPropertyForMainProject(isModularConfiguration, javaProject));
} else {
addStandardClasspathEntries(all, entry, configuration);
}
@@ -148,18 +169,21 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
private void addMavenClasspathEntries(Set<IRuntimeClasspathEntry> resolved,
IRuntimeClasspathEntry runtimeClasspathEntry, ILaunchConfiguration configuration, int scope,
- IProgressMonitor monitor) throws CoreException {
+ IProgressMonitor monitor, boolean isModularConfiguration) throws CoreException {
IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
MavenJdtPlugin plugin = MavenJdtPlugin.getDefault();
IClasspathManager buildpathManager = plugin.getBuildpathManager();
IClasspathEntry[] cp = buildpathManager.getClasspath(javaProject.getProject(), scope, false, monitor);
for(IClasspathEntry entry : cp) {
+ int classpathProperty = isModularConfiguration ? ModuleSupport.determineModularClasspathProperty(entry)
+ : IRuntimeClasspathEntry.USER_CLASSES;
switch(entry.getEntryKind()) {
case IClasspathEntry.CPE_PROJECT:
- addProjectEntries(resolved, entry.getPath(), scope, getArtifactClassifier(entry), configuration, monitor);
+ addProjectEntries(resolved, entry.getPath(), scope, getArtifactClassifier(entry), configuration, monitor,
+ classpathProperty);
break;
case IClasspathEntry.CPE_LIBRARY:
- resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()));
+ resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath(), classpathProperty));
break;
// case IClasspathEntry.CPE_SOURCE:
// resolved.add(newSourceClasspathEntry(javaProject, cp[i]));
@@ -199,13 +223,14 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
} else if(JDT_JUNIT_TEST.equals(typeid) || JDT_TESTNG_TEST.equals(typeid)) {
return IClasspathManager.CLASSPATH_TEST;
} else {
- throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0, NLS.bind(
- Messages.MavenRuntimeClasspathProvider_error_unsupported, typeid), null));
+ throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0,
+ NLS.bind(Messages.MavenRuntimeClasspathProvider_error_unsupported, typeid), null));
}
}
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier,
- ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) throws CoreException {
+ ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor, int classpathProperty)
+ throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(path.segment(0));
@@ -234,9 +259,9 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
.getClassifierClasspathProvider(projectFacade, classifier);
if(IClasspathManager.CLASSPATH_TEST == scope) {
- classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor);
+ classifierClasspathProvider.setTestClasspath(resolved, projectFacade, monitor, classpathProperty);
} else {
- classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor);
+ classifierClasspathProvider.setRuntimeClasspath(resolved, projectFacade, monitor, classpathProperty);
}
projectResolved = true;
@@ -260,7 +285,9 @@ public class MavenRuntimeClasspathProvider extends StandardClasspathProvider {
}
break;
case IClasspathEntry.CPE_LIBRARY:
- rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath());
+ rce = JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath(),
+ classpathProperty == IRuntimeClasspathEntry.USER_CLASSES ? IRuntimeClasspathEntry.USER_CLASSES
+ : ModuleSupport.determineModularClasspathProperty(entry));
break;
case IClasspathEntry.CPE_VARIABLE:
if(!JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) {
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java
index 7d728745..ac6e3f7e 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/launch/MavenSourcePathProvider.java
@@ -41,7 +41,7 @@ public class MavenSourcePathProvider extends MavenRuntimeClasspathProvider {
@Override
protected void addProjectEntries(Set<IRuntimeClasspathEntry> resolved, IPath path, int scope, String classifier,
- ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor) {
+ ILaunchConfiguration launchConfiguration, final IProgressMonitor monitor, int classpathProperty) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(path.segment(0));
IJavaProject javaProject = JavaCore.create(project);

Back to the top