]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Introduce SLC Detached app launcher
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 20 Nov 2008 09:49:18 +0000 (09:49 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 20 Nov 2008 09:49:18 +0000 (09:49 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@1835 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.slc.detached.launcher/pom.xml
org.argeo.slc.detached.launcher/src/main/java/org/argeo/slc/detached/launcher/Main.java
org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/AppLauncher.java [new file with mode: 0644]
org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/DetachedException.java
org.argeo.slc/pom.xml

index e9b7ddaac2f18b496245372fa22a038383256873..9c3137055efb19ece9ea29724e325ff16a339599 100644 (file)
                        <groupId>org.apache.log4j</groupId>
                        <artifactId>com.springsource.org.apache.log4j</artifactId>
                </dependency>
-               <dependency>
-                       <groupId>org.apache.commons</groupId>
-                       <artifactId>
-                               com.springsource.org.apache.commons.logging
-                       </artifactId>
-               </dependency>
-
+               <!-- 
+                       <dependency>
+                               <groupId>org.slf4j</groupId>
+                               <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
+                       </dependency>
+                       <dependency>
+                               <groupId>org.slf4j</groupId>
+                               <artifactId>com.springsource.slf4j.jcl</artifactId>
+                       </dependency>
+                        -->
        </dependencies>
 </project>
\ No newline at end of file
index ffa079611dd294de006236d8b60ecce07f68d7b2..684b15493a08dd837e8ef671e47c55f4f82ef2d1 100644 (file)
@@ -31,7 +31,12 @@ public class Main {
                        startApp(config);
 
                        // Start OSGi framework
-                       startEquinox(config);
+                       try {
+                               startEquinox(config);
+                       } catch (Exception e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
                        info("Argeo SLC Detached launcher started.");
                } catch (Exception e) {
                        e.printStackTrace();
@@ -75,7 +80,7 @@ public class Main {
                                .getCanonicalFile();
                String equinoxConfigurationPath = baseDir.getPath() + File.separator
                                + "slc-detached" + File.separator + "equinoxConfiguration";
-               String[] equinoxArgs = { "-console", "-noExit", "-clean",
+               String[] equinoxArgs = { "-console", "-noExit", "-clean", "-debug",
                                "-configuration", equinoxConfigurationPath };
 
                BundleContext context = EclipseStarter.startup(equinoxArgs, null);
@@ -153,6 +158,7 @@ public class Main {
 
        private static void startBundle(BundleContext bundleContext,
                        String symbolicName) throws BundleException {
+               info("Starting bundle " + symbolicName + "...");
                Bundle bundle = findBundleBySymbolicName(bundleContext, symbolicName);
                if (bundle != null)
                        bundle.start();
@@ -185,16 +191,16 @@ public class Main {
                String[] uiArgs = readArgumentsFromLine(config.getProperty(
                                "slc.detached.appargs", ""));
 
-               if (className == null)
-                       throw new Exception(
-                                       "A main class has to be defined with the system property slc.detached.appclass");
-
-               // Launch main method using reflection
-               Class clss = Class.forName(className);
-               Class[] mainArgsClasses = new Class[] { uiArgs.getClass() };
-               Object[] mainArgs = { uiArgs };
-               Method mainMethod = clss.getMethod("main", mainArgsClasses);
-               mainMethod.invoke(null, mainArgs);
+               if (className == null) {
+                       info("No slc.detached.appclass property define: does not try to launch an app from the standard classpath.");
+               } else {
+                       // Launch main method using reflection
+                       Class clss = Class.forName(className);
+                       Class[] mainArgsClasses = new Class[] { uiArgs.getClass() };
+                       Object[] mainArgs = { uiArgs };
+                       Method mainMethod = clss.getMethod("main", mainArgsClasses);
+                       mainMethod.invoke(null, mainArgs);
+               }
        }
 
        /* UTILITIES */
diff --git a/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/AppLauncher.java b/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/AppLauncher.java
new file mode 100644 (file)
index 0000000..7eb4f48
--- /dev/null
@@ -0,0 +1,52 @@
+package org.argeo.slc.detached;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Properties;
+import java.util.Vector;
+
+public class AppLauncher {
+       private Properties systemProperties = new Properties();
+       private String mainClass = null;
+       private List arguments = new Vector();
+
+       public void launch() {
+               try {
+                       if (mainClass == null)
+                               throw new DetachedException(
+                                               "A main class name muste be specified.");
+
+                       System.getProperties().putAll(systemProperties);
+                       //Class clss = getClass().getClassLoader().loadClass(mainClass);
+                       Class clss = Class.forName(mainClass);
+
+                       String[] args = new String[arguments.size()];
+                       for (int i = 0; i < arguments.size(); i++) {
+                               args[i] = arguments.get(i).toString();
+                       }
+
+                       Class[] mainArgsClasses = new Class[] { args.getClass() };
+                       Object[] mainArgs = { args };
+                       Method mainMethod = clss.getMethod("main", mainArgsClasses);
+                       mainMethod.invoke(null, mainArgs);
+
+               } catch (Exception e) {
+                       throw new DetachedException("Unexpected exception while launching "
+                                       + mainClass, e);
+               }
+
+       }
+
+       public void setSystemProperties(Properties systemProperties) {
+               this.systemProperties = systemProperties;
+       }
+
+       public void setMainClass(String mainClass) {
+               this.mainClass = mainClass;
+       }
+
+       public void setArguments(List arguments) {
+               this.arguments = arguments;
+       }
+
+}
index 6755abd7ef093ad45a4dfc612e17b1314b684aba..dc39ec8ab917cf1a0e308a0d343103034232f06f 100644 (file)
@@ -1,14 +1,13 @@
 package org.argeo.slc.detached;
 
 public class DetachedException extends RuntimeException {
-       private Exception cause;
+       static final long serialVersionUID = 1l;
 
        public DetachedException(String message) {
                super(message);
        }
 
        public DetachedException(String message, Exception cause) {
-               super(message);
-               this.cause = cause;
+               super(message, cause);
        }
 }
index 334483877857709472c2748107a352397dd4608a..b194dc5252b5e436121eacfe2dcb86f2e9e0ce1b 100644 (file)
                                <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
                                <version>1.5.3</version>
                        </dependency>
+                       <dependency>
+                               <groupId>org.slf4j</groupId>
+                               <artifactId>com.springsource.slf4j.jcl</artifactId>
+                               <version>1.5.3</version>
+                       </dependency>
                        <dependency>
                                <groupId>org.slf4j</groupId>
                                <artifactId>com.springsource.slf4j.org.apache.log4j</artifactId>
                        </dependency>
 
                        <!-- OSGi -->
-                       <!-- 
-                       <dependency>
-                               <groupId>org.apache.felix</groupId>
+                       <!--
+                               <dependency> <groupId>org.apache.felix</groupId>
                                <artifactId>org.apache.felix.main</artifactId>
-                               <version>1.2.1</version>
-                               <exclusions>
-                                       <exclusion>
-                                               <groupId>org.apache.felix</groupId>
-                                               <artifactId>
-                                                       org.apache.felix.framework
-                                               </artifactId>
-                                       </exclusion>
-                               </exclusions>
-                       </dependency>
-
-                       <dependency>
-                               <groupId>org.apache.felix</groupId>
-                               <artifactId>org.osgi.core</artifactId>
-                               <version>1.2.0</version>
-                               <scope>provided</scope>
-                       </dependency>
-                        -->
+                               <version>1.2.1</version> <exclusions> <exclusion>
+                               <groupId>org.apache.felix</groupId> <artifactId>
+                               org.apache.felix.framework </artifactId> </exclusion> </exclusions>
+                               </dependency> <dependency> <groupId>org.apache.felix</groupId>
+                               <artifactId>org.osgi.core</artifactId> <version>1.2.0</version>
+                               <scope>provided</scope> </dependency>
+                       -->
                        <dependency>
                                <groupId>org.eclipse.osgi</groupId>
                                <artifactId>org.eclipse.osgi</artifactId>