Bug 541119 - Refactoring due to API removal SecurityManager#getInCheck
Super class method was removed in JDK 10. Check via reflection if the
superclass method is not available and log a warning then.
Added small test case to call the method and added to AutomatedSuite.
Version bump for 4.11
Change-Id: I563db7cd75b50e7708fdc5f54b3f8a34a9a13f5b
Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
diff --git a/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.core/META-INF/MANIFEST.MF
index 34705dd..7139ce0 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 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ant.core; singleton:=true
-Bundle-Version: 3.5.200.qualifier
+Bundle-Version: 3.5.300.qualifier
Bundle-Activator: org.eclipse.ant.core.AntCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/ant/org.eclipse.ant.core/pom.xml b/ant/org.eclipse.ant.core/pom.xml
index 86a602d..be7459d 100644
--- a/ant/org.eclipse.ant.core/pom.xml
+++ b/ant/org.eclipse.ant.core/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.ant</groupId>
<artifactId>org.eclipse.ant.core</artifactId>
- <version>3.5.200-SNAPSHOT</version>
+ <version>3.5.300-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars>
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java
index 6f3f684..8f2309b 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/AntSecurityManager.java
@@ -18,7 +18,12 @@
import java.net.SocketPermission;
import java.security.Permission;
import java.util.PropertyPermission;
+
+import org.eclipse.ant.core.AntCorePlugin;
import org.eclipse.ant.core.AntSecurityException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
/**
* A security manager that always throws an <code>AntSecurityException</code> if the calling thread attempts to cause the Java Virtual Machine to
@@ -438,12 +443,19 @@
* @deprecated
*/
@Deprecated
- @Override
+ // @Override Super class method has been removed in JDK 10
public boolean getInCheck() {
- if (fSecurityManager != null) {
- return fSecurityManager.getInCheck();
+ try {
+ SecurityManager.class.getDeclaredMethod("getInCheck", (Class[]) null); //$NON-NLS-1$
+ if (fSecurityManager != null) {
+ return fSecurityManager.getInCheck();
+ }
+ return super.getInCheck();
}
- return super.getInCheck();
+ catch (NoSuchMethodException | SecurityException e) {
+ Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.WARNING, AntCorePlugin.PI_ANTCORE, InternalCoreAntMessages.AntSecurityManager_0));
+ return false;
+ }
}
/*
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.java b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.java
index 065ab86..8df5b00 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.java
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.java
@@ -31,6 +31,8 @@
public static String AntRunner_Build_Failed__3;
public static String AntRunner_Already_in_progess;
+ public static String AntSecurityManager_0;
+
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, InternalCoreAntMessages.class);
diff --git a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties
index 4e6a43a..f5edc6a 100644
--- a/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties
+++ b/ant/org.eclipse.ant.core/src/org/eclipse/ant/internal/core/InternalCoreAntMessages.properties
@@ -25,3 +25,5 @@
AntRunner_Could_not_find_one_or_more_classes__Please_check_the_Ant_classpath__2=Could not find one or more classes: \"{0}\". Please check the Ant classpath.
AntRunner_Build_Failed__3=BUILD FAILED
AntRunner_Already_in_progess=Ant build {0} already in progress. Concurrent Ant builds are possible if you specify to build in a separate JRE.
+
+AntSecurityManager_0=The method SecurityManager#getInCheck was removed in Java 10
diff --git a/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF
index 7622187..6a58697 100644
--- a/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF
+++ b/ant/org.eclipse.ant.launching/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@
Bundle-Localization: plugin
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ant.launching;singleton:=true
-Bundle-Version: 1.2.300.qualifier
+Bundle-Version: 1.2.400.qualifier
Bundle-Activator: org.eclipse.ant.internal.launching.AntLaunching
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.12.0,4.0.0)",
diff --git a/ant/org.eclipse.ant.launching/pom.xml b/ant/org.eclipse.ant.launching/pom.xml
index 434ba0a..09d0a8a 100644
--- a/ant/org.eclipse.ant.launching/pom.xml
+++ b/ant/org.eclipse.ant.launching/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.ant</groupId>
<artifactId>org.eclipse.ant.launching</artifactId>
- <version>1.2.300-SNAPSHOT</version>
+ <version>1.2.400-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<defaultSigning-excludeInnerJars>true</defaultSigning-excludeInnerJars>
diff --git a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java
index 84a8abf..b6c0d1e 100644
--- a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java
+++ b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java
@@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -19,6 +19,12 @@
import java.security.Permission;
import java.util.PropertyPermission;
+import org.eclipse.ant.core.AntCorePlugin;
+import org.eclipse.ant.core.AntSecurityException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+
/**
* A security manager that always throws an <code>AntSecurityException</code> if the calling thread attempts to cause the Java Virtual Machine to
* exit/halt or if the restricted thread attempts to set a System property. Otherwise this manager just delegates to the pre-existing manager passed
@@ -52,7 +58,8 @@
@Override
public void checkExit(int status) {
// no exit allowed from the restricted thread...System.exit is being called
- // by some ant task...disallow the exit
+ // by some ant task...do not want Eclipse to exit if
+ // in the same VM.
if (Thread.currentThread() == fRestrictedThread) {
throw new AntSecurityException();
}
@@ -436,12 +443,20 @@
* @deprecated
*/
@Deprecated
- @Override
+ // @Override Super class method has been removed in JDK 10
public boolean getInCheck() {
- if (fSecurityManager != null) {
- return fSecurityManager.getInCheck();
+ try {
+ SecurityManager.class.getDeclaredMethod("getInCheck", (Class[]) null); //$NON-NLS-1$
+ if (fSecurityManager != null) {
+ return fSecurityManager.getInCheck();
+ }
+ return super.getInCheck();
}
- return super.getInCheck();
+ catch (NoSuchMethodException | SecurityException e) {
+ Platform.getLog(AntCorePlugin.getPlugin().getBundle()).log(new Status(IStatus.WARNING, "org.eclipse.ant.launching", //$NON-NLS-1$
+ RemoteAntMessages.getString("AntSecurityManager.getInCheck"))); //$NON-NLS-1$
+ return false;
+ }
}
/*
diff --git a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties
index 321885e..683ce1f 100644
--- a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties
+++ b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties
@@ -78,3 +78,5 @@
RemoteAntBuildLogger._seconds_4=\ seconds
RemoteAntBuildLogger._second_5=\ second
RemoteAntBuildLogger._milliseconds_6=\ milliseconds
+
+AntSecurityManager.getInCheck=The method SecurityManager#getInCheck was removed in Java 10
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 5bd67a2..19773ab 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 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ant.tests.core; singleton:=true
-Bundle-Version: 3.5.200.qualifier
+Bundle-Version: 3.5.300.qualifier
Bundle-ClassPath: anttestscore.jar
Bundle-Activator: org.eclipse.ant.tests.core.testplugin.AntTestPlugin
Bundle-Vendor: %providerName
diff --git a/ant/org.eclipse.ant.tests.core/pom.xml b/ant/org.eclipse.ant.tests.core/pom.xml
index 0e4c1b7..2cf204d 100644
--- a/ant/org.eclipse.ant.tests.core/pom.xml
+++ b/ant/org.eclipse.ant.tests.core/pom.xml
@@ -19,7 +19,7 @@
</parent>
<groupId>org.eclipse.ant</groupId>
<artifactId>org.eclipse.ant.tests.core</artifactId>
- <version>3.5.200-SNAPSHOT</version>
+ <version>3.5.300-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<code.ignoredWarnings>${tests.ignoredWarnings}</code.ignoredWarnings>
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java
index 77529f3..c06f0ef 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/AutomatedSuite.java
@@ -13,9 +13,7 @@
*******************************************************************************/
package org.eclipse.ant.tests.core;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
+import org.eclipse.ant.tests.core.tests.AntSecurityManagerTest;
import org.eclipse.ant.tests.core.tests.FrameworkTests;
import org.eclipse.ant.tests.core.tests.OptionTests;
import org.eclipse.ant.tests.core.tests.ProjectTests;
@@ -24,6 +22,9 @@
import org.eclipse.ant.tests.core.tests.TaskTests;
import org.eclipse.ant.tests.core.tests.TypeTests;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
/**
* Test the Eclipse Ant Core.
*
@@ -55,5 +56,6 @@
addTest(new TestSuite(TaskTests.class));
addTest(new TestSuite(TypeTests.class));
addTest(new TestSuite(PropertyTests.class));
+ addTest(new TestSuite(AntSecurityManagerTest.class));
}
}
\ No newline at end of file
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/AntSecurityManagerTest.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/AntSecurityManagerTest.java
new file mode 100644
index 0000000..b4f897e
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/AntSecurityManagerTest.java
@@ -0,0 +1,18 @@
+package org.eclipse.ant.tests.core.tests;
+
+import org.eclipse.ant.internal.core.AntSecurityManager;
+import org.eclipse.ant.tests.core.AbstractAntTest;
+
+public class AntSecurityManagerTest extends AbstractAntTest {
+
+ public AntSecurityManagerTest(String name) {
+ super(name);
+ }
+
+ @SuppressWarnings("deprecation")
+ public void test_getInCheck() {
+ AntSecurityManager securityManager = new AntSecurityManager(System.getSecurityManager(), Thread.currentThread());
+ assertFalse(securityManager.getInCheck());
+ }
+
+}