diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java index 5b40f2f4..9265ced2 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/CompileTestsMojo.java @@ -65,29 +65,30 @@ public class CompileTestsMojo extends AbstractCompileMojo { */ @Override public void execute() throws MojoExecutionException { - if (!skipTests) { + if (skipTests) { + getLog().info("Compilation of tests is skipped."); + return; + } + + try { try { - try { - getLog().debug("Project test classpath:\n" + project.getTestClasspathElements()); - } catch (DependencyResolutionRequiredException e) { - getLog().debug("Unable to log project test classpath"); - } - doCompile(getTestFiles(testSources, false), project.getTestClasspathElements(), testOutputDirectory); - } catch (ClassNotFoundException e) { - throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project?", e); - } catch (InvocationTargetException e) { - throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); - } catch (InstantiationException e) { - throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); - } catch (IllegalAccessException e) { - throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); + getLog().debug("Project test classpath:\n" + project.getTestClasspathElements()); } catch (DependencyResolutionRequiredException e) { - throw new MojoExecutionException("Test dependencies weren't resolved.", e); - } catch (MalformedURLException e) { - throw new MojoExecutionException("Unable to add project test dependencies to classpath.", e); + getLog().debug("Unable to log project test classpath"); } - } else { - getLog().info("Compilation of tests is skipped."); + doCompile(getTestFiles(testSources, false), project.getTestClasspathElements(), testOutputDirectory); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project?", e); + } catch (InvocationTargetException e) { + throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); + } catch (InstantiationException e) { + throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); + } catch (IllegalAccessException e) { + throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); + } catch (DependencyResolutionRequiredException e) { + throw new MojoExecutionException("Test dependencies weren't resolved.", e); + } catch (MalformedURLException e) { + throw new MojoExecutionException("Unable to add project test dependencies to classpath.", e); } } diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java index eb3a6eb8..03b74ff0 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java @@ -85,64 +85,65 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().debug("Unable to log project test classpath"); } - if (groovyVersionSupportsAction()) { - final SecurityManager defaultSecurityManager = System.getSecurityManager(); - try { - if (!allowSystemExits) { - getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal. Therefore `allowSystemExits` is also deprecated for removal."); - try { - System.setSecurityManager(new NoExitSecurityManager()); - } catch (UnsupportedOperationException e) { - getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); - } - } + if (!groovyVersionSupportsAction()) { + getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support running a console. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping console startup."); + return; + } - // get classes we need with reflection - Class consoleClass; + final SecurityManager defaultSecurityManager = System.getSecurityManager(); + try { + if (!allowSystemExits) { + getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal. Therefore `allowSystemExits` is also deprecated for removal."); try { - consoleClass = classWrangler.getClass("groovy.console.ui.Console"); - } catch (ClassNotFoundException e) { - consoleClass = classWrangler.getClass("groovy.ui.Console"); + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); } - Class bindingClass = classWrangler.getClass("groovy.lang.Binding"); + } + + // get classes we need with reflection + Class consoleClass; + try { + consoleClass = classWrangler.getClass("groovy.console.ui.Console"); + } catch (ClassNotFoundException e) { + consoleClass = classWrangler.getClass("groovy.ui.Console"); + } + Class bindingClass = classWrangler.getClass("groovy.lang.Binding"); - // create console to run - Object console = setupConsole(consoleClass, bindingClass); + // create console to run + Object console = setupConsole(consoleClass, bindingClass); - // run the console - invokeMethod(findMethod(consoleClass, "run"), console); + // run the console + invokeMethod(findMethod(consoleClass, "run"), console); - // TODO: for some reason instantiating AntBuilder before calling run() causes its stdout and stderr streams to not be captured by the Console - bindAntBuilder(consoleClass, bindingClass, console); + // TODO: for some reason instantiating AntBuilder before calling run() causes its stdout and stderr streams to not be captured by the Console + bindAntBuilder(consoleClass, bindingClass, console); - // open script file - loadScript(consoleClass, console); + // open script file + loadScript(consoleClass, console); - // wait for console to be closed - waitForConsoleClose(); - } catch (ClassNotFoundException e) { - throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project or the plugin?", e); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof NoClassDefFoundError && "org/apache/ivy/core/report/ResolveReport".equals(e.getCause().getMessage())) { - throw new MojoExecutionException("Groovy 1.7.6 and 1.7.7 have a dependency on Ivy to run the console. Either change your Groovy version or add Ivy as a project or plugin dependency.", e); - } else { - throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); - } - } catch (IllegalAccessException e) { - throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); - } catch (InstantiationException e) { - throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); - } finally { - if (!allowSystemExits) { - try { - System.setSecurityManager(defaultSecurityManager); - } catch (UnsupportedOperationException e) { - getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); - } + // wait for console to be closed + waitForConsoleClose(); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project or the plugin?", e); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof NoClassDefFoundError && "org/apache/ivy/core/report/ResolveReport".equals(e.getCause().getMessage())) { + throw new MojoExecutionException("Groovy 1.7.6 and 1.7.7 have a dependency on Ivy to run the console. Either change your Groovy version or add Ivy as a project or plugin dependency.", e); + } else { + throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); + } + } catch (IllegalAccessException e) { + throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); + } catch (InstantiationException e) { + throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); + } finally { + if (!allowSystemExits) { + try { + System.setSecurityManager(defaultSecurityManager); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); } } - } else { - getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support running a console. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping console startup."); } } diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java index 2f3aae0a..7365bd71 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java @@ -136,45 +136,46 @@ protected synchronized void doExecute() throws MojoExecutionException { getLog().debug("Unable to log project test classpath"); } - if (groovyVersionSupportsAction()) { - final SecurityManager defaultSecurityManager = System.getSecurityManager(); - try { - if (!allowSystemExits) { - getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal. Therefore `allowSystemExits` is also deprecated for removal."); - try { - System.setSecurityManager(new NoExitSecurityManager()); - } catch (UnsupportedOperationException e) { - getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); - } + if (!groovyVersionSupportsAction()) { + getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support script execution. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping script execution."); + return; + } + + final SecurityManager defaultSecurityManager = System.getSecurityManager(); + try { + if (!allowSystemExits) { + getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal. Therefore `allowSystemExits` is also deprecated for removal."); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); } + } - // get classes we need with reflection - Class groovyShellClass = classWrangler.getClass("groovy.lang.GroovyShell"); + // get classes we need with reflection + Class groovyShellClass = classWrangler.getClass("groovy.lang.GroovyShell"); - // create a GroovyShell to run scripts in - Object shell = setupShell(groovyShellClass); + // create a GroovyShell to run scripts in + Object shell = setupShell(groovyShellClass); - // run the scripts - executeScripts(groovyShellClass, shell); - } catch (ClassNotFoundException e) { - throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project or the plugin?", e); - } catch (InvocationTargetException e) { - throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); - } catch (InstantiationException e) { - throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); - } catch (IllegalAccessException e) { - throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); - } finally { - if (!allowSystemExits) { - try { - System.setSecurityManager(defaultSecurityManager); - } catch (UnsupportedOperationException e) { - getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); - } + // run the scripts + executeScripts(groovyShellClass, shell); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project or the plugin?", e); + } catch (InvocationTargetException e) { + throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); + } catch (InstantiationException e) { + throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); + } catch (IllegalAccessException e) { + throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); + } finally { + if (!allowSystemExits) { + try { + System.setSecurityManager(defaultSecurityManager); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); } } - } else { - getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support script execution. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping script execution."); } } diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java index 5a7c2d93..abf2f235 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/GenerateTestStubsMojo.java @@ -65,36 +65,37 @@ public class GenerateTestStubsMojo extends AbstractGenerateStubsMojo { */ @Override public void execute() throws MojoExecutionException { - if (!skipTests) { - minGroovyVersion = GROOVY_1_8_2; - try { - try { - getLog().debug("Project test classpath:\n" + project.getTestClasspathElements()); - } catch (DependencyResolutionRequiredException e) { - getLog().debug("Unable to log project test classpath"); - } - - doStubGeneration(getTestFiles(testSources, false), project.getTestClasspathElements(), testStubsOutputDirectory); - logGeneratedStubs(testStubsOutputDirectory); - resetStubModifiedDates(getStubs(testStubsOutputDirectory)); + if (skipTests) { + getLog().info("Generation of test stubs is skipped."); + return; + } - // add stubs to project source so the Maven Compiler Plugin can find them - project.addTestCompileSourceRoot(testStubsOutputDirectory.getAbsolutePath()); - } catch (ClassNotFoundException e) { - throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project?", e); - } catch (InvocationTargetException e) { - throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); - } catch (InstantiationException e) { - throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); - } catch (IllegalAccessException e) { - throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); + minGroovyVersion = GROOVY_1_8_2; + try { + try { + getLog().debug("Project test classpath:\n" + project.getTestClasspathElements()); } catch (DependencyResolutionRequiredException e) { - throw new MojoExecutionException("Test dependencies weren't resolved.", e); - } catch (MalformedURLException e) { - throw new MojoExecutionException("Unable to add project test dependencies to classpath.", e); + getLog().debug("Unable to log project test classpath"); } - } else { - getLog().info("Generation of test stubs is skipped."); + + doStubGeneration(getTestFiles(testSources, false), project.getTestClasspathElements(), testStubsOutputDirectory); + logGeneratedStubs(testStubsOutputDirectory); + resetStubModifiedDates(getStubs(testStubsOutputDirectory)); + + // add stubs to project source so the Maven Compiler Plugin can find them + project.addTestCompileSourceRoot(testStubsOutputDirectory.getAbsolutePath()); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project?", e); + } catch (InvocationTargetException e) { + throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); + } catch (InstantiationException e) { + throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); + } catch (IllegalAccessException e) { + throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); + } catch (DependencyResolutionRequiredException e) { + throw new MojoExecutionException("Test dependencies weren't resolved.", e); + } catch (MalformedURLException e) { + throw new MojoExecutionException("Unable to add project test dependencies to classpath.", e); } } diff --git a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java index ec426dcf..67a3e672 100644 --- a/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java +++ b/src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java @@ -90,53 +90,54 @@ public void execute() throws MojoExecutionException { getLog().debug("Unable to log project test classpath"); } - if (groovyVersionSupportsAction()) { - final SecurityManager defaultSecurityManager = System.getSecurityManager(); - try { - if (!allowSystemExits) { - getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal. Therefore `allowSystemExits` is also deprecated for removal."); - try { - System.setSecurityManager(new NoExitSecurityManager()); - } catch (UnsupportedOperationException e) { - getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); - } - } + if (!groovyVersionSupportsAction()) { + getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support running a shell. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping shell startup."); + return; + } - // get classes we need with reflection - Class shellClass = classWrangler.getClass(groovyAtLeast(GROOVY_4_0_0_ALPHA1) ? "org.apache.groovy.groovysh.Groovysh" : "org.codehaus.groovy.tools.shell.Groovysh"); - Class bindingClass = classWrangler.getClass("groovy.lang.Binding"); - Class ioClass = classWrangler.getClass("org.codehaus.groovy.tools.shell.IO"); - Class verbosityClass = classWrangler.getClass("org.codehaus.groovy.tools.shell.IO$Verbosity"); - Class loggerClass = classWrangler.getClass("org.codehaus.groovy.tools.shell.util.Logger"); - - // create shell to run - Object shell = setupShell(shellClass, bindingClass, ioClass, verbosityClass, loggerClass); - - // run the shell - invokeMethod(findMethod(shellClass, "run", String.class), shell, (String) null); - } catch (ClassNotFoundException e) { - throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project or the plugin?", e); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof NoClassDefFoundError && e.getCause().getMessage() != null && e.getCause().getMessage().contains("jline")) { - throw new MojoExecutionException("Unable to get a JLine class from classpath. This might be because of a JLine version mismatch. If you are using Groovy < 2.2.0-beta-1, make sure you include JLine 1.0 as a runtime dependency in your project or the plugin.", e); - } else { - throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); + final SecurityManager defaultSecurityManager = System.getSecurityManager(); + try { + if (!allowSystemExits) { + getLog().warn("JEP 411 deprecated Security Manager in Java 17 for removal. Therefore `allowSystemExits` is also deprecated for removal."); + try { + System.setSecurityManager(new NoExitSecurityManager()); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); } - } catch (IllegalAccessException e) { - throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); - } catch (InstantiationException e) { - throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); - } finally { - if (!allowSystemExits) { - try { - System.setSecurityManager(defaultSecurityManager); - } catch (UnsupportedOperationException e) { - getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); - } + } + + // get classes we need with reflection + Class shellClass = classWrangler.getClass(groovyAtLeast(GROOVY_4_0_0_ALPHA1) ? "org.apache.groovy.groovysh.Groovysh" : "org.codehaus.groovy.tools.shell.Groovysh"); + Class bindingClass = classWrangler.getClass("groovy.lang.Binding"); + Class ioClass = classWrangler.getClass("org.codehaus.groovy.tools.shell.IO"); + Class verbosityClass = classWrangler.getClass("org.codehaus.groovy.tools.shell.IO$Verbosity"); + Class loggerClass = classWrangler.getClass("org.codehaus.groovy.tools.shell.util.Logger"); + + // create shell to run + Object shell = setupShell(shellClass, bindingClass, ioClass, verbosityClass, loggerClass); + + // run the shell + invokeMethod(findMethod(shellClass, "run", String.class), shell, (String) null); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException("Unable to get a Groovy class from classpath (" + e.getMessage() + "). Do you have Groovy as a compile dependency in your project or the plugin?", e); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof NoClassDefFoundError && e.getCause().getMessage() != null && e.getCause().getMessage().contains("jline")) { + throw new MojoExecutionException("Unable to get a JLine class from classpath. This might be because of a JLine version mismatch. If you are using Groovy < 2.2.0-beta-1, make sure you include JLine 1.0 as a runtime dependency in your project or the plugin.", e); + } else { + throw new MojoExecutionException("Error occurred while calling a method on a Groovy class from classpath.", e); + } + } catch (IllegalAccessException e) { + throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e); + } catch (InstantiationException e) { + throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e); + } finally { + if (!allowSystemExits) { + try { + System.setSecurityManager(defaultSecurityManager); + } catch (UnsupportedOperationException e) { + getLog().warn("Attempted to use Security Manager in a JVM where it's disabled by default. You might try `-Djava.security.manager=allow` to override this."); } } - } else { - getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support running a shell. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping shell startup."); } }