update to throw full stack trace vs just result of getMessage for debug purposes
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@882531 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/BundleForm.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/BundleForm.java
index 6aa0a48..a805611 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/BundleForm.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/BundleForm.java
@@ -20,6 +20,8 @@
import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -31,6 +33,7 @@
import java.util.LinkedList;
import java.util.Set;
import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
@@ -146,7 +149,11 @@
}
URI[] resolved = resolver.resolve(bundles[i]);
for ( URI uri : resolved ) {
- ret.add( toBundle(uri, isStarted(bundles[i])) );
+ BundleStatus bundle = toBundle(uri, isStarted(bundles[i]));
+ if ( bundle == null ) {
+ throw new IllegalStateException("Failed to read bundle " + uri);
+ }
+ ret.add( bundle );
}
}
@@ -156,32 +163,69 @@
private BundleStatus toBundle(URI uri, boolean started) throws IOException
{
- URL url = uri.toURL();
- InputStream in = url.openStream();
try {
- JarInputStream jin = new JarInputStream(in);
- Manifest mf = jin.getManifest();
+ Manifest mf = findManifest(uri);
+ if ( mf == null ) return null;
Attributes attr = mf.getMainAttributes();
String bsn = attr.getValue(Constants.BUNDLE_SYMBOLICNAME);
String ver = attr.getValue(Constants.BUNDLE_VERSION);
BundleStatus st = new BundleStatus();
st.setBundleSymbolicName(bsn);
st.setVersion(ver);
- st.setLocation(url.toExternalForm());
+ st.setLocation(uri.toURL().toExternalForm());
st.setStatus(started ? Bundle.ACTIVE : Bundle.INSTALLED);
return st;
}
- finally {
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid uri " + uri, e);
+ }
+ }
+
+ private Manifest findManifest(URI uri) throws IOException
+ {
+ Manifest mf = null;
+
+ try {
+ File f = new File(uri);
+ if ( f.isDirectory() ) {
+ f = new File(f, "META-INF/MANIFEST.MF" );
+ if ( f.isFile() ) {
+ FileInputStream fin = new FileInputStream(f);
+ try {
+ mf = new Manifest(fin);
+ }
+ finally {
+ fin.close();
+ }
+ }
}
}
+ catch (IllegalArgumentException e) {
+ // fine
+ }
+
+ if ( mf == null) {
+ InputStream in = uri.toURL().openStream();
+ try {
+ JarInputStream jin = new JarInputStream(in);
+ mf = jin.getManifest();
+ if ( mf == null ) {
+ for(;;) {
+ JarEntry entry = jin.getNextJarEntry();
+ if ( entry == null ) break;
+ if ( "META-INF/MANIFEST.MF".equals(entry.getName()) ) {
+ mf = new Manifest(jin);
+ break;
+ }
+ }
+ }
+
+ }
+ finally {
+ in.close();
+ }
+ }
+ return mf;
}
public static BundleForm create(URL formURL) throws IOException, URISyntaxException {
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java
index c3fe114..3beef14 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/Action.java
@@ -20,9 +20,11 @@
package org.apache.felix.sigil.common.runtime.io;
+import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.io.PrintStream;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
@@ -39,6 +41,7 @@
*/
public abstract class Action<I, O>
{
+ private static final String PREFIX = "\t";
private static final String ASCII = "ASCII";
private final DataInputStream in;
private final DataOutputStream out;
@@ -89,6 +92,11 @@
writeInt( ERROR );
}
+ protected void writeThrowable(Throwable t) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ t.printStackTrace(new PrintStream( bos ));
+ writeString( bos.toString() );
+ }
protected String readString() throws IOException
{
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/InstallAction.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/InstallAction.java
index 4156197..3a822ec 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/InstallAction.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/InstallAction.java
@@ -75,8 +75,9 @@
}
catch ( BundleException e )
{
+ e.printStackTrace();
writeError();
- writeString( e.getMessage() );
+ writeThrowable( e );
}
flush();
}
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StartAction.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StartAction.java
index 6790f74..41958cc 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StartAction.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StartAction.java
@@ -80,7 +80,7 @@
catch ( BundleException e )
{
writeError();
- writeString( e.getMessage() );
+ writeThrowable(e);
}
}
flush();
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StopAction.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StopAction.java
index 9588a25..a44818b 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StopAction.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/StopAction.java
@@ -79,7 +79,7 @@
catch ( BundleException e )
{
writeError();
- writeString( e.getMessage() );
+ writeThrowable( e );
}
}
}
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UninstallAction.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UninstallAction.java
index 0abb739..eddf847 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UninstallAction.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UninstallAction.java
@@ -78,7 +78,7 @@
catch ( BundleException e )
{
writeError();
- writeString( e.getMessage() );
+ writeThrowable( e );
}
}
}
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java
index 562fb14..905e0b7 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/io/UpdateAction.java
@@ -116,7 +116,7 @@
}
catch (IOException e) {
writeError();
- writeString(e.getMessage());
+ writeThrowable( e );
}
}
else