From 216449d3634828730831078825529ed101e3bad3 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 15 Dec 2024 14:05:03 +0100 Subject: [PATCH 1/2] [ANT] Only attempt to set SecurityManager when it is supported This avoids trowing+catching an UnsupportedOperationException and additional (error) logs if setting a SecurityManager is disallowed. The latter breaks ant-tests that check the log output. Part of https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/2623 --- .../internal/core/ant/InternalAntRunner.java | 23 +++++++++++++------ .../tests/core/testplugin/AntTestChecker.java | 3 ++- 2 files changed, 18 insertions(+), 8 deletions(-) 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() { From fbfc5dc71c1fbcdb88926f36c20d4cc189e1370e Mon Sep 17 00:00:00 2001 From: Eclipse Platform Bot Date: Sun, 15 Dec 2024 14:01:49 +0000 Subject: [PATCH 2/2] Version bump(s) for 4.35 stream --- ant/org.eclipse.ant.core/META-INF/MANIFEST.MF | 2 +- ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF index e664ce24fbc..e4fcb869a71 100644 --- a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF +++ b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ant.core; singleton:=true -Bundle-Version: 3.7.500.qualifier +Bundle-Version: 3.7.600.qualifier Bundle-Activator: org.eclipse.ant.core.AntCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF index 8ba96be34d8..94398ae36fa 100644 --- a/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF +++ b/ant/org.eclipse.ant.tests.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ant.tests.core; singleton:=true -Bundle-Version: 3.7.500.qualifier +Bundle-Version: 3.7.600.qualifier Bundle-ClassPath: anttestscore.jar Bundle-Activator: org.eclipse.ant.tests.core.testplugin.AntTestPlugin Bundle-Vendor: %providerName