Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2008-05-07 20:56:51 +0000
committerThomas Watson2008-05-07 20:56:51 +0000
commit7143c9e9fae01c2c5fe1b60d2f97942f6420a86a (patch)
tree9745e7dddea0e2b9103172a5a6d39847ec15dd2c /bundles
parent4375c6a97e50b7852b25d89bc9058c8d75ed7676 (diff)
downloadrt.equinox.bundles-7143c9e9fae01c2c5fe1b60d2f97942f6420a86a.tar.gz
rt.equinox.bundles-7143c9e9fae01c2c5fe1b60d2f97942f6420a86a.tar.xz
rt.equinox.bundles-7143c9e9fae01c2c5fe1b60d2f97942f6420a86a.zip
Bug 230421 [registry] Translation not found when nl pack installed through dropinsv20080507-1815
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java4
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java78
2 files changed, 78 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java
index 2828bb19c..05adb3c3f 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/ExtensionRegistry.java
@@ -464,6 +464,10 @@ public class ExtensionRegistry implements IExtensionRegistry, IDynamicExtensionR
if (!(contributor instanceof RegistryContributor))
throw new IllegalArgumentException(); // should never happen
String contributorId = ((RegistryContributor) contributor).getActualId();
+ return hasContributor(contributorId);
+ }
+
+ public boolean hasContributor(String contributorId) {
access.enterRead();
try {
return registryObjects.hasContribution(contributorId);
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java
index 56ec1f6e7..b678908a5 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/registry/osgi/EclipseBundleListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2007 IBM Corporation and others.
+ * Copyright (c) 2003, 2008 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
@@ -38,6 +38,8 @@ public class EclipseBundleListener implements SynchronousBundleListener {
private ExtensionRegistry registry;
private RegistryStrategyOSGI strategy;
private Object token;
+ private HashMap dynamicAddStateStamps = new HashMap();
+ private long currentStateStamp[] = new long[] {0};
public EclipseBundleListener(ExtensionRegistry registry, Object key, RegistryStrategyOSGI strategy) {
this.registry = registry;
@@ -66,7 +68,15 @@ public class EclipseBundleListener implements SynchronousBundleListener {
Bundle bundle = event.getBundle();
switch (event.getType()) {
case BundleEvent.RESOLVED :
- addBundle(bundle);
+ synchronized (currentStateStamp) {
+ long newStateStamp = registry.computeState();
+ if (currentStateStamp[0] != newStateStamp) {
+ // new state stamp; clear the dynamicaddStateStamps
+ currentStateStamp[0] = newStateStamp;
+ dynamicAddStateStamps.clear();
+ }
+ }
+ addBundle(bundle, true);
break;
case BundleEvent.UNRESOLVED :
removeBundle(bundle);
@@ -77,7 +87,7 @@ public class EclipseBundleListener implements SynchronousBundleListener {
public void processBundles(Bundle[] bundles) {
for (int i = 0; i < bundles.length; i++) {
if (isBundleResolved(bundles[i]))
- addBundle(bundles[i]);
+ addBundle(bundles[i], false);
else
removeBundle(bundles[i]);
}
@@ -137,7 +147,9 @@ public class EclipseBundleListener implements SynchronousBundleListener {
return null;
}
- private void addBundle(Bundle bundle) {
+ private void addBundle(Bundle bundle, boolean checkNLSFragments) {
+ if (checkNLSFragments)
+ checkForNLSFragment(bundle);
// if the given bundle already exists in the registry then return.
// note that this does not work for update cases.
IContributor contributor = ContributorFactoryOSGi.createContributor(bundle);
@@ -167,6 +179,64 @@ public class EclipseBundleListener implements SynchronousBundleListener {
registry.addContribution(is, contributor, true, pluginManifest.getPath(), translationBundle, token, timestamp);
}
+ private void checkForNLSFragment(Bundle fragment) {
+ if (!OSGIUtils.getDefault().isFragment(fragment))
+ return; // only need to worry about fragments
+ Bundle[] hosts = OSGIUtils.getDefault().getHosts(fragment);
+ if (hosts == null)
+ return;
+ // check to see if the hosts should be refreshed because the fragment contains NLS properties files.
+ for (int i = 0; i < hosts.length; i++)
+ checkForNLSFiles(hosts[i], fragment);
+ }
+
+ private void checkForNLSFiles(Bundle host, Bundle fragment) {
+ String hostID = Long.toString(host.getBundleId());
+ Long hostStateStamp = (Long) dynamicAddStateStamps.get(hostID);
+ synchronized (currentStateStamp) {
+ if (hostStateStamp != null && currentStateStamp[0] == hostStateStamp.longValue())
+ return; // already processed this host
+ // mark this host as processed for the current state stamp.
+ dynamicAddStateStamps.put(hostID, new Long(currentStateStamp[0]));
+ }
+
+ if (registry.hasContributor(hostID)) {
+ // get the base localization path from the host
+ Dictionary hostHeaders = host.getHeaders(""); //$NON-NLS-1$
+ String localization = (String) hostHeaders.get(Constants.BUNDLE_LOCALIZATION);
+ if (localization == null)
+ // localization may be empty in which case we should check the default
+ localization = Constants.BUNDLE_LOCALIZATION_DEFAULT_BASENAME;
+ // we do a simple check to make sure the default nls path exists in the host;
+ // this is for performance reasons, but I'm not sure it is valid because a host could ship without the default nls properties file but this seems very unlikely
+ URL baseNLS = host.getEntry(localization + ".properties"); //$NON-NLS-1$
+ if (baseNLS == null)
+ return;
+ int lastSlash = localization.lastIndexOf('/');
+ if (lastSlash == localization.length() - 1)
+ return; // just to be safe
+ String baseDir = lastSlash < 0 ? "" : localization.substring(0, lastSlash); //$NON-NLS-1$
+ String filePattern = (lastSlash < 0 ? localization : localization.substring(lastSlash + 1)) + "_*.properties"; //$NON-NLS-1$
+ Enumeration nlsFiles = fragment.findEntries(baseDir, filePattern, false);
+ if (nlsFiles == null)
+ return;
+ // force the host to be removed and added back
+ removeBundle(host);
+ addBundle(host, false);
+ }
+ // check other fragments of this host
+ Bundle[] fragments = OSGIUtils.getDefault().getFragments(host);
+ for (int i = 0; i < fragments.length; i++) {
+ if (fragment.equals(fragments[i]))
+ continue; // skip fragment that was just resolved; it will be added in our caller
+ String fragmentID = Long.toString(fragments[i].getBundleId());
+ if (registry.hasContributor(fragmentID)) {
+ removeBundle(fragments[i]);
+ addBundle(fragments[i], false);
+ }
+ }
+ }
+
private static boolean isSingleton(Bundle bundle) {
Dictionary allHeaders = bundle.getHeaders(""); //$NON-NLS-1$
String symbolicNameHeader = (String) allHeaders.get(Constants.BUNDLE_SYMBOLICNAME);

Back to the top