Further patches related to FELIX-1324 - now abstracts uri scheme behind a resolver that allows for substitution of "real" urls for meta stubs:
start:sigil:<bsn>:version
for example
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@831004 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/common/runtime/sigil.properties b/sigil/common/runtime/sigil.properties
index 23156cc..e2144c0 100644
--- a/sigil/common/runtime/sigil.properties
+++ b/sigil/common/runtime/sigil.properties
@@ -12,7 +12,7 @@
org.apache.felix.sigil.common.runtime, \
-imports: \
- org.apache.felix.sigil.common.runtime,\
+ org.apache.felix.sigil.common.runtime, \
org.osgi.framework, \
org.osgi.framework.launch, \
org.osgi.service.packageadmin, \
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 57c1ed7..6aa0a48 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
@@ -19,6 +19,7 @@
package org.apache.felix.sigil.common.runtime;
import java.io.BufferedReader;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -38,6 +39,30 @@
public class BundleForm
{
+ public interface Resolver {
+ URI[] resolve(URI base) throws URISyntaxException;
+ }
+
+ public interface ResolutionContext {
+ Resolver findResolver(URI uri);
+ }
+
+ private static final Resolver NULL_RESOLVER = new Resolver() {
+
+ public URI[] resolve(URI base)
+ {
+ return new URI[] { base };
+ }
+
+ };
+ private static final ResolutionContext NULL_CONTEXT = new ResolutionContext()
+ {
+ public Resolver findResolver(URI uri)
+ {
+ return NULL_RESOLVER;
+ }
+ };
+
public static class BundleStatus
{
private String location;
@@ -101,29 +126,83 @@
}
}
- private String[] bundles;
- private Set<String> startMap = new HashSet<String>();
+ private URI[] bundles;
+ private Set<URI> startMap = new HashSet<URI>();
public BundleForm() {
}
- public static BundleForm resolve(URL formURL) throws IOException, URISyntaxException {
+ public BundleStatus[] resolve(ResolutionContext ctx) throws IOException, URISyntaxException {
+ if ( ctx == null ) {
+ ctx = NULL_CONTEXT;
+ }
+
+ ArrayList<BundleStatus> ret = new ArrayList<BundleStatus>(bundles.length);
+
+ for ( int i = 0; i < bundles.length; i++ ) {
+ Resolver resolver = ctx.findResolver(bundles[i]);
+ if ( resolver == null ) {
+ resolver = NULL_RESOLVER;
+ }
+ URI[] resolved = resolver.resolve(bundles[i]);
+ for ( URI uri : resolved ) {
+ ret.add( toBundle(uri, isStarted(bundles[i])) );
+ }
+ }
+
+ return ret.toArray(new BundleStatus[ret.size()] );
+
+ }
+
+ 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();
+ 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.setStatus(started ? Bundle.ACTIVE : Bundle.INSTALLED);
+ return st;
+ }
+ finally {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static BundleForm create(URL formURL) throws IOException, URISyntaxException {
InputStream in = formURL.openStream();
try {
BundleForm f = new BundleForm();
BufferedReader r = new BufferedReader(new InputStreamReader(in));
- LinkedList<String> locs = new LinkedList<String>();
+ LinkedList<URI> locs = new LinkedList<URI>();
for(;;) {
String l = r.readLine();
if ( l == null ) break;
- URI uri = URI.create(l);
- String status = uri.getScheme();
- uri = URI.create(uri.getSchemeSpecificPart());
- String loc = uri.toString();
- locs.add( loc );
- f.setStarted(loc, "start".equalsIgnoreCase(status) );
+ l = l.trim();
+ if ( !l.startsWith( "#" ) ) {
+ URI uri = URI.create(l);
+ String status = uri.getScheme();
+ uri = URI.create(uri.getSchemeSpecificPart());
+ locs.add( uri );
+ f.setStarted(uri, "start".equalsIgnoreCase(status) );
+ }
}
- f.setBundles(locs.toArray(new String[locs.size()]));
+ f.setBundles(locs.toArray(new URI[locs.size()]));
return f;
}
finally {
@@ -139,59 +218,26 @@
}
}
- public void setBundles(String[] bundles) {
+ public void setBundles(URI[] bundles) {
this.bundles = bundles;
}
- public String[] getBundles()
+ public URI[] getBundles()
{
return bundles;
}
- public boolean isStarted(String url)
+ public boolean isStarted(URI uri)
{
- return startMap.contains(url);
+ return startMap.contains(uri);
}
- public void setStarted(String url, boolean started) {
+ public void setStarted(URI uri, boolean started) {
if ( started ) {
- startMap.add(url);
+ startMap.add(uri);
}
else {
- startMap.remove(url);
+ startMap.remove(uri);
}
- }
-
- public BundleStatus[] toStatus() throws IOException {
- ArrayList<BundleStatus> ret = new ArrayList<BundleStatus>(bundles.length);
- for ( String loc : bundles ) {
- URL url = new URL(loc);
- InputStream in = url.openStream();
- try {
- JarInputStream jin = new JarInputStream(in);
- Manifest mf = jin.getManifest();
- 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(loc);
- st.setStatus(isStarted(loc) ? Bundle.ACTIVE : Bundle.INSTALLED);
- ret.add(st);
- }
- finally {
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- return ret.toArray(new BundleStatus[ret.size()] );
- }
+ }
}
diff --git a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/Client.java b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/Client.java
index 807b783..8f9daa3 100644
--- a/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/Client.java
+++ b/sigil/common/runtime/src/org/apache/felix/sigil/common/runtime/Client.java
@@ -92,9 +92,7 @@
out = null;
}
- public void apply(BundleForm form) throws IOException, BundleException {
- BundleStatus[] newStatus = form.toStatus();
-
+ public void apply(BundleForm.BundleStatus[] newStatus) throws IOException, BundleException {
BundleStatus[] currentStatus = status();
stopOldBundles(currentStatus, newStatus);