Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZeb Ford-Reitz2011-09-08 15:29:20 +0000
committerZeb Ford-Reitz2011-09-08 15:29:20 +0000
commitde279de0f0f7518c7b6c86b9cc9247caf56dde4b (patch)
tree57a73c6c9a9dfcbb6cf80ed80aa641007de4484f /org.eclipse.jubula.app.autrun
parent6f1fcc784286f65bb8957bcb56c1126157d4e8bd (diff)
downloadorg.eclipse.jubula.core-de279de0f0f7518c7b6c86b9cc9247caf56dde4b.tar.gz
org.eclipse.jubula.core-de279de0f0f7518c7b6c86b9cc9247caf56dde4b.tar.xz
org.eclipse.jubula.core-de279de0f0f7518c7b6c86b9cc9247caf56dde4b.zip
Converts 'autrun' to an Equinox application.
Diffstat (limited to 'org.eclipse.jubula.app.autrun')
-rw-r--r--org.eclipse.jubula.app.autrun/.classpath7
-rw-r--r--org.eclipse.jubula.app.autrun/.gitignore1
-rw-r--r--org.eclipse.jubula.app.autrun/.project11
-rw-r--r--org.eclipse.jubula.app.autrun/META-INF/MANIFEST.MF21
-rw-r--r--org.eclipse.jubula.app.autrun/build.properties6
-rw-r--r--org.eclipse.jubula.app.autrun/buildScript.xml103
-rw-r--r--org.eclipse.jubula.app.autrun/plugin.xml18
-rw-r--r--org.eclipse.jubula.app.autrun/pom.xml15
-rw-r--r--org.eclipse.jubula.app.autrun/resources/log4j.properties39
-rw-r--r--org.eclipse.jubula.app.autrun/resources/logging.properties50
-rw-r--r--org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/Activator.java73
-rw-r--r--org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRunApplication.java (renamed from org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRun.java)278
-rw-r--r--org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRunner.java157
13 files changed, 396 insertions, 383 deletions
diff --git a/org.eclipse.jubula.app.autrun/.classpath b/org.eclipse.jubula.app.autrun/.classpath
index 889c8eba6..2f8342847 100644
--- a/org.eclipse.jubula.app.autrun/.classpath
+++ b/org.eclipse.jubula.app.autrun/.classpath
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib" path="resources/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.jubula.communication"/>
- <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.jubula.tools"/>
- <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.jubula.rc.common"/>
- <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.jubula.autagent"/>
- <classpathentry kind="lib" path="/org.eclipse.jubula.rc.common.orbit/org.apache.commons.cli_1.2.0.v201011021000.jar"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.eclipse.jubula.app.autrun/.gitignore b/org.eclipse.jubula.app.autrun/.gitignore
index 348c102af..64af1f50f 100644
--- a/org.eclipse.jubula.app.autrun/.gitignore
+++ b/org.eclipse.jubula.app.autrun/.gitignore
@@ -1,2 +1,3 @@
/build
/bin
+/target
diff --git a/org.eclipse.jubula.app.autrun/.project b/org.eclipse.jubula.app.autrun/.project
index 665341964..67dbbff7e 100644
--- a/org.eclipse.jubula.app.autrun/.project
+++ b/org.eclipse.jubula.app.autrun/.project
@@ -15,9 +15,20 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
diff --git a/org.eclipse.jubula.app.autrun/META-INF/MANIFEST.MF b/org.eclipse.jubula.app.autrun/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..49ad70cd0
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: AUT Run Application
+Bundle-SymbolicName: org.eclipse.jubula.app.autrun;singleton:=true
+Bundle-Version: 1.1.0.qualifier
+Bundle-Vendor: Eclipse Jubula
+Bundle-ActivationPolicy: lazy
+Require-Bundle: org.eclipse.osgi;bundle-version="[3.6.1,4.0.0)",
+ org.eclipse.equinox.app;bundle-version="[1.3.1,2.0.0)",
+ org.apache.commons.cli;bundle-version="[1.2.0,2.0.0)",
+ org.apache.commons.lang;bundle-version="[2.4.0,3.0.0)",
+ org.slf4j.api;bundle-version="[1.5.11,2.0.0)",
+ org.eclipse.jubula.tools;bundle-version="[1.1.0,2.0.0)",
+ org.eclipse.jubula.communication;bundle-version="[1.1.0,2.0.0)",
+ org.eclipse.jubula.autagent;bundle-version="[1.1.0,2.0.0)",
+ ch.qos.logback.classic;bundle-version="[0.9.19,1.0.0)",
+ ch.qos.logback.core;bundle-version="[0.9.19,1.0.0)"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ClassPath: resources/,
+ .
+Bundle-Activator: org.eclipse.jubula.app.autrun.Activator
diff --git a/org.eclipse.jubula.app.autrun/build.properties b/org.eclipse.jubula.app.autrun/build.properties
new file mode 100644
index 000000000..5bc1c1e54
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/build.properties
@@ -0,0 +1,6 @@
+bin.includes = META-INF/,\
+ plugin.xml,\
+ .,\
+ resources/,\
+ about.html
+source.. = src/
diff --git a/org.eclipse.jubula.app.autrun/buildScript.xml b/org.eclipse.jubula.app.autrun/buildScript.xml
deleted file mode 100644
index 1148cfb1a..000000000
--- a/org.eclipse.jubula.app.autrun/buildScript.xml
+++ /dev/null
@@ -1,103 +0,0 @@
-<?xml version="1.0"?>
-<!--
- Copyright (c) 2004, 2010 BREDEX GmbH.
- All rights reserved. This program and the accompanying materials
- are made available under the terms of the Eclipse Public License v1.0
- which accompanies this distribution, and is available at
- http://www.eclipse.org/legal/epl-v10.html
- -->
-
-<project name="org.eclipse.jubula.app.autrun" default="compile" basedir=".">
-
- <!--
- general definitions
- ********************
-
- src the name of the diretory(starting at basedir)
- where to find project source files
-
- build the name of the diretory(starting at basedir)
- where to compile to.
-
- classes the name of the diretory(starting at basedir)
- where to put compiled classes to.
-
- jars the name of the diretory(starting at basedir)
- where to put generated jars to.
-
- lib the name of the diretory(starting at basedir)
- where to find libaries, needed for
- compilation.
-
- -->
- <property name="src" value="src"/>
- <property name="build" value="build"/>
- <property name="classes" value="build/classes"/>
- <property name="jars" value="build/jars"/>
-
- <!-- classpath -->
- <property name="javac" value="javac"/>
- <property name="javac.classpath" value="classpathAutRun"/>
- <property name="javac.debug" value="javac.debug"/>
-
- <!--
- Targets
- ********
-
- all calling the targets clean and compile.
- So "all" is replacing compiled files
-
- clean deletes the build directory
-
- compile compiles a project into the $build directory
-
- jar creates one or more jar files from the project.
-
- -->
-
- <target name="all" depends="clean, compile">
- </target>
-
- <target name="clean">
- <delete dir="${build}"/>
- </target>
-
- <target name="compile">
- <mkdir dir="${build}"/>
- <mkdir dir="${classes}"/>
- <mkdir dir="${jars}"/>
- <javac sourcepath=""
- srcdir="${src}"
- destdir="${classes}"
- classpathref="${javac.classpath}"
- debug="${javac.debug}"
- fork="true"
- executable="${javac}">
-
- </javac>
-
- </target>
-
- <target name="jar" depends="compile">
- <pathconvert property="manifest.classpath" pathsep=" ">
- <path refid="${javac.classpath}"/>
- <mapper>
- <chainedmapper>
- <flattenmapper/>
- <globmapper from="*.jar" to="lib/*.jar"/>
- </chainedmapper>
- </mapper>
- </pathconvert>
-
- <jar basedir="${classes}" destfile="${jars}/${ant.project.name}.jar">
- <fileset dir="${src}"
- includes="**/*"
- excludes="**/*.java" />
- <manifest>
- <attribute name="Class-Path" value="${manifest.classpath} ./resources/"/>
- <attribute name="Main-Class" value="org.eclipse.jubula.app.autrun.AutRun"/>
- </manifest>
- </jar>
- </target>
-
-</project>
diff --git a/org.eclipse.jubula.app.autrun/plugin.xml b/org.eclipse.jubula.app.autrun/plugin.xml
new file mode 100644
index 000000000..a0a52b678
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/plugin.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ id="org.eclipse.jubula.app.autrun"
+ name="AUT Run"
+ point="org.eclipse.core.runtime.applications">
+ <application
+ cardinality="singleton-global"
+ thread="main"
+ visible="true">
+ <run
+ class="org.eclipse.jubula.app.autrun.AutRunApplication">
+ </run>
+ </application>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.jubula.app.autrun/pom.xml b/org.eclipse.jubula.app.autrun/pom.xml
new file mode 100644
index 000000000..b7023ebcc
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/pom.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>org.eclipse.jubula.releng.client</artifactId>
+ <groupId>org.eclipse.jubula</groupId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../org.eclipse.jubula.releng.client</relativePath>
+ </parent>
+ <groupId>org.eclipse.jubula</groupId>
+ <artifactId>org.eclipse.jubula.app.autrun</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+</project>
diff --git a/org.eclipse.jubula.app.autrun/resources/log4j.properties b/org.eclipse.jubula.app.autrun/resources/log4j.properties
deleted file mode 100644
index d959367f1..000000000
--- a/org.eclipse.jubula.app.autrun/resources/log4j.properties
+++ /dev/null
@@ -1,39 +0,0 @@
-###############################################################################
-# Copyright (c) 2004, 2010 BREDEX GmbH.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-###############################################################################
-#logging for autrun
-
-
-#[UnixEventlog]
-# log4j.appender.all=org.apache.log4j.net.SyslogAppender
-# log4j.appender.all.SyslogHost=localhost
-# log4j.appender.all.Facility=USER
-#[UnixEventlog]
-
-#[disableLogging]
-# log4j.appender.all=org.apache.log4j.varia.NullAppender
-#[disableLogging]
-
-#[consoleOutput]
-log4j.appender.all=org.apache.log4j.ConsoleAppender
-#[consoleOutput]
-
-#[logFile]
-# change the path and the name for the log-file
-#log4j.appender.all=org.apache.log4j.RollingFileAppender
-#log4j.appender.all.MaxFileSize=10MB
-#log4j.appender.all.MaxBackupIndex=1
-#log4j.appender.all.file=h:/temp/log.txt
-#[logFile]
-
-#[commonSettings]
-log4j.appender.all.layout=org.apache.log4j.PatternLayout
-log4j.appender.all.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n
-log4j.rootLogger=WARN, all
-#[commonSettings]
-
-
diff --git a/org.eclipse.jubula.app.autrun/resources/logging.properties b/org.eclipse.jubula.app.autrun/resources/logging.properties
deleted file mode 100644
index b7b726958..000000000
--- a/org.eclipse.jubula.app.autrun/resources/logging.properties
+++ /dev/null
@@ -1,50 +0,0 @@
-############################################################
-# Default Logging Configuration File
-#
-# You can use a different file by specifying a filename
-# with the java.util.logging.config.file system property.
-# For example java -Djava.util.logging.config.file=myfile
-############################################################
-
-############################################################
-# Global properties
-############################################################
-
-# "handlers" specifies a comma separated list of log Handler
-# classes. These handlers will be installed during VM startup.
-# Note that these classes must be on the system classpath.
-# By default we only configure a ConsoleHandler, which will only
-# show messages at the INFO and above levels.
-#handlers= java.util.logging.ConsoleHandler
-
-# To add the FileHandler, use the following line instead.
-handlers= java.util.logging.FileHandler
-
-# Default global logging level.
-# This specifies which kinds of events are logged across
-# all loggers. For any given facility this global level
-# can be overriden by a facility specific level
-# Note that the ConsoleHandler also has a separate level
-# setting to limit messages printed to the console.
-.level= WARNING
-
-############################################################
-# Handler specific properties.
-# Describes specific configuration info for Handlers.
-############################################################
-
-# default file output is in user's home directory.
-java.util.logging.FileHandler.pattern = %h/.jubula/logs/aut_run_%u.log
-java.util.logging.FileHandler.limit = 50000
-java.util.logging.FileHandler.count = 1
-java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
-java.util.logging.FileHandler.level = WARNING
-
-############################################################
-# Facility specific properties.
-# Provides extra control for each logger.
-############################################################
-
-# For example, set the com.xyz.foo logger to only log SEVERE
-# messages:
-#com.xyz.foo.level = SEVERE
diff --git a/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/Activator.java b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/Activator.java
new file mode 100644
index 000000000..6535f08d5
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/Activator.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2011 BREDEX GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.app.autrun;
+
+import java.io.InputStream;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+
+/**
+ *
+ * @author BREDEX GmbH
+ * @created Sept 07, 2011
+ */
+public class Activator implements BundleActivator {
+
+ /** the bundle context */
+ private static BundleContext context;
+
+ /**
+ *
+ * @return the bundle context.
+ */
+ static BundleContext getContext() {
+ return context;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+ // initialize the logging facility
+ LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ // the context was probably already configured by default
+ // configuration
+ // rules
+ lc.reset();
+ InputStream is = context.getBundle().getResource("logback.xml") //$NON-NLS-1$
+ .openStream();
+ configurator.doConfigure(is);
+ } catch (JoranException je) {
+ // no logging if logger fails :-(
+ }
+
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ }
+
+}
diff --git a/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRun.java b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRunApplication.java
index 8ef921ba3..99406c81c 100644
--- a/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRun.java
+++ b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRunApplication.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 BREDEX GmbH.
+ * Copyright (c) 2004, 2011 BREDEX GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,13 +10,8 @@
*******************************************************************************/
package org.eclipse.jubula.app.autrun;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
import java.net.ConnectException;
import java.net.InetSocketAddress;
-import java.net.Socket;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
@@ -31,9 +26,8 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.Parser;
import org.apache.commons.lang.ArrayUtils;
-import org.eclipse.jubula.autagent.commands.IStartAut;
-import org.eclipse.jubula.communication.connection.ConnectionState;
-import org.eclipse.jubula.communication.connection.RestartAutProtocol;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.jubula.tools.constants.AutConfigConstants;
import org.eclipse.jubula.tools.constants.StringConstants;
import org.eclipse.jubula.tools.i18n.I18n;
@@ -43,12 +37,25 @@ import org.slf4j.LoggerFactory;
/**
+ * Starts an AUT and registers the AUT with an AUT Agent. In order to terminate
+ * at the right time (not too early, not too late) this application assumes
+ * that the following JVM parameters (or equivalent) are used:<ul>
+ * <li>osgi.noShutdown=true</li>
+ * <li>eclipse.jobs.daemon=true</li>
+ * <li>eclipse.enableStateSaver=false</li>
+ * </ul>
+ * These parameters are required because the original application was designed
+ * to run outside of an OSGi context, i.e. the application should end only
+ * when no non-daemon threads are active.
+ *
* @author BREDEX GmbH
* @created Dec 9, 2009
*/
-public class AutRun {
+public class AutRunApplication implements IApplication {
+
/** the logger */
- private static final Logger LOG = LoggerFactory.getLogger(AutRun.class);
+ private static final Logger LOG =
+ LoggerFactory.getLogger(AutRunApplication.class);
/**
* <code>LAUNCHER_NAME</code>
@@ -123,109 +130,6 @@ public class AutRun {
private static final String OPT_EXECUTABLE_LONG = "exec"; //$NON-NLS-1$
// - Command line options - End //
- /** settings used to start the AUT */
- private Map<String, Object> m_autConfiguration;
-
- /** the object responsible for actually starting the AUT */
- private IStartAut m_startAut;
-
- /** the address for the AUT Agent */
- private InetSocketAddress m_agentAddr;
-
- /**
- * Constructor
- *
- * @param autToolkit Toolkit for the AUT managed by this instance.
- * @param autIdentifier Identifier for the AUT managed by this instance.
- * @param agentAddr Address of the Aut Agent with which the AUT should be
- * registered.
- * @param autConfiguration Properties required for starting the AUT.
- *
- * @throws ClassNotFoundException If no class can be found for starting an
- * AUT for the given toolkit.
- * @throws InstantiationException
- * @throws IllegalAccessException
- */
- public AutRun(String autToolkit, AutIdentifier autIdentifier,
- InetSocketAddress agentAddr, Map<String, Object> autConfiguration)
- throws ClassNotFoundException, InstantiationException,
- IllegalAccessException {
- String className = "org.eclipse.jubula.autagent.commands.Start" //$NON-NLS-1$
- + autToolkit + "AutServerCommand"; //$NON-NLS-1$
- Class< ? > autServerClass = Class.forName(className);
- m_agentAddr = agentAddr;
- m_autConfiguration = new HashMap<String, Object>(autConfiguration);
- m_autConfiguration.put(AutConfigConstants.AUT_AGENT_HOST,
- agentAddr.getHostName());
- m_autConfiguration.put(AutConfigConstants.AUT_AGENT_PORT,
- String.valueOf(agentAddr.getPort()));
- m_autConfiguration.put(AutConfigConstants.AUT_NAME,
- autIdentifier.getExecutableName());
- m_startAut = (IStartAut)autServerClass.newInstance();
- }
-
- /**
- * Main method.
- *
- * @param args
- * Command line arguments.
- */
- public static void main(String[] args) throws ClassNotFoundException,
- InstantiationException, IllegalAccessException,
- IOException {
- Options options = createCmdLineOptions();
- Parser parser = new BasicParser();
- CommandLine cmdLine = null;
- try {
- cmdLine = parser.parse(options, args, false);
- } catch (ParseException pe) {
- printHelp(pe);
- }
-
- if (cmdLine != null && !cmdLine.hasOption(OPT_HELP)) {
- String toolkit = StringConstants.EMPTY;
- if (cmdLine.hasOption(TK_SWING)) {
- toolkit = "Swing"; //$NON-NLS-1$
- } else if (cmdLine.hasOption(TK_SWT)) {
- toolkit = "Swt"; //$NON-NLS-1$
- } else if (cmdLine.hasOption(TK_RCP)) {
- toolkit = "Rcp"; //$NON-NLS-1$
- }
-
- int autAgentPort = DEFAULT_AUT_AGENT_PORT;
- if (cmdLine.hasOption(OPT_AUT_AGENT_PORT)) {
- try {
- autAgentPort = Integer.parseInt(cmdLine
- .getOptionValue(OPT_AUT_AGENT_PORT));
- } catch (NumberFormatException nfe) {
- // use default
- }
- }
- String autAgentHost = DEFAULT_AUT_AGENT_HOST;
- if (cmdLine.hasOption(OPT_AUT_AGENT_HOST)) {
- autAgentHost = cmdLine.getOptionValue(OPT_AUT_AGENT_HOST);
- }
-
- InetSocketAddress agentAddr =
- new InetSocketAddress(autAgentHost, autAgentPort);
- AutIdentifier autId = new AutIdentifier(cmdLine
- .getOptionValue(OPT_AUT_ID));
-
- Map<String, Object> autConfiguration = createAutConfig(cmdLine);
-
- AutRun runner = new AutRun(toolkit, autId, agentAddr,
- autConfiguration);
- try {
- runner.run();
- } catch (ConnectException ce) {
- LOG.info("Could not connect to AUT Agent.", ce); //$NON-NLS-1$
- System.err.println(I18n.getString("InfoDetail.connGuiDancerServerFailed")); //$NON-NLS-1$
- }
- } else {
- printHelp(null);
- }
- }
-
/**
* prints help options
* @param pe a parse Execption - may also be null
@@ -289,78 +193,6 @@ public class AutRun {
}
/**
- * Starts the AUT managed by the receiver.
- *
- * @throws ConnectException If unable to connect to the AUT Agent (if,
- * for example, there is no AUT Agent running on the given
- * hostname / port)
- * @throws IOException if an I/O error occurs during AUT startup.
- */
- public void run() throws IOException, ConnectException {
- // Establish connection to AUT Agent
- final Socket agentSocket =
- new Socket(m_agentAddr.getAddress(), m_agentAddr.getPort());
-
- final PrintWriter writer = new PrintWriter(
- agentSocket.getOutputStream(), true);
- final BufferedReader reader = new BufferedReader(
- new InputStreamReader(agentSocket.getInputStream()));
-
- String clientTypeRequest = reader.readLine();
- writer.println(ConnectionState.CLIENT_TYPE_AUTRUN);
-
- writer.println(
- m_autConfiguration.get(AutConfigConstants.AUT_NAME));
-
- Thread agentConnectionThread = new Thread("AUT Agent Connection") { //$NON-NLS-1$
- public void run() {
- try {
- String line = reader.readLine();
- if (line != null) {
- if (line.equals(
- RestartAutProtocol.REQ_PREPARE_FOR_RESTART)) {
-
- // make sure that we have a system thread running so
- // the JVM won't shut down during AUT restart
- Thread restartThread = new Thread() {
- public void run() {
- writer.println("Response.OK"); //$NON-NLS-1$
-
- try {
- String restartReq = reader.readLine();
- if (RestartAutProtocol.REQ_RESTART
- .equals(restartReq)) {
-
- AutRun.this.run();
- }
- } catch (IOException e) {
- LOG.error("Error occured while restarting AUT.", e); //$NON-NLS-1$
- } finally {
- try {
- agentSocket.close();
- } catch (IOException e) {
- // Error while closing socket. Ignore.
- }
- }
- };
- };
- restartThread.setDaemon(false);
- restartThread.start();
- }
- }
- } catch (IOException e) {
- LOG.error("Error occured while restarting AUT.", e); //$NON-NLS-1$
- }
- };
- };
-
- agentConnectionThread.setDaemon(true);
- agentConnectionThread.start();
-
- m_startAut.startAut(m_autConfiguration);
- }
-
- /**
* @return the command line options available when invoking the main method.
*/
@SuppressWarnings("nls")
@@ -456,4 +288,78 @@ public class AutRun {
return 0;
}
}
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public Object start(IApplicationContext context) throws Exception {
+ String[] args = (String[])context.getArguments().get(
+ IApplicationContext.APPLICATION_ARGS);
+ if (args == null) {
+ args = new String[0];
+ }
+
+ Options options = createCmdLineOptions();
+ Parser parser = new BasicParser();
+ CommandLine cmdLine = null;
+ try {
+ cmdLine = parser.parse(options, args, false);
+ } catch (ParseException pe) {
+ printHelp(pe);
+ }
+
+ if (cmdLine != null && !cmdLine.hasOption(OPT_HELP)) {
+ String toolkit = StringConstants.EMPTY;
+ if (cmdLine.hasOption(TK_SWING)) {
+ toolkit = "Swing"; //$NON-NLS-1$
+ } else if (cmdLine.hasOption(TK_SWT)) {
+ toolkit = "Swt"; //$NON-NLS-1$
+ } else if (cmdLine.hasOption(TK_RCP)) {
+ toolkit = "Rcp"; //$NON-NLS-1$
+ }
+
+ int autAgentPort = DEFAULT_AUT_AGENT_PORT;
+ if (cmdLine.hasOption(OPT_AUT_AGENT_PORT)) {
+ try {
+ autAgentPort = Integer.parseInt(cmdLine
+ .getOptionValue(OPT_AUT_AGENT_PORT));
+ } catch (NumberFormatException nfe) {
+ // use default
+ }
+ }
+ String autAgentHost = DEFAULT_AUT_AGENT_HOST;
+ if (cmdLine.hasOption(OPT_AUT_AGENT_HOST)) {
+ autAgentHost = cmdLine.getOptionValue(OPT_AUT_AGENT_HOST);
+ }
+
+ InetSocketAddress agentAddr =
+ new InetSocketAddress(autAgentHost, autAgentPort);
+ AutIdentifier autId = new AutIdentifier(cmdLine
+ .getOptionValue(OPT_AUT_ID));
+
+ Map<String, Object> autConfiguration = createAutConfig(cmdLine);
+
+ AutRunner runner = new AutRunner(
+ toolkit, autId, agentAddr, autConfiguration);
+ try {
+ runner.run();
+ } catch (ConnectException ce) {
+ LOG.info("Could not connect to AUT Agent.", ce); //$NON-NLS-1$
+ System.err.println(I18n.getString("InfoDetail.connGuiDancerServerFailed")); //$NON-NLS-1$
+ }
+ } else {
+ printHelp(null);
+ }
+
+ return IApplication.EXIT_OK;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ public void stop() {
+ // no-op
+ }
}
diff --git a/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRunner.java b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRunner.java
new file mode 100644
index 000000000..87df09139
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRunner.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2011 BREDEX GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.app.autrun;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.ConnectException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jubula.autagent.commands.IStartAut;
+import org.eclipse.jubula.communication.connection.ConnectionState;
+import org.eclipse.jubula.communication.connection.RestartAutProtocol;
+import org.eclipse.jubula.tools.constants.AutConfigConstants;
+import org.eclipse.jubula.tools.registration.AutIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author BREDEX GmbH
+ * @created Sept 07, 2011
+ */
+public class AutRunner {
+
+ /** the logger */
+ private static final Logger LOG =
+ LoggerFactory.getLogger(AutRunner.class);
+
+ /** settings used to start the AUT */
+ private Map<String, Object> m_autConfiguration;
+
+ /** the object responsible for actually starting the AUT */
+ private IStartAut m_startAut;
+
+ /** the address for the AUT Agent */
+ private InetSocketAddress m_agentAddr;
+
+
+ /**
+ * Constructor
+ *
+ * @param autToolkit Toolkit for the AUT managed by this instance.
+ * @param autIdentifier Identifier for the AUT managed by this instance.
+ * @param agentAddr Address of the Aut Agent with which the AUT should be
+ * registered.
+ * @param autConfiguration Properties required for starting the AUT.
+ *
+ * @throws ClassNotFoundException If no class can be found for starting an
+ * AUT for the given toolkit.
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ public AutRunner(String autToolkit, AutIdentifier autIdentifier,
+ InetSocketAddress agentAddr, Map<String, Object> autConfiguration)
+ throws ClassNotFoundException, InstantiationException,
+ IllegalAccessException {
+ String className = "org.eclipse.jubula.autagent.commands.Start" //$NON-NLS-1$
+ + autToolkit + "AutServerCommand"; //$NON-NLS-1$
+ Class< ? > autServerClass = Class.forName(className);
+ m_agentAddr = agentAddr;
+ m_autConfiguration = new HashMap<String, Object>(autConfiguration);
+ m_autConfiguration.put(AutConfigConstants.AUT_AGENT_HOST,
+ agentAddr.getHostName());
+ m_autConfiguration.put(AutConfigConstants.AUT_AGENT_PORT,
+ String.valueOf(agentAddr.getPort()));
+ m_autConfiguration.put(AutConfigConstants.AUT_NAME,
+ autIdentifier.getExecutableName());
+ m_startAut = (IStartAut)autServerClass.newInstance();
+ }
+
+ /**
+ * Starts the AUT managed by the receiver.
+ *
+ * @throws ConnectException If unable to connect to the AUT Agent (if,
+ * for example, there is no AUT Agent running on the given
+ * hostname / port)
+ * @throws IOException if an I/O error occurs during AUT startup.
+ */
+ public void run() throws IOException, ConnectException {
+ // Establish connection to AUT Agent
+ final Socket agentSocket =
+ new Socket(m_agentAddr.getAddress(), m_agentAddr.getPort());
+
+ final PrintWriter writer = new PrintWriter(
+ agentSocket.getOutputStream(), true);
+ final BufferedReader reader = new BufferedReader(
+ new InputStreamReader(agentSocket.getInputStream()));
+
+ String clientTypeRequest = reader.readLine();
+ writer.println(ConnectionState.CLIENT_TYPE_AUTRUN);
+
+ writer.println(
+ m_autConfiguration.get(AutConfigConstants.AUT_NAME));
+
+ Thread agentConnectionThread = new Thread("AUT Agent Connection") { //$NON-NLS-1$
+ public void run() {
+ try {
+ String line = reader.readLine();
+ if (line != null) {
+ if (line.equals(
+ RestartAutProtocol.REQ_PREPARE_FOR_RESTART)) {
+
+ // make sure that we have a system thread running so
+ // the JVM won't shut down during AUT restart
+ Thread restartThread = new Thread() {
+ public void run() {
+ writer.println("Response.OK"); //$NON-NLS-1$
+
+ try {
+ String restartReq = reader.readLine();
+ if (RestartAutProtocol.REQ_RESTART
+ .equals(restartReq)) {
+
+ AutRunner.this.run();
+ }
+ } catch (IOException e) {
+ LOG.error("Error occured while restarting AUT.", e); //$NON-NLS-1$
+ } finally {
+ try {
+ agentSocket.close();
+ } catch (IOException e) {
+ // Error while closing socket. Ignore.
+ }
+ }
+ };
+ };
+
+ restartThread.setDaemon(false);
+ restartThread.start();
+ }
+ }
+ } catch (IOException e) {
+ LOG.error("Error occured while restarting AUT.", e); //$NON-NLS-1$
+ }
+ };
+ };
+
+ agentConnectionThread.setDaemon(true);
+ agentConnectionThread.start();
+
+ m_startAut.startAut(m_autConfiguration);
+ }
+
+}

Back to the top