diff options
author | John Ross | 2013-08-09 10:30:55 -0400 |
---|---|---|
committer | John Ross | 2013-08-12 16:21:35 -0400 |
commit | e84af5afdba10d6b489a88d7c40cd20761e0c0ae (patch) | |
tree | 9e8c47821ceef87b29ebee91087e7d2f13034a1e | |
parent | 07670433d11dd8ebcca2377523e4e9d176ccdb5a (diff) | |
download | rt.equinox.bundles-e84af5afdba10d6b489a88d7c40cd20761e0c0ae.zip rt.equinox.bundles-e84af5afdba10d6b489a88d7c40cd20761e0c0ae.tar.gz rt.equinox.bundles-e84af5afdba10d6b489a88d7c40cd20761e0c0ae.tar.xz |
Bug 413053 - [DS] Component descriptors not reloaded on bundle update when using wildcards in Service-ComponentI20130813-0800
When computing the last modified timestamp, bundle.findEntries (supports wildcard characters) is now used rather than
bundle.getEntry (does not support wildcard characters).
2 files changed, 67 insertions, 63 deletions
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ComponentStorage.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ComponentStorage.java index 7993524..2124ab6 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ComponentStorage.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/ComponentStorage.java @@ -14,8 +14,7 @@ package org.eclipse.equinox.internal.ds; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.util.Enumeration; -import java.util.Vector; +import java.util.*; import org.eclipse.equinox.internal.ds.model.DeclarationParser; import org.eclipse.osgi.util.ManifestElement; import org.eclipse.osgi.util.NLS; @@ -58,55 +57,40 @@ public abstract class ComponentStorage { if (dsHeader == null) return components; ManifestElement[] elements = ManifestElement.parseHeader(ComponentConstants.SERVICE_COMPONENT, dsHeader); + Collection/*<URL>*/urlCollection = computeComponentDefinitionUrls(bundle, elements); // the parser is not thread safe!!! synchronized (parser) { - // process all definition file - for (int i = 0; i < elements.length; i++) { - String[] definitionFiles = elements[i].getValueComponents(); - for (int j = 0; j < definitionFiles.length; j++) { - String definitionFile = definitionFiles[j]; - int ind = definitionFile.lastIndexOf('/'); - String path = ind != -1 ? definitionFile.substring(0, ind) : "/"; //$NON-NLS-1$ - InputStream is = null; - - Enumeration urls = bundle.findEntries(path, ind != -1 ? definitionFile.substring(ind + 1) : definitionFile, false); - if (urls == null || !urls.hasMoreElements()) { - Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.COMPONENT_XML_NOT_FOUND, bundle.getSymbolicName(), definitionFile), null); - continue; - } - - // illegal components are ignored, but framework event is posted for - // them; however, it will continue and try to load any legal - // definitions - URL url; - while (urls.hasMoreElements()) { - url = (URL) urls.nextElement(); - if (Activator.DEBUG) { - Activator.log.debug("ComponentStorage.parseXMLDeclaration(): loading " + url.toString(), null); //$NON-NLS-1$ + // illegal components are ignored, but framework event is posted for + // them; however, it will continue and try to load any legal + // definitions + URL url; + for (Iterator/*<URL>*/urls = urlCollection.iterator(); urls.hasNext();) { + url = (URL) urls.next(); + if (Activator.DEBUG) { + Activator.log.debug("ComponentStorage.parseXMLDeclaration(): loading " + url.toString(), null); //$NON-NLS-1$ + } + InputStream is = null; + try { + is = url.openStream(); + if (is == null) { + Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.CANT_OPEN_STREAM_TO_COMPONENT_XML, url), null); + } else { + int compSize = components.size(); + parser.parse(is, bundle, components, url.toString()); + if (compSize == components.size()) { + Activator.log(bundle.getBundleContext(), LogService.LOG_WARNING, NLS.bind(Messages.NO_COMPONENTS_FOUND, url), null); } - try { - is = url.openStream(); - if (is == null) { - Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.CANT_OPEN_STREAM_TO_COMPONENT_XML, url), null); - } else { - int compSize = components.size(); - parser.parse(is, bundle, components, url.toString()); - if (compSize == components.size()) { - Activator.log(bundle.getBundleContext(), LogService.LOG_WARNING, NLS.bind(Messages.NO_COMPONENTS_FOUND, url), null); - } - } - } catch (IOException ie) { - Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.ERROR_OPENING_COMP_XML, url), ie); - } catch (Throwable t) { - Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.ILLEGAL_DEFINITION_FILE, url), t); - } finally { - if (is != null) { - is.close(); - } - } - } // end while - } // end for definitionFiles - } // end for elements + } + } catch (IOException ie) { + Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.ERROR_OPENING_COMP_XML, url), ie); + } catch (Throwable t) { + Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.ILLEGAL_DEFINITION_FILE, url), t); + } finally { + if (is != null) { + is.close(); + } + } + } // end while components = parser.components; // make sure the clean-up the parser cache, for the next bundle to @@ -116,4 +100,27 @@ public abstract class ComponentStorage { return components; } + protected Collection/*<URL>*/computeComponentDefinitionUrls(Bundle bundle, ManifestElement[] elements) { + Collection/*<URL>*/result = new ArrayList/*<URL>*/(5); + // process all definition file + for (int i = 0; i < elements.length; i++) { + String[] definitionFiles = elements[i].getValueComponents(); + for (int j = 0; j < definitionFiles.length; j++) { + String definitionFile = definitionFiles[j]; + int ind = definitionFile.lastIndexOf('/'); + String path = ind != -1 ? definitionFile.substring(0, ind) : "/"; //$NON-NLS-1$ + + Enumeration/*<URL>*/urls = bundle.findEntries(path, ind != -1 ? definitionFile.substring(ind + 1) : definitionFile, false); + if (urls == null || !urls.hasMoreElements()) { + Activator.log(bundle.getBundleContext(), LogService.LOG_ERROR, NLS.bind(Messages.COMPONENT_XML_NOT_FOUND, bundle.getSymbolicName(), definitionFile), null); + continue; + } + + while (urls.hasMoreElements()) + result.add(urls.nextElement()); + } + } + return result; + } + } diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/storage/file/FileStorage.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/storage/file/FileStorage.java index 2886c0b..88a13d1 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/storage/file/FileStorage.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/storage/file/FileStorage.java @@ -14,8 +14,7 @@ package org.eclipse.equinox.internal.ds.storage.file; import java.io.*; import java.net.URL; import java.net.URLConnection; -import java.util.Dictionary; -import java.util.Vector; +import java.util.*; import org.eclipse.equinox.internal.ds.*; import org.eclipse.equinox.internal.ds.model.ServiceComponent; import org.eclipse.equinox.internal.util.io.ExternalizableDictionary; @@ -228,19 +227,17 @@ public class FileStorage extends ComponentStorage { if (bundle == null) return 0; long result = 0; - ManifestElement[] elements = parseManifestHeader(bundle); - for (int i = 0; i < elements.length; i++) { - URL componentURL = bundle.getEntry(elements[i].getValue()); - if (componentURL != null) { - try { - URLConnection connection = componentURL.openConnection(); - long lastModified = connection.getLastModified(); - if (lastModified > result) - result = lastModified; - } catch (IOException e) { - //last modified cannot be calculated. should force reparse - return Long.MAX_VALUE; - } + Collection/*<URL>*/urls = computeComponentDefinitionUrls(bundle, parseManifestHeader(bundle)); + for (Iterator/*<URL>*/i = urls.iterator(); i.hasNext();) { + URL url = (URL) i.next(); + try { + URLConnection connection = url.openConnection(); + long lastModified = connection.getLastModified(); + if (lastModified > result) + result = lastModified; + } catch (IOException e) { + //last modified cannot be calculated. should force reparse + return Long.MAX_VALUE; } } return result; |