[488507] Duplicate entries in New Runtime Wizard for Installed server
adapters

Change-Id: Id55e7565e7e73191900534a647ed6cc30c72fedd
diff --git a/plugins/org.eclipse.wst.server.discovery/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.server.discovery/META-INF/MANIFEST.MF
index 7e68138..bc41103 100644
--- a/plugins/org.eclipse.wst.server.discovery/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.server.discovery/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@
 Bundle-Name: %bundleName
 Bundle-Vendor: %bundleVendor
 Bundle-SymbolicName: org.eclipse.wst.server.discovery;singleton:=true
-Bundle-Version: 1.2.100.qualifier
+Bundle-Version: 1.3.0.qualifier
 Bundle-Activator: org.eclipse.wst.server.discovery.internal.Activator
 Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0)",
  org.eclipse.ui;bundle-version="[3.5.0,4.0)",
diff --git a/plugins/org.eclipse.wst.server.discovery/serverAdapterSitesDetails.xml b/plugins/org.eclipse.wst.server.discovery/serverAdapterSitesDetails.xml
index a53eb45..ce08b9a 100644
--- a/plugins/org.eclipse.wst.server.discovery/serverAdapterSitesDetails.xml
+++ b/plugins/org.eclipse.wst.server.discovery/serverAdapterSitesDetails.xml
@@ -1,25 +1,29 @@
 <extensionDetails>

 	<feature

 		uri="http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/updates/bluemixAdapter/neon/"

-		id="com.ibm.cftools.wtp.serveradapter.feature.feature.group" name="IBM Bluemix Tools Server Adapter"

+		id="com.ibm.cftools.wtp.serveradapter.feature.feature.group"

+		name="IBM Bluemix Tools Server Adapter"

 		description="Cloud Tools for IBM Bluemix" provider="IBM"

-		version="1.0.0.v20150801_1001" serverId="com.ibm.cftools.server" runtime-vendor="IBM"/>

+		version="1.0.0.v20150801_1001" serverId="com.ibm.cftools.server"

+		runtime-vendor="IBM" runtimeId="com.ibm.cftools.runtime" />

 	<feature

-		uri="http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/updates/libertyAdapter/neon/"

+		uri="http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/updates/libertyAdapter/noen/"

 		id="com.ibm.ws.st.tools.base.feature.group"

 		name="WebSphere Application Server Liberty Profile Tools"

 		description="Tools for developing and administering WebSphere Application Server Liberty Profile"

-		provider="IBM" version="1.0.400.v20150617_2241" serverId="com.ibm.ws.st.server.wlp" runtime-vendor="IBM">

+		provider="IBM" version="1.0.400.v20150617_2241"

+		serverId="com.ibm.ws.st.server.wlp" runtime-vendor="IBM"

+		runtimeId="com.ibm.ws.st.runtime.wlp">

 	</feature>

-	<feature

-		uri="http://www.apache.org/dist/geronimo/eclipse/updates/"

-		id="org.apache.geronimo.v10.feature.feature.group" name="Geronimo v1.0 Server Adapter"

+	<feature uri="http://www.apache.org/dist/geronimo/eclipse/updates/"

+		id="org.apache.geronimo.v10.feature.feature.group"

+		name="Geronimo v1.0 Server Adapter"

 		description="This feature provides the WTP Server Adapter and additional development tools for Apache Geronimo."

 		provider="Apache" version="2.0.0" runtime-vendor="Apache">

 	</feature>

-	<feature

-		uri="http://www.apache.org/dist/geronimo/eclipse/updates/"

-		id="org.apache.geronimo.v22.feature.feature.group" name="Geronimo v2.2 Server Adapter"

+	<feature uri="http://www.apache.org/dist/geronimo/eclipse/updates/"

+		id="org.apache.geronimo.v22.feature.feature.group"

+		name="Geronimo v2.2 Server Adapter"

 		description="This feature provides the WTP Server Adapters and additional development tools for the Apache Geronimo v2.0, v2.1 and v2.2 servers."

 		provider="Apache" version="2.2.1" runtime-vendor="Apache">

 	</feature>

@@ -55,44 +59,52 @@
 	</feature>

 	<feature

 		uri="http://master.dl.sourceforge.net/project/sapnweclipse/updates/"

-		id="com.sap.netweaver.porta.ide.eclipse.feature.feature.group" name="SAP NetWeaver Server Adapter"

