From c457d113b3ef0f537ab0043254ba255078d9f85b Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Mon, 31 Aug 2009 17:30:01 +0400 Subject: [PATCH] Maven: runtime classpath support + refactoring --- .../JavaClasspathPolicyExtender.java | 17 +++++++++++ .../configurations/JavaParameters.java | 30 +++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 java/execution/openapi/src/com/intellij/execution/configurations/JavaClasspathPolicyExtender.java diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaClasspathPolicyExtender.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaClasspathPolicyExtender.java new file mode 100644 index 000000000000..2f860ff481fc --- /dev/null +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaClasspathPolicyExtender.java @@ -0,0 +1,17 @@ +package com.intellij.execution.configurations; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectRootsTraversing; +import org.jetbrains.annotations.NotNull; + +public interface JavaClasspathPolicyExtender { + ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.javaClasspathPolicyExtender"); + + @NotNull + ProjectRootsTraversing.RootTraversePolicy extend(Project project, @NotNull ProjectRootsTraversing.RootTraversePolicy policy); + + @NotNull + ProjectRootsTraversing.RootTraversePolicy extend(Module module, @NotNull ProjectRootsTraversing.RootTraversePolicy policy); +} diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java index df4c04e41900..2c84a9536905 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java @@ -18,6 +18,7 @@ package com.intellij.execution.configurations; import com.intellij.execution.CantRunException; import com.intellij.execution.ExecutionBundle; import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; @@ -34,12 +35,12 @@ public class JavaParameters extends SimpleJavaParameters { public String getJdkPath() throws CantRunException { final Sdk jdk = getJdk(); - if(jdk == null) { + if (jdk == null) { throw new CantRunException(ExecutionBundle.message("no.jdk.specified..error.message")); } final String jdkHome = jdk.getHomeDirectory().getPresentableUrl(); - if(jdkHome == null || jdkHome.length() == 0) { + if (jdkHome == null || jdkHome.length() == 0) { throw new CantRunException(ExecutionBundle.message("home.directory.not.specified.for.jdk.error.message")); } return jdkHome; @@ -59,7 +60,7 @@ public class JavaParameters extends SimpleJavaParameters { setJdk(jdk); } - if((classPathType & CLASSES_ONLY) == 0) { + if ((classPathType & CLASSES_ONLY) == 0) { return; } @@ -67,7 +68,8 @@ public class JavaParameters extends SimpleJavaParameters { if (encoding != null) { setCharset(encoding); } - ProjectRootsTraversing.collectRoots(module, (classPathType & TESTS_ONLY) != 0 ? ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE : ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS, getClassPath()); + + ProjectRootsTraversing.collectRoots(module, getPolicy(null, module, classPathType), getClassPath()); } public void configureByModule(final Module module, final int classPathType) throws CantRunException { @@ -86,7 +88,7 @@ public class JavaParameters extends SimpleJavaParameters { return jdk; } - public void configureByProject(final Project project, final int classPathType, final Sdk jdk ) throws CantRunException { + public void configureByProject(final Project project, final int classPathType, final Sdk jdk) throws CantRunException { if ((classPathType & JDK_ONLY) != 0) { if (jdk == null) { throw CantRunException.noJdkConfigured(); @@ -98,6 +100,22 @@ public class JavaParameters extends SimpleJavaParameters { return; } - ProjectRootsTraversing.collectRoots(project, (classPathType & TESTS_ONLY) != 0 ? ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE : ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS, getClassPath()); + ProjectRootsTraversing.collectRoots(project, getPolicy(project, null, classPathType), getClassPath()); + } + + private ProjectRootsTraversing.RootTraversePolicy getPolicy(Project project, Module module, int classPathType) { + ProjectRootsTraversing.RootTraversePolicy result = (classPathType & TESTS_ONLY) != 0 + ? ProjectClasspathTraversing.FULL_CLASSPATH_RECURSIVE + : ProjectClasspathTraversing.FULL_CLASSPATH_WITHOUT_TESTS; + + for (JavaClasspathPolicyExtender each : Extensions.getExtensions(JavaClasspathPolicyExtender.EP_NAME)) { + if (project == null) { + result = each.extend(module, result); + } + else { + result = each.extend(project, result); + } + } + return result; } } \ No newline at end of file