Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-02-16 15:57:50 +0000
committerThomas Watson2011-02-16 15:57:50 +0000
commitff19c1c47e54a5c00a1f114e2768b3a99d7f3d82 (patch)
tree7199b0a38ad35875491c895fe651de60180556a0
parentbdf83d63c4d084455187e7014a384ed66d439bc5 (diff)
downloadrt.equinox.bundles-20110216.tar.gz
rt.equinox.bundles-20110216.tar.xz
rt.equinox.bundles-20110216.zip
Bug 337219 - Metatype Impl failing CT due to recent change in Bundle Wiring APIv20110221v20110216OSGI_R4_3_Wiring
-rw-r--r--bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/FragmentUtils.java70
-rw-r--r--bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/MetaTypeProviderImpl.java88
2 files changed, 56 insertions, 102 deletions
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/FragmentUtils.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/FragmentUtils.java
index 0bd4d2792..0253eaa9e 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/FragmentUtils.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/FragmentUtils.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 IBM Corporation.
+ * Copyright (c) 2005, 2011 IBM Corporation.
* 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
@@ -11,7 +11,7 @@
package org.eclipse.equinox.metatype;
import java.net.URL;
-import java.util.*;
+import java.util.List;
import org.osgi.framework.Bundle;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWiring;
@@ -29,60 +29,30 @@ public class FragmentUtils {
}
/*
- * Find all the paths to entries for the bundle and its fragments.
- * Returned data is got by Bundle.getEntryPaths().
- */
- public static Enumeration<String> findEntryPaths(Bundle bundle, String path) {
- BundleWiring wiring = bundle.adapt(BundleWiring.class);
- if (wiring == null)
- return null;
-
- Vector<String> result = new Vector<String>();
- addEntryPaths(bundle.getEntryPaths(path), result);
- List<BundleRevision> fragments = wiring.getFragmentRevisions();
- if (fragments != null) {
- for (BundleRevision fragment : fragments)
- addEntryPaths(fragment.getBundle().getEntryPaths(path), result);
- }
- return result.size() == 0 ? null : result.elements();
- }
-
- /*
- * Internal method - add an path to vector, and check for duplucate.
- */
- private static void addEntryPaths(Enumeration<String> ePaths, Vector<String> pathList) {
-
- if (ePaths == null)
- return;
- while (ePaths.hasMoreElements()) {
- String path = ePaths.nextElement();
- if (!pathList.contains(path))
- pathList.add(path);
- }
- }
-
- /*
* Find all the URLs to entries for the bundle and its fragments.
- * Returned data is got by Bundle.getEntry().
*/
public static URL[] findEntries(Bundle bundle, String path) {
BundleWiring wiring = bundle.adapt(BundleWiring.class);
if (wiring == null)
return null;
-
- URL url = bundle.getEntry(path);
- List<BundleRevision> fragments = wiring.getFragmentRevisions();
- if (fragments == null || fragments.size() == 0)
- return url == null ? null : new URL[] {url};
- ArrayList<URL> result = new ArrayList<URL>();
- if (url != null)
- result.add(url);
-
- for (BundleRevision fragment : fragments) {
- URL fragUrl = fragment.getBundle().getEntry(path);
- if (fragUrl != null)
- result.add(fragUrl);
+ String directory = "/"; //$NON-NLS-1$
+ String file = "*"; //$NON-NLS-1$
+ int index = path.lastIndexOf(MetaTypeProviderImpl.DIRECTORY_SEP);
+ switch (index) {
+ case -1 :
+ file = path;
+ break;
+ case 0 :
+ if (path.length() > 1)
+ file = path.substring(1);
+ break;
+ default :
+ directory = path.substring(0, index);
+ file = path.substring(index + 1);
}
- return result.size() == 0 ? null : result.toArray(new URL[result.size()]);
+ List<URL> entries = wiring.findEntries(directory, file, 0);
+ if (entries == null)
+ return null;
+ return entries.toArray(new URL[entries.size()]);
}
}
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/MetaTypeProviderImpl.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/MetaTypeProviderImpl.java
index d84c99d84..d52c44075 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/MetaTypeProviderImpl.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/MetaTypeProviderImpl.java
@@ -11,11 +11,13 @@
package org.eclipse.equinox.metatype;
import java.io.IOException;
+import java.net.URL;
import java.util.*;
import javax.xml.parsers.SAXParserFactory;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleWiring;
import org.osgi.service.log.LogService;
import org.osgi.service.metatype.*;
@@ -82,50 +84,30 @@ public class MetaTypeProviderImpl implements MetaTypeProvider {
* @throws IOException If there are errors accessing the metadata.xml file
*/
private boolean readMetaFiles(Bundle bundle, SAXParserFactory parserFactory) throws IOException {
-
- boolean isThereMetaHere = false;
-
- Enumeration<String> allFileKeys = FragmentUtils.findEntryPaths(bundle, MetaTypeService.METATYPE_DOCUMENTS_LOCATION);
- if (allFileKeys == null)
- return isThereMetaHere;
-
- while (allFileKeys.hasMoreElements()) {
- boolean _isMetaDataFile;
- String fileName = allFileKeys.nextElement();
-
- Collection<Designate> designates = null;
- java.net.URL[] urls = FragmentUtils.findEntries(bundle, fileName);
- if (urls != null) {
- for (int i = 0; i < urls.length; i++) {
- try {
- // Assume all XML files are what we want by default.
- _isMetaDataFile = true;
- DataParser parser = new DataParser(bundle, urls[i], parserFactory, logger);
- designates = parser.doParse();
- if (designates.isEmpty()) {
- _isMetaDataFile = false;
- }
- } catch (Exception e) {
- // Ok, looks like it is not what we want.
- _isMetaDataFile = false;
- }
-
- if (_isMetaDataFile) {
- // We got some OCDs now.
- isThereMetaHere = true;
- for (Designate d : designates) {
- if (d.isFactory()) {
- _allFPidOCDs.put(d.getFactoryPid(), d.getObjectClassDefinition());
- } else {
- _allPidOCDs.put(d.getPid(), d.getObjectClassDefinition());
- }
- }
- }
+ BundleWiring wiring = bundle.adapt(BundleWiring.class);
+ if (wiring == null)
+ return false;
+ List<URL> entries = wiring.findEntries(MetaTypeService.METATYPE_DOCUMENTS_LOCATION, "*", 0); //$NON-NLS-1$
+ if (entries == null)
+ return false;
+ boolean result = false;
+ for (URL entry : entries) {
+ DataParser parser = new DataParser(bundle, entry, parserFactory, logger);
+ try {
+ Collection<Designate> designates = parser.doParse();
+ if (!designates.isEmpty())
+ result = true;
+ for (Designate designate : designates) {
+ if (designate.isFactory())
+ _allFPidOCDs.put(designate.getFactoryPid(), designate.getObjectClassDefinition());
+ else
+ _allPidOCDs.put(designate.getPid(), designate.getObjectClassDefinition());
}
- } // End of if(urls!=null)
- } // End of while
-
- return isThereMetaHere;
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ return result;
}
/*
@@ -183,7 +165,9 @@ public class MetaTypeProviderImpl implements MetaTypeProvider {
if (_locales != null)
return checkForDefault(_locales);
-
+ BundleWiring wiring = _bundle.adapt(BundleWiring.class);
+ if (wiring == null)
+ return null;
Vector<String> localizationFiles = new Vector<String>(7);
// get all the localization resources for PIDS
Enumeration<ObjectClassDefinitionImpl> ocds = _allPidOCDs.elements();
@@ -213,14 +197,14 @@ public class MetaTypeProviderImpl implements MetaTypeProvider {
} else {
baseDir = localizationFile.substring(0, iSlash);
}
- baseFileName = localizationFile + RESOURCE_FILE_CONN;
- Enumeration<String> resources = FragmentUtils.findEntryPaths(this._bundle, baseDir);
- if (resources != null) {
- while (resources.hasMoreElements()) {
- String resource = resources.nextElement();
- if (resource.startsWith(baseFileName) && resource.toLowerCase().endsWith(RESOURCE_FILE_EXT))
- locales.add(resource.substring(baseFileName.length(), resource.length() - RESOURCE_FILE_EXT.length()));
- }
+ baseFileName = '/' + localizationFile + RESOURCE_FILE_CONN;
+ List<URL> entries = wiring.findEntries(baseDir, "*.properties", 0); //$NON-NLS-1$
+ if (entries == null)
+ continue;
+ for (URL entry : entries) {
+ String resource = entry.getPath();
+ if (resource.startsWith(baseFileName) && resource.toLowerCase().endsWith(RESOURCE_FILE_EXT))
+ locales.add(resource.substring(baseFileName.length(), resource.length() - RESOURCE_FILE_EXT.length()));
}
}
_locales = locales.toArray(new String[locales.size()]);

Back to the top