Merge remote-tracking branch 'origin/master' into BETA_JAVA9

Conflicts:
	org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
	org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaFxLibraryResolver.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaFxLibraryResolver.java
index 42c139d..d1917c9 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaFxLibraryResolver.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaFxLibraryResolver.java
@@ -52,7 +52,7 @@
 	public URL getJavadocLocation(IPath libraryPath) {
 		if (isJavaFx(libraryPath)) {
 			/*
-			 * TODO: We don't know if JavaSE-1.9 will ship JavaFX in the ext folder as well. If yes, then we have to use something like
+			 * TODO: We don't know if JavaSE-9 will ship JavaFX in the ext folder as well. If yes, then we have to use something like
 			 * JavaRuntime#getVMInstall(IPath) and IVMInstall2#getJavaVersion() to determine the right Javadoc URL.
 			 */
 			try {
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java
index 6d27b25..b120007 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMRunner.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2000, 2015 IBM Corporation and others.
+ *  Copyright (c) 2000, 2016 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
@@ -591,9 +591,10 @@
 			// use old single attribute instead of new attributes if not specified
 			bootCP = config.getBootClassPath();
 		}
-		if (prependBootCP != null) {
-			arguments.add("-Xbootclasspath/p:" + convertClassPath(prependBootCP)); //$NON-NLS-1$
-		}
+		// Bug 497945 -Temporary testing to see if we can launch inner eclipse in Mac after this.
+		/*
+		 * if (prependBootCP != null) { arguments.add("-Xbootclasspath/p:" + convertClassPath(prependBootCP)); //$NON-NLS-1$ }
+		 */
 		if (bootCP != null) {
 			if (bootCP.length > 0) {
 				arguments.add("-Xbootclasspath:" + convertClassPath(bootCP)); //$NON-NLS-1$
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
index a7080e7..ff2eec0 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/StandardVMType.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 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
@@ -19,6 +19,8 @@
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
@@ -29,6 +31,8 @@
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.stream.Stream;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
@@ -68,6 +72,8 @@
 	private static final String JRE = "jre"; //$NON-NLS-1$
 	private static final String LIB = "lib"; //$NON-NLS-1$
 	private static final String BAR = "|"; //$NON-NLS-1$
+	private static final String RELEASE_FILE = "release"; //$NON-NLS-1$
+	private static final String JAVA_VERSION = "JAVA_VERSION"; //$NON-NLS-1$
 
 	public static final String ID_STANDARD_VM_TYPE = "org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType"; //$NON-NLS-1$
 
@@ -205,13 +211,19 @@
 		if (info == null || LaunchingPlugin.timeStampChanged(installPath)) {
 			info = fgFailedInstallPath.get(installPath);
 			if (info == null) {
-				info = generateLibraryInfo(javaHome, javaExecutable);
-				if (info == null) {
-					info = getDefaultLibraryInfo(javaHome);
-					fgFailedInstallPath.put(installPath, info);
+				String version = readReleaseVersion(javaHome);
+				if (JavaCore.compareJavaVersions(version, JavaCore.VERSION_1_8) > 0) {
+					info = new LibraryInfo(version, new String[0], new String[0], new String[0]);
+					LaunchingPlugin.setLibraryInfo(installPath, info);
 				} else {
-				    // only persist if we were able to generate information - see bug 70011
-				    LaunchingPlugin.setLibraryInfo(installPath, info);
+					info = generateLibraryInfo(javaHome, javaExecutable);
+					if (info == null) {
+						info = getDefaultLibraryInfo(javaHome);
+						fgFailedInstallPath.put(installPath, info);
+					} else {
+						// only persist if we were able to generate information - see bug 70011
+						LaunchingPlugin.setLibraryInfo(installPath, info);
+					}
 				}
 			}
 		}
@@ -422,11 +434,41 @@
 
 			// Add all endorsed libraries - they are first, as they replace
 			allLibs = new ArrayList<>(gatherAllLibraries(libInfo.getEndorsedDirs()));
+			URL url = getDefaultJavadocLocation(installLocation);
+			if (libInfo.getBootpath().length == 0) {
+				// TODO: Bug 489207: Temporary workaround for Jigsaw-previews that don't declare a bootpath.
+				// JDT Core currently requires a non-empty library path, so let's give it jrt-fs.jar as a stand-in for now.
+				// Code referencing org.eclipse.jdt.internal.compiler.util.JimageUtil.JRT_FS_JAR looks for this file.
+				IPath sourceRootPath = Path.EMPTY;
+				// src zip moved to lib folder from JDK 9 EA Build 151
+				IPath path = new Path(installLocation.getAbsolutePath()).append("lib").append("src.zip"); //$NON-NLS-1$ //$NON-NLS-2$
+				File lib = path.toFile();
+				if (lib.exists() && lib.isFile()) {
+					sourceRootPath = getDefaultSystemLibrarySource(lib); // To attach source if available
+				} else {
+					path = new Path(installLocation.getAbsolutePath()).append("src.zip"); //$NON-NLS-1$
+					lib = path.toFile();
+					if (lib.exists() && lib.isFile()) {
+						sourceRootPath = getDefaultSystemLibrarySource(lib); // To attach source if available
+					}
+				}
+				IPath pathName = new Path(installLocation.getAbsolutePath()).append("lib").append("jrt-fs.jar"); //$NON-NLS-1$ //$NON-NLS-2$
+				// From Java 9 149 version, we see that jrt-fs.jar is moved to lib directory so we need to look at both places
+				File jrtfsJar = pathName.toFile();
+				if (!jrtfsJar.exists()) {
+					pathName = new Path(installLocation.getAbsolutePath()).append("jrt-fs.jar"); //$NON-NLS-1$
+				}
+
+				LibraryLocation libraryLocation = new LibraryLocation(pathName,
+						sourceRootPath, getDefaultPackageRootPath(),
+						getDefaultJavadocLocation(installLocation));
+				allLibs.add(libraryLocation);
+			}
 
 			// next is the boot path libraries
 			String[] bootpath = libInfo.getBootpath();
 			List<LibraryLocation> boot = new ArrayList<>(bootpath.length);
-			URL url = getDefaultJavadocLocation(installLocation);
+
 			for (int i = 0; i < bootpath.length; i++) {
 				IPath path = new Path(bootpath[i]);
 				File lib = path.toFile();
@@ -762,7 +804,9 @@
 	 */
 	public static URL getDefaultJavadocLocation(String version) {
 		try {
-			if (version.startsWith(JavaCore.VERSION_1_8)) {
+			if (version.startsWith(JavaCore.VERSION_9)) {
+				return new URL("http://download.java.net/java/jdk9/docs/api/"); //$NON-NLS-1$
+			} else if (version.startsWith(JavaCore.VERSION_1_8)) {
 				return new URL("https://docs.oracle.com/javase/8/docs/api/"); //$NON-NLS-1$
 			} else if (version.startsWith(JavaCore.VERSION_1_7)) {
 				return new URL("https://docs.oracle.com/javase/7/docs/api/"); //$NON-NLS-1$
@@ -782,4 +826,22 @@
 		return null;
 	}
 
+	private synchronized String readReleaseVersion(File javaHome) {
+
+		String version = ""; //$NON-NLS-1$
+		try (Stream<String> lines = Files.lines(Paths.get(javaHome.getAbsolutePath(), RELEASE_FILE)).filter(s -> s.contains(JAVA_VERSION))) {
+			Optional<String> hasVersion = lines.findFirst();
+			if (hasVersion.isPresent()) {
+				String line = hasVersion.get();
+				version = line.substring(14, line.length() - 1); // length of JAVA_VERSION + 2 in JAVA_VERSION="9"
+			}
+		}
+		catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		return version;
+
+	}
+
 }
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java
index ca101f0..06c30c6 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2005, 2015 IBM Corporation and others.
+ *  Copyright (c) 2005, 2017 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
@@ -451,6 +451,7 @@
 				if (is != null) {
 					Properties profile = new Properties();
 					profile.load(is);
+					fixJavaSE9ComplianceSourceTargetLevels(profile);
 					return profile;
 				}
 			} catch (IOException e) {
@@ -459,6 +460,20 @@
 		return null;
 	}
 
+
+	/**
+	 * Bug 470616: [1.9] JavaSE-9 Execution Environment should set proper compiler compliance/source/target levels
+	 * <p>
+	 * This is a workaround for Bug 495497: [9] JavaSE-9.profile Execution Environment should set compiler levels to 9
+	 */
+	private void fixJavaSE9ComplianceSourceTargetLevels(Properties profile) {
+		if (ExecutionEnvironmentAnalyzer.JavaSE_9.equals(getId())) {
+			profile.setProperty(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_9);
+			profile.setProperty(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_9);
+			profile.setProperty(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_9);
+		}
+	}
+
 	/* (non-Javadoc)
 	 * @see org.eclipse.jdt.launching.environments.IExecutionEnvironment#getSubEnvironments()
 	 */
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironmentAnalyzer.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironmentAnalyzer.java
index 780e2a7..980a141 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironmentAnalyzer.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironmentAnalyzer.java
@@ -1,10 +1,14 @@
 /*******************************************************************************
- * Copyright (c) 2006, 2015 IBM Corporation and others.
+ * Copyright (c) 2006, 2016 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
  * http://www.eclipse.org/legal/epl-v10.html
  *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -18,10 +22,8 @@
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-
 import org.eclipse.jdt.internal.launching.EEVMInstall;
 import org.eclipse.jdt.internal.launching.EEVMType;
-
 import org.eclipse.jdt.launching.IVMInstall;
 import org.eclipse.jdt.launching.IVMInstall2;
 import org.eclipse.jdt.launching.IVMInstall3;
@@ -38,6 +40,7 @@
 public class ExecutionEnvironmentAnalyzer implements IExecutionEnvironmentAnalyzerDelegate {
 
 	// XXX: Note that this string is not yet standardized by OSGi, see http://wiki.osgi.org/wiki/Execution_Environment
+	static final String JavaSE_9 = "JavaSE-9"; //$NON-NLS-1$
 	private static final String JavaSE_1_8 = "JavaSE-1.8"; //$NON-NLS-1$
 
 	private static final String JavaSE_1_7 = "JavaSE-1.7"; //$NON-NLS-1$
@@ -76,6 +79,7 @@
 		mappings.put(JavaSE_1_6, new String[] {J2SE_1_5});
 		mappings.put(JavaSE_1_7, new String[] {JavaSE_1_6});
 		mappings.put(JavaSE_1_8, new String[] { JavaSE_1_7 });
+		mappings.put(JavaSE_9, new String[] { JavaSE_1_8 });
 	}
 	@Override
 	public CompatibleEnvironment[] analyze(IVMInstall vm, IProgressMonitor monitor) throws CoreException {
@@ -101,7 +105,9 @@
 					types = getTypes(CDC_FOUNDATION_1_1);
 				}
 			} else {
-				if (javaVersion.startsWith("1.8")) { //$NON-NLS-1$
+				if (javaVersion.startsWith("9")) { //$NON-NLS-1$
+					types = getTypes(JavaSE_9);
+				} else if (javaVersion.startsWith("1.8")) { //$NON-NLS-1$
 					types = getTypes(JavaSE_1_8);
 				} else if (javaVersion.startsWith("1.7")) { //$NON-NLS-1$
 					types = getTypes(JavaSE_1_7);
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
index 3f112f4..660a104 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
@@ -2796,8 +2796,11 @@
             		compliance = JavaCore.VERSION_1_7;
 				} else if (javaVersion.startsWith(JavaCore.VERSION_1_8)) {
 					compliance = JavaCore.VERSION_1_8;
+				} else if (javaVersion.startsWith(JavaCore.VERSION_9)
+						&& (javaVersion.length() == JavaCore.VERSION_9.length() || javaVersion.charAt(JavaCore.VERSION_9.length()) == '.')) {
+					compliance = JavaCore.VERSION_9;
 				} else {
-					compliance = JavaCore.VERSION_1_8; // use latest by default
+					compliance = JavaCore.VERSION_9; // use latest by default
 				}
 
             	Hashtable<String, String> options= JavaCore.getOptions();
diff --git a/org.eclipse.jdt.launching/plugin.properties b/org.eclipse.jdt.launching/plugin.properties
index 5d024d7..792acb3 100644
--- a/org.eclipse.jdt.launching/plugin.properties
+++ b/org.eclipse.jdt.launching/plugin.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2014 IBM Corporation and others.
+# Copyright (c) 2000, 2016 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
@@ -58,6 +58,7 @@
 environment.description.9 = Java Platform, Standard Edition 6.0
 environment.description.11 = Java Platform, Standard Edition 7.0
 environment.description.12 = Java Platform, Standard Edition 8.0
+environment.description.13 = Java Platform, Standard Edition 9
 
 classpathVariableInitializer.deprecated = Use the JRE System Library instead
 
diff --git a/org.eclipse.jdt.launching/plugin.xml b/org.eclipse.jdt.launching/plugin.xml
index 81d9bb0..a16e355 100644
--- a/org.eclipse.jdt.launching/plugin.xml
+++ b/org.eclipse.jdt.launching/plugin.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.0"?>
 <!--
-     Copyright (c) 2005, 2014 IBM Corporation and others.
+     Copyright (c) 2005, 2016 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
@@ -292,6 +292,11 @@
             description="%environment.description.12"
             id="JavaSE-1.8"
             ruleParticipant="org.eclipse.jdt.internal.launching.environments.DefaultAccessRuleParticipant">
+      </environment>
+      <environment
+            description="%environment.description.13"
+            id="JavaSE-9"
+            ruleParticipant="org.eclipse.jdt.internal.launching.environments.DefaultAccessRuleParticipant">
       </environment>            
       <analyzer
             class="org.eclipse.jdt.internal.launching.environments.ExecutionEnvironmentAnalyzer"