Bug 531642 - Avoid using the incomplete JavaSE-9.profile


Change-Id: I645abc26e626c637407ecdadf83f66f46d969807
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/ExecutionEnvironmentTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/ExecutionEnvironmentTests.java
index 354c32a..e128d3b 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/ExecutionEnvironmentTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/ExecutionEnvironmentTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -20,6 +20,7 @@
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.debug.testplugin.JavaProjectHelper;
 import org.eclipse.jdt.debug.tests.AbstractDebugTest;
+import org.eclipse.jdt.launching.AbstractVMInstall;
 import org.eclipse.jdt.launching.IVMInstall;
 import org.eclipse.jdt.launching.JavaRuntime;
 import org.eclipse.jdt.launching.LibraryLocation;
@@ -64,6 +65,22 @@
 		assertTrue("vm should be J2SE-1.4 compliant", false);
 	}
 
+	private int compareJavaVersions(IVMInstall vm, String ver) {
+		if (vm instanceof AbstractVMInstall) {
+			AbstractVMInstall install = (AbstractVMInstall) vm;
+			String vmver = install.getJavaVersion();
+			if (vmver == null) {
+				return -1;
+			}
+			// versionToJdkLevel only handles 3 char versions = 1.5, 1.6, 1.7, etc
+			if (vmver.length() > 3) {
+				vmver = vmver.substring(0, 3);
+			}
+			return JavaCore.compareJavaVersions(vmver, ver);
+		}
+		return -1;
+
+	}
 	public void testAccessRuleParticipants() throws Exception {
 		IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
 		IExecutionEnvironment environment = manager.getEnvironment("org.eclipse.jdt.debug.tests.environment.j2se14x");
@@ -72,6 +89,10 @@
 		LibraryLocation[] libraries = JavaRuntime.getLibraryLocations(vm);
 		IAccessRule[][] accessRules = environment.getAccessRules(vm, libraries, get14Project());
 		assertNotNull("Missing access rules", accessRules);
+		if (compareJavaVersions(vm, "9") >= 0) {
+			assertEquals("Wrong number of rules", 1, accessRules.length);
+			return;
+		}
 		assertEquals("Wrong number of rules", libraries.length, accessRules.length);
 		for (int i = 0; i < accessRules.length; i++) {
 			IAccessRule[] rules = accessRules[i];
@@ -91,6 +112,10 @@
 		LibraryLocation[] libraries = JavaRuntime.getLibraryLocations(vm);
 		IAccessRule[][] accessRules = environment.getAccessRules(vm, libraries, get14Project());
 		assertNotNull("Missing access rules", accessRules);
+		if (compareJavaVersions(vm, "9") >= 0) {
+			assertEquals("Wrong number of rules", 1, accessRules.length);
+			return;
+		}
 		assertEquals("Wrong number of rules", libraries.length, accessRules.length);
 		for (int i = 0; i < accessRules.length; i++) {
 			IAccessRule[] rules = accessRules[i];
@@ -106,6 +131,10 @@
 		LibraryLocation[] libraries = JavaRuntime.getLibraryLocations(vm);
 		IAccessRule[][] accessRules = environment.getAccessRules(vm, libraries, get14Project());
 		assertNotNull("Missing access rules", accessRules);
+		if (compareJavaVersions(vm, "9") >= 0) {
+			assertEquals("Wrong number of rules", 1, accessRules.length);
+			return;
+		}
 		assertEquals("Wrong number of rules", libraries.length, accessRules.length);
 		for (int i = 0; i < accessRules.length; i++) {
 			IAccessRule[] rules = accessRules[i];
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/DefaultAccessRuleParticipant.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/DefaultAccessRuleParticipant.java
index df824ae..8543b15 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/DefaultAccessRuleParticipant.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/DefaultAccessRuleParticipant.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2006, 2015 IBM Corporation and others.
+ *  Copyright (c) 2006, 2018 IBM Corporation and others.
  *  All rights reserved. This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
@@ -44,6 +44,13 @@
 	 */
 	@Override
 	public IAccessRule[][] getAccessRules(IExecutionEnvironment environment, IVMInstall vm, LibraryLocation[] libraries, IJavaProject project) {
+		Map<String, String> complianceOptions = environment.getComplianceOptions();
+		if (complianceOptions != null) {
+			String compliance = complianceOptions.get(JavaCore.COMPILER_COMPLIANCE);
+			if (JavaCore.compareJavaVersions(compliance, "9") >= 0) { //$NON-NLS-1$
+				return new IAccessRule[0][]; // in 9+ access rules are superseded by limit-modules
+			}
+		}
 		IAccessRule[][] allRules = null;
 		allRules = fgRules.get(environment.getId());
 		if (allRules == null || allRules.length != libraries.length) {