[570036] Add a Java 15 project facet
diff --git a/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/feature.xml b/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/feature.xml
index 1e70c58..2bc3a20 100644
--- a/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/feature.xml
+++ b/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/feature.xml
@@ -2,7 +2,7 @@
 <feature
       id="org.eclipse.jst.common.fproj.enablement.jdt"
       label="%featureName"
-      version="3.13.1.qualifier"
+      version="3.21.0.qualifier"
       provider-name="%providerName"
       plugin="org.eclipse.jst.common.project.facet.core"
       license-feature="org.eclipse.license"
diff --git a/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/pom.xml b/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/pom.xml
index 29e5460..ddf5e46 100644
--- a/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/pom.xml
+++ b/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/pom.xml
@@ -21,6 +21,6 @@
 

   <groupId>org.eclipse.webtools.common</groupId>

   <artifactId>org.eclipse.jst.common.fproj.enablement.jdt</artifactId>

-  <version>3.13.1-SNAPSHOT</version>

+  <version>3.21.0-SNAPSHOT</version>

   <packaging>eclipse-feature</packaging>

 </project>
diff --git a/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/sourceTemplateBundle/build.properties b/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/sourceTemplateBundle/build.properties
new file mode 100644
index 0000000..90b8764
--- /dev/null
+++ b/features/org.eclipse.jst.common.fproj.enablement.jdt.feature/sourceTemplateBundle/build.properties
@@ -0,0 +1 @@
+bin.includes = about.html
diff --git a/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/feature.xml b/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/feature.xml
index 48804c8..53fa0b2 100644
--- a/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/feature.xml
+++ b/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/feature.xml
@@ -2,7 +2,7 @@
 <feature

       id="org.eclipse.jst.common.fproj.enablement.jdt.sdk"

       label="%featureName"

-      version="3.8.1.qualifier"

+      version="3.21.0.qualifier"

       provider-name="%providerName"

       plugin="org.eclipse.jst.common.fproj.enablement.jdt.sdk"

       license-feature="org.eclipse.license"

diff --git a/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/pom.xml b/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/pom.xml
index c7ba413..c4953c5 100644
--- a/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/pom.xml
+++ b/features/org.eclipse.jst.common.fproj.enablement.jdt.sdk.feature/pom.xml
@@ -21,6 +21,6 @@
 

   <groupId>org.eclipse.webtools.common</groupId>

   <artifactId>org.eclipse.jst.common.fproj.enablement.jdt.sdk</artifactId>

-  <version>3.8.1-SNAPSHOT</version>

+  <version>3.21.0-SNAPSHOT</version>

   <packaging>eclipse-feature</packaging>

 </project>
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/.classpath b/plugins/org.eclipse.jst.common.project.facet.core/.classpath
index 304e861..b6bc721 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/.classpath
+++ b/plugins/org.eclipse.jst.common.project.facet.core/.classpath
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="schemas/"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.jst.common.project.facet.core/.settings/org.eclipse.jdt.core.prefs
index eb5358d..c767d0c 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.jst.common.project.facet.core/.settings/org.eclipse.jdt.core.prefs
@@ -1,9 +1,8 @@
-#Mon Jan 24 08:45:15 PST 2011
 eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.compliance=1.8
 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
 org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -75,4 +74,5 @@
 org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
 org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
 org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.jst.common.project.facet.core/META-INF/MANIFEST.MF
index e22febe..dd7d671 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jst.common.project.facet.core/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@
 Bundle-Vendor: %providerName
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jst.common.project.facet.core; singleton:=true
-Bundle-Version: 1.9.100.qualifier
+Bundle-Version: 1.10.0.qualifier
 Bundle-ClassPath: .
 Bundle-Localization: plugin
 Export-Package: org.eclipse.jst.common.project.facet.core,
