Bug 547754 - Slow loading "org.eclipse.e4.ui.swt.css.theme" when
using shared drive as workspace directory

Currently we go through all the bundles for Css Theme contributions.
Instead it would be better if we get the contributions to the Extention
point "org.eclipse.e4.ui.css.swt.theme" and get the plugins that these
contributions belong to and only search in these plugins for the theme
related information. This patch implements the above idea. Also added
code to consider "org.eclipse.ui.themes" extension contributions.

Tested this patch for Eclipse 4.4 and also updated the plugin versions

Change-Id: I491592cce79eccee96b2b643fe287d8fb9e54139
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF
index 8f5f9a3..c4d3bfb 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-SymbolicName: org.eclipse.e4.ui.workbench.swt;singleton:=true
-Bundle-Version: 0.12.100.qualifier
+Bundle-Version: 0.12.101.qualifier
 Bundle-Name: %pluginName
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/pom.xml b/bundles/org.eclipse.e4.ui.workbench.swt/pom.xml
index 6af4e99..28f0cfb 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/pom.xml
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/pom.xml
@@ -19,6 +19,6 @@
   </parent>
   <groupId>org.eclipse.e4</groupId>
   <artifactId>org.eclipse.e4.ui.workbench.swt</artifactId>
-  <version>0.12.100-SNAPSHOT</version>
+  <version>0.12.101-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 </project>
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
index 2f37807..faa02e0 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008, 2014 IBM Corporation and others.
+ * Copyright (c) 2008, 2019 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
@@ -25,7 +25,11 @@
 import javax.inject.Named;
 import org.eclipse.core.databinding.observable.Realm;
 import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
 import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.SafeRunner;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.core.runtime.preferences.InstanceScope;
@@ -87,10 +91,9 @@
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Widget;
 import org.eclipse.ui.testing.TestableObject;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventHandler;
+import org.osgi.service.log.LogService;
 import org.w3c.dom.Element;
 import org.w3c.dom.css.CSSStyleDeclaration;
 
@@ -1466,7 +1469,7 @@
 		}
 
 		protected void resetOverriddenPreferences() {
-			for (IEclipsePreferences preferences : getPreferences()) {
+			for (IEclipsePreferences preferences : getThemeRelatedPreferences()) {
 				resetOverriddenPreferences(preferences);
 			}
 		}
@@ -1490,15 +1493,28 @@
 					.getOverriddenPropertyNames(preferences);
 		}
 
