]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java
Force clean in SLC command line
[gpl/argeo-slc.git] / runtime / org.argeo.slc.launcher / src / main / java / org / argeo / slc / cli / SlcMain.java
index 606748279a0a57fc398b6ac340a1ca0ade276f5f..7bda5c84f7c7f6141deb44460c18f2d06a2908a1 100644 (file)
@@ -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<String> {
 
        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<String> {
        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<String> {
                        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<String> {
                                                .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<String> {
 
                        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<String> {
                                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<String> {
         */
        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);
        }