- List<String> arguments = cl.getArgList();
- if (arguments.size() == 0) {
- // TODO default behaviour
- } else {
- module = arguments.get(0);
- File moduleFile = new File(module);
- if (moduleFile.exists()) {
- if (moduleFile.isDirectory()) {
- moduleUrl = "reference:file:"
- + moduleFile.getCanonicalPath();
- } else {
- moduleUrl = "file:" + moduleFile.getCanonicalPath();
- }
+ // Spring configs currently require System properties
+ System.getProperties().putAll(configuration);
+
+ framework = frameworkFactory.newFramework(configuration);
+ framework.start();
+ BundleContext bundleContext = framework.getBundleContext();
+
+ // OSGi bootstrap
+ OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
+
+ // working copy modules
+ if (modulesDir.exists())
+ osgiBoot.installUrls(osgiBoot.getBundlesUrls(modulesDir
+ .getCanonicalPath() + ";in=*;ex=.gitignore"));
+
+ // system modules
+ if (System.getProperty(OsgiBoot.PROP_ARGEO_OSGI_BUNDLES) != null)
+ osgiBoot.installUrls(osgiBoot.getBundlesUrls(System
+ .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BUNDLES)));
+ else
+ osgiBoot.installUrls(osgiBoot.getBundlesUrls(System
+ .getProperty("user.home") + "/.slc/modules/;in=**"));
+
+ // Start runtime
+ osgiBoot.startBundles(bundlesToStart);
+
+ // Find SLC Agent
+ ServiceReference sr = null;
+ while (sr == null) {
+ sr = bundleContext
+ .getServiceReference("org.argeo.slc.execution.SlcAgentCli");
+ if (System.currentTimeMillis() - begin > timeout)
+ throw new RuntimeException("Cannot find SLC agent CLI");
+ Thread.sleep(100);
+ }
+ Object agentCli = bundleContext.getService(sr);
+
+ // Initialization completed
+ long duration = System.currentTimeMillis() - begin;
+ info("[[ Initialized in " + (duration / 1000) + "s "
+ + (duration % 1000) + "ms ]]");
+
+ if (args.length == 0)
+ return null;// console mode
+
+ // Subject.doAs(Subject.getSubject(AccessController.getContext()),
+ // new AgentCliCall(agentCli));
+ Class<?>[] parameterTypes = { String[].class };
+ Method method = agentCli.getClass().getMethod("process",
+ parameterTypes);
+ Object[] methodArgs = { args };
+ Object ret = method.invoke(agentCli, methodArgs);
+
+ // Shutdown OSGi runtime
+ framework.stop();
+ framework.waitForStop(60 * 1000);
+
+ return ret.toString();
+ } catch (Exception e) {
+ // Shutdown OSGi runtime
+ if (framework != null)
+ try {
+ framework.stop();
+ framework.waitForStop(15 * 1000);
+ } catch (Exception silent) {