[434185] Server Discovery should allow sites without site.xml
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 180f2ce..19cb572 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.0.700.qualifier
+Bundle-Version: 1.0.701.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/pom.xml b/plugins/org.eclipse.wst.server.discovery/pom.xml
index 87a0dbc..1986b01 100644
--- a/plugins/org.eclipse.wst.server.discovery/pom.xml
+++ b/plugins/org.eclipse.wst.server.discovery/pom.xml
@@ -22,6 +22,6 @@
 

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

   <artifactId>org.eclipse.wst.server.discovery</artifactId>

-  <version>1.0.700-SNAPSHOT</version>

+  <version>1.0.701-SNAPSHOT</version>

   <packaging>eclipse-plugin</packaging>

 </project>

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 44d452e..09a7116 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
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2010 IBM Corporation and others.
+ * Copyright (c) 2008, 2015 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
@@ -12,13 +12,18 @@
 
 import java.net.URI;
 import java.util.Collection;
+
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.equinox.p2.core.IProvisioningAgent;
 import org.eclipse.equinox.p2.engine.*;
-import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.ILicense;
+import org.eclipse.equinox.p2.metadata.Version;
 import org.eclipse.equinox.p2.planner.IPlanner;
 import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
+import org.eclipse.equinox.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.wst.server.discovery.internal.Activator;
 import org.eclipse.wst.server.discovery.internal.ExtensionUtility;
@@ -98,15 +103,41 @@
 		pcr.add(iu);
 		IProvisioningAgent agent = ExtensionUtility.getAgent(bundleContext);
 		if (agent == null) {
-			// TODO eek!
 			return null;
 		}
+		
+		// Get all the known repositories when installing the server adapter.
+		// If these repositories are not added, it can cause install problems if 
+		// the server adapter relies on the list of available software install sites
+		URI[] knownRepositories = null;
+		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
+		if (manager != null){
+			manager.addRepository(uri);
+			// Note: IRepositoryManager.REPOSITORIES_ALL will exclude the deselected update sites
+			knownRepositories = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
+			
+			// A fall back in case known repositories returns null
+			if (knownRepositories == null){
+				knownRepositories = new URI[] {uri};
+			}
+		}
+		else {
+			knownRepositories = new URI[] {uri};
+		}		
+		
 		provContext = new ProvisioningContext(agent);
-		provContext.setMetadataRepositories(new URI[] {uri});
-		provContext.setArtifactRepositories(new URI[] {uri});
+		
+		// Add the new URLs to both the Metadata and Artifact repositories.
+		// Note: only the IInstallableUnit that is passed into this class will be installed
+		// as a server adapter. For example, if multiple update site URLs for discovery server
+		// adapters are present, they will not be installed.
+		provContext.setMetadataRepositories(knownRepositories);
+		provContext.setArtifactRepositories(knownRepositories);
 		if (!explain)
-			provContext.setProperty("org.eclipse.equinox.p2.director.explain", "false");
-		//provContext = new ProvisioningContext();
+			provContext.setProperty("org.eclipse.equinox.p2.director.explain", "false"); //$NON-NLS-1$ //$NON-NLS-2$
+		
+		provContext.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES,"true"); //$NON-NLS-1$
+		
 		plan = planner.getProvisioningPlan(pcr, provContext, monitor);
 		//System.out.println("Time: " + (System.currentTimeMillis() - time)); // TODO
 		return plan;