On 8/7/09 9:27, David Savage wrote:
On Fri, Aug 7, 2009 at 2:04 PM, Richard S. Hall<[email protected]> wrote:
On 8/7/09 4:44, David Savage wrote:
So the idea is to create an Eclipse PDE Framework Launcher hooked into
the Sigil project model that uses the RFC 132 launching api vs a
framework specific mechanism. This would allow sigil to launch any
OSGi framework from this common API. There are some gotcha's here
though - it looks like the equinox 3.5 release and the spec didn't
quite meet - so from my testing so far it looks like equinox is
expecting some framework specific headers that aren't in the spec :-s.
I haven't yet tried the equinox trunk so perhaps this is fixed by now?
Really? Like what? I have used a common launcher to launch both Equinox and
Felix...it was a simple launcher, but it worked.
So I'm seeing the following error message:
Exception in thread "main" java.lang.IllegalArgumentException: Cannot
start without the following system properties set: osgi.framework,
osgi.install.area
at
org.eclipse.osgi.framework.internal.core.FrameworkProperties.initializeProperties(FrameworkProperties.java:120)
at
org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalInit(EquinoxLauncher.java:65)
at
org.eclipse.osgi.framework.internal.core.EquinoxLauncher.init(EquinoxLauncher.java:38)
at org.eclipse.osgi.launch.Equinox.init(Equinox.java:89)
at org.apache.felix.sigil.common.runtime.Main.main(Main.java:47)
This is when using org.eclipse.osgi_3.5.100.v20090629.jar which I
resolve from the spring bundle repository - I guess there's the added
possibility that the bundle in the spring repository is not the latest
3.5 from eclipse?
I am told that this is a very early build of Equinox 3.6, so it doesn't
sound like it is a good one to use.
From what I am told, Equinox assumes it is loaded from a class loader
with a protection domain that provides CodeSource objects, e.g.,
URLClassLoader, so it may be failing depending on how you are loading
its framework classes. The other workaround is to set osgi.framework to
a file: URL that points to the org.eclipse.osgi jar and
osgi.install.area to a file: URL that points to the directory the
org.eclipse.osgi jar is located.
Of course, the easy way to avoid all of this is to always use Felix. ;-)
I've just committed the skeleton code I've been putting together for a
sigil launcher in svn revision 801990 - it's trivial at this stage as
I haven't had much time to look at this yet, also by the sounds of
things I might be duplicating effort if I'm able to use the launcher
you refer to?
Well, the launching code I am referring to is based on the code from our
book:
http://code.google.com/p/osgi-in-action/source/browse/trunk/launcher/src/launcher/Main.java
However, to work with Equinox I created the attached modified version,
which I will try to merge back into the above example.
-> richard
package launcher;
import java.io.*;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.*;
import org.osgi.framework.*;
import org.osgi.framework.launch.*;
public class Main {
private static Framework fwk;
public static void main(String[] args) throws Exception {
if (args.length != 1 || !new File(args[0]).isDirectory()) {
System.out.println("Usage: <bundle-directory>");
} else {
File[] files = new File(args[0]).listFiles();
Arrays.sort(files);
List<File> jars = new ArrayList<File>();
for (int i = 0; i < files.length; i++)
if (files[i].getName().endsWith(".jar"))
jars.add(files[i]);
if (jars.isEmpty()) {
System.out.println("No bundles to install.");
} else {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
if (fwk != null) {
fwk.stop();
fwk.waitForStop(0);
}
} catch (Exception ex) {
System.err.println("Error stopping framework: " + ex);
}
}
});
try {
List<Bundle> bundleList = new ArrayList<Bundle>();
Map<String,Object> m = new HashMap<String,Object>();
m.put(Constants.FRAMEWORK_STORAGE_CLEAN, "onFirstInit");
Iterator<FrameworkFactory> it =
ServiceLoader.load(FrameworkFactory.class).iterator();
if (!it.hasNext()) {
throw new Exception("No framework factory found!");
}
fwk = it.next().newFramework(m);
fwk.start();
BundleContext ctxt = fwk.getBundleContext();
Bundle b = null;
for (int i = 0; i < jars.size(); i++) {
b = ctxt.installBundle((jars.get(i)).toURI().toString());
bundleList.add(b);
}
for (int i = 0; i < bundleList.size(); i++) {
if (!isFragment(bundleList.get(i))) {
bundleList.get(i).start();
}
}
fwk.waitForStop(0);
System.exit(0);
} catch (Exception ex) {
System.err.println("Error starting framework: " + ex);
ex.printStackTrace();
System.exit(0);
}
}
}
}
public static boolean isFragment(Bundle bundle) {
return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
}
}