Skip to content

Commit

Permalink
[ANT] De-duplicat SecurityManager support check and update remote.jar
Browse files Browse the repository at this point in the history
Also remove obsolete comments.

Follow-up on
#1662
  • Loading branch information
HannesWell committed Dec 17, 2024
1 parent a8960ab commit 7d2553d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -83,7 +83,7 @@
@SuppressWarnings("removal") // SecurityManager
public class InternalAntRunner {

private static final boolean IS_SECURITY_MANAGER_SUPPORTED = isSecurityManagerAllowed();
public static final boolean IS_SECURITY_MANAGER_SUPPORTED = isSecurityManagerAllowed();

private static boolean isSecurityManagerAllowed() {
String sm = System.getProperty("java.security.manager"); //$NON-NLS-1$
Expand Down Expand Up @@ -708,8 +708,6 @@ private void run(List<String> argList) {
printArguments(getCurrentProject());
}
if (IS_SECURITY_MANAGER_SUPPORTED) {
// TODO: call SecurityManagerUtil.isSecurityManagerAllowed() once it's more fine-grained,
// i.e. once https://github.com/apache/ant/pull/216 is available.
System.setSecurityManager(new AntSecurityManager(originalSM, Thread.currentThread()));
}
if (targets == null) {
Expand Down
Binary file modified ant/org.eclipse.ant.launching/lib/remote.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -49,7 +49,6 @@
import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskAdapter;
import org.apache.tools.ant.UnknownElement;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.eclipse.ant.core.AntCorePlugin;
import org.eclipse.ant.core.AntCorePreferences;
import org.eclipse.ant.core.AntSecurityException;
Expand All @@ -59,6 +58,7 @@
import org.eclipse.ant.internal.core.AntCoreUtil;
import org.eclipse.ant.internal.core.AntSecurityManager;
import org.eclipse.ant.internal.core.IAntCoreConstants;
import org.eclipse.ant.internal.core.ant.InternalAntRunner;
import org.eclipse.ant.internal.ui.AntUIPlugin;
import org.eclipse.ant.internal.ui.AntUtil;
import org.eclipse.ant.internal.ui.editor.DecayCodeCompletionDataStructuresThread;
Expand Down Expand Up @@ -90,17 +90,6 @@
@SuppressWarnings("removal") // SecurityManager
public class AntModel implements IAntModel {

private static final boolean IS_SECURITY_MANAGER_SUPPORTED = isSecurityManagerAllowed();

private static boolean isSecurityManagerAllowed() {
String sm = System.getProperty("java.security.manager"); //$NON-NLS-1$
if (sm == null) { // default is 'disallow' since 18 and was 'allow' before
return !JavaEnvUtils.isAtLeastJavaVersion("18"); //$NON-NLS-1$
}
// Value is either 'disallow' or 'allow' or specifies the SecurityManager class to set
return !"disallow".equals(sm); //$NON-NLS-1$
}

private static ClassLoader fgClassLoader;
private static int fgInstanceCount = 0;
private static Object loaderLock = new Object();
Expand Down Expand Up @@ -375,7 +364,9 @@ private void parseDocument(IDocument input) {
SecurityManager origSM = System.getSecurityManager();
processAntHome(true);
try {
if (IS_SECURITY_MANAGER_SUPPORTED) {
@SuppressWarnings("restriction")
boolean isSecurityManagerSupported = InternalAntRunner.IS_SECURITY_MANAGER_SUPPORTED;
if (isSecurityManagerSupported) {
// set a security manager to disallow system exit and system property setting
System.setSecurityManager(new AntSecurityManager(origSM, Thread.currentThread(), false));
}
Expand Down

0 comments on commit 7d2553d

Please sign in to comment.