[219996] Consolidate java facet and standard.jre component code in one place
diff --git a/plugins/org.eclipse.jst.server.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.jst.server.core/META-INF/MANIFEST.MF
index 359ba60..69882d9 100644
--- a/plugins/org.eclipse.jst.server.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jst.server.core/META-INF/MANIFEST.MF
@@ -18,5 +18,5 @@
  org.eclipse.wst.server.core;bundle-version="[1.0.103,1.1.0)",
  org.eclipse.wst.common.project.facet.core;bundle-version="[1.1.0,2.0.0)",
  org.eclipse.jst.common.project.facet.core;bundle-version="[1.1.0,1.2.0)"
-Eclipse-LazyStart: true
+Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/plugins/org.eclipse.jst.server.core/plugin.xml b/plugins/org.eclipse.jst.server.core/plugin.xml
index 6a1a052..f3f2b03 100644
--- a/plugins/org.eclipse.jst.server.core/plugin.xml
+++ b/plugins/org.eclipse.jst.server.core/plugin.xml
@@ -97,49 +97,6 @@
   </extension>
 
   <extension point="org.eclipse.wst.common.project.facet.core.runtimes">
-    <runtime-component-type id="standard.jre"/>
-
-    <runtime-component-version
-       type="standard.jre"
-       version="1.3"/>
-    <runtime-component-version
-       type="standard.jre"
-       version="1.4"/>
-    <runtime-component-version
-       type="standard.jre"
-       version="5.0"/>
-    <runtime-component-version
-       type="standard.jre"
-       version="6.0"/>
-
-    <adapter>
-      <runtime-component id="standard.jre"/>
-      <factory class="org.eclipse.jst.server.core.internal.StandardJreClasspathProvider$Factory"/>
-      <type class="org.eclipse.jst.common.project.facet.core.IClasspathProvider"/>
-    </adapter>
-
-    <supported>
-      <facet id="jst.java" version="1.3"/>
-      <runtime-component id="standard.jre" version="[1.3"/>
-    </supported>
-
-    <supported>
-      <facet id="jst.java" version="1.4"/>
-      <runtime-component id="standard.jre" version="[1.4"/>
-    </supported>
-
-    <supported>
-      <facet id="jst.java" version="5.0"/>
-      <runtime-component id="standard.jre" version="[5.0"/>
-    </supported>
-
-    <supported>
-      <facet id="jst.java" version="6.0"/>
-      <runtime-component id="standard.jre" version="[6.0"/>
-    </supported>
-  </extension>
-
-  <extension point="org.eclipse.wst.common.project.facet.core.runtimes">
     <runtime-component-type
        id="org.eclipse.jst.server.core.runtimeType"/>
 
diff --git a/plugins/org.eclipse.jst.server.core/src/org/eclipse/jst/server/core/internal/JRERuntimeComponentProvider.java b/plugins/org.eclipse.jst.server.core/src/org/eclipse/jst/server/core/internal/JRERuntimeComponentProvider.java
index 10eaf82..89afad8 100644
--- a/plugins/org.eclipse.jst.server.core/src/org/eclipse/jst/server/core/internal/JRERuntimeComponentProvider.java
+++ b/plugins/org.eclipse.jst.server.core/src/org/eclipse/jst/server/core/internal/JRERuntimeComponentProvider.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007,2008 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
@@ -10,120 +10,24 @@
  *******************************************************************************/
 package org.eclipse.jst.server.core.internal;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
-import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.IVMInstall2;
-import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jst.common.project.facet.core.StandardJreRuntimeComponent;
 import org.eclipse.jst.server.core.IJavaRuntime;
 import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent;
