Hi community,
I tried getting help in a few Newsgroups before but without success. Now I have big hope, that you guys could help me a little.
A year ago I've been following Neil Bartletts superb OSGi tutorial which is btw really really really great work! And I'm really looking forward to get a copy of his book as soon as it's done.
Anyway, I coded a command line tool based on declarative services with a CommandProvider and several Runnable bundles. Now I need to integrate that tool into the buildprocess of some other department within our company. Now there are two problems: a) They want to run it in an read-only ClearCase environment by using a makefile, which means they b) don't want any user interaction. But because of my tool was just developed to be "user interactive", I'm now about to write an wrapper application that launches the Equinox framework and automatically commits the user commands.
It seems to me as if there's something wrong with either the instance of the framework or with my settings, because my code doesn't take any note of my config.ini. There aren't any bundles installed. The only bundle I see is the system bundle. I can read the "ping" done within execute() just before m_consle.run() but nothing more. There's no "pong", no Exception and not even the finally part from main() is done. Btw: starting the framework the usual way like "java -jar -Doutput=bla org.eclipse.osgi.<bla>.jar -console" works just fine! For use with the makefile I want to substitute that with "java -jar -Doutput=bla my_launcher.jar -console"
Code:
package com.cruehl.osgi;
import java.io.File;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.framework.adaptor.FrameworkAdaptor;
import org.eclipse.osgi.framework.internal.core.OSGi;
import org.eclipse.osgi.framework.internal.core.FrameworkConsole;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
public class FooStarter
{
private FrameworkAdaptor m_adaptor;
private FrameworkConsole m_console;
private OSGi m_osgi;
private BundleContext m_context;
private static int m_errorcode = 3; // implicit error
/**
* Constructor.
*
* @param args
*/
public FooStarter(String[] args)
{
File test = new File("");
String path = test.getAbsolutePath();
System.setProperty("osgi.install.area", path);
System.setProperty("osgi.configuration.area", "file:configuration");
System.setProperty("osgi.framework", "file:org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar");
//System.setProperty("osgi.launcherIni", "eclipse");
m_adaptor = new BaseAdaptor(args);
m_osgi = new OSGi(m_adaptor);
m_context = m_osgi.getBundleContext();
}
/**
* Launches Equinox, runs bundles and closes framework when done.
*/
public void start()
{
m_osgi.launch();
// TODO run bundles
execute();
// testing stuff
System.out.println(System.getProperty("output"));
System.out.println(m_context.getProperty("output"));
printInstalledBundles();
getBundleErrorFlag();
// testing stuff end
m_osgi.close();
}
/**
* Du erträgst die Erniedrigung mit einem Lächeln im Gesicht,
* doch was mal aus Dir werden soll, das weisst Du nicht!
* Der Eine hats, der Andere nicht - doch das hast Du nicht so gemacht!
* Dein Weg führt Dich in dunkle Straßen. Hörst Du wie man über Dich lacht?
* Die Stunde des Siegers kommt für jeden irgendwann...
*/
private void execute()
{
// TODO seems that it takes no note of my config.ini
// the following commands will be sequentially executed
String[] cmds = { "ss", "diag 1", "diag 5", "close" };
m_console = new FrameworkConsole(m_osgi, cmds);
System.out.println("ping");
m_console.run(); // here something goes wrong...
System.out.println("pong");
m_console.shutdown();
System.out.println("ping");
}
/**
* Collects Global error flag from framework. Flag should be set by CrimsonGore.
*/
private void getBundleErrorFlag()
{
// TODO problem: both return null
System.out.println(System.getProperty("error"));
System.out.println(m_context.getProperty("error"));
// get error flag value
if (m_context.getProperty("error") != null)
{
String bundleErrorFlagValue = m_context.getProperty("error");
m_errorcode = Integer.parseInt(bundleErrorFlagValue);
}
else
{
System.out.println("\nERROR Could not read bundle error flag\n");
m_errorcode = 2;
}
}
/**
* For testing: prints all currently installed bundles.
*/
private void printInstalledBundles()
{
Bundle[] installed = m_context.getBundles();
for (int i = 0; i < installed.length; i++)
System.out.println(i + "\t" + installed[i].getSymbolicName());
}
/**
* Main method.
*
* @param args
*/
public static void main(String[] args)
{
try
{
FooStarter starter = new FooStarter(args);
starter.start();
}
catch (Exception ex)
{
// TODO
System.out.println("ERROR Ooops, something went wrong!");
ex.printStackTrace();
}
finally
{
System.out.println("pong " + m_errorcode);
System.exit(m_errorcode);
}
}
}
Here's the config.ini which can be found in configuration directory.
Code:
org.osgi.framework.bootdelegation=*
osgi.bundles=org.eclipse.osgi.services_3.1.200.v20071203.jar@start,\
org.eclipse.equinox.util_1.0.0.v20080414.jar@start,\
org.eclipse.equinox.ds_1.0.0.v20080427-0830.jar@start,\
bundles/de.<bla>.loggingunit.jar@start,\
bundles/de.<bla>.crimsongore.jar@start,\
bundles/de.<bla>.basicchecker.jar@start,\
bundles/de.<bla>.extendedchecker.jar@start,\
bundles/de.<bla>.importexport.jar@start,\
bundles/de.<bla>.businesslogic.jar@start,\
bundles/de.<bla>.compiler.jar@start
eclipse.ignoreApp=true
eclipse.application.noDefault=true
osgi.clean=true
eclipse.log.backup.max=1
That brings me to my second question: How can I suppress the logging behaviour of the framework? As said above they want to use it in an read-only environment and there should be nothing more than just the bundle cache.
Thanks!