Bug 537505 - Fix issues with priming multiple cp entries

When a host bundle has many classpath entries it was possible to
miss the priming of the entries CDSBundleFile

Change-Id: I4816b57bf425e202cbc4fa02ce5f0b7bd015a8ff
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java
index 39588af..941a411 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java
@@ -128,4 +128,12 @@
 			return null;
 		return urlHelper.findSharedClass(null, url, name);
 	}
+
+	/**
+	 * Returns the primed flag for this bundle file.
+	 * @return the primed flag
+	 */
+	public boolean getPrimed() {
+		return this.primed;
+	}
 }
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java
index 3322768..bde9bde 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java
@@ -35,6 +35,7 @@
 import org.eclipse.osgi.internal.loader.ModuleClassLoader;
 import org.eclipse.osgi.internal.loader.classpath.ClasspathEntry;
 import org.eclipse.osgi.internal.loader.classpath.ClasspathManager;
+import org.eclipse.osgi.internal.loader.classpath.FragmentClasspath;
 import org.eclipse.osgi.storage.BundleInfo.Generation;
 import org.eclipse.osgi.storage.bundlefile.BundleEntry;
 import org.eclipse.osgi.storage.bundlefile.BundleFile;
@@ -143,18 +144,41 @@
 		if (factory == null) {
 			return;
 		}
-		CDSBundleFile hostFile = null;
 		try {
 			SharedClassURLHelper urlHelper = factory.getURLHelper(classLoader);
+			boolean minimizeUpdateChecks = urlHelper.setMinimizeUpdateChecks();
 			// set the url helper for the host base CDSBundleFile
-			hostFile = getCDSBundleFile(classLoader.getClasspathManager().getGeneration().getBundleFile());
+			CDSBundleFile hostFile = getCDSBundleFile(classLoader.getClasspathManager().getGeneration().getBundleFile());
 			if (hostFile != null) {
 				hostFile.setURLHelper(urlHelper);
-				if (urlHelper.setMinimizeUpdateChecks()) {
-					// no need to prime if we were able to setsetMinimizeUpdateChecks
+				if (minimizeUpdateChecks) {
+					// no need to prime if we were able to setMinimizeUpdateChecks
 					hostFile.setPrimed(true);
 				}
 			}
+			// No need to prime if we were able to setMinimizeUpdateChecks.
+			// Mark all the BundleFiles on the classpath as primed.
+			ClasspathManager cpManager = classLoader.getClasspathManager();
+			for (ClasspathEntry entry : cpManager.getHostClasspathEntries()) {
+				CDSBundleFile cdsBundleFile = getCDSBundleFile(entry.getBundleFile());
+				if (cdsBundleFile != null) {
+					cdsBundleFile.setURLHelper(urlHelper);
+					if (minimizeUpdateChecks) {
+						cdsBundleFile.setPrimed(true);
+					}
+				}
+			}
+			for (FragmentClasspath fragCP : cpManager.getFragmentClasspaths()) {
+				for (ClasspathEntry entry : fragCP.getEntries()) {
+					CDSBundleFile cdsBundleFile = getCDSBundleFile(entry.getBundleFile());
+					if (cdsBundleFile != null) {
+						cdsBundleFile.setURLHelper(urlHelper);
+						if (minimizeUpdateChecks) {
+							cdsBundleFile.setPrimed(true);
+						}
+					}
+				}
+			}
 		} catch (HelperAlreadyDefinedException e) {
 			// We should never get here. 
 			// If we do, we simply won't share for this ClassLoader
@@ -165,9 +189,11 @@
 		CDSBundleFile hostFile = getCDSBundleFile(hostmanager.getGeneration().getBundleFile());
 		CDSBundleFile sourceFile = getCDSBundleFile(sourceGeneration.getBundleFile());
 		if ((hostFile != sourceFile) && (null != hostFile) && (null != sourceFile)) {
-			// set the helper that got set on the host base bundle file in initializedClassLoader
+			// Set the helper that got set on the host base bundle file in classLoaderCreated.
+			// This is to handle the case where fragments are dynamically attached
 			SharedClassURLHelper urlHelper = hostFile.getURLHelper();
 			sourceFile.setURLHelper(urlHelper);
+			sourceFile.setPrimed(hostFile.getPrimed());
 		}
 
 		return false;