Tried to update the launcher to use standard embedding and launching API.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@790997 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/gogo/gogo.launcher/pom.xml b/gogo/gogo.launcher/pom.xml
index 273e922..32e07b5 100644
--- a/gogo/gogo.launcher/pom.xml
+++ b/gogo/gogo.launcher/pom.xml
@@ -31,7 +31,8 @@
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
- <artifactId>org.osgi.core</artifactId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>1.8.1</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git a/gogo/gogo.launcher/src/main/java/org/apache/felix/gogo/launcher/Launcher.java b/gogo/gogo.launcher/src/main/java/org/apache/felix/gogo/launcher/Launcher.java
index e1fe721..5ac5272 100644
--- a/gogo/gogo.launcher/src/main/java/org/apache/felix/gogo/launcher/Launcher.java
+++ b/gogo/gogo.launcher/src/main/java/org/apache/felix/gogo/launcher/Launcher.java
@@ -22,7 +22,8 @@
import org.apache.felix.gogo.runtime.threadio.ThreadIOImpl;
import org.apache.felix.gogo.console.stdio.Console;
import org.osgi.framework.Bundle;
-import org.osgi.service.command.CommandProcessor;
+import org.osgi.framework.launch.FrameworkFactory;
+import org.osgi.framework.launch.Framework;
import org.osgi.service.command.CommandSession;
import java.io.*;
@@ -40,7 +41,7 @@
public static void main(String args[]) throws Exception
{
StringBuffer sb = new StringBuffer();
- String framework = null;
+ String fwkClassName = null;
PrintStream out = System.out;
InputStream in = System.in;
boolean console = false;
@@ -50,7 +51,7 @@
String arg = args[i];
if (arg.equals("-f"))
{
- framework = args[++i];
+ fwkClassName = args[++i];
}
else
{
@@ -87,28 +88,31 @@
}
}
- if (framework == null)
+ URL[] urls = classpath.toArray(new URL[classpath.size()]);
+ URLClassLoader cl = new URLClassLoader(urls, Launcher.class.getClassLoader());
+
+ Properties p = new Properties(System.getProperties());
+
+ Framework framework;
+ if (fwkClassName == null)
{
- System.err.println("No framework set");
- System.exit(1);
+ framework = getFrameworkFactory(cl).newFramework(p);
+ }
+ else
+ {
+ Class<?> fw = cl.loadClass(fwkClassName);
+ Constructor<?> c = fw.getConstructor(Map.class, List.class);
+ framework = (Framework) c.newInstance(p);
}
ThreadIOImpl threadio = new ThreadIOImpl();
threadio.start();
- URL[] urls = classpath.toArray(new URL[classpath.size()]);
- URLClassLoader urlcl = new URLClassLoader(urls, Launcher.class.getClassLoader());
- Class<?> fw = urlcl.loadClass(framework);
-
- Constructor<?> c = fw.getConstructor(Map.class, List.class);
- Properties p = new Properties(System.getProperties());
- Bundle bundle = (Bundle) c.newInstance(p, null);
OSGiShell shell = new OSGiShell();
shell.setThreadio(threadio);
- shell.setBundle(bundle);
+ shell.setBundle(framework);
shell.start();
-
CommandSession session = shell.createSession(in, out, System.err);
session.put("shell", shell);
session.put("threadio", threadio);
@@ -116,7 +120,7 @@
session.execute(sb);
out.flush();
- if (bundle.getState() == Bundle.ACTIVE)
+ if (framework.getState() == Bundle.ACTIVE)
{
}
if (console)
@@ -127,6 +131,42 @@
}
}
+ /**
+ * Simple method to search for META-INF/services for a FrameworkFactory
+ * provider. It simply looks for the first non-commented line and assumes
+ * it is the name of the provider class.
+ * @return a <tt>FrameworkFactory</tt> instance.
+ * @throws Exception if anything goes wrong.
+ **/
+ private static FrameworkFactory getFrameworkFactory(ClassLoader cl)
+ throws Exception
+ {
+ URL url = cl.getResource(
+ "META-INF/services/org.osgi.framework.launch.FrameworkFactory");
+ if (url != null)
+ {
+ BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
+ try
+ {
+ for (String s = br.readLine(); s != null; s = br.readLine())
+ {
+ s = s.trim();
+ // Try to load first non-empty, non-commented line.
+ if ((s.length() > 0) && (s.charAt(0) != '#'))
+ {
+ return (FrameworkFactory) cl.loadClass(s).newInstance();
+ }
+ }
+ }
+ finally
+ {
+ if (br != null) br.close();
+ }
+ }
+
+ throw new Exception("Could not find framework factory.");
+ }
+
private static void classpath(String string) throws MalformedURLException
{
StringTokenizer st = new StringTokenizer(string, File.pathSeparator);