Skip to content

Commit

Permalink
Print a warning about SecurityManager being deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
keeganwitt committed Oct 22, 2023
1 parent 8e83de7 commit f480905
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
17 changes: 8 additions & 9 deletions src/main/java/org/codehaus/gmavenplus/mojo/ConsoleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().debug("Unable to log project test classpath");
}

if (groovyVersionSupportsAction()) {
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.");
}

if (!allowSystemExits) {
final SecurityManager sm = System.getSecurityManager();
try {
if (!allowSystemExits) {
System.setSecurityManager(new NoExitSecurityManager());
}
getLog().warn("This feature relies on Java's SecurityManager, which is deprecated for removal in Java 17. Java 18 and later will require `-Djava.security.manager=allow` be used to continue using this feature.");
System.setSecurityManager(new NoExitSecurityManager());

// get classes we need with reflection
Class<?> consoleClass;
Expand Down Expand Up @@ -128,12 +131,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
} catch (InstantiationException e) {
throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e);
} finally {
if (!allowSystemExits) {
System.setSecurityManager(sm);
}
System.setSecurityManager(sm);
}
} 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.");
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/codehaus/gmavenplus/mojo/ExecuteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ protected synchronized void doExecute() throws MojoExecutionException {
getLog().debug("Unable to log project test classpath");
}

if (groovyVersionSupportsAction()) {
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;
}

if (!allowSystemExits) {
final SecurityManager sm = System.getSecurityManager();
try {
if (!allowSystemExits) {
System.setSecurityManager(new NoExitSecurityManager());
}
getLog().warn("This feature relies on Java's SecurityManager, which is deprecated for removal in Java 17. Java 18 and later will require `-Djava.security.manager=allow` be used to continue using this feature.");
System.setSecurityManager(new NoExitSecurityManager());

// get classes we need with reflection
Class<?> groovyShellClass = classWrangler.getClass("groovy.lang.GroovyShell");
Expand All @@ -160,12 +164,8 @@ protected synchronized void doExecute() throws MojoExecutionException {
} catch (IllegalAccessException e) {
throw new MojoExecutionException("Unable to access a method on a Groovy class from classpath.", e);
} finally {
if (!allowSystemExits) {
System.setSecurityManager(sm);
}
System.setSecurityManager(sm);
}
} else {
getLog().error("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support script execution. The minimum version of Groovy required is " + minGroovyVersion + ". Skipping script execution.");
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/main/java/org/codehaus/gmavenplus/mojo/ShellMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ public void execute() throws MojoExecutionException {
getLog().debug("Unable to log project test classpath");
}

if (groovyVersionSupportsAction()) {
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.");
}

if (!allowSystemExits) {
final SecurityManager sm = System.getSecurityManager();
try {
if (!allowSystemExits) {
System.setSecurityManager(new NoExitSecurityManager());
}
getLog().warn("This feature relies on Java's SecurityManager, which is deprecated for removal in Java 17. Java 18 and later will require `-Djava.security.manager=allow` be used to continue using this feature.");
System.setSecurityManager(new NoExitSecurityManager());

// 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");
Expand All @@ -122,12 +125,8 @@ public void execute() throws MojoExecutionException {
} catch (InstantiationException e) {
throw new MojoExecutionException("Error occurred while instantiating a Groovy class from classpath.", e);
} finally {
if (!allowSystemExits) {
System.setSecurityManager(sm);
}
System.setSecurityManager(sm);
}
} 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.");
}
}

Expand Down

0 comments on commit f480905

Please sign in to comment.