summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/contribution-osgi/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-13 19:28:31 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-04-13 19:28:31 +0000
commitfb5e8b3e96c37d4099a5468256e1132e527a05eb (patch)
treeafa814ad982f1e05160eb83bf15578fce8fafd2f /java/sca/modules/contribution-osgi/src
parent3fee48a0cb04ca9bf57fabe3846a15d7ce0f3232 (diff)
Start to add the DefinitionsExtensionPoint
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@764574 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/contribution-osgi/src')
-rw-r--r--java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionScanner.java106
1 files changed, 52 insertions, 54 deletions
diff --git a/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionScanner.java b/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionScanner.java
index d64d2ec46c..0b32d7ac10 100644
--- a/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionScanner.java
+++ b/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleContributionScanner.java
@@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
package org.apache.tuscany.sca.contribution.osgi.impl;
@@ -56,72 +56,70 @@ public class OSGiBundleContributionScanner implements ContributionScanner {
bundle = OSGiBundleActivator.findBundle(sourceURL);
if (bundle != null) {
URL url = bundle.getResource(artifact);
- if (url == null)
- System.out.println("Could not load resource " + artifact);
return url;
}
} catch (Exception e) {
}
return null;
}
-
- public List<String> getJarArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException,
- IOException {
- if (packageSourceURL == null) {
- throw new IllegalArgumentException("Invalid null package source URL.");
- }
- if (inputStream == null) {
- throw new IllegalArgumentException("Invalid null source inputstream.");
- }
+ public List<String> getJarArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException,
+ IOException {
+ if (packageSourceURL == null) {
+ throw new IllegalArgumentException("Invalid null package source URL.");
+ }
- // Assume the root is a jar file
- JarInputStream jar = new JarInputStream(inputStream);
- try {
- Set<String> names = new HashSet<String>();
- while (true) {
- JarEntry entry = jar.getNextJarEntry();
- if (entry == null) {
- // EOF
- break;
- }
+ if (inputStream == null) {
+ throw new IllegalArgumentException("Invalid null source inputstream.");
+ }
- // FIXME: Maybe we should externalize the filter as a property
- String name = entry.getName();
- if (!name.startsWith(".") && !entry.isDirectory()) {
-
- // Trim trailing /
- if (name.endsWith("/")) {
- name = name.substring(0, name.length() - 1);
+ // Assume the root is a jar file
+ JarInputStream jar = new JarInputStream(inputStream);
+ try {
+ Set<String> names = new HashSet<String>();
+ while (true) {
+ JarEntry entry = jar.getNextJarEntry();
+ if (entry == null) {
+ // EOF
+ break;
}
- // Add the entry name
- if (!names.contains(name) && name.length() > 0) {
- names.add(name);
-
+ // FIXME: Maybe we should externalize the filter as a property
+ String name = entry.getName();
+ if (!name.startsWith(".") && !entry.isDirectory()) {
+
+ // Trim trailing /
+ if (name.endsWith("/")) {
+ name = name.substring(0, name.length() - 1);
+ }
+
+ // Add the entry name
+ if (!names.contains(name) && name.length() > 0) {
+ names.add(name);
+
+ }
}
}
+
+ // Return list of URIs
+ List<String> artifacts = new ArrayList<String>();
+ for (String name : names) {
+ artifacts.add(name);
+ }
+ return artifacts;
+
+ } finally {
+ jar.close();
}
-
- // Return list of URIs
- List<String> artifacts = new ArrayList<String>();
- for (String name: names) {
- artifacts.add(name);
- }
- return artifacts;
-
- } finally {
- jar.close();
}
-}
public List<String> getArtifacts(URL packageSourceURL) throws ContributionReadException {
-
+
if (packageSourceURL == null) {
throw new IllegalArgumentException("Invalid null package source URL.");
}
Bundle bundle = OSGiBundleActivator.findBundle(packageSourceURL);
-
+
if (bundle == null) {
throw new IllegalArgumentException("Could not find OSGi bundle " + packageSourceURL);
}
@@ -133,16 +131,16 @@ public class OSGiBundleContributionScanner implements ContributionScanner {
while (entries.hasMoreElements()) {
URL entry = (URL)entries.nextElement();
String entryName = entry.getPath();
- if (entryName.startsWith("/"))
+ if (entryName.startsWith("/")) {
entryName = entryName.substring(1);
+ }
artifacts.add(entryName);
-
- if (entryName.endsWith(".jar")) {
- URL jarResource = bundle.getResource(entryName);
- artifacts.addAll(getJarArtifacts(jarResource, jarResource.openStream()));
+ // FIXME: We probably should honor Bundle-ClassPath headers to deal with inner jars
+ if (entryName.endsWith(".jar")) {
+ artifacts.addAll(getJarArtifacts(entry, entry.openStream()));
}
-
+
}
} catch (Exception e) {
throw new RuntimeException(e);