-		protected Set<IEclipsePreferences> getPreferences() {
+		protected Set<IEclipsePreferences> getThemeRelatedPreferences() {
 			if (prefs == null) {
 				prefs = new HashSet<IEclipsePreferences>();
-				BundleContext context = WorkbenchSWTActivator.getDefault()
-						.getContext();
-				for (Bundle bundle : context.getBundles()) {
-					if (bundle.getSymbolicName() != null) {
-						prefs.add(InstanceScope.INSTANCE.getNode(bundle
-								.getSymbolicName()));
+				final IExtensionRegistry registry = Platform.getExtensionRegistry();
+				Set<String> bundleIDs = new HashSet<String>();
+				String[] themeRelatedExtensionPoints = {"org.eclipse.e4.ui.css.swt.theme","org.eclipse.ui.themes"};
+				for (String extensionPoint : themeRelatedExtensionPoints) {
+					IConfigurationElement[] elements = registry.getConfigurationElementsFor(extensionPoint);
+					for (IConfigurationElement element : elements) {
+						try {
+							String nameSpace = element.getNamespaceIdentifier();
+							if (nameSpace != null) {
+								bundleIDs.add(nameSpace);
+							}
+						} catch (InvalidRegistryObjectException e) {
+							Activator.log(LogService.LOG_ERROR, e.getMessage(),	e);
+						}
+					}
+				}
+				for (String bundleId : bundleIDs) {
+					if (bundleId != null) {
+						prefs.add(InstanceScope.INSTANCE.getNode(bundleId));
 					}
 				}
 			}
@@ -1507,7 +1523,7 @@
 
 		private void overridePreferences(IThemeEngine themeEngine) {
 			if (themeEngine != null) {
-				for (IEclipsePreferences preferences : getPreferences()) {
+				for (IEclipsePreferences preferences : getThemeRelatedPreferences()) {
 					themeEngine.applyStyles(preferences, false);
 				}
 			}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/themes/StylingPreferencesHandlerTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/themes/StylingPreferencesHandlerTest.java
index 4c4cfd0..b0db703 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/themes/StylingPreferencesHandlerTest.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/themes/StylingPreferencesHandlerTest.java
@@ -26,7 +26,7 @@
 		IEclipsePreferences pref2 = mock(IEclipsePreferences.class);
 
 		StylingPreferencesHandlerTestable handler = spy(new StylingPreferencesHandlerTestable(mock(Display.class)));
-		doReturn(new HashSet<IEclipsePreferences>(Arrays.asList(pref1, pref2))).when(handler).getPreferences();
+		doReturn(new HashSet<IEclipsePreferences>(Arrays.asList(pref1, pref2))).when(handler).getThemeRelatedPreferences();
 		doReturn(Arrays.asList("pref1.prop1", "pref1.prop2")).when(handler).getOverriddenPropertyNames(pref1);
 		doReturn(Arrays.asList("pref2.prop1")).when(handler).getOverriddenPropertyNames(pref2);
 
@@ -51,7 +51,7 @@
 		IEclipsePreferences pref2 = mock(IEclipsePreferences.class);
 
 		StylingPreferencesHandlerTestable handler = spy(new StylingPreferencesHandlerTestable(mock(Display.class)));
-		doReturn(new HashSet<IEclipsePreferences>(Arrays.asList(pref1, pref2))).when(handler).getPreferences();
+		doReturn(new HashSet<IEclipsePreferences>(Arrays.asList(pref1, pref2))).when(handler).getThemeRelatedPreferences();
 		doReturn(Arrays.asList("pref1.prop1", "pref1.prop2")).when(handler).getOverriddenPropertyNames(pref1);
 		doReturn(Arrays.asList("pref2.prop1", "pref2.prop2")).when(handler).getOverriddenPropertyNames(pref2);
 
@@ -73,10 +73,10 @@
 	public void testGetPreferences() {
 		Set<IEclipsePreferences> result = new StylingPreferencesHandler(mock(Display.class)) {
 			@Override
-			public Set<IEclipsePreferences> getPreferences() {
-				return super.getPreferences();
+			public Set<IEclipsePreferences> getThemeRelatedPreferences() {
+				return super.getThemeRelatedPreferences();
 			}
-		}.getPreferences();
+		}.getThemeRelatedPreferences();
 
 		assertFalse(result.isEmpty());
 	}
@@ -118,7 +118,7 @@
 		}
 
 		@Override
-		public Set<IEclipsePreferences> getPreferences() {
+		public Set<IEclipsePreferences> getThemeRelatedPreferences() {
 			return Collections.emptySet();
 		}
 
diff --git a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF
index f5052ca..13d6a6a 100644
--- a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: Eclipse UI Tests
 Bundle-SymbolicName: org.eclipse.ui.tests; singleton:=true
-Bundle-Version: 3.9.2.qualifier
+Bundle-Version: 3.9.3.qualifier
 Eclipse-BundleShape: dir
 Bundle-Activator: org.eclipse.ui.tests.TestPlugin
 Bundle-Vendor: Eclipse.org
diff --git a/tests/org.eclipse.ui.tests/pom.xml b/tests/org.eclipse.ui.tests/pom.xml
index 94532bd..852739e 100644
--- a/tests/org.eclipse.ui.tests/pom.xml
+++ b/tests/org.eclipse.ui.tests/pom.xml
@@ -18,7 +18,7 @@
   </parent>
   <groupId>org.eclipse.ui</groupId>
   <artifactId>org.eclipse.ui.tests</artifactId>
-  <version>3.9.2-SNAPSHOT</version>
+  <version>3.9.3-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
 
   <properties>