+ * Implementation notice: For Java 21 and above, + * the implementation must be a no-op and issue a warning. + * + */ +public interface SecurityManagerSetter { + + /** + * For Java until 20, this method should set the given Security manager if property {@code allowSystemExits} is set. + */ + void setNoExitSecurityManager(); + + void revertToPreviousSecurityManager(); +} diff --git a/src/main/java21/org/codehaus/gmavenplus/util/DefaultSecurityManagerSetter.java b/src/main/java21/org/codehaus/gmavenplus/util/DefaultSecurityManagerSetter.java new file mode 100644 index 00000000..57f230bb --- /dev/null +++ b/src/main/java21/org/codehaus/gmavenplus/util/DefaultSecurityManagerSetter.java @@ -0,0 +1,30 @@ +package org.codehaus.gmavenplus.util; + +import java.util.concurrent.atomic.AtomicReference; +import org.apache.maven.plugin.logging.Log; + +public class DefaultSecurityManagerSetter extends AbstractSecurityManagerSetter { + + public DefaultSecurityManagerSetter(Log log, final boolean allowSystemExits) { + super(log, allowSystemExits); + } + + @Override + public void setNoExitSecurityManager() { + if (this.getAllowSystemExits()) { + return; + } + + getLog().warn("Setting a security manager is not supported starting with Java 21."); + } + + @Override + public void revertToPreviousSecurityManager() { + if (this.getAllowSystemExits()) { + return; + } + + getLog().warn("Setting a security manager is not supported starting with Java 21."); + + } +}