From fb220e2cf06f393537eaa432428e1aaaaf934fcc Mon Sep 17 00:00:00 2001 From: Keegan Witt Date: Wed, 9 Dec 2020 23:47:00 -0500 Subject: [PATCH] Fix multi-module classpath issues (closes #183) --- pom.xml | 8 +- .../a/pom.xml | 55 ++++++ .../b/pom.xml | 55 ++++++ .../invoker.properties | 2 + .../pom.xml | 87 ++++++++++ .../a/pom.xml | 55 ++++++ .../b/pom.xml | 55 ++++++ .../invoker.properties | 2 + .../pom.xml | 125 +++++++++++++ src/it/multimodulePluginClasspath/a/pom.xml | 56 ++++++ src/it/multimodulePluginClasspath/b/pom.xml | 56 ++++++ .../invoker.properties | 2 + src/it/multimodulePluginClasspath/pom.xml | 125 +++++++++++++ src/it/multimoduleProjectClasspath/a/pom.xml | 56 ++++++ src/it/multimoduleProjectClasspath/b/pom.xml | 56 ++++++ .../invoker.properties | 2 + src/it/multimoduleProjectClasspath/pom.xml | 78 +++++++++ src/it/pom.xml | 8 + .../gmavenplus/mojo/AbstractGroovyMojo.java | 11 +- .../codehaus/gmavenplus/mojo/CompileMojo.java | 3 +- .../gmavenplus/mojo/CompileTestsMojo.java | 3 +- .../codehaus/gmavenplus/mojo/ConsoleMojo.java | 4 +- .../codehaus/gmavenplus/mojo/ExecuteMojo.java | 6 +- .../gmavenplus/mojo/GenerateStubsMojo.java | 3 +- .../mojo/GenerateTestStubsMojo.java | 3 +- .../gmavenplus/mojo/GroovyDocJarMojo.java | 3 +- .../gmavenplus/mojo/GroovyDocMojo.java | 2 +- .../mojo/GroovyDocTestsJarMojo.java | 3 +- .../gmavenplus/mojo/GroovyDocTestsMojo.java | 2 +- .../codehaus/gmavenplus/mojo/ShellMojo.java | 4 +- ...jectDependenciesComponentConfigurator.java | 164 ------------------ ...pileDependenciesComponentConfigurator.java | 83 --------- ...timeDependenciesComponentConfigurator.java | 83 --------- ...TestDependenciesComponentConfigurator.java | 83 --------- .../gmavenplus/plexus/package-info.java | 20 --- .../gmavenplus/util/ClassWrangler.java | 122 ++++++------- ...DependenciesComponentConfiguratorTest.java | 125 ------------- ...DependenciesComponentConfiguratorTest.java | 125 ------------- ...DependenciesComponentConfiguratorTest.java | 125 ------------- .../gmavenplus/util/ClassWranglerTest.java | 15 +- 40 files changed, 962 insertions(+), 913 deletions(-) create mode 100644 src/it/multimodulePluginAndProjectClasspath/a/pom.xml create mode 100644 src/it/multimodulePluginAndProjectClasspath/b/pom.xml create mode 100644 src/it/multimodulePluginAndProjectClasspath/invoker.properties create mode 100644 src/it/multimodulePluginAndProjectClasspath/pom.xml create mode 100644 src/it/multimodulePluginAndProjectClasspath2/a/pom.xml create mode 100644 src/it/multimodulePluginAndProjectClasspath2/b/pom.xml create mode 100644 src/it/multimodulePluginAndProjectClasspath2/invoker.properties create mode 100644 src/it/multimodulePluginAndProjectClasspath2/pom.xml create mode 100644 src/it/multimodulePluginClasspath/a/pom.xml create mode 100644 src/it/multimodulePluginClasspath/b/pom.xml create mode 100644 src/it/multimodulePluginClasspath/invoker.properties create mode 100644 src/it/multimodulePluginClasspath/pom.xml create mode 100644 src/it/multimoduleProjectClasspath/a/pom.xml create mode 100644 src/it/multimoduleProjectClasspath/b/pom.xml create mode 100644 src/it/multimoduleProjectClasspath/invoker.properties create mode 100644 src/it/multimoduleProjectClasspath/pom.xml delete mode 100644 src/main/java/org/codehaus/gmavenplus/plexus/AbstractIncludeProjectDependenciesComponentConfigurator.java delete mode 100644 src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfigurator.java delete mode 100644 src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfigurator.java delete mode 100644 src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfigurator.java delete mode 100644 src/main/java/org/codehaus/gmavenplus/plexus/package-info.java delete mode 100644 src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfiguratorTest.java delete mode 100644 src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfiguratorTest.java delete mode 100644 src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfiguratorTest.java diff --git a/pom.xml b/pom.xml index 1039ad5b0..1cf7bdfa2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.gmavenplus gmavenplus-plugin maven-plugin - 1.11.2-SNAPSHOT + 1.12.0-SNAPSHOT UTF-8 @@ -55,11 +55,6 @@ 3.6.0 provided - - org.codehaus.plexus - plexus-classworlds - 2.6.0 - org.apache.maven maven-archiver @@ -391,7 +386,6 @@ version may not match the compilation version --> org/apache/maven/* org/codehaus/plexus/* - org/codehaus/classworlds/* diff --git a/src/it/multimodulePluginAndProjectClasspath/a/pom.xml b/src/it/multimodulePluginAndProjectClasspath/a/pom.xml new file mode 100644 index 000000000..1492e4147 --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath/a/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath-a + testing + GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test A Module + + + + junit + junit + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + + + + + + + + + diff --git a/src/it/multimodulePluginAndProjectClasspath/b/pom.xml b/src/it/multimodulePluginAndProjectClasspath/b/pom.xml new file mode 100644 index 000000000..83d9a9c7b --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath/b/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath-b + testing + GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test B Module + + + + org.junit.jupiter + junit-jupiter + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + + + + + + + + + diff --git a/src/it/multimodulePluginAndProjectClasspath/invoker.properties b/src/it/multimodulePluginAndProjectClasspath/invoker.properties new file mode 100644 index 000000000..1bfdef1c7 --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean test +#invoker.debug = true diff --git a/src/it/multimodulePluginAndProjectClasspath/pom.xml b/src/it/multimodulePluginAndProjectClasspath/pom.xml new file mode 100644 index 000000000..b07f77ef7 --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-root + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath + testing + GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test + pom + + + + indy + + + @groovyGroupId@ + groovy + indy + + + @groovyGroupId@ + groovy-ant + indy + + + + + nonindy + + + @groovyGroupId@ + groovy + + + @groovyGroupId@ + groovy-ant + + + + + pre2.3-indy + + + @groovyGroupId@ + groovy + indy + + + + + pre2.3-nonindy + + + @groovyGroupId@ + groovy + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + a + b + + + diff --git a/src/it/multimodulePluginAndProjectClasspath2/a/pom.xml b/src/it/multimodulePluginAndProjectClasspath2/a/pom.xml new file mode 100644 index 000000000..27e1ee6ce --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath2/a/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath2 + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath2-a + testing + GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test 2 A Module + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + + + + + + + junit + junit + @junitVersion@ + + + + + + + diff --git a/src/it/multimodulePluginAndProjectClasspath2/b/pom.xml b/src/it/multimodulePluginAndProjectClasspath2/b/pom.xml new file mode 100644 index 000000000..24dd0d16b --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath2/b/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath2 + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath2-b + testing + GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test 2 B Module + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + + + + + + + org.junit.jupiter + junit-jupiter + ${junit5Version} + + + + + + + diff --git a/src/it/multimodulePluginAndProjectClasspath2/invoker.properties b/src/it/multimodulePluginAndProjectClasspath2/invoker.properties new file mode 100644 index 000000000..1bfdef1c7 --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath2/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean test +#invoker.debug = true diff --git a/src/it/multimodulePluginAndProjectClasspath2/pom.xml b/src/it/multimodulePluginAndProjectClasspath2/pom.xml new file mode 100644 index 000000000..3963d0c56 --- /dev/null +++ b/src/it/multimodulePluginAndProjectClasspath2/pom.xml @@ -0,0 +1,125 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-root + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginAndProjectClasspath2 + testing + GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test 2 + pom + + + + indy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + indy + + + @groovyGroupId@ + groovy-ant + @groovyVersion@ + indy + + + + + + + + nonindy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + + + @groovyGroupId@ + groovy-ant + @groovyVersion@ + + + + + + + + pre2.3-indy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + indy + + + + + + + + pre2.3-nonindy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + a + b + + + diff --git a/src/it/multimodulePluginClasspath/a/pom.xml b/src/it/multimodulePluginClasspath/a/pom.xml new file mode 100644 index 000000000..5ae59712c --- /dev/null +++ b/src/it/multimodulePluginClasspath/a/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimodulePluginClasspath + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginClasspath-a + testing + GMavenPlus Plugin Multi-Module Plugin Classpath Test A Module + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + PLUGIN_ONLY + + + + + + + junit + junit + @junitVersion@ + + + + + + + diff --git a/src/it/multimodulePluginClasspath/b/pom.xml b/src/it/multimodulePluginClasspath/b/pom.xml new file mode 100644 index 000000000..88a108763 --- /dev/null +++ b/src/it/multimodulePluginClasspath/b/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimodulePluginClasspath + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginClasspath-b + testing + GMavenPlus Plugin Multi-Module Plugin Classpath Test B Module + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + PLUGIN_ONLY + + + + + + + org.junit.jupiter + junit-jupiter + ${junit5Version} + + + + + + + diff --git a/src/it/multimodulePluginClasspath/invoker.properties b/src/it/multimodulePluginClasspath/invoker.properties new file mode 100644 index 000000000..1bfdef1c7 --- /dev/null +++ b/src/it/multimodulePluginClasspath/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean test +#invoker.debug = true diff --git a/src/it/multimodulePluginClasspath/pom.xml b/src/it/multimodulePluginClasspath/pom.xml new file mode 100644 index 000000000..e336acdea --- /dev/null +++ b/src/it/multimodulePluginClasspath/pom.xml @@ -0,0 +1,125 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-root + testing + ../pom.xml + + + gmavenplus-plugin-it-multimodulePluginClasspath + testing + GMavenPlus Plugin Multi-Module Plugin and Project Classpath Test + pom + + + + indy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + indy + + + @groovyGroupId@ + groovy-ant + @groovyVersion@ + indy + + + + + + + + nonindy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + + + @groovyGroupId@ + groovy-ant + @groovyVersion@ + + + + + + + + pre2.3-indy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + indy + + + + + + + + pre2.3-nonindy + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + @groovyGroupId@ + groovy + @groovyVersion@ + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + a + b + + + diff --git a/src/it/multimoduleProjectClasspath/a/pom.xml b/src/it/multimoduleProjectClasspath/a/pom.xml new file mode 100644 index 000000000..3b9edab73 --- /dev/null +++ b/src/it/multimoduleProjectClasspath/a/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimoduleProjectClasspath + testing + ../pom.xml + + + gmavenplus-plugin-it-multimoduleProjectClasspath-a + testing + GMavenPlus Plugin Multi-Module Project Classpath Test A Module + + + + junit + junit + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + PROJECT_ONLY + + + + + + + + + diff --git a/src/it/multimoduleProjectClasspath/b/pom.xml b/src/it/multimoduleProjectClasspath/b/pom.xml new file mode 100644 index 000000000..56e232788 --- /dev/null +++ b/src/it/multimoduleProjectClasspath/b/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-multimoduleProjectClasspath + testing + ../pom.xml + + + gmavenplus-plugin-it-multimoduleProjectClasspath-b + testing + GMavenPlus Plugin Multi-Module Project Classpath Test B Module + + + + org.junit.jupiter + junit-jupiter + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + + + test + + execute + + + + + PROJECT_ONLY + + + + + + + + + diff --git a/src/it/multimoduleProjectClasspath/invoker.properties b/src/it/multimoduleProjectClasspath/invoker.properties new file mode 100644 index 000000000..1bfdef1c7 --- /dev/null +++ b/src/it/multimoduleProjectClasspath/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals=clean test +#invoker.debug = true diff --git a/src/it/multimoduleProjectClasspath/pom.xml b/src/it/multimoduleProjectClasspath/pom.xml new file mode 100644 index 000000000..d860977c5 --- /dev/null +++ b/src/it/multimoduleProjectClasspath/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + + org.codehaus.gmavenplus + gmavenplus-plugin-it-root + testing + ../pom.xml + + + gmavenplus-plugin-it-multimoduleProjectClasspath + testing + GMavenPlus Plugin Multi-Module Project Classpath Test + pom + + + + indy + + + @groovyGroupId@ + groovy + indy + + + + + nonindy + + + @groovyGroupId@ + groovy + + + + + pre2.3-indy + + + @groovyGroupId@ + groovy + indy + + + + + pre2.3-nonindy + + + @groovyGroupId@ + groovy + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + a + b + + + diff --git a/src/it/pom.xml b/src/it/pom.xml index 6296f5375..17102a3b6 100644 --- a/src/it/pom.xml +++ b/src/it/pom.xml @@ -13,6 +13,7 @@ @project.build.sourceEncoding@ 3.7 3.6.3 + 5.7.0 @@ -23,6 +24,13 @@ @junitVersion@ test + + org.junit + junit-bom + ${junit5Version} + pom + import + org.apache.maven maven-plugin-api diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGroovyMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGroovyMojo.java index 997907eaa..a744fb413 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGroovyMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/AbstractGroovyMojo.java @@ -30,6 +30,8 @@ import java.net.MalformedURLException; import java.util.List; +import static java.util.Collections.emptyList; + /** * The base mojo class, which all other mojos extend. @@ -238,10 +240,13 @@ protected boolean isGroovyIndy() { protected void setupClassWrangler(List classpath, IncludeClasspath includeClasspath) throws MalformedURLException { if (IncludeClasspath.PROJECT_ONLY.equals(includeClasspath)) { getLog().info("Using isolated classloader, without GMavenPlus classpath."); - classWrangler = new ClassWrangler(classpath, getLog()); + classWrangler = new ClassWrangler(classpath, ClassLoader.getSystemClassLoader(), getLog()); + } else if (IncludeClasspath.PROJECT_AND_PLUGIN.equals(includeClasspath)) { + getLog().info("Using plugin classloader, includes GMavenPlus and project classpath."); + classWrangler = new ClassWrangler(classpath, getClass().getClassLoader(), getLog()); } else { - getLog().info("Using plugin classloader, includes GMavenPlus classpath."); - classWrangler = new ClassWrangler(Thread.currentThread().getContextClassLoader(), getLog()); + getLog().info("Using plugin classloader, includes GMavenPlus classpath, but not project classpath."); + classWrangler = new ClassWrangler(emptyList(), getClass().getClassLoader(), getLog()); } } } diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/CompileMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/CompileMojo.java index 554ce3cd2..f8eb3f9c2 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/CompileMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/CompileMojo.java @@ -36,8 +36,7 @@ * @author Keegan Witt * @since 1.0-beta-1 */ -@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true, - configurator = "include-project-compile-dependencies") +@Mojo(name = "compile", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) public class CompileMojo extends AbstractCompileMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java index 60bfe6c4d..3c9106a46 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java @@ -36,8 +36,7 @@ * @author Keegan Witt * @since 1.0-beta-1 */ -@Mojo(name = "compileTests", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true, - configurator = "include-project-test-dependencies") +@Mojo(name = "compileTests", defaultPhase = LifecyclePhase.TEST_COMPILE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true) public class CompileTestsMojo extends AbstractCompileMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java index c66a9b486..4631b461f 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java @@ -43,7 +43,7 @@ * @author Keegan Witt * @since 1.1 */ -@Mojo(name = "console", requiresDependencyResolution = ResolutionScope.TEST, configurator = "include-project-test-dependencies") +@Mojo(name = "console", requiresDependencyResolution = ResolutionScope.TEST) public class ConsoleMojo extends AbstractToolsMojo { /** @@ -178,7 +178,7 @@ protected Object setupConsole(final Class consoleClass, final Class bindin invokeMethod(setVariable, binding, "properties", properties); } - return invokeConstructor(findConstructor(consoleClass, ClassLoader.class, bindingClass), Thread.currentThread().getContextClassLoader(), binding); + return invokeConstructor(findConstructor(consoleClass, ClassLoader.class, bindingClass), classWrangler.getClassLoader(), binding); } /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java index ee7357073..09dd663c3 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java @@ -43,7 +43,7 @@ * @author Keegan Witt * @since 1.0-beta-1 */ -@Mojo(name = "execute", requiresDependencyResolution = ResolutionScope.TEST, configurator = "include-project-test-dependencies", threadSafe = true) +@Mojo(name = "execute", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true) public class ExecuteMojo extends AbstractToolsMojo { /** @@ -174,9 +174,9 @@ protected Object setupShell(final Class groovyShellClass) throws InvocationTa Class compilerConfigurationClass = classWrangler.getClass("org.codehaus.groovy.control.CompilerConfiguration"); Object compilerConfiguration = invokeConstructor(findConstructor(compilerConfigurationClass)); invokeMethod(findMethod(compilerConfigurationClass, "setSourceEncoding", String.class), compilerConfiguration, sourceEncoding); - shell = invokeConstructor(findConstructor(groovyShellClass, compilerConfigurationClass), compilerConfiguration); + shell = invokeConstructor(findConstructor(groovyShellClass, ClassLoader.class, compilerConfigurationClass), classWrangler.getClassLoader(), compilerConfiguration); } else { - shell = invokeConstructor(findConstructor(groovyShellClass)); + shell = invokeConstructor(findConstructor(groovyShellClass, ClassLoader.class), classWrangler.getClassLoader()); } initializeProperties(); Method setProperty = findMethod(groovyShellClass, "setProperty", String.class, Object.class); diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/GenerateStubsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/GenerateStubsMojo.java index d595a98ce..2ee2f2410 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/GenerateStubsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/GenerateStubsMojo.java @@ -36,8 +36,7 @@ * @author Keegan Witt * @since 1.0-beta-1 */ -@Mojo(name = "generateStubs", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true, - configurator = "include-project-compile-dependencies") +@Mojo(name = "generateStubs", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) public class GenerateStubsMojo extends AbstractGenerateStubsMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java index d57f0b735..6677a9880 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java @@ -36,8 +36,7 @@ * @author Keegan Witt * @since 1.0-beta-1 */ -@Mojo(name = "generateTestStubs", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true, - configurator = "include-project-test-dependencies") +@Mojo(name = "generateTestStubs", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true) public class GenerateTestStubsMojo extends AbstractGenerateStubsMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocJarMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocJarMojo.java index 80a69345b..7baeb1dc8 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocJarMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocJarMojo.java @@ -38,8 +38,7 @@ * @author Keegan Witt * @since 1.7.1 */ -@Mojo(name = "groovydoc-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true, - configurator = "include-project-compile-dependencies") +@Mojo(name = "groovydoc-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true) public class GroovyDocJarMojo extends GroovyDocMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocMojo.java index d4895687d..bd3dc8d8d 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocMojo.java @@ -34,7 +34,7 @@ * @author Keegan Witt * @since 1.0-beta-1 */ -@Mojo(name = "groovydoc", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true, configurator = "include-project-compile-dependencies") +@Mojo(name = "groovydoc", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true) public class GroovyDocMojo extends AbstractGroovyDocMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsJarMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsJarMojo.java index ce0f9a5a2..9a9031b7f 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsJarMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsJarMojo.java @@ -38,8 +38,7 @@ * @author Keegan Witt * @since 1.7.1 */ -@Mojo(name = "groovydocTests-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true, - configurator = "include-project-test-dependencies") +@Mojo(name = "groovydocTests-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true) public class GroovyDocTestsJarMojo extends GroovyDocTestsMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsMojo.java index d1f9222e3..4502874f9 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/GroovyDocTestsMojo.java @@ -34,7 +34,7 @@ * @author Keegan Witt * @since 1.0-beta-1 */ -@Mojo(name = "groovydocTests", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true, configurator = "include-project-test-dependencies") +@Mojo(name = "groovydocTests", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true) public class GroovyDocTestsMojo extends AbstractGroovyDocMojo { /** diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java index a921900b5..79456f7e9 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java @@ -40,7 +40,7 @@ * @author Keegan Witt * @since 1.1 */ -@Mojo(name = "shell", requiresDependencyResolution = ResolutionScope.TEST, configurator = "include-project-test-dependencies") +@Mojo(name = "shell", requiresDependencyResolution = ResolutionScope.TEST) public class ShellMojo extends AbstractToolsMojo { /** @@ -155,7 +155,7 @@ protected Object setupShell(final Class shellClass, final Class bindingCla invokeMethod(findMethod(ioClass, "setVerbosity", verbosityClass), io, invokeStaticMethod(findMethod(verbosityClass, "forName", String.class), verbosity)); findField(loggerClass, "io", ioClass).set(null, io); - return invokeConstructor(findConstructor(shellClass, ClassLoader.class, bindingClass, ioClass), Thread.currentThread().getContextClassLoader(), binding, io); + return invokeConstructor(findConstructor(shellClass, ClassLoader.class, bindingClass, ioClass), classWrangler.getClassLoader(), binding, io); } } diff --git a/src/main/java/org/codehaus/gmavenplus/plexus/AbstractIncludeProjectDependenciesComponentConfigurator.java b/src/main/java/org/codehaus/gmavenplus/plexus/AbstractIncludeProjectDependenciesComponentConfigurator.java deleted file mode 100644 index ac61d8b3b..000000000 --- a/src/main/java/org/codehaus/gmavenplus/plexus/AbstractIncludeProjectDependenciesComponentConfigurator.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.codehaus.gmavenplus.plexus; - -//import org.apache.maven.plugin.logging.Log; -//import org.apache.maven.plugin.logging.SystemStreamLog; - -import org.codehaus.gmavenplus.model.IncludeClasspath; -import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - - -/** - * A custom ComponentConfigurator which adds the project's classpath elements to the plugin's ClassRealm. - * Note that there are two method signatures for addDependenciesToClassRealm, since different versions of Maven have different expectations. - * - * @author Brian Jackson - * @author Keegan Witt - * @since 1.0-beta-3 - */ -public abstract class AbstractIncludeProjectDependenciesComponentConfigurator extends AbstractComponentConfigurator { - -// private static final Log LOG = new SystemStreamLog(); - - /** - * Adds the project's compile dependencies to the specified ClassRealm. - * - * @param expressionEvaluator The expression evaluator to use to get project elements - * @param classpath The classpath to load into the container realm - * @param containerRealm The ClassRealm to add dependencies to - * @throws ComponentConfigurationException when parsing components configuration fails - */ - protected void addDependenciesToClassRealm(final ExpressionEvaluator expressionEvaluator, final Classpath classpath, - final org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm) throws ComponentConfigurationException { - List classpathElements; - - try { - classpathElements = (List) expressionEvaluator.evaluate("${project." + classpath.toString().toLowerCase() + "ClasspathElements}"); - } catch (ExpressionEvaluationException e) { - throw new ComponentConfigurationException("There was a problem evaluating: ${project." + classpath.toString().toLowerCase() + "ClasspathElements}.", e); - } - - // add the project dependencies to the ClassRealm - final URL[] urls = buildURLs(classpathElements); - for (URL url : urls) { - containerRealm.addURL(url); - } - } - - /** - * Adds the project's compile dependencies to the specified ClassRealm. - * - * @param expressionEvaluator The expression evaluator to use to get project elements - * @param classpath The classpath to load into the container realm - * @param containerRealm The ClassRealm to add dependencies to - * @throws ComponentConfigurationException when parsing components configuration fails - */ - @SuppressWarnings("deprecation") - protected void addDependenciesToClassRealm(final ExpressionEvaluator expressionEvaluator, final Classpath classpath, - final org.codehaus.classworlds.ClassRealm containerRealm) throws ComponentConfigurationException { - List classpathElements; - - try { - classpathElements = (List) expressionEvaluator.evaluate("${project." + classpath.toString().toLowerCase() + "ClasspathElements}"); - } catch (ExpressionEvaluationException e) { - throw new ComponentConfigurationException("There was a problem evaluating: ${project." + classpath.toString().toLowerCase() + "ClasspathElements}.", e); - } - - // add the project dependencies to the ClassRealm - final URL[] urls = buildURLs(classpathElements); - for (URL url : urls) { - containerRealm.addConstituent(url); - } - } - - /** - * Create an array of URLs for all the elements in the classpath. - * - * @param classpathElements The classpath elements to create URLs for - * @return URLs for all the classpath elements - * @throws ComponentConfigurationException when parsing components configuration fails - */ - protected URL[] buildURLs(final List classpathElements) throws ComponentConfigurationException { - List urls = new ArrayList<>(classpathElements.size()); - for (Object element : classpathElements) { - try { - final URL url = new File((String) element).toURI().toURL(); - if (!urls.contains(url)) { - urls.add(url); - } - // commented out because debug seems to be on all the time -// LOG.debug("Added to project class loader: " + url); - } catch (MalformedURLException e) { - throw new ComponentConfigurationException("Unable to access project dependency: " + element + ".", e); - } - } - - return urls.toArray(new URL[0]); - } - - /** - * Enum of the various possible classpaths. - */ - protected enum Classpath { - - /** - * Compile classpath. - */ - COMPILE, - - /** - * Runtime classpath. - */ - RUNTIME, - - /** - * Test classpath. - */ - TEST, - - /** - * System classpath. - */ - SYSTEM - } - - /** - * Determines whether to add project dependencies to the plugin classpath. - * - * @param configuration the PlexusConfiguration to check for the specified IncludeClasspath option. - * @return true if the project dependencies should be added to the plugin classpath, false otherwise. - */ - protected boolean shouldIncludeProjectDependencies(PlexusConfiguration configuration) { - PlexusConfiguration includeClasspathConfig = configuration.getChild("includeClasspath"); - String includeClasspath = includeClasspathConfig.getValue(); - if (includeClasspath == null) { - includeClasspath = includeClasspathConfig.getAttribute("default-value"); - } - return IncludeClasspath.PROJECT_AND_PLUGIN.equals(IncludeClasspath.valueOf(includeClasspath)); - } -} diff --git a/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfigurator.java b/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfigurator.java deleted file mode 100644 index 0725d5403..000000000 --- a/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfigurator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Originally from http://stackoverflow.com/questions/2659048/add-maven-build-classpath-to-plugin-execution-classpath - */ - -package org.codehaus.gmavenplus.plexus; - -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.ComponentConfigurator; -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; -import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; - - -/** - * A custom ComponentConfigurator which adds the project's compile classpath - * elements. - * - * @author Brian Jackson - * @author Keegan Witt - * @since 1.0-beta-3 - */ -@Component(role = ComponentConfigurator.class, hint = "include-project-compile-dependencies") -public class IncludeProjectCompileDependenciesComponentConfigurator extends AbstractIncludeProjectDependenciesComponentConfigurator { - - /** - * Configures the specified component. - * - * @param component the Component to configure - * @param configuration the Configuration to use to configure the component - * @param expressionEvaluator the ExpressionEvaluator - * @param containerRealm the Classrealm to use to configure the component - * @param listener the component's Listener - * @throws ComponentConfigurationException when an exception occurs in component configuration - */ - public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, - final org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm, final ConfigurationListener listener) throws ComponentConfigurationException { - if (shouldIncludeProjectDependencies(configuration)) { - addDependenciesToClassRealm(expressionEvaluator, Classpath.COMPILE, containerRealm); - } - converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); - new ObjectWithFieldsConverter().processConfiguration(converterLookup, component, containerRealm.getParentClassLoader(), configuration, expressionEvaluator, listener); - } - - /** - * Configures the specified component. - * - * @param component the Component to configure - * @param configuration the Configuration to use to configure the component - * @param expressionEvaluator the ExpressionEvaluator - * @param containerRealm the Classrealm to use to configure the component - * @param listener the component's Listener - * @throws ComponentConfigurationException when an exception occurs in component configuration - */ - @SuppressWarnings("deprecation") - public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, - final org.codehaus.classworlds.ClassRealm containerRealm, final ConfigurationListener listener) throws ComponentConfigurationException { - if (shouldIncludeProjectDependencies(configuration)) { - addDependenciesToClassRealm(expressionEvaluator, Classpath.COMPILE, containerRealm); - } - converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); - new ObjectWithFieldsConverter().processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); - } - -} diff --git a/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfigurator.java b/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfigurator.java deleted file mode 100644 index f49fbd968..000000000 --- a/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfigurator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Originally from http://stackoverflow.com/questions/2659048/add-maven-build-classpath-to-plugin-execution-classpath - */ - -package org.codehaus.gmavenplus.plexus; - -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.ComponentConfigurator; -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; -import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; - - -/** - * A custom ComponentConfigurator which adds the project's runtime classpath - * elements. - * - * @author Brian Jackson - * @author Keegan Witt - * @since 1.0-beta-3 - */ -@Component(role = ComponentConfigurator.class, hint = "include-project-runtime-dependencies") -public class IncludeProjectRuntimeDependenciesComponentConfigurator extends AbstractIncludeProjectDependenciesComponentConfigurator { - - /** - * Configures the specified component. - * - * @param component the Component to configure - * @param configuration the Configuration to use to configure the component - * @param expressionEvaluator the ExpressionEvaluator - * @param containerRealm the Classrealm to use to configure the component - * @param listener the component's Listener - * @throws ComponentConfigurationException when an exception occurs in component configuration - */ - public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, - final org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm, final ConfigurationListener listener) throws ComponentConfigurationException { - if (shouldIncludeProjectDependencies(configuration)) { - addDependenciesToClassRealm(expressionEvaluator, Classpath.RUNTIME, containerRealm); - } - converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); - new ObjectWithFieldsConverter().processConfiguration(converterLookup, component, containerRealm.getParentClassLoader(), configuration, expressionEvaluator, listener); - } - - /** - * Configures the specified component. - * - * @param component the Component to configure - * @param configuration the Configuration to use to configure the component - * @param expressionEvaluator the ExpressionEvaluator - * @param containerRealm the Classrealm to use to configure the component - * @param listener the component's Listener - * @throws ComponentConfigurationException when an exception occurs in component configuration - */ - @SuppressWarnings("deprecation") - public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, - final org.codehaus.classworlds.ClassRealm containerRealm, final ConfigurationListener listener) throws ComponentConfigurationException { - if (shouldIncludeProjectDependencies(configuration)) { - addDependenciesToClassRealm(expressionEvaluator, Classpath.RUNTIME, containerRealm); - } - converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); - new ObjectWithFieldsConverter().processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); - } - -} diff --git a/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfigurator.java b/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfigurator.java deleted file mode 100644 index 05c84fea3..000000000 --- a/src/main/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfigurator.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Originally from http://stackoverflow.com/questions/2659048/add-maven-build-classpath-to-plugin-execution-classpath - */ - -package org.codehaus.gmavenplus.plexus; - -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.ComponentConfigurator; -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter; -import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; - - -/** - * A custom ComponentConfigurator which adds the project's test classpath - * elements. - * - * @author Brian Jackson - * @author Keegan Witt - * @since 1.0-beta-3 - */ -@Component(role = ComponentConfigurator.class, hint = "include-project-test-dependencies") -public class IncludeProjectTestDependenciesComponentConfigurator extends AbstractIncludeProjectDependenciesComponentConfigurator { - - /** - * Configures the specified component. - * - * @param component the Component to configure - * @param configuration the Configuration to use to configure the component - * @param expressionEvaluator the ExpressionEvaluator - * @param containerRealm the Classrealm to use to configure the component - * @param listener the component's Listener - * @throws ComponentConfigurationException when an exception occurs in component configuration - */ - public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, - final org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm, final ConfigurationListener listener) throws ComponentConfigurationException { - if (shouldIncludeProjectDependencies(configuration)) { - addDependenciesToClassRealm(expressionEvaluator, Classpath.TEST, containerRealm); - } - converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); - new ObjectWithFieldsConverter().processConfiguration(converterLookup, component, containerRealm.getParentClassLoader(), configuration, expressionEvaluator, listener); - } - - /** - * Configures the specified component. - * - * @param component the Component to configure - * @param configuration the Configuration to use to configure the component - * @param expressionEvaluator the ExpressionEvaluator - * @param containerRealm the Classrealm to use to configure the component - * @param listener the component's Listener - * @throws ComponentConfigurationException when an exception occurs in component configuration - */ - @SuppressWarnings("deprecation") - public void configureComponent(final Object component, final PlexusConfiguration configuration, final ExpressionEvaluator expressionEvaluator, - final org.codehaus.classworlds.ClassRealm containerRealm, final ConfigurationListener listener) throws ComponentConfigurationException { - if (shouldIncludeProjectDependencies(configuration)) { - addDependenciesToClassRealm(expressionEvaluator, Classpath.TEST, containerRealm); - } - converterLookup.registerConverter(new ClassRealmConverter(containerRealm)); - new ObjectWithFieldsConverter().processConfiguration(converterLookup, component, containerRealm.getClassLoader(), configuration, expressionEvaluator, listener); - } - -} diff --git a/src/main/java/org/codehaus/gmavenplus/plexus/package-info.java b/src/main/java/org/codehaus/gmavenplus/plexus/package-info.java deleted file mode 100644 index d9f068755..000000000 --- a/src/main/java/org/codehaus/gmavenplus/plexus/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Classes to work with the Plexus container. - */ -package org.codehaus.gmavenplus.plexus; diff --git a/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java b/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java index 80ff5aa2e..a464f4dd2 100644 --- a/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java +++ b/src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java @@ -53,7 +53,7 @@ public class ClassWrangler { /** * ClassLoader to use for class wrangling. */ - private ClassLoader classLoader; + private final ClassLoader classLoader; /** * Plugin log. @@ -61,28 +61,16 @@ public class ClassWrangler { private final Log log; /** - * Creates a new ClassWrangler using the specified ClassLoader. + * Creates a new ClassWrangler using the specified parent ClassLoader, loaded with the items from the specified classpath. * - * @param classLoaderForLoading the ClassLoader to use to load classes - * @param pluginLog the Maven log to use for logging - */ - public ClassWrangler(final ClassLoader classLoaderForLoading, final Log pluginLog) { - log = pluginLog; - classLoader = classLoaderForLoading; - } - - /** - * Creates a new ClassWrangler using a new ClassLoader, loaded with the items from the specified classpath. - * - * @param classpath the classpath to load the new ClassLoader with - * @param pluginLog the Maven log to use for logging + * @param classpath the classpath to load the new ClassLoader with + * @param parentClassLoader the parent for the new ClassLoader used to use to load classes + * @param pluginLog the Maven log to use for logging * @throws MalformedURLException when a classpath element provides a malformed URL */ - public ClassWrangler(final List classpath, final Log pluginLog) throws MalformedURLException { + public ClassWrangler(final List classpath, final ClassLoader parentClassLoader, final Log pluginLog) throws MalformedURLException { log = pluginLog; - // create an isolated ClassLoader with all the appropriate project dependencies in it - classLoader = createNewClassLoader(classpath); - Thread.currentThread().setContextClassLoader(classLoader); + classLoader = createNewClassLoader(classpath, parentClassLoader); } /** @@ -226,90 +214,90 @@ public boolean isGroovyIndy() { } /** - * Returns the filename of the Groovy jar on the classpath. + * Logs the version of groovy used by this mojo. * - * @return the Groovy jar filename + * @param goal The goal to mention in the log statement showing Groovy version */ - public String getGroovyJar() { - try { - String groovyObjectClassPath = getJarPath(); - String groovyJar = null; - if (groovyObjectClassPath != null) { - groovyJar = groovyObjectClassPath.replaceAll("!.+", ""); - groovyJar = groovyJar.substring(groovyJar.lastIndexOf("/") + 1); - } - - return groovyJar; - } catch (ClassNotFoundException e) { - log.error("Unable to determine Groovy version. Is Groovy declared as a dependency?"); - return null; + public void logGroovyVersion(final String goal) { + if (log.isInfoEnabled()) { + log.info("Using Groovy " + getGroovyVersionString() + " to perform " + goal + "."); } } /** - * Returns the path of the Groovy jar on the classpath. + * Gets a class for the given class name. * - * @return the path of the Groovy jar - * @throws ClassNotFoundException when Groovy couldn't be found on the classpath + * @param className the class name to retrieve the class for + * @return the class for the given class name + * @throws ClassNotFoundException when a class for the specified class name cannot be found */ - protected String getJarPath() throws ClassNotFoundException { - Class groovyObjectClass = getClass("groovy.lang.GroovyObject"); - String groovyObjectClassPath = String.valueOf(groovyObjectClass.getResource("/" + groovyObjectClass.getName().replace('.', '/') + ".class")); - if (groovyObjectClassPath == null) { - CodeSource codeSource = groovyObjectClass.getProtectionDomain().getCodeSource(); - if (codeSource != null) { - groovyObjectClassPath = String.valueOf(codeSource.getLocation()); - } - } - return groovyObjectClassPath; + public Class getClass(final String className) throws ClassNotFoundException { + return Class.forName(className, true, classLoader); } /** - * Logs the version of groovy used by this mojo. + * Returns the classloader used for loading classes. * - * @param goal The goal to mention in the log statement showing Groovy version + * @return the classloader used for loading classes */ - public void logGroovyVersion(final String goal) { - if (log.isInfoEnabled()) { - log.info("Using Groovy " + getGroovyVersionString() + " to perform " + goal + "."); - } + public ClassLoader getClassLoader() { + return classLoader; } /** * Creates a new ClassLoader with the specified classpath. * - * @param classpath the classpath (a list of file path Strings) to include in the new loader + * @param classpath the classpath (a list of file path Strings) to include in the new loader + * @param classLoader the ClassLoader to use as the parent for the new CLassLoader * @return the new ClassLoader * @throws MalformedURLException when a classpath element provides a malformed URL */ - public ClassLoader createNewClassLoader(final List classpath) throws MalformedURLException { + protected ClassLoader createNewClassLoader(final List classpath, final ClassLoader classLoader) throws MalformedURLException { List urlsList = new ArrayList<>(); for (Object classPathObject : classpath) { String path = (String) classPathObject; urlsList.add(new File(path).toURI().toURL()); } URL[] urlsArray = urlsList.toArray(new URL[0]); - return new URLClassLoader(urlsArray, ClassLoader.getSystemClassLoader()); + return new URLClassLoader(urlsArray, classLoader); } /** - * Gets a class for the given class name. + * Returns the filename of the Groovy jar on the classpath. * - * @param className the class name to retrieve the class for - * @return the class for the given class name - * @throws ClassNotFoundException when a class for the specified class name cannot be found + * @return the Groovy jar filename */ - public Class getClass(final String className) throws ClassNotFoundException { - return Class.forName(className, true, classLoader); + protected String getGroovyJar() { + try { + String groovyObjectClassPath = getJarPath(); + String groovyJar = null; + if (groovyObjectClassPath != null) { + groovyJar = groovyObjectClassPath.replaceAll("!.+", ""); + groovyJar = groovyJar.substring(groovyJar.lastIndexOf("/") + 1); + } + + return groovyJar; + } catch (ClassNotFoundException e) { + log.error("Unable to determine Groovy version. Is Groovy declared as a dependency?"); + return null; + } } /** - * Returns the classloader used for loading classes. + * Returns the path of the Groovy jar on the classpath. * - * @return the classloader used for loading classes + * @return the path of the Groovy jar + * @throws ClassNotFoundException when Groovy couldn't be found on the classpath */ - public ClassLoader getClassLoader() { - return classLoader; + protected String getJarPath() throws ClassNotFoundException { + Class groovyObjectClass = getClass("groovy.lang.GroovyObject"); + String groovyObjectClassPath = String.valueOf(groovyObjectClass.getResource("/" + groovyObjectClass.getName().replace('.', '/') + ".class")); + if (groovyObjectClassPath == null) { + CodeSource codeSource = groovyObjectClass.getProtectionDomain().getCodeSource(); + if (codeSource != null) { + groovyObjectClassPath = String.valueOf(codeSource.getLocation()); + } + } + return groovyObjectClassPath; } - } diff --git a/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfiguratorTest.java b/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfiguratorTest.java deleted file mode 100644 index cf3fbeaac..000000000 --- a/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectCompileDependenciesComponentConfiguratorTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.codehaus.gmavenplus.plexus; - -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; -import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.junit.Before; -import org.junit.Test; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -import java.lang.reflect.Field; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; - - -/** - * Unit tests for the IncludeProjectCompileDependenciesComponentConfigurator class. - * - * @author Keegan Witt - */ -public class IncludeProjectCompileDependenciesComponentConfiguratorTest { - @Spy - private IncludeProjectCompileDependenciesComponentConfigurator configurator = new IncludeProjectCompileDependenciesComponentConfigurator(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testConfigureComponent_1() throws Exception { - ConverterLookup converterLookup = mock(ConverterLookup.class); - Field modifiersField = configurator.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("converterLookup"); - modifiersField.setAccessible(true); - modifiersField.set(configurator, converterLookup); - Object component = mock(Object.class); - PlexusConfiguration configuration = mock(PlexusConfiguration.class); - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm = mock(org.codehaus.plexus.classworlds.realm.ClassRealm.class); - ConfigurationListener listener = mock(ConfigurationListener.class); - doReturn(true).when(configurator).shouldIncludeProjectDependencies(any(PlexusConfiguration.class)); - doNothing().when(configurator).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.plexus.classworlds.realm.ClassRealm.class)); - - configurator.configureComponent(component, configuration, expressionEvaluator, containerRealm, listener); - - verify(configurator, atLeastOnce()).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.plexus.classworlds.realm.ClassRealm.class)); - verify(converterLookup, atLeastOnce()).registerConverter(any(ClassRealmConverter.class)); - } - - @Test - @SuppressWarnings("deprecation") - public void testConfigureComponent_2() throws Exception { - ConverterLookup converterLookup = mock(ConverterLookup.class); - Field modifiersField = configurator.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("converterLookup"); - modifiersField.setAccessible(true); - modifiersField.set(configurator, converterLookup); - Object component = mock(Object.class); - PlexusConfiguration configuration = mock(PlexusConfiguration.class); - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - org.codehaus.classworlds.ClassRealm containerRealm = mock(org.codehaus.classworlds.ClassRealm.class); - ConfigurationListener listener = mock(ConfigurationListener.class); - doReturn(true).when(configurator).shouldIncludeProjectDependencies(any(PlexusConfiguration.class)); - doNothing().when(configurator).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.classworlds.ClassRealm.class)); - - configurator.configureComponent(component, configuration, expressionEvaluator, containerRealm, listener); - - verify(configurator, atLeastOnce()).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.classworlds.ClassRealm.class)); - verify(converterLookup, atLeastOnce()).registerConverter(any(ClassRealmConverter.class)); - } - - @Test - @SuppressWarnings("deprecation") - public void testAddProjectCompileDependenciesToClassRealm() throws Exception { - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - List classpathElements = singletonList("CLASSPATH_ELEMENT"); - doReturn(classpathElements).when(expressionEvaluator).evaluate(anyString()); - org.codehaus.classworlds.ClassRealm containerRealm = mock(org.codehaus.classworlds.ClassRealm.class); - configurator.addDependenciesToClassRealm(expressionEvaluator, IncludeProjectCompileDependenciesComponentConfigurator.Classpath.COMPILE, containerRealm); - verify(expressionEvaluator, times(1)).evaluate(anyString()); - verify(containerRealm, times(1)).addConstituent(any(URL.class)); - } - - @Test - public void testAddProjectCompileDependenciesToPlexusClassRealm() throws Exception { - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - List classpathElements = singletonList("CLASSPATH_ELEMENT"); - doReturn(classpathElements).when(expressionEvaluator).evaluate(anyString()); - org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm = mock(org.codehaus.plexus.classworlds.realm.ClassRealm.class); - configurator.addDependenciesToClassRealm(expressionEvaluator, IncludeProjectCompileDependenciesComponentConfigurator.Classpath.COMPILE, containerRealm); - verify(expressionEvaluator, times(1)).evaluate(anyString()); - verify(containerRealm, times(1)).addURL(any(URL.class)); - } - - @Test - public void testBuildURLs() throws Exception { - List elements = new ArrayList<>(); - elements.add("ELEMENT_1"); - URL[] urls = configurator.buildURLs(elements); - assertEquals(elements.size(), urls.length); - } - -} diff --git a/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfiguratorTest.java b/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfiguratorTest.java deleted file mode 100644 index e2aba2df5..000000000 --- a/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectRuntimeDependenciesComponentConfiguratorTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.codehaus.gmavenplus.plexus; - -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; -import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.junit.Before; -import org.junit.Test; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -import java.lang.reflect.Field; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; - - -/** - * Unit tests for the IncludeProjectRuntimeDependenciesComponentConfigurator class. - * - * @author Keegan Witt - */ -public class IncludeProjectRuntimeDependenciesComponentConfiguratorTest { - @Spy - private IncludeProjectRuntimeDependenciesComponentConfigurator configurator = new IncludeProjectRuntimeDependenciesComponentConfigurator(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testConfigureComponent_1() throws Exception { - ConverterLookup converterLookup = mock(ConverterLookup.class); - Field modifiersField = configurator.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("converterLookup"); - modifiersField.setAccessible(true); - modifiersField.set(configurator, converterLookup); - Object component = mock(Object.class); - PlexusConfiguration configuration = mock(PlexusConfiguration.class); - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm = mock(org.codehaus.plexus.classworlds.realm.ClassRealm.class); - ConfigurationListener listener = mock(ConfigurationListener.class); - doReturn(true).when(configurator).shouldIncludeProjectDependencies(any(PlexusConfiguration.class)); - doNothing().when(configurator).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.plexus.classworlds.realm.ClassRealm.class)); - - configurator.configureComponent(component, configuration, expressionEvaluator, containerRealm, listener); - - verify(configurator, atLeastOnce()).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.plexus.classworlds.realm.ClassRealm.class)); - verify(converterLookup, atLeastOnce()).registerConverter(any(ClassRealmConverter.class)); - } - - @Test - @SuppressWarnings("deprecation") - public void testConfigureComponent_2() throws Exception { - ConverterLookup converterLookup = mock(ConverterLookup.class); - Field modifiersField = configurator.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("converterLookup"); - modifiersField.setAccessible(true); - modifiersField.set(configurator, converterLookup); - Object component = mock(Object.class); - PlexusConfiguration configuration = mock(PlexusConfiguration.class); - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - org.codehaus.classworlds.ClassRealm containerRealm = mock(org.codehaus.classworlds.ClassRealm.class); - ConfigurationListener listener = mock(ConfigurationListener.class); - doReturn(true).when(configurator).shouldIncludeProjectDependencies(any(PlexusConfiguration.class)); - doNothing().when(configurator).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.classworlds.ClassRealm.class)); - - configurator.configureComponent(component, configuration, expressionEvaluator, containerRealm, listener); - - verify(configurator, atLeastOnce()).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.classworlds.ClassRealm.class)); - verify(converterLookup, atLeastOnce()).registerConverter(any(ClassRealmConverter.class)); - } - - @Test - @SuppressWarnings("deprecation") - public void testAddProjectRuntimeDependenciesToClassRealm() throws Exception { - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - List classpathElements = singletonList("CLASSPATH_ELEMENT"); - doReturn(classpathElements).when(expressionEvaluator).evaluate(anyString()); - org.codehaus.classworlds.ClassRealm containerRealm = mock(org.codehaus.classworlds.ClassRealm.class); - configurator.addDependenciesToClassRealm(expressionEvaluator, IncludeProjectRuntimeDependenciesComponentConfigurator.Classpath.RUNTIME, containerRealm); - verify(expressionEvaluator, times(1)).evaluate(anyString()); - verify(containerRealm, times(1)).addConstituent(any(URL.class)); - } - - @Test - public void testAddProjectRuntimeDependenciesToPlexusClassRealm() throws Exception { - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - List classpathElements = singletonList("CLASSPATH_ELEMENT"); - doReturn(classpathElements).when(expressionEvaluator).evaluate(anyString()); - org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm = mock(org.codehaus.plexus.classworlds.realm.ClassRealm.class); - configurator.addDependenciesToClassRealm(expressionEvaluator, IncludeProjectRuntimeDependenciesComponentConfigurator.Classpath.RUNTIME, containerRealm); - verify(expressionEvaluator, times(1)).evaluate(anyString()); - verify(containerRealm, times(1)).addURL(any(URL.class)); - } - - @Test - public void testBuildURLs() throws Exception { - List elements = new ArrayList<>(); - elements.add("ELEMENT_1"); - URL[] urls = configurator.buildURLs(elements); - assertEquals(elements.size(), urls.length); - } - -} diff --git a/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfiguratorTest.java b/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfiguratorTest.java deleted file mode 100644 index 13bd72b09..000000000 --- a/src/test/java/org/codehaus/gmavenplus/plexus/IncludeProjectTestDependenciesComponentConfiguratorTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.codehaus.gmavenplus.plexus; - -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; -import org.codehaus.plexus.component.configurator.converters.special.ClassRealmConverter; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.junit.Before; -import org.junit.Test; -import org.mockito.MockitoAnnotations; -import org.mockito.Spy; - -import java.lang.reflect.Field; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; - - -/** - * Unit tests for the IncludeProjectTestDependenciesComponentConfigurator class. - * - * @author Keegan Witt - */ -public class IncludeProjectTestDependenciesComponentConfiguratorTest { - @Spy - private IncludeProjectTestDependenciesComponentConfigurator configurator = new IncludeProjectTestDependenciesComponentConfigurator(); - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testConfigureComponent_1() throws Exception { - ConverterLookup converterLookup = mock(ConverterLookup.class); - Field modifiersField = configurator.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("converterLookup"); - modifiersField.setAccessible(true); - modifiersField.set(configurator, converterLookup); - Object component = mock(Object.class); - PlexusConfiguration configuration = mock(PlexusConfiguration.class); - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm = mock(org.codehaus.plexus.classworlds.realm.ClassRealm.class); - ConfigurationListener listener = mock(ConfigurationListener.class); - doReturn(true).when(configurator).shouldIncludeProjectDependencies(any(PlexusConfiguration.class)); - doNothing().when(configurator).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.plexus.classworlds.realm.ClassRealm.class)); - - configurator.configureComponent(component, configuration, expressionEvaluator, containerRealm, listener); - - verify(configurator, atLeastOnce()).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.plexus.classworlds.realm.ClassRealm.class)); - verify(converterLookup, atLeastOnce()).registerConverter(any(ClassRealmConverter.class)); - } - - @Test - @SuppressWarnings("deprecation") - public void testConfigureComponent_2() throws Exception { - ConverterLookup converterLookup = mock(ConverterLookup.class); - Field modifiersField = configurator.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredField("converterLookup"); - modifiersField.setAccessible(true); - modifiersField.set(configurator, converterLookup); - Object component = mock(Object.class); - PlexusConfiguration configuration = mock(PlexusConfiguration.class); - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - org.codehaus.classworlds.ClassRealm containerRealm = mock(org.codehaus.classworlds.ClassRealm.class); - ConfigurationListener listener = mock(ConfigurationListener.class); - doReturn(true).when(configurator).shouldIncludeProjectDependencies(any(PlexusConfiguration.class)); - doNothing().when(configurator).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.classworlds.ClassRealm.class)); - - configurator.configureComponent(component, configuration, expressionEvaluator, containerRealm, listener); - - verify(configurator, atLeastOnce()).addDependenciesToClassRealm(any(ExpressionEvaluator.class), any(AbstractIncludeProjectDependenciesComponentConfigurator.Classpath.class), any(org.codehaus.classworlds.ClassRealm.class)); - verify(converterLookup, atLeastOnce()).registerConverter(any(ClassRealmConverter.class)); - } - - @Test - @SuppressWarnings("deprecation") - public void testAddProjectTestDependenciesToClassRealm() throws Exception { - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - List classpathElements = singletonList("CLASSPATH_ELEMENT"); - doReturn(classpathElements).when(expressionEvaluator).evaluate(anyString()); - org.codehaus.classworlds.ClassRealm containerRealm = mock(org.codehaus.classworlds.ClassRealm.class); - configurator.addDependenciesToClassRealm(expressionEvaluator, IncludeProjectTestDependenciesComponentConfigurator.Classpath.TEST, containerRealm); - verify(expressionEvaluator, times(1)).evaluate(anyString()); - verify(containerRealm, times(1)).addConstituent(any(URL.class)); - } - - @Test - public void testAddProjectTestDependenciesToPlexusClassRealm() throws Exception { - ExpressionEvaluator expressionEvaluator = mock(ExpressionEvaluator.class); - List classpathElements = singletonList("CLASSPATH_ELEMENT"); - doReturn(classpathElements).when(expressionEvaluator).evaluate(anyString()); - org.codehaus.plexus.classworlds.realm.ClassRealm containerRealm = mock(org.codehaus.plexus.classworlds.realm.ClassRealm.class); - configurator.addDependenciesToClassRealm(expressionEvaluator, IncludeProjectTestDependenciesComponentConfigurator.Classpath.TEST, containerRealm); - verify(expressionEvaluator, times(1)).evaluate(anyString()); - verify(containerRealm, times(1)).addURL(any(URL.class)); - } - - @Test - public void testBuildURLs() throws Exception { - List elements = new ArrayList<>(); - elements.add("ELEMENT_1"); - URL[] urls = configurator.buildURLs(elements); - assertEquals(elements.size(), urls.length); - } - -} diff --git a/src/test/java/org/codehaus/gmavenplus/util/ClassWranglerTest.java b/src/test/java/org/codehaus/gmavenplus/util/ClassWranglerTest.java index bc996a21b..9663fc928 100644 --- a/src/test/java/org/codehaus/gmavenplus/util/ClassWranglerTest.java +++ b/src/test/java/org/codehaus/gmavenplus/util/ClassWranglerTest.java @@ -20,6 +20,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; +import static java.util.Collections.emptyList; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -33,7 +34,7 @@ public class ClassWranglerTest { @Test public void testGetGroovyJar() throws Exception { - ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class))); + ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class))); doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString()); doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath(); assertEquals("groovy-all-1.5.0.jar", classWrangler.getGroovyJar()); @@ -41,7 +42,7 @@ public void testGetGroovyJar() throws Exception { @Test public void testGetGroovyVersionStringFromGroovySystemThenFromInvokerHelper() throws Exception { - ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class))); + ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class))); doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to try other methods.")) .when(classWrangler).getClass(anyString()); doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath(); @@ -54,7 +55,7 @@ public void testGetGroovyVersionStringFromGroovySystemThenFromInvokerHelper() th @Test public void testGetGroovyVersionStringFromJar() throws Exception { - ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class))); + ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class))); doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString()); doReturn("some/path/groovy-all-1.5.0.jar").when(classWrangler).getJarPath(); assertEquals("1.5.0", classWrangler.getGroovyVersionString()); @@ -62,7 +63,7 @@ public void testGetGroovyVersionStringFromJar() throws Exception { @Test public void testGetGroovyVersionWithIndyFromJar() throws Exception { - ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class))); + ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class))); doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString()); doReturn("some/path/groovy-all-2.4.0-indy.jar").when(classWrangler).getJarPath(); assertEquals("2.4.0", classWrangler.getGroovyVersion().toString()); @@ -70,7 +71,7 @@ public void testGetGroovyVersionWithIndyFromJar() throws Exception { @Test public void testGetGroovyVersionWithGrooidFromJar() throws Exception { - ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class))); + ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class))); doThrow(new ClassNotFoundException("Throwing exception to force GMavenPlus to get version from jar.")).when(classWrangler).getClass(anyString()); doReturn("some/path/groovy-all-2.4.0-grooid.jar").when(classWrangler).getJarPath(); assertEquals("2.4.0", classWrangler.getGroovyVersion().toString()); @@ -78,14 +79,14 @@ public void testGetGroovyVersionWithGrooidFromJar() throws Exception { @Test public void testIsGroovyIndyTrue() throws Exception { - ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class))); + ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class))); doReturn(null).when(classWrangler).getClass(anyString()); // make it appear Groovy is indy assertTrue(classWrangler.isGroovyIndy()); } @Test public void testIsGroovyIndyFalse() throws Exception { - ClassWrangler classWrangler = spy(new ClassWrangler((ClassLoader) null, mock(Log.class))); + ClassWrangler classWrangler = spy(new ClassWrangler(emptyList(), null, mock(Log.class))); doThrow(new ClassNotFoundException("Throwing exception to make it appear Groovy is not indy.")).when(classWrangler).getClass(anyString()); assertFalse(classWrangler.isGroovyIndy()); }