You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xbean-scm@geronimo.apache.org by ge...@apache.org on 2012/04/27 15:39:19 UTC
svn commit: r1331428 - in
/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util:
BundleResourceHelper.java BundleUtils.java
Author: genspring
Date: Fri Apr 27 13:39:19 2012
New Revision: 1331428
URL: http://svn.apache.org/viewvc?rev=1331428&view=rev
Log:
Move reference based bundle utils methods from geornimo kerneal to xbean bundleutils because we need to call them from BundleResourceHelper.
Modified:
geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleResourceHelper.java
geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleResourceHelper.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleResourceHelper.java?rev=1331428&r1=1331427&r2=1331428&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleResourceHelper.java (original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleResourceHelper.java Fri Apr 27 13:39:19 2012
@@ -244,7 +244,7 @@ public class BundleResourceHelper {
}
public boolean foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream inputStream) throws Exception {
- URL jarURL = bundle.getEntry(jarName);
+ URL jarURL = BundleUtils.getEntry(bundle, jarName);
URL url = new URL("jar:" + jarURL.toString() + "!/" + entry.getName());
resources.add(url);
return continueScanning;
Modified: geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java?rev=1331428&r1=1331427&r2=1331428&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java (original)
+++ geronimo/xbean/trunk/xbean-bundleutils/src/main/java/org/apache/xbean/osgi/bundle/util/BundleUtils.java Fri Apr 27 13:39:19 2012
@@ -19,6 +19,9 @@
package org.apache.xbean.osgi.bundle.util;
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Dictionary;
@@ -52,6 +55,12 @@ public class BundleUtils {
}
}
+ public final static String REFERENCE_SCHEME = "reference:";
+
+ public final static String FILE_SCHEMA = "file:";
+
+ public final static String REFERENCE_FILE_SCHEMA = "reference:file:";
+
/**
* Based on the constant field values, if it is bigger than the RESOLVED status value, the bundle has been resolved by the framework
* @param bundle
@@ -181,19 +190,35 @@ public class BundleUtils {
}
/**
- * Works like {@link Bundle#getEntry(String)} but also checks
- * attached fragment bundles for the given entry.
+ * 1, If the bundle was installed with reference directory mode
+ * return the file URL directly.
+ * 2, For traditional package bundle, Works like {@link Bundle#getEntry(String)}
+ *
+ * In addition to the searching abaove, it also checks attached fragment bundles for the given entry.
*
* @param bundle
* @param name
* @return
+ * @throws MalformedURLException
*/
- public static URL getEntry(Bundle bundle, String name) {
- if (name.equals("/")) {
- return bundle.getEntry(name);
- } else if (name.endsWith("/")) {
+ public static URL getEntry(Bundle bundle, String name) throws MalformedURLException {
+
+ if (name.endsWith("/")) {
name = name.substring(0, name.length() - 1);
+ }
+
+ File bundleFile = toFile(bundle);
+ if (bundleFile != null && bundleFile.isDirectory()) {
+ File entryFile = new File(bundleFile, name);
+ if (entryFile.exists()) {
+ return entryFile.toURI().toURL();
+ }
}
+
+ if (name.equals("/")) {
+ return bundle.getEntry(name);
+ }
+
String path;
String pattern;
int pos = name.lastIndexOf("/");
@@ -214,6 +239,54 @@ public class BundleUtils {
return null;
}
}
+
+ public static URL getNestedEntry(Bundle bundle, String jarEntryName, String subEntryName) throws MalformedURLException {
+ File bundleFile = toFile(bundle);
+ if (bundleFile != null && bundleFile.isDirectory()) {
+ File entryFile = new File(bundleFile, jarEntryName);
+ if (entryFile.exists()) {
+ if (entryFile.isFile()) {
+ return new URL("jar:" + entryFile.toURI().toURL() + "!/" + subEntryName);
+ } else {
+ return new File(entryFile, subEntryName).toURI().toURL();
+ }
+ }
+ return null;
+ }
+ return new URL("jar:" + bundle.getEntry(jarEntryName).toString() + "!/" + subEntryName);
+ }
+
+
+ public static File toFile(Bundle bundle) {
+ return toFile(bundle.getLocation());
+ }
+
+ public static File toFile(URL url) {
+ return toFile(url.toExternalForm());
+ }
+
+ /**
+ * Translate the reference:file:// style URL to the underlying file instance
+ * @param url
+ * @return
+ */
+ public static File toFile(String url) {
+ if (url.startsWith(REFERENCE_FILE_SCHEMA)) {
+ File file = new File(url.substring(REFERENCE_FILE_SCHEMA.length()));
+ if (file.exists()) {
+ return file;
+ }
+ }
+ return null;
+ }
+
+ public static String toReferenceFileLocation(File file) throws IOException {
+ if (!file.exists()) {
+ throw new IOException("file not exist " + file.getAbsolutePath());
+ }
+ return REFERENCE_SCHEME + file.toURI();
+ }
+
public static LinkedHashSet<Bundle> getWiredBundles(Bundle bundle) {
if (isOSGi43) {