Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Bauman2007-08-27 20:41:21 +0000
committerBrian Bauman2007-08-27 20:41:21 +0000
commited7a983a3839847d3e1463437e3a0b7a022c7f55 (patch)
tree89d0debf8d1df208a91a0bfd53042c356db0e556
parent792957f067ef024bba9927478f4c42e36893f20c (diff)
downloadeclipse.pde.ui-New_Registry.tar.gz
eclipse.pde.ui-New_Registry.tar.xz
eclipse.pde.ui-New_Registry.zip
Modifications:New_Registry
1. Added support for a new PDEExtensionRegistry to be created for use in the Target Platform Preference Page (source locations tab). 2. Corrected a bug where we move any registry listeners from the old registry to the new one when the target platform is reloaded. 3. Updated some logic used when target platform is reloaded. Don't need to dispose of PDERegistryStrategy, just reuse it.
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEExtensionRegistry.java70
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDERegistryStrategy.java77
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPDERegistryStrategy.java26
3 files changed, 131 insertions, 42 deletions
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEExtensionRegistry.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEExtensionRegistry.java
index eab021fa1c..58571b2da0 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEExtensionRegistry.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEExtensionRegistry.java
@@ -1,8 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package org.eclipse.pde.internal.core;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.ListIterator;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
@@ -24,10 +35,12 @@ public class PDEExtensionRegistry {
private Object fMasterKey = new Object();
private Object fUserKey = new Object();
-
private IExtensionRegistry fRegistry = null;
private PDERegistryStrategy fStrategy = null;
+ private IPluginModelBase[] fModels = null;
+ private ArrayList fListeners = new ArrayList();
+
private static final String EXTENSION_DIR = ".extensions"; //$NON-NLS-1$
public PDEExtensionRegistry() {
@@ -39,27 +52,57 @@ public class PDEExtensionRegistry {
}
}
+ public PDEExtensionRegistry(IPluginModelBase[] models) {
+ fModels = models;
+ if (fStrategy == null) {
+ File extensionsDir = new File(PDECore.getDefault().getStateLocation().toFile(), EXTENSION_DIR);
+ // Use TargetPDERegistryStrategy so we don't connect listeners to PluginModelManager. This is used only in target so we don't need change events.
+ fStrategy = new TargetPDERegistryStrategy(new File[] {extensionsDir}, new boolean[] {false}, fMasterKey, this);
+ }
+ }
+
+ // Methods used to control information/status of Extension Registry
+
+ protected IPluginModelBase[] getModels() {
+ return (fModels == null) ? PluginRegistry.getActiveModels() : fModels;
+ }
+
public void stop() {
if (fRegistry != null)
fRegistry.stop(fMasterKey);
+ dispose();
}
- private synchronized IExtensionRegistry getRegistry() {
- if (fRegistry == null)
- createRegistry();
+ protected synchronized IExtensionRegistry getRegistry() {
+ if (fRegistry == null) {
+ fRegistry = createRegistry();
+ for (ListIterator li = fListeners.listIterator(); li.hasNext();)
+ fRegistry.addRegistryChangeListener((IRegistryChangeListener)li.next());
+ }
return fRegistry;
}
- public void targetReloaded() {
- // disconnect listeners
- fStrategy.dispose();
+ private IExtensionRegistry createRegistry() {
+ return RegistryFactory.createRegistry(fStrategy, fMasterKey, fUserKey);
+ }
+
+ public void targetReloaded() {
// stop old registry (which will write contents to FS) and delete the cache it creates
- // might see if we can dispose of a registry without writing to file system
- stop();
+ // might see if we can dispose of a registry without writing to file system. NOTE: Don't call stop() because we want to still reuse fStrategy
+ if (fRegistry != null)
+ fRegistry.stop(fMasterKey);
CoreUtility.deleteContent(new File(PDECore.getDefault().getStateLocation().toFile(), EXTENSION_DIR));
fRegistry = null;
}
+ // dispose of registry without writing contents.
+ public void dispose() {
+ fStrategy.dispose();
+ fRegistry = null;
+ }
+
+ // Methods to access data in Extension Registry
+
public IPluginModelBase[] findExtensionPlugins(String pointId) {
IExtensionPoint point = getExtensionPoint(pointId);
if (point == null) {
@@ -114,10 +157,6 @@ public class PDEExtensionRegistry {
return null;
}
- void createRegistry() {
- fRegistry = RegistryFactory.createRegistry(fStrategy, fMasterKey, fUserKey);
- }
-
public IPluginExtension[] findExtensionsForPlugin(String pluginId) {
IPluginModelBase base = PluginRegistry.findModel(pluginId);
IContributor contributor = fStrategy.createContributor(base);
@@ -175,12 +214,17 @@ public class PDEExtensionRegistry {
return (IExtension[]) list.toArray(new IExtension[list.size()]);
}
+ // Methods to add/remove listeners
+
public void addListener(IRegistryChangeListener listener) {
fRegistry.addRegistryChangeListener(listener);
+ if (!fListeners.contains(listener))
+ fListeners.add(listener);
}
public void removeListener(IRegistryChangeListener listener) {
fRegistry.removeRegistryChangeListener(listener);
+ fListeners.remove(listener);
}
}
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDERegistryStrategy.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDERegistryStrategy.java
index 78c6f817b7..f60429ff4e 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDERegistryStrategy.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDERegistryStrategy.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package org.eclipse.pde.internal.core;
import java.io.BufferedInputStream;
@@ -18,13 +28,8 @@ import org.eclipse.core.runtime.spi.RegistryContributor;
import org.eclipse.core.runtime.spi.RegistryStrategy;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.HostSpecification;
-import org.eclipse.pde.core.plugin.IExtensions;
-import org.eclipse.pde.core.plugin.IPluginBase;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.ModelEntry;
-import org.eclipse.pde.core.plugin.PluginRegistry;
-import org.eclipse.pde.internal.core.bundle.BundlePluginBase;
-import org.eclipse.pde.internal.core.plugin.AbstractExtensions;
import org.osgi.util.tracker.ServiceTracker;
public class PDERegistryStrategy extends RegistryStrategy{
@@ -46,7 +51,7 @@ public class PDERegistryStrategy extends RegistryStrategy{
protected final void removeModels(IPluginModelBase[] bases, boolean onlyInactive) {
for (int i = 0; i < bases.length; i++) {
- resetModel(bases[i]);
+// resetModel(bases[i]);
if (onlyInactive && bases[i].isEnabled())
continue;
removeBundle(fRegistry, bases[i]);
@@ -93,27 +98,39 @@ public class PDERegistryStrategy extends RegistryStrategy{
public PDERegistryStrategy(File[] storageDirs, boolean[] cacheReadOnly, Object key, PDEExtensionRegistry registry) {
super(storageDirs, cacheReadOnly);
+ init();
fKey = key;
-
+ fPDERegistry = registry;
+ }
+
+ protected void init() {
+ connectListeners();
+ }
+
+ protected void connectListeners() {
// Listen for model changes to register new bundles and unregister removed bundles
PluginModelManager manager = PDECore.getDefault().getModelManager();
manager.addPluginModelListener(fModelListener = new ModelListener());
manager.addExtensionDeltaListener(fExtensionListener = new ExtensionListener());
-
- fPDERegistry = registry;
+ }
+
+ protected void setListenerRegistry(IExtensionRegistry registry) {
+ if (fModelListener != null)
+ fModelListener.setRegistry(registry);
+ if (fExtensionListener != null)
+ fExtensionListener.setRegistry(registry);
}
public void onStart(IExtensionRegistry registry, boolean loadedFromCache) {
super.onStart(registry, loadedFromCache);
- fModelListener.setRegistry(registry);
- fExtensionListener.setRegistry(registry);
+ setListenerRegistry(registry);
if (!loadedFromCache)
processBundles(registry);
}
public void onStop(IExtensionRegistry registry) {
super.onStop(registry);
- dispose();
+ setListenerRegistry(null);
}
/* (non-Javadoc)
@@ -128,7 +145,7 @@ public class PDERegistryStrategy extends RegistryStrategy{
}
private void processBundles(IExtensionRegistry registry) {
- addBundles(registry, PluginRegistry.getActiveModels());
+ addBundles(registry, fPDERegistry.getModels());
}
private void addBundles(IExtensionRegistry registry, IPluginModelBase[] bases) {
@@ -167,17 +184,18 @@ public class PDERegistryStrategy extends RegistryStrategy{
}
}
- private void resetModel(IPluginModelBase model) {
- IPluginBase base = model.getPluginBase();
- if (base instanceof BundlePluginBase) {
- IExtensions ext = ((BundlePluginBase)base).getExtensionsRoot();
- if (ext != null && ext instanceof AbstractExtensions) {
- ((AbstractExtensions)ext).reset();
- }
- } else if (base instanceof AbstractExtensions){
- ((AbstractExtensions)base).resetExtensions();
- }
- }
+// added for releasing cached information from IPluginModelBase
+// private void resetModel(IPluginModelBase model) {
+// IPluginBase base = model.getPluginBase();
+// if (base instanceof BundlePluginBase) {
+// IExtensions ext = ((BundlePluginBase)base).getExtensionsRoot();
+// if (ext != null && ext instanceof AbstractExtensions) {
+// ((AbstractExtensions)ext).reset();
+// }
+// } else if (base instanceof AbstractExtensions){
+// ((AbstractExtensions)base).resetExtensions();
+// }
+// }
private File getFile(IPluginModelBase base) {
String loc = base.getInstallLocation();
@@ -237,17 +255,18 @@ public class PDERegistryStrategy extends RegistryStrategy{
PluginModelManager manager = PDECore.getDefault().getModelManager();
manager.removePluginModelListener(fModelListener);
manager.removeExtensionDeltaListener(fExtensionListener);
+ if (xmlTracker != null) {
+ xmlTracker.close();
+ xmlTracker = null;
+ }
}
private void createRegistry() {
- fPDERegistry.createRegistry();
+ fPDERegistry.getRegistry();
}
public long getContributionsTimestamp() {
- // TODO: don't need complicated timestamp algorithm. Just need to figure out if there was a workspace crash after the last time we loaded.
- // Can probably do something with a flag set to true upon shutdown and it set to false after the first query.
- // That way if a crash happened the flag would be set to false.
- IPluginModelBase[] bases = PluginRegistry.getActiveModels();
+ IPluginModelBase[] bases = fPDERegistry.getModels();
long timeStamp = 0;
for (int i = 0; i < bases.length; i++) {
File location = getFile(bases[i]);
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPDERegistryStrategy.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPDERegistryStrategy.java
new file mode 100644
index 0000000000..3d1e1c00bf
--- /dev/null
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/TargetPDERegistryStrategy.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.core;
+
+import java.io.File;
+
+public class TargetPDERegistryStrategy extends PDERegistryStrategy {
+
+ public TargetPDERegistryStrategy(File[] storageDirs,
+ boolean[] cacheReadOnly, Object key, PDEExtensionRegistry registry) {
+ super(storageDirs, cacheReadOnly, key, registry);
+ }
+
+ protected void init() {
+ // don't attach listeners to ModelManager since we don't need to listen for changes
+ }
+
+}

Back to the top