@@ -22,5 +22,5 @@
  org.eclipse.core.net;bundle-version="[1.2.0,2.0.0)",
  org.eclipse.core.filesystem;bundle-version="[1.3.0,2.0.0)"
 Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-Activator: org.eclipse.jst.common.project.facet.core.internal.FacetCorePlugin
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml b/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml
index 6bd6449..1a2f4b5 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml
+++ b/plugins/org.eclipse.jst.common.project.facet.core/plugin.xml
@@ -33,6 +33,7 @@
     <runtime-component-version type="standard.jre" version="13"/>
     <runtime-component-version type="standard.jre" version="14"/>
     <runtime-component-version type="standard.jre" version="15"/>
+    <runtime-component-version type="standard.jre" version="16"/>
 
     <supported>
       <facet id="java" version="1.3"/>
@@ -99,6 +100,11 @@
       <runtime-component id="standard.jre" version="[15"/>
     </supported>
 
+    <supported>
+      <facet id="java" version="16"/>
+      <runtime-component id="standard.jre" version="[16"/>
+    </supported>
+
     <adapter>
       <runtime-component id="standard.jre"/>
       <factory class="org.eclipse.jst.common.project.facet.core.internal.StandardJreClasspathProvider$Factory"/>
@@ -141,6 +147,8 @@
     
     <project-facet-version facet="java" version="15"/>
 
+    <project-facet-version facet="java" version="16"/>
+
     <action facet="java" type="install" id="java.install">
       <delegate class="org.eclipse.jst.common.project.facet.core.internal.JavaFacetInstallDelegate"/>
       <config-factory class="org.eclipse.jst.common.project.facet.core.internal.JavaFacetInstallConfigFactory"/>
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/pom.xml b/plugins/org.eclipse.jst.common.project.facet.core/pom.xml
index f8c2956..f6f4ae2 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/pom.xml
+++ b/plugins/org.eclipse.jst.common.project.facet.core/pom.xml
@@ -21,6 +21,6 @@
 

   <groupId>org.eclipse.webtools.common</groupId>

   <artifactId>org.eclipse.jst.common.project.facet.core</artifactId>

-  <version>1.9.100-SNAPSHOT</version>

+  <version>1.10.0-SNAPSHOT</version>

   <packaging>eclipse-plugin</packaging>

 </project>
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/JavaFacet.java b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/JavaFacet.java
index a865077..455c727 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/JavaFacet.java
+++ b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/JavaFacet.java
@@ -1,15 +1,16 @@
 /******************************************************************************
- * Copyright (c) 2010, 2019 Oracle
+ * Copyright (c) 2010, 2021 Oracle and others
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
  * https://www.eclipse.org/legal/epl-2.0/
  *
  * Contributors:
- *    Konstantin Komissarchik - initial implementation and ongoing maintenance
+ *    Konstantin Komissarchik - initial implementation
  *    Carl Anderson - Java 9 support
  *    John Collier - Java 10-11, 13-15 support
  *    Leon Keuroglian - Java 12 support
+ *    Nitin Dahyabhai - Java 12, 16 support
  ******************************************************************************/
 
 package org.eclipse.jst.common.project.facet.core;
@@ -44,6 +45,7 @@
     public static final IProjectFacetVersion VERSION_13 = FACET.getVersion( "13" ); //$NON-NLS-1$
     public static final IProjectFacetVersion VERSION_14 = FACET.getVersion( "14" ); //$NON-NLS-1$
     public static final IProjectFacetVersion VERSION_15 = FACET.getVersion( "15" ); //$NON-NLS-1$
