Skip to content

Commit 7d2553d

Browse files
committed
[ANT] De-duplicat SecurityManager support check and update remote.jar
Also remove obsolete comments. Follow-up on #1662
1 parent a8960ab commit 7d2553d

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -83,7 +83,7 @@
8383
@SuppressWarnings("removal") // SecurityManager
8484
public class InternalAntRunner {
8585

86-
private static final boolean IS_SECURITY_MANAGER_SUPPORTED = isSecurityManagerAllowed();
86+
public static final boolean IS_SECURITY_MANAGER_SUPPORTED = isSecurityManagerAllowed();
8787

8888
private static boolean isSecurityManagerAllowed() {
8989
String sm = System.getProperty("java.security.manager"); //$NON-NLS-1$
@@ -708,8 +708,6 @@ private void run(List<String> argList) {
708708
printArguments(getCurrentProject());
709709
}
710710
if (IS_SECURITY_MANAGER_SUPPORTED) {
711-
// TODO: call SecurityManagerUtil.isSecurityManagerAllowed() once it's more fine-grained,
712-
// i.e. once https://github.com/apache/ant/pull/216 is available.
713711
System.setSecurityManager(new AntSecurityManager(originalSM, Thread.currentThread()));
714712
}
715713
if (targets == null) {
-890 Bytes
Binary file not shown.

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModel.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -49,7 +49,6 @@
4949
import org.apache.tools.ant.Task;
5050
import org.apache.tools.ant.TaskAdapter;
5151
import org.apache.tools.ant.UnknownElement;
52-
import org.apache.tools.ant.util.JavaEnvUtils;
5352
import org.eclipse.ant.core.AntCorePlugin;
5453
import org.eclipse.ant.core.AntCorePreferences;
5554
import org.eclipse.ant.core.AntSecurityException;
@@ -59,6 +58,7 @@
5958
import org.eclipse.ant.internal.core.AntCoreUtil;
6059
import org.eclipse.ant.internal.core.AntSecurityManager;
6160
import org.eclipse.ant.internal.core.IAntCoreConstants;
61+
import org.eclipse.ant.internal.core.ant.InternalAntRunner;
6262
import org.eclipse.ant.internal.ui.AntUIPlugin;
6363
import org.eclipse.ant.internal.ui.AntUtil;
6464
import org.eclipse.ant.internal.ui.editor.DecayCodeCompletionDataStructuresThread;
@@ -90,17 +90,6 @@
9090
@SuppressWarnings("removal") // SecurityManager
9191
public class AntModel implements IAntModel {
9292

93-
private static final boolean IS_SECURITY_MANAGER_SUPPORTED = isSecurityManagerAllowed();
94-
95-
private static boolean isSecurityManagerAllowed() {
96-
String sm = System.getProperty("java.security.manager"); //$NON-NLS-1$
97-
if (sm == null) { // default is 'disallow' since 18 and was 'allow' before
98-
return !JavaEnvUtils.isAtLeastJavaVersion("18"); //$NON-NLS-1$
99-
}
100-
// Value is either 'disallow' or 'allow' or specifies the SecurityManager class to set
101-
return !"disallow".equals(sm); //$NON-NLS-1$
102-
}
103-
10493
private static ClassLoader fgClassLoader;
10594
private static int fgInstanceCount = 0;
10695
private static Object loaderLock = new Object();
@@ -375,7 +364,9 @@ private void parseDocument(IDocument input) {
375364
SecurityManager origSM = System.getSecurityManager();
376365
processAntHome(true);
377366
try {
378-
if (IS_SECURITY_MANAGER_SUPPORTED) {
367+
@SuppressWarnings("restriction")
368+
boolean isSecurityManagerSupported = InternalAntRunner.IS_SECURITY_MANAGER_SUPPORTED;
369+
if (isSecurityManagerSupported) {
379370
// set a security manager to disallow system exit and system property setting
380371
System.setSecurityManager(new AntSecurityManager(origSM, Thread.currentThread(), false));
381372
}

0 commit comments

Comments
 (0)