]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - org.argeo.slc.autoui.launcher/src/main/java/org/argeo/slc/autoui/launcher/Main.java
Use SLC Detached (aka. SLC AutoUI) as a bundle.
[gpl/argeo-slc.git] / org.argeo.slc.autoui.launcher / src / main / java / org / argeo / slc / autoui / launcher / Main.java
index cf5ec37902c965558773ce6bffa86fe62b42e4d4..1d719cf299d5de9e8a92d4a76f68ded1e7b6d932 100644 (file)
@@ -3,36 +3,44 @@ package org.argeo.slc.autoui.launcher;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Properties;
 import java.util.Vector;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.felix.framework.Felix;
 import org.apache.felix.framework.cache.BundleCache;
 import org.apache.felix.main.AutoActivator;
 import org.argeo.slc.autoui.AutoUiActivator;
-import org.argeo.slc.autoui.AutoUiApplication;
-import org.netbeans.jemmy.ClassReference;
+import org.argeo.slc.autoui.DetachedExecutionServer;
+import org.argeo.slc.autoui.DetachedStep;
+import org.argeo.slc.autoui.DetachedStepRequest;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 
 public class Main {
+       private final static Log log = LogFactory.getLog(Main.class);
 
        public static void main(String[] args) {
                try {
-                       // Start OSGi system
+                       // Load properties
                        Properties config = prepareConfig();
-                       Felix felix = startSystem(config);
 
                        // Start UI (in main class loader)
                        startUi(config);
+                       //Thread.sleep(10000);
+                       
+                       // Start OSGi system
+                       Felix felix = startSystem(config);
 
                        // Automate
-                       automateUi(felix.getBundleContext());
-                       
-                       felix.stop();
+                       //automateUi(felix.getBundleContext());
+
+                       // felix.stop();
                } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(-1);
@@ -87,7 +95,7 @@ public class Main {
                // Add activator to process auto-start/install properties.
                list.add(new AutoActivator(config));
                // Add our own activator.
-               list.add(new AutoUiActivator());
+               //list.add(new AutoUiActivator());
 
                // Now create an instance of the framework.
                Felix felix = new Felix(config, list);
@@ -100,18 +108,27 @@ public class Main {
                String className = config.getProperty("argeo.scl.autoui.uiclass");
                String[] uiArgs = readArgumentsFromLine(config.getProperty(
                                "argeo.slc.autoui.uiargs", ""));
-               ClassReference classReference = new ClassReference(className);
-               classReference.startApplication(uiArgs);
+
+               // 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);
        }
 
-       protected static void automateUi(BundleContext context) throws Exception {
+       protected static void automateUi(BundleContext bundleContext)
+                       throws Exception {
                // Retrieve service and execute it
-               ServiceReference ref = context
-                               .getServiceReference("org.argeo.slc.autoui.AutoUiApplication");
-               Object service = context.getService(ref);
-               AutoUiActivator.stdOut("service.class=" + service.getClass());
-               AutoUiApplication app = (AutoUiApplication) service;
-               app.execute(null);
+               ServiceReference ref = bundleContext
+                               .getServiceReference(DetachedExecutionServer.class.getName());
+               Object service = bundleContext.getService(ref);
+
+               log.debug("service.class=" + service.getClass());
+               DetachedExecutionServer app = (DetachedExecutionServer) service;
+               DetachedStepRequest request = new DetachedStepRequest();
+               request.setStepRef("jemmyTest");
+               app.executeStep(request);
        }
 
        /* UTILITIES */