+    public static final IProjectFacetVersion VERSION_16 = FACET.getVersion( "16" ); //$NON-NLS-1$
 
     @Deprecated
     public static final IProjectFacetVersion JAVA_13 = VERSION_1_3;
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/StandardJreRuntimeComponent.java b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/StandardJreRuntimeComponent.java
index d162e02..2989e7c 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/StandardJreRuntimeComponent.java
+++ b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/StandardJreRuntimeComponent.java
@@ -1,15 +1,16 @@
 /******************************************************************************
- * Copyright (c) 2010, 2019 Oracle
+ * Copyright (c) 2010, 2021 Oracle and others
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
  * https://www.eclipse.org/legal/epl-2.0/
  *
  * Contributors:
- *    Konstantin Komissarchik - initial implementation and ongoing maintenance
+ *    Konstantin Komissarchik - initial implementation
  *    Carl Anderson - Java 9 support
- *    John Collier - Java 10-11, 13 support
+ *    John Collier - Java 10-11, 13-15 support
  *    Leon Keuroglian - Java 12 support
+ *    Nitin Dahyabhai - Java 12, 16 support
  ******************************************************************************/
 
 package org.eclipse.jst.common.project.facet.core;
@@ -45,6 +46,7 @@
     public static final IRuntimeComponentVersion VERSION_13 = TYPE.getVersion( "13" ); //$NON-NLS-1$
     public static final IRuntimeComponentVersion VERSION_14 = TYPE.getVersion( "14" ); //$NON-NLS-1$
     public static final IRuntimeComponentVersion VERSION_15 = TYPE.getVersion( "15" ); //$NON-NLS-1$
+    public static final IRuntimeComponentVersion VERSION_16 = TYPE.getVersion( "16" ); //$NON-NLS-1$
 
     @Deprecated
     public static final IRuntimeComponentVersion VERSION_5_0 = VERSION_1_5;
@@ -69,7 +71,7 @@
         
         if( jvmver == null ) 
         {
-            rcv = StandardJreRuntimeComponent.VERSION_1_7;
+            rcv = StandardJreRuntimeComponent.VERSION_1_8;
         } 
         else if( jvmver.startsWith( "1.3" ) ) //$NON-NLS-1$
         {
@@ -125,7 +127,7 @@
         }
         else
         {
-            rcv = StandardJreRuntimeComponent.VERSION_15;
+            rcv = StandardJreRuntimeComponent.VERSION_16;
         }
         
         final Map<String,String> properties = new HashMap<String,String>();
diff --git a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/internal/JavaFacetUtil.java b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/internal/JavaFacetUtil.java
index b2ebbf8..09aafbc 100644
--- a/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/internal/JavaFacetUtil.java
+++ b/plugins/org.eclipse.jst.common.project.facet.core/src/org/eclipse/jst/common/project/facet/core/internal/JavaFacetUtil.java
@@ -1,20 +1,22 @@
 /******************************************************************************
- * Copyright (c) 2010, 2019 Oracle
+ * Copyright (c) 2010, 2021 Oracle and others
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
  * https://www.eclipse.org/legal/epl-2.0/
  *
  * Contributors:
- *    Konstantin Komissarchik - initial implementation and ongoing maintenance
+ *    Konstantin Komissarchik - initial implementation
  *    Carl Anderson - Java 9 support
- *    John Collier - Java 10-11, 13 support
+ *    John Collier - Java 10-11, 13-15 support
  *    Leon Keuroglian - Java 12 support
+ *    Nitin Dahyabhai - Java 12, 16 support
  ******************************************************************************/
 
 package org.eclipse.jst.common.project.facet.core.internal;
 
-import java.util.Collections;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
@@ -28,6 +30,7 @@
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
@@ -35,9 +38,7 @@
 import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.launching.IVMInstall;
 import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jst.common.project.facet.core.ClasspathHelper;
 import org.eclipse.jst.common.project.facet.core.JavaFacet;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
@@ -71,6 +72,7 @@
         FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_13, "JavaSE-13" ); //$NON-NLS-1$
         FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_14, "JavaSE-14" ); //$NON-NLS-1$
         FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_15, "JavaSE-15" ); //$NON-NLS-1$
+        FACET_VER_TO_EXEC_ENV.put( JavaFacet.VERSION_16, "JavaSE-16" ); //$NON-NLS-1$
     }
     
     public static String getCompilerLevel()
@@ -173,68 +175,44 @@
     
         throws CoreException
         
