Bug 478175 - Adapt EE definition to java 9s new version scheme (JEP 223
ak verona)

Change-Id: I395c83ef3863a3d73598687819506c4d3e0c50de
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
index 570c596..2decd58 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
@@ -2587,6 +2587,51 @@
 		assertNotNull("No system bundle class loader.", cl);
 	}
 
+	public void testJavaProfile() {
+		String original = System.getProperty("java.specification.version");
+		try {
+			doTestJavaProfile("9.3.1", "JavaSE-9.0");
+			doTestJavaProfile("9", "JavaSE-9.0");
+			doTestJavaProfile("8.4", "JavaSE-1.8");
+			doTestJavaProfile("1.10.1", "JavaSE-1.8");
+			doTestJavaProfile("1.9", "JavaSE-1.8");
+			doTestJavaProfile("1.8", "JavaSE-1.8");
+			doTestJavaProfile("1.7", "JavaSE-1.7");
+		} finally {
+			System.setProperty("java.specification.version", original);
+		}
+	}
+
+	private void doTestJavaProfile(String javaSpecVersion, String expectedEEName) {
+		System.setProperty("java.specification.version", javaSpecVersion);
+		// create/stop/ test
+		File config = OSGiTestsActivator.getContext().getDataFile(getName() + javaSpecVersion);
+		Map<String, Object> configuration = new HashMap<String, Object>();
+		configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
+		Equinox equinox = new Equinox(configuration);
+		try {
+			equinox.init();
+		} catch (BundleException e) {
+			fail("Unexpected exception in init()", e); //$NON-NLS-1$
+		}
+		@SuppressWarnings("deprecation")
+		String osgiEE = equinox.getBundleContext().getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
+		// don't do anything; just put the framework back to the RESOLVED state
+		try {
+			equinox.stop();
+		} catch (BundleException e) {
+			fail("Unexpected error stopping framework", e); //$NON-NLS-1$
+		}
+		try {
+			equinox.waitForStop(10000);
+		} catch (InterruptedException e) {
+			fail("Unexpected interrupted exception", e); //$NON-NLS-1$
+		}
+		assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$
+
+		assertTrue("Wrong osgi EE: " + osgiEE, osgiEE.endsWith(expectedEEName));
+	}
+
 	private static File[] createBundles(File outputDir, int bundleCount) throws IOException {
 		outputDir.mkdirs();
 
diff --git a/bundles/org.eclipse.osgi/JavaSE-1.9.profile b/bundles/org.eclipse.osgi/JavaSE-9.0.profile
similarity index 94%
rename from bundles/org.eclipse.osgi/JavaSE-1.9.profile
rename to bundles/org.eclipse.osgi/JavaSE-9.0.profile
index f26f22c..9c84008 100644
--- a/bundles/org.eclipse.osgi/JavaSE-1.9.profile
+++ b/bundles/org.eclipse.osgi/JavaSE-9.0.profile
@@ -195,15 +195,15 @@
  JavaSE-1.6,\
  JavaSE-1.7,\
  JavaSE-1.8,\
- JavaSE-1.9
+ JavaSE-9.0
 org.osgi.framework.system.capabilities = \
  osgi.ee; osgi.ee="OSGi/Minimum"; version:List<Version>="1.0, 1.1, 1.2",\
  osgi.ee; osgi.ee="JRE"; version:List<Version>="1.0, 1.1",\
- osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9",\
- osgi.ee; osgi.ee="JavaSE/compact1"; version:List<Version>="1.8",\
- osgi.ee; osgi.ee="JavaSE/compact2"; version:List<Version>="1.8",\
- osgi.ee; osgi.ee="JavaSE/compact3"; version:List<Version>="1.8"
-osgi.java.profile.name = JavaSE-1.9
+ osgi.ee; osgi.ee="JavaSE"; version:List<Version>="1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 9.0",\
+ osgi.ee; osgi.ee="JavaSE/compact1"; version:List<Version>="1.8, 9.0",\
+ osgi.ee; osgi.ee="JavaSE/compact2"; version:List<Version>="1.8, 9.0",\
+ osgi.ee; osgi.ee="JavaSE/compact3"; version:List<Version>="1.8, 9.0"
+osgi.java.profile.name = JavaSE-9.0
 org.eclipse.jdt.core.compiler.compliance=1.9
 org.eclipse.jdt.core.compiler.source=1.8
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
index c0a4288..8cf7de1 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
@@ -1480,11 +1480,19 @@
 
 	private InputStream findNextBestProfile(Generation systemGeneration, String javaEdition, Version javaVersion, String embeddedProfileName) {
 		InputStream result = null;
+		int major = javaVersion.getMajor();
 		int minor = javaVersion.getMinor();
 		do {
-			result = findInSystemBundle(systemGeneration, javaEdition + embeddedProfileName + javaVersion.getMajor() + "." + minor + PROFILE_EXT); //$NON-NLS-1$
-			minor = minor - 1;
-		} while (result == null && minor > 0);
+			result = findInSystemBundle(systemGeneration, javaEdition + embeddedProfileName + major + "." + minor + PROFILE_EXT); //$NON-NLS-1$
+			if (minor > 0) {
+				minor -= 1;
+			} else if (major > 9) {
+				major -= 1;
+			} else if (major <= 9 && major > 1) {
+				minor = 8;
+				major = 1;
+			}
+		} while (result == null && minor >= 0);
 		return result;
 	}