Browse Source

Pass -Djava.security.manager=allow while launching JUnit forked VM to allow JUnit triggered code to set security manager at runtime

master
Jaikiran Pai 3 years ago
parent
commit
13e6e30958
1 changed files with 10 additions and 0 deletions
  1. +10
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java

+ 10
- 0
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -64,6 +64,7 @@ import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Permissions;
import org.apache.tools.ant.types.PropertySet;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.LoaderUtils;
import org.apache.tools.ant.util.SplitClassLoader;
import org.apache.tools.ant.util.StringUtils;
@@ -1164,6 +1165,15 @@ public class JUnitTask extends Task {
} catch (final CloneNotSupportedException e) {
throw new BuildException("This shouldn't happen", e, getLocation());
}
// if Java 18, then we set -Djava.security.manager=allow so as to allow
// Ant code to internally set the security manager
if (JavaEnvUtils.isAtLeastJavaVersion("18")) {
log("Setting -Djava.security.manager=allow on forked JVM of JUnit task", Project.MSG_VERBOSE);
final Environment.Variable securityManagerSysProp = new Environment.Variable();
securityManagerSysProp.setKey("java.security.manager");
securityManagerSysProp.setValue("allow");
cmd.addSysproperty(securityManagerSysProp);
}
if (casesFile == null) {
cmd.createArgument().setValue(test.getName());
if (test.getMethods() != null) {


Loading…
Cancel
Save