-    {
-        if( oldver != null )
-        {
-            ClasspathHelper.removeClasspathEntries( project, oldver );
-        }
-        
-        // If this was a java project before it became a faceted project or
-        // the JRE container has been added manually, the above method will not
-        // delete the old JRE container. Do it manually.
-        
-        removeJreContainer( project );
-        
-        if( ! ClasspathHelper.addClasspathEntries( project, newver ) ) 
-        {
-            final IVMInstall vm = JavaRuntime.getDefaultVMInstall();
-            
-            if( vm != null )
-            {
-                final IPath path = CPE_PREFIX_FOR_EXEC_ENV.append( getCorrespondingExecutionEnvironment( newver ) );
-                final IClasspathEntry cpe = JavaCore.newContainerEntry( path );
-                final List<IClasspathEntry> entries = Collections.singletonList( cpe );
-                
-                ClasspathHelper.addClasspathEntries( project, newver, entries );
-            }
-        }
-    }
-    
-    private static void removeJreContainer( final IProject proj ) 
-    
-        throws CoreException
-        
-    {
-        final IJavaProject jproj = JavaCore.create( proj );
-        final IClasspathEntry[] cp = jproj.getRawClasspath();
-        
-        int pos = -1;
-        
-        for( int i = 0; i < cp.length; i++ )
-        {
-            final IClasspathEntry cpe = cp[ i ];
-            
-            if( cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER &&
-                cpe.getPath().segment( 0 ).equals( JavaRuntime.JRE_CONTAINER ) )
-            {
-                pos = i;
-                break;
-            }
-        }
-            
-        if( pos == -1 )
-        {
-            return;
-        }
-        
-        final IClasspathEntry[] newcp 
-            = new IClasspathEntry[ cp.length - 1 ];
-        
-        System.arraycopy( cp, 0, newcp, 0, pos );
-        System.arraycopy( cp, pos + 1, newcp, pos, newcp.length - pos );
-        
-        jproj.setRawClasspath( newcp, null );
-    }
+	{
+		IJavaProject javaProject = JavaCore.create(project);
+		IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
+		/*
+		 * We're only handling the "java" facet. Avoid needlessly reordering
+		 * the build path and change the container directly.
+		 */
+		boolean changed = false;
+		boolean hadJRE = false;
+		for (int i = 0; i < rawClasspath.length; i++) {
+			if (rawClasspath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER && JavaRuntime.JRE_CONTAINER.equals(rawClasspath[i].getPath().segment(0))) {
+				hadJRE = true;
+				IClasspathEntry oldEntry = rawClasspath[i];
+				IPath path = CPE_PREFIX_FOR_EXEC_ENV.append(getCorrespondingExecutionEnvironment(newver));
+				IClasspathEntry newEntry = JavaCore.newContainerEntry(path, oldEntry.getAccessRules(), oldEntry.getExtraAttributes(), oldEntry.isExported());
+				rawClasspath[i] = newEntry;
+				changed = true;
+			}
+		}
+		if (!hadJRE) {
+			boolean insertedJRE = false;
+			List<IClasspathEntry> entries = new ArrayList<>(Arrays.asList(rawClasspath));
+			for (int i = rawClasspath.length - 1; i >= 0; i++) {
+				if (rawClasspath[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+					entries.add(i, JavaCore.newContainerEntry(CPE_PREFIX_FOR_EXEC_ENV.append(getCorrespondingExecutionEnvironment(newver))));
+					insertedJRE = true;
+					break;
+				}
+			}
+			if (!insertedJRE) {
+				entries.add(0, JavaCore.newContainerEntry(CPE_PREFIX_FOR_EXEC_ENV.append(getCorrespondingExecutionEnvironment(newver))));
+			}
+			rawClasspath = entries.toArray(new IClasspathEntry[entries.size()]);
+		}
+		if (changed || !hadJRE) {
+			javaProject.setRawClasspath(rawClasspath, new NullProgressMonitor());
+		}
+	}
     
     public static String getCorrespondingExecutionEnvironment( final IProjectFacetVersion fv )
     {