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.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 {
// Automate
automateUi(felix.getBundleContext());
- felix.stop();
+ // felix.stop();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
throws Exception {
// Retrieve service and execute it
ServiceReference ref = bundleContext
- .getServiceReference("org.argeo.slc.autoui.DetachedStep");
+ .getServiceReference(DetachedExecutionServer.class.getName());
Object service = bundleContext.getService(ref);
- AutoUiActivator.stdOut("service.class=" + service.getClass());
- DetachedStep app = (DetachedStep) service;
- app.execute(null, null);
+ log.debug("service.class=" + service.getClass());
+ DetachedExecutionServer app = (DetachedExecutionServer) service;
+ DetachedStepRequest request = new DetachedStepRequest();
+ request.setStepRef("jemmyTest");
+ app.executeStep(request);
}
/* UTILITIES */
org.osgi.util.tracker; version=1.3.3, \
org.argeo.slc.autoui; version=0.10.3.SNAPSHOT, \
org.argeo.slc.testui, \
+ org.apache.commons.logging, \
org.springframework.beans.factory.support,\
org.springframework.beans.factory.xml,\
org.springframework.context,\
${argeo.slc.mavenBase}org/apache/felix/org.apache.felix.shell/1.0.2/org.apache.felix.shell-1.0.2.jar \
${argeo.slc.mavenBase}org/apache/felix/org.apache.felix.shell.tui/1.0.2/org.apache.felix.shell.tui-1.0.2.jar \
${argeo.slc.mavenBase}org/argeo/dep/jemmy/org.argeo.dep.jemmy.nb61/0.2.2/org.argeo.dep.jemmy.nb61-0.2.2.jar \
- ${argeo.slc.mavenBase}org/argeo/slc/sandbox/org.argeo.slc.sandbox.jemmytest/0.1.2-SNAPSHOT/org.argeo.slc.sandbox.jemmytest-0.1.2-SNAPSHOT.jar"
+ reference:file:/home/mbaudier/dev/src/slc/sandbox/argeo.slc.jemmytest/bin/
+# ${argeo.slc.mavenBase}org/argeo/slc/sandbox/org.argeo.slc.sandbox.jemmytest/0.1.2-SNAPSHOT/org.argeo.slc.sandbox.jemmytest-0.1.2-SNAPSHOT.jar"
felix.log.level=1
<version>1.4.3</version>
<extensions>true</extensions>
<configuration>
- <manifestLocation>META-INF</manifestLocation>
+ <manifestLocation>src/main/resources/META-INF</manifestLocation>
<instructions>
<Bundle-SymbolicName>
${pom.artifactId}
package org.argeo.slc.autoui;
import java.net.URL;
+import java.util.Properties;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.springframework.core.io.UrlResource;
public class AbstractDetachedActivator implements BundleActivator {
- private AbstractApplicationContext applicationContext;
+ private SpringStaticRefProvider staticRefProvider;
public final void start(BundleContext context) throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
+ // Creates application context
Thread cur = Thread.currentThread();
ClassLoader save = cur.getContextClassLoader();
cur.setContextClassLoader(classLoader);
// applicationContext = new ClassPathXmlApplicationContext(
// "/slc/conf/applicationContext.xml");
- applicationContext = new GenericApplicationContext();
+ AbstractApplicationContext applicationContext = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
(BeanDefinitionRegistry) applicationContext);
Bundle bundle = context.getBundle();
xmlReader.loadBeanDefinitions(new UrlResource(url));
}
+ // Register static ref provider
+ staticRefProvider = new SpringStaticRefProvider(applicationContext);
+ Properties properties = new Properties();
+ properties.setProperty("slc.detached.bundle", bundle
+ .getSymbolicName());
+ context.registerService(StaticRefProvider.class.getName(),
+ staticRefProvider, properties);
+
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Could not initialize application context");
public final void stop(BundleContext context) throws Exception {
stopAutoBundle(context);
- if (applicationContext != null) {
- applicationContext.close();
+ if (staticRefProvider != null) {
+ staticRefProvider.close();
}
}
}
- public Object getStaticRef(String id) {
- return applicationContext.getBean(id);
+ protected StaticRefProvider getStaticRefProvider() {
+ return staticRefProvider;
}
-
}
package org.argeo.slc.autoui;
-import org.osgi.framework.BundleActivator;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.autoui.internal.DetachedExecutionServerImpl;
import org.osgi.framework.BundleContext;
-public class AutoUiActivator implements BundleActivator {
+public class AutoUiActivator extends AbstractDetachedActivator {
+ private final Log log = LogFactory.getLog(getClass());
- public void start(BundleContext context) throws Exception {
- stdOut("AutoUi started");
- }
+ private DetachedExecutionServerImpl executionServer;
+
+ public void startAutoBundle(BundleContext context) throws Exception {
+ Object obj = getStaticRefProvider().getStaticRef("executionServer");
+ if (obj != null)
+ executionServer = (DetachedExecutionServerImpl) obj;
+ else
+ throw new DetachedException("Could not find execution server.");
+
+ executionServer.setBundleContext(context);
- public void stop(BundleContext context) throws Exception {
- stdOut("AutoUi stopped");
+ context.registerService(DetachedExecutionServer.class.getName(),
+ executionServer, new Properties());
+ log.info("AutoUi started");
}
- public static void stdOut(Object obj) {
- System.out.println(obj);
+ public void stopAutoBundle(BundleContext context) throws Exception {
+ log.info("AutoUi stopped");
}
}
--- /dev/null
+package org.argeo.slc.autoui;
+
+public interface DetachedDriver {
+ /** Blocks until it receives a request. */
+ public DetachedStepRequest receiveRequest();
+}
--- /dev/null
+package org.argeo.slc.autoui;
+
+public class DetachedException extends RuntimeException {
+ private Exception cause;
+
+ public DetachedException(String message) {
+ super(message);
+ }
+
+ public DetachedException(String message, Exception cause) {
+ super(message);
+ this.cause = cause;
+ }
+}
--- /dev/null
+package org.argeo.slc.autoui;
+
+public interface DetachedExecutionServer {
+ public DetachedStepAnswer executeStep(DetachedStepRequest request);
+}
private Properties inputParameters;
private String stepRef;
private String path;
+
+ public Properties getInputParameters() {
+ return inputParameters;
+ }
+
+ public void setInputParameters(Properties inputParameters) {
+ this.inputParameters = inputParameters;
+ }
+
+ public String getStepRef() {
+ return stepRef;
+ }
+
+ public void setStepRef(String stepRef) {
+ this.stepRef = stepRef;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
}
--- /dev/null
+package org.argeo.slc.autoui;
+
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.context.ConfigurableApplicationContext;
+
+public class SpringStaticRefProvider implements StaticRefProvider {
+ private final ConfigurableApplicationContext applicationContext;
+
+ public SpringStaticRefProvider(
+ ConfigurableApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ public Object getStaticRef(String id) {
+ try {
+ return applicationContext.getBean(id);
+ } catch (NoSuchBeanDefinitionException e) {
+ // silent
+ return null;
+ }
+ }
+
+ public void close(){
+ applicationContext.close();
+ }
+}
--- /dev/null
+package org.argeo.slc.autoui;
+
+public interface StaticRefProvider {
+ /** Returns null if no such ref. */
+ public Object getStaticRef(String id);
+}
--- /dev/null
+package org.argeo.slc.autoui.internal;
+
+import org.argeo.slc.autoui.DetachedContextImpl;
+import org.argeo.slc.autoui.DetachedException;
+import org.argeo.slc.autoui.DetachedExecutionServer;
+import org.argeo.slc.autoui.DetachedStep;
+import org.argeo.slc.autoui.DetachedStepAnswer;
+import org.argeo.slc.autoui.DetachedStepRequest;
+import org.argeo.slc.autoui.StaticRefProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class DetachedExecutionServerImpl implements DetachedExecutionServer {
+ private final DetachedContextImpl detachedContext;
+
+ private BundleContext bundleContext;
+
+ public DetachedExecutionServerImpl() {
+ detachedContext = new DetachedContextImpl();
+ }
+
+ public DetachedStepAnswer executeStep(DetachedStepRequest request) {
+ try {
+ DetachedStep step = null;
+
+ // Find step
+ ServiceReference[] refs = bundleContext.getAllServiceReferences(
+ StaticRefProvider.class.getName(), null);
+ for (int i = 0; i < refs.length; i++) {
+ StaticRefProvider provider = (StaticRefProvider) bundleContext
+ .getService(refs[i]);
+ Object obj = provider.getStaticRef(request.getStepRef());
+ if (obj != null) {
+ step = (DetachedStep) obj;
+ break;
+ }
+ }
+
+ if (step == null)
+ throw new DetachedException("Could not find step with ref "
+ + request.getStepRef());
+
+ return step.execute(detachedContext, request);
+ } catch (DetachedException e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new DetachedException(
+ "Unexpected exception while executing request " + request,
+ e);
+ }
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+}
--- /dev/null
+Manifest-Version: 1.0\r
+Export-Package: org.argeo.slc.autoui.rmi,org.argeo.slc.autoui;uses:="o\r
+ rg.springframework.beans.factory.support,org.apache.commons.logging,o\r
+ rg.springframework.context.support,org.springframework.core.io,org.os\r
+ gi.framework,org.springframework.beans.factory.xml,org.springframewor\r
+ k.context,org.springframework.beans.factory",org.argeo.slc.autoui.int\r
+ ernal;uses:="org.argeo.slc.autoui"\r
+Built-By: mbaudier\r
+Tool: Bnd-0.0.255\r
+Bundle-Name: SLC Auto UI\r
+Created-By: Apache Maven Bundle Plugin\r
+Bundle-Vendor: Argeo\r
+Build-Jdk: 1.6.0_0\r
+Bundle-Version: 0.11.1.SNAPSHOT\r
+Bnd-LastModified: 1222511849722\r
+Bundle-ManifestVersion: 2\r
+Bundle-Activator: org.argeo.slc.autoui.AutoUiActivator\r
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt\r
+Import-Package: org.apache.commons.logging,org.argeo.slc.autoui,org.ar\r
+ geo.slc.autoui.internal,org.argeo.slc.autoui.rmi,org.osgi.framework;v\r
+ ersion="1.4",org.springframework.beans.factory,org.springframework.be\r
+ ans.factory.support,org.springframework.beans.factory.xml,org.springf\r
+ ramework.context,org.springframework.context.support,org.springframew\r
+ ork.core.io\r
+Bundle-SymbolicName: org.argeo.slc.autoui\r
+Bundle-DocURL: http://www.argeo.org\r
+Originally-Created-By: Apache Maven Bundle Plugin\r
+\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <bean id="executionServer"
+ class="org.argeo.slc.autoui.internal.DetachedExecutionServerImpl">
+ </bean>
+
+</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="output" path="bin"/>
<name>SLC Sandbox JemmyTest</name>
<version>0.1.2-SNAPSHOT</version>
<packaging>bundle</packaging>
- <build>
+ <build><!--
<resources>
<resource>
<directory>src/main/slc</directory>
<include>**/*</include>
</includes>
</resource>
- </resources>
+ </resources>-->
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<version>1.4.3</version>
<extensions>true</extensions>
<configuration>
- <manifestLocation>META-INF</manifestLocation>
+ <manifestLocation>src/main/resources/META-INF</manifestLocation>
<instructions>
<Bundle-SymbolicName>
${pom.artifactId}
package org.argeo.slc.jemmytest;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.slc.autoui.AutoUiActivator;
import org.argeo.slc.autoui.DetachedContext;
import org.argeo.slc.autoui.DetachedStep;
import org.netbeans.jemmy.operators.JLabelOperator;
public class DummyStep implements DetachedStep {
+ private final static Log log = LogFactory.getLog(DummyStep.class);
+
public DetachedStepAnswer execute(DetachedContext detachedContext,
DetachedStepRequest detachedStepRequest) {
// Performs checks
String textAfterPush = jLabelOperator.getText();
- AutoUiActivator.stdOut("textAfterPush=" + textAfterPush);
+ log.info("textAfterPush=" + textAfterPush);
return null;
}
import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.argeo.slc.autoui.AbstractDetachedActivator;
import org.argeo.slc.autoui.DetachedStep;
import org.osgi.framework.BundleContext;
public class JemmyTestActivator extends AbstractDetachedActivator {
+ private final Log log = LogFactory.getLog(getClass());
+
protected void startAutoBundle(BundleContext context) throws Exception {
- Properties properties = new Properties();
- DummyStep applicationJemmy = (DummyStep) getStaticRef("jemmyTest");
- context.registerService(DetachedStep.class.getName(),
- applicationJemmy, properties);
- stdOut("JemmyTest started");
+// Properties properties = new Properties();
+// DummyStep applicationJemmy = (DummyStep) getStaticRef("jemmyTest");
+// context.registerService(DetachedStep.class.getName(),
+// applicationJemmy, properties);
+ log.info("JemmyTest started");
}
public void stopAutoBundle(BundleContext context) throws Exception {
- stdOut("JemmyTest stopped");
+ log.info("JemmyTest stopped");
}
-
- public static void stdOut(Object obj) {
- System.out.println(obj);
- }
-
}
--- /dev/null
+Manifest-Version: 1.0\r
+Build-Jdk: 1.5.0\r
+Bnd-LastModified: 1222510300891\r
+Bundle-Name: SLC Sandbox JemmyTest\r
+Originally-Created-By: Apache Maven Bundle Plugin\r
+Bundle-SymbolicName: org.argeo.slc.sandbox.jemmytest\r
+Bundle-ManifestVersion: 2\r
+Bundle-Activator: org.argeo.slc.jemmytest.JemmyTestActivator\r
+Tool: Bnd-0.0.255\r
+Created-By: Apache Maven Bundle Plugin\r
+Bundle-Version: 0.1.2.SNAPSHOT\r
+Built-By: mbaudier\r
+Import-Package: org.apache.commons.logging,org.argeo.slc.autoui,org.arge\r
+ o.slc.jemmytest,org.netbeans.jemmy.operators,org.osgi.framework;version\r
+ ="1.4",org.springframework.beans.factory.xml\r
+Export-Package: org.argeo.slc.jemmytest;uses:="org.argeo.slc.autoui,org.\r
+ osgi.framework,org.netbeans.jemmy.operators,org.apache.commons.logging"\r
+\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <import resource="common/import.xml"/>
+
+ <bean id="jemmyTest"
+ class="org.argeo.slc.jemmytest.DummyStep">
+ </bean>
+
+</beans>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+ <bean id="jemmyTest2"
+ class="org.argeo.slc.jemmytest.DummyStep">
+ </bean>
+
+</beans>
\ No newline at end of file