|
52 | 52 | import org.apache.tools.ant.Target;
|
53 | 53 | import org.apache.tools.ant.TaskAdapter;
|
54 | 54 | import org.apache.tools.ant.XmlLogger;
|
| 55 | +import org.apache.tools.ant.util.JavaEnvUtils; |
55 | 56 | import org.eclipse.ant.core.AntCorePlugin;
|
56 | 57 | import org.eclipse.ant.core.AntCorePreferences;
|
57 | 58 | import org.eclipse.ant.core.AntSecurityException;
|
|
82 | 83 | @SuppressWarnings("removal") // SecurityManager
|
83 | 84 | public class InternalAntRunner {
|
84 | 85 |
|
| 86 | + private static final boolean IS_SECURITY_MANAGER_SUPPORTED = isSecurityManagerAllowed(); |
| 87 | + |
| 88 | + private static boolean isSecurityManagerAllowed() { |
| 89 | + String sm = System.getProperty("java.security.manager"); //$NON-NLS-1$ |
| 90 | + if (sm == null) { // default is 'disallow' since 18 and was 'allow' before |
| 91 | + return !JavaEnvUtils.isAtLeastJavaVersion("18"); //$NON-NLS-1$ |
| 92 | + } |
| 93 | + // Value is either 'disallow' or 'allow' or specifies the SecurityManager class to set |
| 94 | + return !"disallow".equals(sm); //$NON-NLS-1$ |
| 95 | + } |
| 96 | + |
85 | 97 | private IProgressMonitor monitor;
|
86 | 98 | private ArrayList<String> buildListeners;
|
87 | 99 | private String buildFileLocation;
|
@@ -695,12 +707,11 @@ private void run(List<String> argList) {
|
695 | 707 | if (extraArguments != null) {
|
696 | 708 | printArguments(getCurrentProject());
|
697 | 709 | }
|
698 |
| - try { |
| 710 | + 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. |
699 | 713 | System.setSecurityManager(new AntSecurityManager(originalSM, Thread.currentThread()));
|
700 | 714 | }
|
701 |
| - catch (UnsupportedOperationException ex) { |
702 |
| - AntCorePlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, AntCorePlugin.PI_ANTCORE, 0, InternalAntMessages.InternalAntRunner_SecurityManagerError, ex)); |
703 |
| - } |
704 | 715 | if (targets == null) {
|
705 | 716 | targets = new Vector<>(1);
|
706 | 717 | }
|
@@ -1432,9 +1443,7 @@ protected void loadPropertyFiles() {
|
1432 | 1443 | }
|
1433 | 1444 | try {
|
1434 | 1445 | List<Properties> allProperties = AntCoreUtil.loadPropertyFiles(propertyFiles, currentProject.getUserProperty("basedir"), getBuildFileLocation()); //$NON-NLS-1$
|
1435 |
| - Iterator<Properties> iter = allProperties.iterator(); |
1436 |
| - while (iter.hasNext()) { |
1437 |
| - Properties props = iter.next(); |
| 1446 | + for (Properties props : allProperties) { |
1438 | 1447 | Enumeration<?> propertyNames = props.propertyNames();
|
1439 | 1448 | while (propertyNames.hasMoreElements()) {
|
1440 | 1449 | String name = (String) propertyNames.nextElement();
|
|
0 commit comments