-
- CommandLineParser clParser = new GnuParser();
- CommandLine cl = clParser.parse(options, args);
-
- // Mode
- String modeStr = cl.getOptionValue(modeOpt.getOpt());
- if (modeStr == null) {
- mode = Mode.single;
- } else {
- try {
- mode = Mode.valueOf(modeStr);
- } catch (IllegalArgumentException e) {
- throw new SlcException("Unrecognized mode '" + modeStr
- + "'", e);
- }
- }
-
- // Script
- if (mode.equals(Mode.single)) {
- if (!cl.hasOption(scriptOpt.getOpt()))
- throw new SlcException("Mode " + Mode.single
- + " requires option '" + scriptOpt.getLongOpt()
- + "'");
- script = cl.getOptionValue(scriptOpt.getOpt());
-
- // Targets
- if (cl.hasOption(targetsOpt.getOpt()))
- targets = cl.getOptionValue(targetsOpt.getOpt());
- }
-
- // Properties
- if (cl.hasOption(propertiesOpt.getOpt())) {
- for (String propertyFile : cl.getOptionValues(propertiesOpt
- .getOpt())) {
- loadPropertyFile(properties, propertyFile);
- }
+ // Authenticate
+ lc = new LoginContext(os);
+ lc.login();
+
+ // Prepare directories
+ String executionDir = System.getProperty("user.dir");
+ File slcDir = new File(executionDir, ".slc");
+ File tempDir = new File(System.getProperty("java.io.tmpdir"));
+
+ if (isTransient)
+ dataDir = new File(tempDir, "slc-data-"
+ + UUID.randomUUID().toString());
+ else
+ dataDir = new File(slcDir, "data");
+ if (!dataDir.exists())
+ dataDir.mkdirs();
+
+ File confDir = new File(slcDir, "conf");
+ if (!confDir.exists())
+ confDir.mkdirs();
+
+ System.setProperty("log4j.configuration", "file:./log4j.properties");
+ if (isTransient)
+ System.setProperty("argeo.node.repo.configuration",
+ "osgibundle:repository-memory.xml");
+
+ // Start Equinox
+ ServiceLoader<FrameworkFactory> ff = ServiceLoader
+ .load(FrameworkFactory.class);
+ FrameworkFactory frameworkFactory = ff.iterator().next();
+ Map<String, String> configuration = new HashMap<String, String>();
+ configuration.put("osgi.configuration.area",
+ confDir.getCanonicalPath());
+ configuration.put("osgi.instance.area", dataDir.getCanonicalPath());
+ // configuration.put("osgi.clean", "true");
+ // configuration.put("osgi.console", "");
+
+ // Spring configs currently require System properties
+ System.getProperties().putAll(configuration);
+
+ Framework framework = frameworkFactory.newFramework(configuration);
+ framework.start();
+ BundleContext bundleContext = framework.getBundleContext();
+ // String[] osgiRuntimeArgs = { "-configuration",
+ // confDir.getCanonicalPath(), "-data",
+ // dataDir.getCanonicalPath(), "-clean" };
+ // BundleContext bundleContext = EclipseStarter.startup(
+ // osgiRuntimeArgs, null);
+
+ // OSGi bootstrap
+ OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
+ osgiBoot.installUrls(osgiBoot.getBundlesUrls(bundlesToInstall));
+
+ // 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);