+		id="com.sap.netweaver.porta.ide.eclipse.feature.feature.group"

+		name="SAP NetWeaver Server Adapter"

 		description="Server adapter for the SAP NetWeaver Application Server. Supports J2EE 1.4 and Java EE 5 modules."

-		provider="SAP" version="0.7.2.201006211643" runtime-vendor="SAP">

+		provider="SAP" version="0.7.2.201006211643" serverId="com.sap.netweaver.server.ce.720"

+		runtime-vendor="SAP" runtimeId="com.sap.netweaver.runtime.ce.720">

 	</feature>

-	<feature

-		uri="http://jope.ow2.org/update/jope/"

+	<feature uri="http://jope.ow2.org/update/jope/"

 		id="org.ow2.jonas.wtp.adapter.feature.group" name="Jonas WTP Adapter"

 		description="JOPE (JOnAS Plugin for Eclipse) is an open source JOnAS plugin for Eclipse."

-		provider="OW2" version="5.1.2" runtime-vendor="OW2">

+		provider="OW2" version="5.1.2" serverId="org.eclipse.jst.server.generic.jonas4"

+		runtime-vendor="OW2" runtimeId="org.eclipse.jst.server.generic.runtime.jonas4">

 	</feature>

-	<feature

-		uri="http://www.caucho.com/eclipse/"

-		id="com.caucho.resin.eclipse.feature.group" name="Resin (Java EE Web Profile) Server"

+	<feature uri="http://www.caucho.com/eclipse/"

+		id="com.caucho.resin.eclipse.feature.group"

+		name="Resin (Java EE Web Profile) Server"

 		description="Resin Eclipse Plugin based on WebTools Generic Server."

-		provider="Resin" version="4.0.27" runtime-vendor="Resin">

+		provider="Resin" version="4.0.27" serverId="org.eclipse.jst.server.generic.resin40"

+		runtime-vendor="Resin" runtimeId="org.eclipse.jst.server.generic.runtime.resin40">

 	</feature>

 	<feature

 		uri="http://download.jboss.org/jbosstools/updates/webtools/neon/"

-		id="org.jboss.ide.eclipse.as.feature.feature.group" name="JBoss AS, WildFly, &amp; EAP Server Tools"

+		id="org.jboss.ide.eclipse.as.feature.feature.group"

+		name="JBoss AS, WildFly, &amp; EAP Server Tools"

 		description="Provides WTP server adapters for JBoss installations. These adapters are capable of deployment and providing classpaths for projects. Zipped or exploded deployments, JMX integration, and other extensions are included."

-		provider="Red Hat JBoss Middleware" version="3.1.0.Beta2-v20150723-0026-B29" runtime-vendor="Red Hat JBoss Middleware">

+		provider="Red Hat JBoss Middleware" version="3.1.0.Beta2-v20150723-0026-B29" serverId="org.jboss.ide.eclipse.as.eap.70"

+		runtime-vendor="Red Hat JBoss Middleware" runtimeId="org.jboss.ide.eclipse.as.runtime.eap.70">

 	</feature>

-	<feature

-		uri="http://download.oracle.com/otn_software/oepe/mars/"

-		id="oracle.eclipse.tools.cloud.feature.group" name="Oracle Cloud Tools"

+	<feature uri="http://download.oracle.com/otn_software/oepe/mars/"

+		id="oracle.eclipse.tools.cloud.feature.group"

+		name="Oracle Cloud Tools"

 		description="Additional tools for developing Oracle Cloud applications."

-		provider="Oracle" version="8.2.0.201507100122" runtime-vendor="Oracle">

+		provider="Oracle" version="8.2.0.201507100122" serverId="oracle.cloud.server" 

+		runtime-vendor="Oracle" runtimeId="oracle.cloud">

 	</feature>

-	<feature

-		uri="http://download.oracle.com/otn_software/oepe/mars/"

-		id="oracle.eclipse.tools.weblogic.feature.group" name="Oracle WebLogic Server Tools"

+	<feature uri="http://download.oracle.com/otn_software/oepe/mars/"

+		id="oracle.eclipse.tools.weblogic.feature.group"

+		name="Oracle WebLogic Server Tools"

 		description="Tools for developing applications for Oracle WebLogic Server (versions 12.1.x, 10.3.x, 10.0 and 9.2)."

