You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2010/02/05 07:55:31 UTC
svn commit: r906827 - in
/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi:
BundleResourceFinder.java jar/ jar/BundleJarEntry.java jar/BundleJarFile.java
Author: gawor
Date: Fri Feb 5 06:55:31 2010
New Revision: 906827
URL: http://svn.apache.org/viewvc?rev=906827&view=rev
Log:
some updates to BundleResourceFinder and added JarFile facade for a bundle object
Added:
geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/
geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java (with props)
geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java (with props)
Modified:
geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java
Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java?rev=906827&r1=906826&r2=906827&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/BundleResourceFinder.java Fri Feb 5 06:55:31 2010
@@ -20,7 +20,7 @@
package org.apache.geronimo.kernel.osgi;
import java.io.IOException;
-import java.net.MalformedURLException;
+import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.LinkedHashSet;
@@ -102,7 +102,7 @@
Enumeration e = bundle.findEntries(basePath, "*" + suffix, true);
if (e != null) {
while (e.hasMoreElements()) {
- callback.foundDirectory(bundle, basePath, (URL) e.nextElement());
+ callback.foundInDirectory(bundle, basePath, (URL) e.nextElement());
}
}
}
@@ -118,7 +118,7 @@
while ((entry = in.getNextEntry()) != null) {
String name = entry.getName();
if (prefixMatches(name) && suffixMatches(name)) {
- callback.foundJar(bundle, zipName, entry);
+ callback.foundInJar(bundle, zipName, entry, in);
}
}
} catch (IOException e) {
@@ -148,9 +148,9 @@
}
public interface ResourceFinderCallback {
- void foundDirectory(Bundle bundle, String baseDir, URL url) throws Exception;
+ void foundInDirectory(Bundle bundle, String baseDir, URL url) throws Exception;
- void foundJar(Bundle bundle, String jarName, ZipEntry entry) throws Exception;
+ void foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream in) throws Exception;
}
public static class DefaultResourceFinderCallback implements ResourceFinderCallback {
@@ -169,11 +169,11 @@
return resources;
}
- public void foundDirectory(Bundle bundle, String baseDir, URL url) throws Exception {
+ public void foundInDirectory(Bundle bundle, String baseDir, URL url) throws Exception {
resources.add(url);
}
- public void foundJar(Bundle bundle, String jarName, ZipEntry entry) throws Exception {
+ public void foundInJar(Bundle bundle, String jarName, ZipEntry entry, InputStream in) throws Exception {
URL jarURL = bundle.getEntry(jarName);
URL url = new URL("jar:" + jarURL.toString() + "!/" + entry.getName());
resources.add(url);
Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java?rev=906827&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java Fri Feb 5 06:55:31 2010
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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.
+ */
+package org.apache.geronimo.kernel.osgi.jar;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BundleJarEntry extends JarEntry {
+ private final URL entryURL;
+ private final Manifest manifest;
+
+ public BundleJarEntry(String name, URL entryURL, Manifest manifest) {
+ super(name);
+ this.entryURL = entryURL;
+ this.manifest = manifest;
+ }
+
+ public URL getEntryURL() {
+ return entryURL;
+ }
+
+ public Attributes getAttributes() throws IOException {
+ if (manifest == null) {
+ return null;
+ }
+ return manifest.getAttributes(getName());
+ }
+
+ public Certificate[] getCertificates() {
+ return null;
+ }
+
+ public void setTime(long time) throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("Can not change the time of unpacked jar entry");
+ }
+
+ public long getTime() {
+ return -1;
+ }
+
+ public void setSize(long size) throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("Can not change the size of unpacked jar entry");
+ }
+
+ public long getSize() {
+ return -1;
+ }
+
+ public long getCompressedSize() {
+ return getSize();
+ }
+
+ public void setCompressedSize(long compressedSize) {
+ throw new UnsupportedOperationException("Can not change the compressed size of unpacked jar entry");
+ }
+
+ public long getCrc() {
+ return super.getCrc();
+ }
+
+ public void setCrc(long crc) {
+ throw new UnsupportedOperationException("Can not change the crc of unpacked jar entry");
+ }
+
+ public int getMethod() {
+ return ZipEntry.STORED;
+ }
+
+ public void setMethod(int method) {
+ throw new UnsupportedOperationException("Can not change the method of unpacked jar entry");
+ }
+
+ public byte[] getExtra() {
+ return null;
+ }
+
+ public void setExtra(byte[] extra) {
+ throw new UnsupportedOperationException("Can not change the extra data of unpacked jar entry");
+ }
+
+ public String getComment() {
+ return null;
+ }
+
+ public void setComment(String comment) {
+ throw new UnsupportedOperationException("Can not change the comment of unpacked jar entry");
+ }
+
+ public boolean isDirectory() {
+ return entryURL.getPath().endsWith("/");
+ }
+
+}
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarEntry.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java?rev=906827&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java (added)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java Fri Feb 5 06:55:31 2010
@@ -0,0 +1,139 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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.
+ */
+package org.apache.geronimo.kernel.osgi.jar;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.apache.geronimo.kernel.util.IOUtils;
+import org.apache.geronimo.kernel.util.JarUtils;
+import org.osgi.framework.Bundle;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BundleJarFile extends JarFile {
+
+ private final Bundle bundle;
+ private boolean manifestLoaded = false;
+ private Manifest manifest;
+
+ public BundleJarFile(Bundle bundle) throws IOException {
+ super(JarUtils.DUMMY_JAR_FILE);
+ this.bundle = bundle;
+ }
+
+ public Bundle getBundle() {
+ return bundle;
+ }
+
+ public Manifest getManifest() throws IOException {
+ if (!manifestLoaded) {
+ URL manifestURL = bundle.getEntry("META-INF/MANIFEST.MF");
+ if (manifestURL != null) {
+ InputStream in = null;
+ try {
+ in = manifestURL.openStream();
+ manifest = new Manifest(in);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ manifestLoaded = true;
+ }
+ return manifest;
+ }
+
+ public BundleJarEntry getBundleJarEntry(String name) {
+ URL url = bundle.getEntry(name);
+ if (url == null) {
+ return null;
+ }
+ return new BundleJarEntry(name, url, getManifestSafe());
+ }
+
+ public JarEntry getJarEntry(String name) {
+ return getBundleJarEntry(name);
+ }
+
+ public ZipEntry getEntry(String name) {
+ return getBundleJarEntry(name);
+ }
+
+ public Enumeration entries() {
+ Manifest manifest = getManifestSafe();
+ Enumeration e = bundle.findEntries("/", "*", true);
+ LinkedList entries = new LinkedList();
+ while (e.hasMoreElements()) {
+ URL entryURL = (URL) e.nextElement();
+ entries.add(new BundleJarEntry(entryURL.getPath(), entryURL, manifest));
+ }
+ return Collections.enumeration(entries);
+ }
+
+ public InputStream getInputStream(ZipEntry zipEntry) throws IOException {
+ BundleJarEntry entry;
+ if (zipEntry instanceof BundleJarEntry) {
+ entry = (BundleJarEntry) zipEntry;
+ } else {
+ entry = getBundleJarEntry(zipEntry.getName());
+ }
+
+ if (entry == null) {
+ throw new IOException("Entry not found: name=" + zipEntry.getName());
+ } else if (entry.isDirectory()) {
+ return new IOUtils.EmptyInputStream();
+ } else {
+ return entry.getEntryURL().openStream();
+ }
+ }
+
+ public String getName() {
+ return bundle.getSymbolicName();
+ }
+
+ public int size() {
+ return -1;
+ }
+
+ public void close() throws IOException {
+ }
+
+ private Manifest getManifestSafe() {
+ Manifest manifest = null;
+ try {
+ manifest = getManifest();
+ } catch (IOException e) {
+ // ignore
+ }
+ return manifest;
+ }
+}
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/osgi/jar/BundleJarFile.java
------------------------------------------------------------------------------
svn:mime-type = text/plain