X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.launcher%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcli%2FSlcMain.java;h=7bda5c84f7c7f6141deb44460c18f2d06a2908a1;hb=94ced3cb126cdc46436f84cad15ef4464e495071;hp=606748279a0a57fc398b6ac340a1ca0ade276f5f;hpb=d79f9ae2d1a5f459e7ba5c1dc0264e2957c70a93;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java b/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java index 606748279..7bda5c84f 100644 --- a/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java +++ b/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java @@ -17,6 +17,7 @@ package org.argeo.slc.cli; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.security.AccessController; @@ -46,6 +47,8 @@ public class SlcMain implements PrivilegedAction { public final static String os; public final static String slcDirName = ".slc"; + final static File homeDir = new File(System.getProperty("user.home")); + static { String osName = System.getProperty("os.name"); if (osName.startsWith("Win")) @@ -83,6 +86,7 @@ public class SlcMain implements PrivilegedAction { public String run() { long begin = System.currentTimeMillis(); + Framework framework = null; try { info("## Date : " + new Date()); info("## Data : " + dataDir.getCanonicalPath()); @@ -95,15 +99,17 @@ public class SlcMain implements PrivilegedAction { configuration.put("osgi.configuration.area", confDir.getCanonicalPath()); configuration.put("osgi.instance.area", dataDir.getCanonicalPath()); + // FIXME must clean configuration area because jars are installed as + // file: by OSGi boot and not as reference:file: + configuration.put("osgi.clean", "true"); if (args.length == 0) { - // 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 = frameworkFactory.newFramework(configuration); framework.start(); BundleContext bundleContext = framework.getBundleContext(); @@ -121,7 +127,7 @@ public class SlcMain implements PrivilegedAction { .getProperty(OsgiBoot.PROP_ARGEO_OSGI_BUNDLES))); else osgiBoot.installUrls(osgiBoot.getBundlesUrls(System - .getProperty("user.home") + "/.slc/modules/**")); + .getProperty("user.home") + "/.slc/modules/;in=**")); // Start runtime osgiBoot.startBundles(bundlesToStart); @@ -159,7 +165,16 @@ public class SlcMain implements PrivilegedAction { return ret.toString(); } catch (Exception e) { + // Shutdown OSGi runtime + if (framework != null) + try { + framework.stop(); + framework.waitForStop(15 * 1000); + } catch (Exception silent) { + } throw new RuntimeException("Cannot run SLC command line", e); + } finally { + } } @@ -182,6 +197,7 @@ public class SlcMain implements PrivilegedAction { if (slcDir == null) { slcDir = new File(executionDir, slcDirName); slcDir.mkdirs(); + info("## Creating an SLC node at " + slcDir + " ..."); } } @@ -230,11 +246,19 @@ public class SlcMain implements PrivilegedAction { */ protected static File findSlcDir(File currentDir) { File slcDir = new File(currentDir, slcDirName); + // covers the use case of running from the home directory if (slcDir.exists() && slcDir.isDirectory()) return slcDir; File parentDir = currentDir.getParentFile(); if (parentDir == null) return null; + try { + // ~/.slc reserved for agent + if (parentDir.getCanonicalPath().equals(homeDir.getCanonicalPath())) + return null; + } catch (IOException e) { + throw new RuntimeException("Cannot check home directory", e); + } return findSlcDir(parentDir); }