-		provider="Oracle" version="8.2.0.201507100122" runtime-vendor="Oracle">

+		provider="Oracle" version="8.2.0.201507100122" serverId="com.bea.weblogic1221.server"

+		runtime-vendor="Oracle" runtimeId="com.bea.weblogic1221">

 	</feature>

-	<feature

-		uri="http://download.oracle.com/otn_software/oepe/mars/"

-		id="oracle.eclipse.tools.glassfish.feature.group" name="GlassFish Tools"

+	<feature uri="http://download.oracle.com/otn_software/oepe/mars/"

+		id="oracle.eclipse.tools.glassfish.feature.group"

+		name="GlassFish Tools"

 		description="Tools for developing applications for GlassFish."

-		provider="Oracle" version="8.2.0.201507100122" runtime-vendor="Oracle">

+		provider="Oracle" version="8.2.0.201507100122" serverId="org.glassfish.jst.server.glassfish4"

+		runtime-vendor="Oracle" runtimeId="org.glassfish.jst.server.runtime.glassfish4" >

 	</feature>

 </extensionDetails>
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/RuntimeProxy.java b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/RuntimeProxy.java
index 0d03072..ac779e5 100644
--- a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/RuntimeProxy.java
+++ b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/RuntimeProxy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2015 IBM Corporation and others.

+ * Copyright (c) 2015, 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

@@ -19,6 +19,11 @@
 	private String name;

 	private String vendor;

 	private String description;

+	private String proxyRuntimeId;

+

+	/**

+	 * @since 1.2

+	 */

 

 	public RuntimeProxy(String id, String name, String description, String vendor) {

 		super();

@@ -60,6 +65,23 @@
 		return null;

 	}

 

+	/**

+	 * @since 1.3 Returns the runtime id for downloadable adapter if specified

+	 *        by the site This helps identifying the installed runtimes This is

+	 *        important because one downloadable adapter can install more than

+	 *        one server/runtime

+	 */

+	public String getProxyRuntimeId() {

+		return proxyRuntimeId;

+	}

+

+	/**

+	 * @since 1.3

+	 */

+	public void setProxyRuntimeId(String proxyRuntimeId) {

+		this.proxyRuntimeId = proxyRuntimeId;

+	}

+

 	public String toString() {

 		return "RuntimeType[" + getId() + ", " + getName() + "]";

 	}

