Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZeb Ford-Reitz2011-09-07 10:42:24 +0000
committerZeb Ford-Reitz2011-09-07 10:42:24 +0000
commitdfda4c1ffa3c6c173190a6277bf644c4fe3a4562 (patch)
tree87db5ee0158476d73fc415f959c2dd4afb70f72d
parent22824b78203cec969b554f7fec40055b205e37f7 (diff)
downloadorg.eclipse.jubula.core-dfda4c1ffa3c6c173190a6277bf644c4fe3a4562.tar.gz
org.eclipse.jubula.core-dfda4c1ffa3c6c173190a6277bf644c4fe3a4562.tar.xz
org.eclipse.jubula.core-dfda4c1ffa3c6c173190a6277bf644c4fe3a4562.zip
Renames o.e.j.autrun project to o.e.j.app.autrun.
This refactoring makes the application nature of the project more clear.
-rw-r--r--org.eclipse.jubula.app.autrun/.checkstyle7
-rw-r--r--org.eclipse.jubula.app.autrun/.classpath11
-rw-r--r--org.eclipse.jubula.app.autrun/.gitignore2
-rw-r--r--org.eclipse.jubula.app.autrun/.project23
-rw-r--r--org.eclipse.jubula.app.autrun/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--org.eclipse.jubula.app.autrun/about.html28
-rw-r--r--org.eclipse.jubula.app.autrun/buildScript.xml103
-rw-r--r--org.eclipse.jubula.app.autrun/resources/log4j.properties39
-rw-r--r--org.eclipse.jubula.app.autrun/resources/logback.xml20
-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/AutRun.java459
11 files changed, 754 insertions, 0 deletions
diff --git a/org.eclipse.jubula.app.autrun/.checkstyle b/org.eclipse.jubula.app.autrun/.checkstyle
new file mode 100644
index 000000000..0afff8669
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/.checkstyle
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
+ <fileset name="all" enabled="true" check-config-name="Jubula" local="false">
+ <file-match-pattern match-pattern="." include-pattern="true"/>
+ </fileset>
+</fileset-config>
diff --git a/org.eclipse.jubula.app.autrun/.classpath b/org.eclipse.jubula.app.autrun/.classpath
new file mode 100644
index 000000000..889c8eba6
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <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="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.jubula.app.autrun/.gitignore b/org.eclipse.jubula.app.autrun/.gitignore
new file mode 100644
index 000000000..348c102af
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/.gitignore
@@ -0,0 +1,2 @@
+/build
+/bin
diff --git a/org.eclipse.jubula.app.autrun/.project b/org.eclipse.jubula.app.autrun/.project
new file mode 100644
index 000000000..665341964
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jubula.app.autrun</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.jubula.app.autrun/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jubula.app.autrun/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..95dfd70e9
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Wed Dec 09 12:37:53 CET 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/org.eclipse.jubula.app.autrun/about.html b/org.eclipse.jubula.app.autrun/about.html
new file mode 100644
index 000000000..f1be81099
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 22, 2011</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/org.eclipse.jubula.app.autrun/buildScript.xml b/org.eclipse.jubula.app.autrun/buildScript.xml
new file mode 100644
index 000000000..1148cfb1a
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/buildScript.xml
@@ -0,0 +1,103 @@
+<?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/resources/log4j.properties b/org.eclipse.jubula.app.autrun/resources/log4j.properties
new file mode 100644
index 000000000..d959367f1
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/resources/log4j.properties
@@ -0,0 +1,39 @@
+###############################################################################
+# 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/logback.xml b/org.eclipse.jubula.app.autrun/resources/logback.xml
new file mode 100644
index 000000000..c24c27128
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/resources/logback.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration scan="true">
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are by default assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+ </pattern>
+ </encoder>
+ </appender>
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${user.home}/.jubula/logs/aut_run.log</file>
+ <encoder>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+ </pattern>
+ </encoder>
+ </appender>
+ <root level="warn">
+ <appender-ref ref="FILE" />
+ </root>
+</configuration>
diff --git a/org.eclipse.jubula.app.autrun/resources/logging.properties b/org.eclipse.jubula.app.autrun/resources/logging.properties
new file mode 100644
index 000000000..b7b726958
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/resources/logging.properties
@@ -0,0 +1,50 @@
+############################################################
+# 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/AutRun.java b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRun.java
new file mode 100644
index 000000000..8ef921ba3
--- /dev/null
+++ b/org.eclipse.jubula.app.autrun/src/org/eclipse/jubula/app/autrun/AutRun.java
@@ -0,0 +1,459 @@
+/*******************************************************************************
+ * 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
+ *
+ * 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.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+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.jubula.tools.constants.AutConfigConstants;
+import org.eclipse.jubula.tools.constants.StringConstants;
+import org.eclipse.jubula.tools.i18n.I18n;
+import org.eclipse.jubula.tools.registration.AutIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * @author BREDEX GmbH
+ * @created Dec 9, 2009
+ */
+public class AutRun {
+ /** the logger */
+ private static final Logger LOG = LoggerFactory.getLogger(AutRun.class);
+
+ /**
+ * <code>LAUNCHER_NAME</code>
+ */
+ private static final String LAUNCHER_NAME = "autrun"; //$NON-NLS-1$
+
+ /** <code>TOOLKIT_RCP</code> */
+ private static final String TK_RCP = "rcp"; //$NON-NLS-1$
+
+ /** <code>TK_SWT</code> */
+ private static final String TK_SWT = "swt"; //$NON-NLS-1$
+
+ /** <code>TK_SWING</code> */
+ private static final String TK_SWING = "swing"; //$NON-NLS-1$
+
+ /** <code>DEFAULT_NAME_TECHNICAL_COMPONENTS</code> */
+ private static final boolean DEFAULT_NAME_TECHNICAL_COMPONENTS = true;
+
+ /** <code>DEFAULT_AUT_AGENT_PORT</code> */
+ private static final int DEFAULT_AUT_AGENT_PORT = 60000;
+
+ /** <code>DEFAULT_AUT_AGENT_HOST</code> */
+ private static final String DEFAULT_AUT_AGENT_HOST = "localhost"; //$NON-NLS-1$
+
+ // - Command line options - Start //
+ /** port number for the Aut Agent with which to register */
+ private static final String OPT_AUT_AGENT_PORT = "p"; //$NON-NLS-1$
+
+ /** port number for the Aut Agent with which to register */
+ private static final String OPT_AUT_AGENT_PORT_LONG = "autagentport"; //$NON-NLS-1$
+
+ /** hostname for the Aut Agent with which to register */
+ private static final String OPT_AUT_AGENT_HOST = "a"; //$NON-NLS-1$
+
+ /** hostname for the Aut Agent with which to register */
+ private static final String OPT_AUT_AGENT_HOST_LONG = "autagenthost"; //$NON-NLS-1$
+
+ /** help option */
+ private static final String OPT_HELP = "h"; //$NON-NLS-1$
+
+ /** hostname for the Aut Agent with which to register */
+ private static final String OPT_HELP_LONG = "help"; //$NON-NLS-1$
+
+ /** name of the AUT to register */
+ private static final String OPT_AUT_ID = "i"; //$NON-NLS-1$
+
+ /** name of the AUT to register */
+ private static final String OPT_AUT_ID_LONG = "autid"; //$NON-NLS-1$
+
+ /** flag for name generation for certain technical components */
+ private static final String OPT_NAME_TECHNICAL_COMPONENTS = "g"; //$NON-NLS-1$
+
+ /** flag for name generation for certain technical components */
+ private static final String OPT_NAME_TECHNICAL_COMPONENTS_LONG = "generatenames"; //$NON-NLS-1$
+
+ /** keyboard layout */
+ private static final String OPT_KEYBOARD_LAYOUT = "k"; //$NON-NLS-1$
+
+ /** keyboard layout */
+ private static final String OPT_KEYBOARD_LAYOUT_LONG = "kblayout"; //$NON-NLS-1$
+
+ /** AUT working directory */
+ private static final String OPT_WORKING_DIR = "w"; //$NON-NLS-1$
+
+ /** AUT working directory */
+ private static final String OPT_WORKING_DIR_LONG = "workingdir"; //$NON-NLS-1$
+
+ /** executable file used to start the AUT */
+ private static final String OPT_EXECUTABLE = "e"; //$NON-NLS-1$
+
+ /** executable file used to start the AUT */
+ 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
+ */
+ private static void printHelp(ParseException pe) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.setOptionComparator(new OptionComparator());
+ if (pe != null) {
+ formatter.printHelp(
+ LAUNCHER_NAME,
+ StringConstants.EMPTY,
+ createCmdLineOptions(),
+ "\n" + pe.getLocalizedMessage(), //$NON-NLS-1$
+ true);
+ } else {
+ formatter.printHelp(LAUNCHER_NAME,
+ createCmdLineOptions(), true);
+ }
+ }
+
+ /**
+ * Creates and returns settings for starting an AUT based on the given
+ * command line.
+ *
+ * @param cmdLine Provides the settings for the AUT configuration.
+ * @return new settings for starting an AUT.
+ */
+ private static Map<String, Object> createAutConfig(CommandLine cmdLine) {
+ Map<String, Object> autConfig = new HashMap<String, Object>();
+ if (cmdLine.hasOption(OPT_WORKING_DIR)) {
+ autConfig.put(AutConfigConstants.WORKING_DIR, cmdLine
+ .getOptionValue(OPT_WORKING_DIR));
+ } else {
+ autConfig.put(AutConfigConstants.WORKING_DIR, System
+ .getProperty("user.dir")); //$NON-NLS-1$
+ }
+
+ if (cmdLine.hasOption(OPT_NAME_TECHNICAL_COMPONENTS)) {
+ autConfig.put(AutConfigConstants.NAME_TECHNICAL_COMPONENTS, Boolean
+ .valueOf(cmdLine
+ .getOptionValue(OPT_NAME_TECHNICAL_COMPONENTS)));
+ } else {
+ autConfig.put(AutConfigConstants.NAME_TECHNICAL_COMPONENTS,
+ DEFAULT_NAME_TECHNICAL_COMPONENTS);
+ }
+ autConfig.put(AutConfigConstants.EXECUTABLE, cmdLine
+ .getOptionValue(OPT_EXECUTABLE));
+
+ if (cmdLine.hasOption(OPT_KEYBOARD_LAYOUT)) {
+ autConfig.put(AutConfigConstants.KEYBOARD_LAYOUT,
+ cmdLine.getOptionValue(OPT_KEYBOARD_LAYOUT));
+ }
+
+ String[] autArguments = cmdLine.getOptionValues(OPT_EXECUTABLE);
+ if (autArguments.length > 1) {
+ autConfig.put(AutConfigConstants.AUT_RUN_AUT_ARGUMENTS,
+ ArrayUtils.subarray(autArguments, 1, autArguments.length));
+ }
+
+ return autConfig;
+ }
+
+ /**
+ * 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")
+ private static Options createCmdLineOptions() {
+ Options options = new Options();
+ Option autAgentHostOption =
+ new Option(OPT_AUT_AGENT_HOST, true,
+ "AUT Agent Host"
+ + " (default \"" + DEFAULT_AUT_AGENT_HOST + "\")");
+ autAgentHostOption.setLongOpt(OPT_AUT_AGENT_HOST_LONG);
+ autAgentHostOption.setArgName("hostname");
+ options.addOption(autAgentHostOption);
+
+ Option autAgentPortOption =
+ new Option(OPT_AUT_AGENT_PORT, true,
+ "AUT Agent Port between 1024 and 65536"
+ + " (default \"" + DEFAULT_AUT_AGENT_PORT + "\")");
+ autAgentPortOption.setLongOpt(OPT_AUT_AGENT_PORT_LONG);
+ autAgentPortOption.setArgName("port");
+ options.addOption(autAgentPortOption);
+
+ OptionGroup autToolkitOptionGroup = new OptionGroup();
+ autToolkitOptionGroup.addOption(
+ new Option(TK_SWING, "AUT uses Swing toolkit"));
+ autToolkitOptionGroup.addOption(
+ new Option(TK_SWT, "AUT uses SWT toolkit"));
+ autToolkitOptionGroup.addOption(
+ new Option(TK_RCP, "AUT uses RCP toolkit"));
+ autToolkitOptionGroup.setRequired(true);
+ options.addOptionGroup(autToolkitOptionGroup);
+
+ Option autIdOption =
+ new Option(OPT_AUT_ID, true, "AUT ID");
+ autIdOption.setLongOpt(OPT_AUT_ID_LONG);
+ autIdOption.setArgName("id");
+ autIdOption.setRequired(true);
+ options.addOption(autIdOption);
+
+ Option nameTechnicalComponentsOption =
+ new Option(OPT_NAME_TECHNICAL_COMPONENTS,
+ true, "Generate Names for Technical Components (true / false)");
+ nameTechnicalComponentsOption
+ .setLongOpt(OPT_NAME_TECHNICAL_COMPONENTS_LONG);
+ nameTechnicalComponentsOption.setArgName("true / false");
+ options.addOption(nameTechnicalComponentsOption);
+
+ Option keyboardLayoutOption =
+ new Option(OPT_KEYBOARD_LAYOUT,
+ true, "Keyboard Layout");
+ keyboardLayoutOption
+ .setLongOpt(OPT_KEYBOARD_LAYOUT_LONG);
+ keyboardLayoutOption.setArgName("locale");
+ options.addOption(keyboardLayoutOption);
+
+ Option workingDirOption = new Option(OPT_WORKING_DIR,
+ true, "AUT Working Directory");
+ workingDirOption.setLongOpt(OPT_WORKING_DIR_LONG);
+ workingDirOption.setArgName("directory");
+ options.addOption(workingDirOption);
+
+ Option helpOption = new Option(OPT_HELP,
+ false, "Displays this help");
+ helpOption.setLongOpt(OPT_HELP_LONG);
+ options.addOption(helpOption);
+
+ OptionBuilder.hasArgs();
+ Option autExecutableFileOption = OptionBuilder.create(OPT_EXECUTABLE);
+ autExecutableFileOption.setDescription("AUT Executable File");
+ autExecutableFileOption.setLongOpt(OPT_EXECUTABLE_LONG);
+ autExecutableFileOption.setRequired(true);
+ autExecutableFileOption.setArgName("command");
+ options.addOption(autExecutableFileOption);
+
+ return options;
+ }
+
+ /**
+ * This class implements the <code>Comparator</code> interface for comparing
+ * Options.
+ */
+ private static class OptionComparator implements Comparator {
+ /** {@inheritDoc} */
+ public int compare(Object o1, Object o2) {
+ Option opt1 = (Option)o1;
+ Option opt2 = (Option)o2;
+ // always list -exec as last option
+ if (opt1.getOpt().equals(OPT_EXECUTABLE)) {
+ return 1;
+ }
+ if (opt2.getOpt().equals(OPT_EXECUTABLE)) {
+ return -1;
+ }
+ return 0;
+ }
+ }
+}

Back to the top