diff --git a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java index 78a78d5f512..9f24bc20c46 100644 --- a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java +++ b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java @@ -52,6 +52,7 @@ import org.apache.tools.ant.Target; import org.apache.tools.ant.TaskAdapter; import org.apache.tools.ant.XmlLogger; +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; @@ -82,6 +83,17 @@ @SuppressWarnings("removal") // SecurityManager public class InternalAntRunner { + 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 IProgressMonitor monitor; private ArrayList buildListeners; private String buildFileLocation; @@ -695,12 +707,11 @@ private void run(List argList) { if (extraArguments != null) { printArguments(getCurrentProject()); } - try { + 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())); } - catch (UnsupportedOperationException ex) { - AntCorePlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, 0, InternalAntMessages.InternalAntRunner_SecurityManagerError, ex)); - } if (targets == null) { targets = new Vector<>(1); } @@ -1432,9 +1443,7 @@ protected void loadPropertyFiles() { } try { List allProperties = AntCoreUtil.loadPropertyFiles(propertyFiles, currentProject.getUserProperty("basedir"), getBuildFileLocation()); //$NON-NLS-1$ - Iterator iter = allProperties.iterator(); - while (iter.hasNext()) { - Properties props = iter.next(); + for (Properties props : allProperties) { Enumeration propertyNames = props.propertyNames(); while (propertyNames.hasMoreElements()) { String name = (String) propertyNames.nextElement(); diff --git a/ant/org.eclipse.ant.tests.core/test plugin/org/eclipse/ant/tests/core/testplugin/AntTestChecker.java b/ant/org.eclipse.ant.tests.core/test plugin/org/eclipse/ant/tests/core/testplugin/AntTestChecker.java index 1ede0d34e1c..beff191668a 100644 --- a/ant/org.eclipse.ant.tests.core/test plugin/org/eclipse/ant/tests/core/testplugin/AntTestChecker.java +++ b/ant/org.eclipse.ant.tests.core/test plugin/org/eclipse/ant/tests/core/testplugin/AntTestChecker.java @@ -14,6 +14,7 @@ package org.eclipse.ant.tests.core.testplugin; import java.util.ArrayList; +import java.util.Collections; import java.util.Hashtable; import java.util.List; @@ -219,7 +220,7 @@ public String getUserProperty(String name) { } public List getMessages() { - return messages; + return Collections.unmodifiableList(messages); } public List getListeners() {