diff --git a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/ExtensionUtility.java b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/ExtensionUtility.java
index e0efdd5..45f5da8 100644
--- a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/ExtensionUtility.java
+++ b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/ExtensionUtility.java
@@ -77,14 +77,13 @@
 			if (extnList != null){
 				ProcessingInstruction processInstrn = ((XMLMemento)memento).getProcessingInstruction();
 				Bundle bundle = Activator.getDefault().getBundle();
-				//String dateString = new Date(System.currentTimeMillis()).toString();
 				DateFormat df = new SimpleDateFormat("EEE MMM dd yyyy kk:mm:ss zzz", Locale.ENGLISH);
 				Date date = new Date(System.currentTimeMillis());
 				String dateString = df.format(date);
 				String comment ="Generated by " + bundle.getSymbolicName() + " " + bundle.getVersion() + " on " + 	dateString	;
 				XMLMemento newMemento = null;
 				if (processInstrn == null)
-					newMemento = XMLMemento.createWriteRoot("extensionDetails", "serverAdapter", "version=\"2\"", comment);
+					newMemento = XMLMemento.createWriteRoot("extensionDetails", "serverAdapter", "version=\"3\"", comment);
 				else
 					 newMemento = XMLMemento.createWriteRoot("extensionDetails", processInstrn.getTarget(), processInstrn.getData(), comment);
 				
@@ -92,6 +91,7 @@
 					IMemento childMemento = newMemento.createChild("feature");
 					String vendor = extnList[j].getRuntimeVendor();
 					String serverId = extnList[j].getServerId();
+					String runtimeId = extnList[j].getRuntimeId();
 					childMemento.putString("id", extnList[j].getId());
 					childMemento.putString("description", extnList[j].getDescription());
 					childMemento.putString("name", extnList[j].getName());
@@ -99,6 +99,7 @@
 					childMemento.putString("version", extnList[j].getVersion().toString());
 					childMemento.putString("provider", extnList[j].getProvider());
 					childMemento.putString("serverId", serverId );
+					childMemento.putString("runtimeId", runtimeId );
 
 					for (int i = 0; i < children.length; i++) {
 						if (children[i].getString("id").equals(extnList[j].getId())){
@@ -115,6 +116,11 @@
 								childMemento.putString("serverId", children[i].getString("serverId"));
 							else
 								childMemento.putString("serverId",serverId);
+							// use the cache data if sites have not provided the data
+							if ((runtimeId == null || (runtimeId != null && runtimeId.length() ==0)))
+								childMemento.putString("runtimeId", children[i].getString("runtimeId"));
+							else
+								childMemento.putString("runtimeId",runtimeId);
 							
 							break;
 						}
@@ -122,7 +128,7 @@
 
 					
 					ExtensionProxy item = new ExtensionProxy(childMemento.getString("id"), childMemento.getString("name"), childMemento.getString("description"), 
-							childMemento.getString("provider"), childMemento.getString("uri"), childMemento.getString("version"), childMemento.getString("serverId"), childMemento.getString("vendor"));
+							childMemento.getString("provider"), childMemento.getString("uri"), childMemento.getString("version"), childMemento.getString("serverId"), childMemento.getString("vendor"), childMemento.getString("runtimeId"));
 						list.add(item);
 				}
 				synchronized (cacheFileLock) {
@@ -147,7 +153,7 @@
 					DiscoveryPreferences.getInstance().setCacheLastUpdatedDate(Messages.cacheUpdate_Never);
 				for (int i = 0; i < children.length; i++) {
 					ExtensionProxy item = new ExtensionProxy(children[i].getString("id"), children[i].getString("name"), children[i].getString("description"), 
-						children[i].getString("provider"), children[i].getString("uri"), children[i].getString("version"), children[i].getString("serverId"), children[i].getString("vendor"));
+						children[i].getString("provider"), children[i].getString("uri"), children[i].getString("version"), children[i].getString("serverId"), children[i].getString("vendor"), children[i].getString("runtimeId"));
 					list.add(item);
 				}
 			}
@@ -384,6 +390,7 @@
 			runtimeVendor = newFeature.getProvider();
 		}
 		RuntimeProxy runtimeProxy = new RuntimeProxy("com.eclipse.runtime.proxy", newFeature.getName(), newFeature.getDescription(), runtimeVendor);
+		runtimeProxy.setProxyRuntimeId(newFeature.getRuntimeId());
 		ServerProxy serverProxy = new ServerProxy("com.eclipse.server.proxy", newFeature.getName(), newFeature.getDescription(),  runtimeProxy, newFeature.getId(), newFeature.getURI(), newFeature.getServerId());
 		return serverProxy;
 	}
diff --git a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/Extension.java b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/Extension.java
index f070e57..763a15c 100644
--- a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/Extension.java
+++ b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/Extension.java
@@ -163,6 +163,10 @@
 		return iu.getProperty("serverId", null);
 	}
 	
+	public String getRuntimeId() {
+		return iu.getProperty("runtimeId", null);
+	}
+	
 	public String getRuntimeVendor() {
 		return iu.getProperty("vendor", null);
 	}
diff --git a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/ExtensionProxy.java b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/ExtensionProxy.java
index a571ae1..57d4985 100644
--- a/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/ExtensionProxy.java
+++ b/plugins/org.eclipse.wst.server.discovery/src/org/eclipse/wst/server/discovery/internal/model/ExtensionProxy.java
@@ -24,9 +24,10 @@
 	private String version;

 	private String serverId;

 	private String vendor;

+	private String runtimeId;

 

 

-	public ExtensionProxy(String id, String name, String description, String provider, String uri, String version, String serverId, String vendor) {

+	public ExtensionProxy(String id, String name, String description, String provider, String uri, String version, String serverId, String vendor, String runtimeId) {

 		this.id= id;

 		this.name= name;

 		this.description= description;

@@ -35,6 +36,7 @@
 		this.version = version;

 		this.serverId = serverId;

 		this.vendor = vendor;

+		this.runtimeId = runtimeId;

 	}

 

 	public String getName() {

@@ -73,4 +75,7 @@
 		return vendor;

 	}

 

+	public String getRuntimeId() {

+		return runtimeId;

+	}

 }
\ No newline at end of file