-import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponentVersion;
-import org.eclipse.wst.common.project.facet.core.runtime.RuntimeManager;
 import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.internal.Runtime;
 
 public class JRERuntimeComponentProvider extends RuntimeComponentProviderDelegate {
-	public static final String CLASSPATH = "classpath";
-
-	private Map<String, VMInstallCache> vmCache = new HashMap<String, VMInstallCache>();
-
-	class VMInstallCache {
-		// cached attributes
-		IVMInstall vmInstall;
-		String jvmver;
-		
-		// caching validation
-		int timestamp;
-		File location;
-	}
 
 	public List<IRuntimeComponent> getRuntimeComponents(IRuntime runtime) {
 		// define JRE component
 		IJavaRuntime javaRuntime = (IJavaRuntime) runtime.loadAdapter(IJavaRuntime.class, null);
 		if (javaRuntime != null) {
-			VMInstallCache cache = vmCache.get(runtime.getId());
-			if (cache != null) {
-				if (cache.timestamp != ((Runtime) runtime).getTimestamp())
-					cache = null;
-				if (cache != null && cache.location != null && cache.vmInstall != null && !cache.location.equals(cache.vmInstall.getInstallLocation()))
-					cache = null;
-			}
-			
-			if (cache == null) {
-				cache = new VMInstallCache();
-				cache.timestamp = ((Runtime) runtime).getTimestamp();
-				cache.vmInstall = javaRuntime.getVMInstall();
-				
-				if (cache.vmInstall != null) {
-					if (cache.vmInstall instanceof IVMInstall2) {
-						IVMInstall2 vmInstall2 = (IVMInstall2) cache.vmInstall;
-						if (vmInstall2 != null)
-							cache.jvmver = vmInstall2.getJavaVersion();
-					}
-					cache.location = cache.vmInstall.getInstallLocation();
-				}
-				vmCache.put(runtime.getId(), cache);
-			}
-			
-			IVMInstall vmInstall = cache.vmInstall;
-			String jvmver = cache.jvmver;
-			
-			String vmInstallName;
-			if (vmInstall != null)
-				vmInstallName = vmInstall.getName();
-			else
-				vmInstallName = "Unknown";
-			
-			IRuntimeComponentVersion rcv = null;
-			if (vmInstall == null) {
-				// JRE couldn't be found - assume 6.0 for now
-				rcv = RuntimeManager.getRuntimeComponentType("standard.jre").getVersion("6.0");
-			} else if (jvmver == null) {
-				Trace.trace(Trace.WARNING, "Could not determine VM version for: " + vmInstallName);
-				rcv = RuntimeManager.getRuntimeComponentType("standard.jre").getVersion("6.0");
-			} else if (jvmver.startsWith("1.3"))
-				rcv = RuntimeManager.getRuntimeComponentType("standard.jre").getVersion("1.3");
-			else if (jvmver.startsWith("1.4"))
-				rcv = RuntimeManager.getRuntimeComponentType("standard.jre").getVersion("1.4");
-			else if (jvmver.startsWith("1.5") || jvmver.startsWith("5.0"))
-				rcv = RuntimeManager.getRuntimeComponentType("standard.jre").getVersion("5.0");
-			else if (jvmver.startsWith("1.6") || jvmver.startsWith("6.0"))
-				rcv = RuntimeManager.getRuntimeComponentType("standard.jre").getVersion("6.0");
-			else {
-				Trace.trace(Trace.WARNING, "Invalid Java version: " + vmInstallName + ", " + jvmver);
-				rcv = RuntimeManager.getRuntimeComponentType("standard.jre").getVersion("6.0");
-			}
-			
-			if (rcv != null) {
-				Map<String, String> properties = new HashMap<String, String>(3);
-				String name = "-";
-				if (vmInstallName != null)
-					name = vmInstallName;
-				properties.put("name", name);
-				
-				StringBuffer buf = new StringBuffer();
-				buf.append("JRE ");
-				buf.append(rcv.getVersionString());
-				buf.append(": ");
-				buf.append(name);
-				properties.put("type", buf.toString());
-				
-				if (vmInstall == null) {
-					// no classpath
-				} else if (javaRuntime.isUsingDefaultJRE())
-					properties.put(CLASSPATH, new Path(JavaRuntime.JRE_CONTAINER).toPortableString());
-				else
-					properties.put(CLASSPATH, JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
-				
-				List<IRuntimeComponent> list = new ArrayList<IRuntimeComponent>();
-				list.add(RuntimeManager.createRuntimeComponent(rcv, properties));
-				return list;
-			}
+		    final IVMInstall vmInstall = javaRuntime.getVMInstall();
+		    final IRuntimeComponent rc = StandardJreRuntimeComponent.create( vmInstall );
+			return Collections.singletonList( rc );
 		}
 		return null;
 	}
diff --git a/plugins/org.eclipse.jst.server.core/src/org/eclipse/jst/server/core/internal/StandardJreClasspathProvider.java b/plugins/org.eclipse.jst.server.core/src/org/eclipse/jst/server/core/internal/StandardJreClasspathProvider.java
deleted file mode 100644
index adb5156..0000000
--- a/plugins/org.eclipse.jst.server.core/src/org/eclipse/jst/server/core/internal/StandardJreClasspathProvider.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2005 BEA Systems, Inc.
- * 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
- *
- * Contributors:
- *    Konstantin Komissarchik - initial API and implementation
- *    IBM Corporation - Cleanup
- ******************************************************************************/
-package org.eclipse.jst.server.core.internal;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jst.common.project.facet.core.IClasspathProvider;
-import org.eclipse.wst.common.project.facet.core.IProjectFacet;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent;
-/**
- * 
- */
-public final class StandardJreClasspathProvider implements IClasspathProvider {
-	private static final IProjectFacet JAVA_FACET = ProjectFacetsManager.getProjectFacet("jst.java");
-
-	private IRuntimeComponent rc;
-
-	public StandardJreClasspathProvider(IRuntimeComponent rc) {
-		this.rc = rc;
-	}
-
-	public List getClasspathEntries(IProjectFacetVersion fv) {
-		if (fv.getProjectFacet() == JAVA_FACET) {
-			String s = rc.getProperty(JRERuntimeComponentProvider.CLASSPATH);
-			if (s == null || s.length() == 0)
-				return null;
-			
-			IClasspathEntry cpentry = JavaCore.newContainerEntry(new Path(s));
-			return Collections.singletonList(cpentry);
-		}
-		
-		return null;
-	}
-
-	public static final class Factory implements IAdapterFactory {
-		private static final Class[] ADAPTER_TYPES = { IClasspathProvider.class };
-
-		public Object getAdapter(Object adaptable, Class adapterType) {
-			IRuntimeComponent rc = (IRuntimeComponent) adaptable;
-			return new StandardJreClasspathProvider(rc);
-		}
-
-		public Class[] getAdapterList() {
-			return ADAPTER_TYPES;
-		}
-	}
-}
\ No newline at end of file