You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2015/02/17 12:37:31 UTC
[16/50] [abbrv] incubator-taverna-commandline git commit:
taverna-commandline-launcher/
taverna-commandline-launcher/
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/commit/a8e6b3ed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/tree/a8e6b3ed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/diff/a8e6b3ed
Branch: refs/heads/master
Commit: a8e6b3edeb4682e71de34024376c51756de55474
Parents: e8f020f
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Sun Dec 28 01:44:56 2014 -0600
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Sun Dec 28 01:44:56 2014 -0600
----------------------------------------------------------------------
.gitignore | 24 -
.project | 23 -
.travis.yml | 1 -
README.md | 3 -
pom.xml | 96 ----
.../commandline/CommandLineOptionsImpl.java | 445 -------------------
.../taverna/commandline/TavernaCommandLine.java | 139 ------
src/main/resources/help.txt | 87 ----
.../TestCommandLineOptionsHandler.java | 267 -----------
taverna-commandline-launcher/pom.xml | 96 ++++
.../commandline/CommandLineOptionsImpl.java | 445 +++++++++++++++++++
.../taverna/commandline/TavernaCommandLine.java | 139 ++++++
.../src/main/resources/help.txt | 87 ++++
.../TestCommandLineOptionsHandler.java | 267 +++++++++++
14 files changed, 1034 insertions(+), 1085 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index ebe0e5b..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# ignore project files #
-.classpath
-.project
-.settings/
-catalog-v001.xml
-
-# ignore target files #
-target/
-bin/
-build/
-dist/
-apidoc/
-*.swp
-
-# ignore svn files if there
-.svn
-
-# ignore log files #
-*.log
-/logs/*
-*/logs/*
-
-
-
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/.project
----------------------------------------------------------------------
diff --git a/.project b/.project
deleted file mode 100644
index 86e9dca..0000000
--- a/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>taverna-command-line</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- </natures>
-</projectDescription>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index dff5f3a..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1 +0,0 @@
-language: java
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
deleted file mode 100644
index 31ac549..0000000
--- a/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-Taverna 3 command line
-
-This code was previously hosted at http://taverna.googlecode.com/svn/taverna/command-line/
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index ad8330e..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,96 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>net.sf.taverna</groupId>
- <artifactId>taverna-parent</artifactId>
- <version>3.0.1-SNAPSHOT</version>
- </parent>
- <groupId>uk.org.taverna.commandline</groupId>
- <artifactId>taverna-command-line</artifactId>
- <version>0.1.2-SNAPSHOT</version>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.4</version>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <mainClass>uk.org.taverna.commandline.TavernaCommandLine</mainClass>
- <classpathLayoutType>custom</classpathLayoutType>
- <customClasspathLayout>../${artifact.groupId}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</customClasspathLayout>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>net.sf.taverna.t2.taverna-commandline</groupId>
- <artifactId>taverna-commandline-api</artifactId>
- <version>${t2.taverna-commandline.version}</version>
- </dependency>
- <dependency>
- <groupId>uk.org.taverna.osgi</groupId>
- <artifactId>osgi-launcher</artifactId>
- <version>${osgi.launcher.version}</version>
- </dependency>
- <dependency>
- <groupId>uk.org.taverna.configuration</groupId>
- <artifactId>taverna-app-configuration-impl</artifactId>
- <version>${taverna.configuration.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>com.springsource.org.apache.commons.cli</artifactId>
- <version>${commons.cli.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>${commons.io.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.log4j</groupId>
- <artifactId>com.springsource.org.apache.log4j</artifactId>
- <version>${log4j.version}</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse</groupId>
- <artifactId>org.eclipse.osgi</artifactId>
- <version>${osgi.equinox.version}</version>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <repositories>
- <repository>
- <releases />
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- <id>mygrid-repository</id>
- <name>myGrid Repository</name>
- <url>http://www.mygrid.org.uk/maven/repository</url>
- </repository>
- <repository>
- <releases>
- <enabled>false</enabled>
- </releases>
- <snapshots />
- <id>mygrid-snapshot-repository</id>
- <name>myGrid Snapshot Repository</name>
- <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
- </repository>
- </repositories>
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java b/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java
deleted file mode 100644
index b702e03..0000000
--- a/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java
+++ /dev/null
@@ -1,445 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2007 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package uk.org.taverna.commandline;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import net.sf.taverna.t2.commandline.exceptions.ArgumentsParsingException;
-import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
-import net.sf.taverna.t2.commandline.options.CommandLineOptions;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.io.IOUtils;
-import org.apache.log4j.Logger;
-
-/**
- * Handles the processing of command line arguments for enacting a workflow.
- * This class encapsulates all command line options, and exposes them through higher-level
- * accessors. Upon creation it checks the validity of the command line options and raises an
- * {@link InvalidOptionException} if they are invalid.
- *
- * @author Stuart Owen
- * @author David Withers
- */
-public class CommandLineOptionsImpl implements CommandLineOptions {
-
- private static final String OUTPUTDIR = "outputdir";
- private static final String BUNDLE = "bundle";
- private static final Logger logger = Logger.getLogger(CommandLineOptionsImpl.class);
- private Options options;
- private CommandLine commandLine;
-
- public CommandLineOptionsImpl(String[] args) throws ArgumentsParsingException, InvalidOptionException {
- this.options = intitialiseOptions();
- this.commandLine = processArgs(args);
- checkForInvalid();
- }
-
- @Override
- public boolean askedForHelp() {
- return hasOption("help") || (getArgs().length==0 && getOptions().length==0);
- }
-
- @Override
- public boolean isProvenanceEnabled() {
- return hasOption("provenance");
- }
-
- protected void checkForInvalid() throws InvalidOptionException {
- if (askedForHelp()) return;
- if (isProvenanceEnabled()
- && !(hasOption("embedded") || hasOption("clientserver") || hasOption("dbproperties")))
- throw new InvalidOptionException(
- "You should be running with a database to use provenance");
- if (isProvenanceEnabled() && hasOption("inmemory"))
- throw new InvalidOptionException(
- "You should be running with a database to use provenance");
- if ((hasOption("inputfile") || hasOption("inputvalue"))
- && hasOption("inputdoc"))
- throw new InvalidOptionException(
- "You can't provide both -input and -inputdoc arguments");
-
- if (hasOption("inputdelimiter") && hasOption("inputdoc"))
- throw new InvalidOptionException("You cannot combine the -inputdelimiter and -inputdoc arguments");
-
- if (getArgs().length == 0
- && !(hasOption("help") || hasOption("startdb")))
- throw new InvalidOptionException("You must specify a workflow");
-
- if (hasOption("inmemory") && hasOption("embedded"))
- throw new InvalidOptionException(
- "The options -embedded, -clientserver and -inmemory cannot be used together");
- if (hasOption("inmemory") && hasOption("clientserver"))
- throw new InvalidOptionException(
- "The options -embedded, -clientserver and -inmemory cannot be used together");
- if (hasOption("embedded") && hasOption("clientserver"))
- throw new InvalidOptionException(
- "The options -embedded, -clientserver and -inmemory cannot be used together");
- }
-
- @Override
- public void displayHelp() {
- boolean full = false;
- if (hasOption("help")) full=true;
- displayHelp(full);
- }
-
- @Override
- public void displayHelp(boolean showFullText) {
-
- HelpFormatter formatter = new HelpFormatter();
- try {
- formatter
- .printHelp("executeworkflow [options] [workflow]", options);
- if (showFullText) {
- InputStream helpStream = CommandLineOptionsImpl.class
- .getClassLoader().getResourceAsStream("help.txt");
- String helpText = IOUtils.toString(helpStream);
- System.out.println(helpText);
- }
-
- } catch (IOException e) {
- logger.error("Failed to load the help document", e);
- System.out.println("Failed to load the help document");
- //System.exit(-1);
- }
- }
-
- @Override
- public String[] getArgs() {
- return commandLine.getArgs();
- }
-
- /**
- *
- * @return the port that the database should run on
- */
- @Override
- public String getDatabasePort() {
- return getOptionValue("port");
- }
-
- /**
- *
- * @return a path to a properties file that contains database configuration
- * settings
- */
- @Override
- public String getDatabaseProperties() {
- return getOptionValue("dbproperties");
- }
-
- /**
- * Returns an array that alternates between a portname and path to a file
- * containing the input values. Therefore the array will always contain an
- * even number of elements
- *
- * @return an array of portname and path to files containing individual
- * inputs.
- */
- @Override
- public String[] getInputFiles() {
- if (hasInputFiles()) {
- return getOptionValues("inputfile");
- } else {
- return new String[] {};
- }
- }
-
- @Override
- public String[] getInputValues() {
- if (hasInputValues()) {
- return getOptionValues("inputvalue");
- } else {
- return new String[] {};
- }
- }
-
- @Override
- public String getLogFile() {
- return getOptionValue("logfile");
- }
-
- public Option [] getOptions() {
- return commandLine.getOptions();
- }
-
- private String getOptionValue(String opt) {
- return commandLine.getOptionValue(opt);
- }
-
- private String[] getOptionValues(String arg0) {
- return commandLine.getOptionValues(arg0);
- }
-
- /**
- *
- * @return the directory to write the results to
- */
- @Override
- public String getOutputDirectory() {
- return getOptionValue(OUTPUTDIR);
- }
-
- @Override
- public boolean getStartDatabase() {
- return hasOption("startdb");
- }
-
- /**
- * @return the directory with Credential Manager's files
- */
- @Override
- public String getCredentialManagerDir() {
- return getOptionValue(CREDENTIAL_MANAGER_DIR_OPTION);
- }
-
- @Override
- public boolean getStartDatabaseOnly() throws InvalidOptionException {
- return (getStartDatabase() && (getWorkflow() == null));
- }
-
- @Override
- public String getWorkflow() throws InvalidOptionException {
- if (getArgs().length == 0) {
- return null;
- } else if (getArgs().length != 1) {
- throw new InvalidOptionException(
- "You should only specify one workflow file");
- } else {
- return getArgs()[0];
- }
- }
-
- @Override
- public boolean hasDelimiterFor(String inputName) {
- boolean result = false;
- if (hasOption("inputdelimiter")) {
- String [] values = getOptionValues("inputdelimiter");
- for (int i=0;i<values.length;i+=2) {
- if (values[i].equals(inputName))
- {
- result=true;
- break;
- }
- }
- }
- return result;
- }
-
- @Override
- public boolean hasInputFiles() {
- return hasOption("inputfile");
- }
-
- @Override
- public boolean hasInputValues() {
- return hasOption("inputvalue");
- }
-
- @Override
- public boolean hasLogFile() {
- return hasOption("logfile");
- }
-
- @Override
- public boolean hasOption(String option) {
- return commandLine.hasOption(option);
- }
-
- @Override
- public String inputDelimiter(String inputName) {
- String result = null;
- if (hasOption("inputdelimiter")) {
- String [] values = getOptionValues("inputdelimiter");
- for (int i=0;i<values.length;i+=2) {
- if (values[i].equals(inputName))
- {
- result=values[i+1];
- break;
- }
- }
- }
- return result;
- }
-
- @SuppressWarnings("static-access")
- private Options intitialiseOptions() {
- Option helpOption = new Option("help", "Display comprehensive help information.");
-
- Option outputOption = OptionBuilder
- .withArgName("directory")
- .hasArg()
- .withDescription(
- "Save outputs as files in directory, default "
- + "is to make a new directory workflowName_output.")
- .create(OUTPUTDIR);
-
- Option bundleOption = OptionBuilder.withArgName(BUNDLE).hasArg()
- .withDescription("Save outputs to a new Workflow Run Bundle (zip).")
- .create(BUNDLE);
-
- Option logFileOption = OptionBuilder
- .withArgName("filename")
- .hasArg()
- .withDescription(
- "The logfile to which more verbose logging will be written to.")
- .create("logfile");
-
- Option inputdocOption = OptionBuilder.withArgName("document").hasArg()
- .withDescription("Load inputs from a Baclava document.").create(
- "inputdoc");
-
- Option inputFileOption = OptionBuilder
- .withArgName("inputname filename").hasArgs(2)
- .withValueSeparator(' ').withDescription(
- "Load the named input from file or URL.").create(
- "inputfile");
-
- Option inputValueOption = OptionBuilder.withArgName("inputname value")
- .hasArgs(2).withValueSeparator(' ').withDescription(
- "Directly use the value for the named input.").create(
- "inputvalue");
-
- Option inputDelimiterOption = OptionBuilder
- .withArgName("inputname delimiter")
- .hasArgs(2)
- .withValueSeparator(' ')
- .withDescription(
- "Cause an inputvalue or inputfile to be split into a list according to the delimiter. The associated workflow input must be expected to receive a list.")
- .create("inputdelimiter");
-
- Option dbProperties = OptionBuilder.withArgName("filename").hasArg()
- .withDescription(
- "Load a properties file to configure the database.")
- .create("dbproperties");
-
- Option port = OptionBuilder
- .withArgName("portnumber")
- .hasArg()
- .withDescription(
- "The port that the database is running on. If set requested to start its own internal server, this is the start port that will be used.")
- .create("port");
-
- Option embedded = new Option("embedded",
- "Connect to an embedded Derby database. This can prevent mulitple invocations.");
- Option clientserver = new Option("clientserver",
- "Connect as a client to a derby server instance.");
- Option inMemOption = new Option(
- "inmemory",
- "Run the workflow with data stored in-memory rather than in a database (this is the default option). This can give performance inprovements, at the cost of overall memory usage.");
- Option startDB = new Option("startdb",
- "Automatically start an internal Derby database server.");
- Option provenance = new Option("provenance",
- "Generate provenance information and store it in the database.");
-
-
- Option credentialManagerDirectory = OptionBuilder.withArgName("directory path").
- hasArg().withDescription(
- "Absolute path to a directory where Credential Manager's files (keystore and truststore) are located.")
- .create(CREDENTIAL_MANAGER_DIR_OPTION);
- Option credentialManagerPassword = new Option(CREDENTIAL_MANAGER_PASSWORD_OPTION, "Indicate that the master password for Credential Manager will be provided on standard input."); // optional password option, to be read from standard input
-
- Options options = new Options();
- options.addOption(helpOption);
- options.addOption(inputFileOption);
- options.addOption(inputValueOption);
- options.addOption(inputDelimiterOption);
- options.addOption(inputdocOption);
- options.addOption(outputOption);
- options.addOption(bundleOption);
- options.addOption(inMemOption);
- options.addOption(embedded);
- options.addOption(clientserver);
- options.addOption(dbProperties);
- options.addOption(port);
- options.addOption(startDB);
- options.addOption(provenance);
- options.addOption(logFileOption);
- options.addOption(credentialManagerDirectory);
- options.addOption(credentialManagerPassword);
-
- return options;
- }
-
- @Override
- public boolean isClientServer() {
- return hasOption("clientserver");
- }
-
- @Override
- public boolean isEmbedded() {
- return hasOption("embedded");
- }
-
- @Override
- public boolean isInMemory() {
- return hasOption("inmemory");
- }
-
- private CommandLine processArgs(String[] args) throws ArgumentsParsingException {
- CommandLineParser parser = new GnuParser();
- CommandLine line = null;
- try {
- // parse the command line arguments
- line = parser.parse(options, args);
- } catch (ParseException exp) {
- // oops, something went wrong
-// System.err.println("Taverna command line arguments' parsing failed. Reason: " + exp.getMessage());
-// System.exit(1);
- throw new ArgumentsParsingException("Taverna command line arguments' parsing failed. Reason: " + exp.getMessage(), exp);
- }
- return line;
- }
-
- /**
- * Save the results to a directory if -outputdir has been explicitly defined,
- * or if -outputdoc has not been defined.
- *
- * @return boolean
- */
- @Override
- public boolean saveResultsToDirectory() {
- return (options.hasOption(OUTPUTDIR) || !hasSaveResultsToBundle());
- }
-
- @Override
- public String saveResultsToBundle() {
- if (! hasSaveResultsToBundle()) {
- return null;
- }
- return getOptionValue(BUNDLE);
- }
-
- @Override
- public boolean hasSaveResultsToBundle() {
- return hasOption(BUNDLE);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java
----------------------------------------------------------------------
diff --git a/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java b/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java
deleted file mode 100644
index a462ba3..0000000
--- a/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2012 The University of Manchester
- *
- * Modifications to the initial code base are copyright of their
- * respective authors, or their employers as appropriate.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- ******************************************************************************/
-package uk.org.taverna.commandline;
-
-import java.io.File;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import net.sf.taverna.t2.commandline.exceptions.ArgumentsParsingException;
-import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
-import net.sf.taverna.t2.commandline.options.CommandLineOptions;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-
-import uk.org.taverna.commons.profile.xml.jaxb.ApplicationProfile;
-import uk.org.taverna.commons.profile.xml.jaxb.BundleInfo;
-import uk.org.taverna.commons.profile.xml.jaxb.FrameworkConfiguration;
-import uk.org.taverna.configuration.app.ApplicationConfiguration;
-import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl;
-import uk.org.taverna.configuration.app.impl.Log4JConfiguration;
-import uk.org.taverna.osgi.OsgiLauncher;
-
-/**
- * Main entry point for starting the Taverna Command Line Tool.
- *
- * @author David Withers
- */
-public class TavernaCommandLine {
-
- private static final String COMMANDLINE_BUNDLE_NAME = "net.sf.taverna.t2.taverna-commandline.common";
-
- private static File commandlineBundle;
-
- private static ApplicationConfiguration applicationConfiguration = new ApplicationConfigurationImpl();
-
- private static Log4JConfiguration log4jConfiguration = new Log4JConfiguration();
-
- /**
- * Starts the Taverna Command Line Tool.
- *
- * @param args
- * Taverna Command Line arguments
- */
- public static void main(final String[] args) {
- try {
- CommandLineOptions commandLineOptions = new CommandLineOptionsImpl(args);
- if (commandLineOptions.askedForHelp()) {
- commandLineOptions.displayHelp();
- } else {
- log4jConfiguration.setApplicationConfiguration(applicationConfiguration);
- log4jConfiguration.prepareLog4J();
- setDerbyPaths();
- OsgiLauncher osgilauncher = new OsgiLauncher(getAppDirectory(), getBundleURIs());
- setFrameworkConfiguration(osgilauncher);
- osgilauncher.start();
- BundleContext context = osgilauncher.getContext();
- context.registerService("net.sf.taverna.t2.commandline.options.CommandLineOptions",
- commandLineOptions, null);
- osgilauncher.startServices(true);
- osgilauncher.startBundle(osgilauncher.installBundle(commandlineBundle.toURI()));
- }
- } catch (ArgumentsParsingException e) {
- System.out.println(e.getMessage());
- } catch (InvalidOptionException e) {
- System.out.println(e.getMessage());
- } catch (BundleException e) {
- System.out.println(e.getMessage());
- }
- }
-
- /**
- * Sets the OSGi Framework configuration.
- *
- * @param osgilauncher
- */
- private static void setFrameworkConfiguration(OsgiLauncher osgilauncher) {
- ApplicationProfile applicationProfile = applicationConfiguration.getApplicationProfile();
- List<FrameworkConfiguration> frameworkConfigurations = applicationProfile
- .getFrameworkConfiguration();
- if (!frameworkConfigurations.isEmpty()) {
- Map<String, String> configurationMap = new HashMap<String, String>();
- for (FrameworkConfiguration frameworkConfiguration : frameworkConfigurations) {
- configurationMap.put(frameworkConfiguration.getName(),
- frameworkConfiguration.getValue());
- }
- osgilauncher.setFrameworkConfiguration(configurationMap);
- }
- }
-
- private static List<URI> getBundleURIs() {
- List<URI> bundleURIs = new ArrayList<URI>();
- ApplicationProfile applicationProfile = applicationConfiguration.getApplicationProfile();
- File libDir = new File(applicationConfiguration.getStartupDir(), "lib");
- if (applicationProfile != null) {
- for (BundleInfo bundle : applicationProfile.getBundle()) {
- File bundleFile = new File(libDir, bundle.getFileName());
- if (bundle.getSymbolicName().equals(COMMANDLINE_BUNDLE_NAME)) {
- commandlineBundle = bundleFile;
- } else {
- bundleURIs.add(bundleFile.toURI());
- }
- }
- }
- return bundleURIs;
- }
-
- private static File getAppDirectory() {
- return new File(applicationConfiguration.getApplicationHomeDir().getAbsolutePath());
- }
-
- private static void setDerbyPaths() {
- System.setProperty("derby.system.home", getAppDirectory().getAbsolutePath());
- File logFile = new File(applicationConfiguration.getLogDir(), "derby.log");
- System.setProperty("derby.stream.error.file", logFile.getAbsolutePath());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/src/main/resources/help.txt
----------------------------------------------------------------------
diff --git a/src/main/resources/help.txt b/src/main/resources/help.txt
deleted file mode 100644
index fb082cc..0000000
--- a/src/main/resources/help.txt
+++ /dev/null
@@ -1,87 +0,0 @@
-By default, the workflow is executed using the -inmemory option, and the
-results are written out to a directory named after the workflow name.
-
-If this directory already exists then a new directory is created, and
-appended with _<n>, where n is incremented to the next available index.
-
-Results are written out to files named after the output port for that result.
-If a result is composed of lists, then a directory is created for the output
-port and individual list items are named after the list element index (with 1
-being the first index). The the output is the result of an error, the filename
-is appended with '.error'.
-
-You can provide your own output directory with the -outputdir option. There
-will be an error if the directory already exists.
-
-You can also record your results to a Baclava document using -outputdoc
-option. The document will be overwritten if it already exists.
-
-Inputs can be provided in three ways. Both -inputfile and -inputvalue options
-can be used together; -inputdoc option must be used on its own. -inputfile and
--inputvalue options both take two additional arguments, the name of the port
-for the input, and either a file containing the input data, or the input value
-itself respectively.
-
-If one of more of your workflow inputs is a list, you can create a list
-input by using the -inputdelimiter option, which may be used with either
--inputfile or -inputvalue. This option takes two parameters - an input name
-and the delimiter by which to split the input into a list.
-
-The delimiter may be a simple character, such as a comma or a new-line
-character, or a regular expression. The input string, or file, will then be
-converted into a list being split by the delimiter specified. Make sure to
-put the delimiter character in quotes as it may be interpreted by the shell
-as a special character, e.g. ;.
-
-If a list of greater depth (i.e. a list or lists or deeper) is required then
-you will need to use the -inputdoc option. However, if you provide an input
-of lower depth to that required, then it will automatically be wrapped in one
-or more lists up to the required depth. Providing an input of greater depth
-than that required will result in an error.
-
-If a workflow has a high memory requirement, then it may be better to run it
-using a database to store data rather than storing it in memory, which is the
-default option. There are three options for using a database:
-
--embedded option, runs with an embedded database. This is slightly faster than
-the -clientserver option (below), but has the limitation that only one
-executeworkflow script may be executed simultaneously.
-
--clientserver option allows the workflow to be executed backed by the database
-running as a server. By default a database is not started for you, but may be
-started using -startdb option.
-
--startdb option starts a database. It may be used without providing a workflow
-to allow a database to be started separately, allowing multiple simultaneous
-executeworkflow script runs.
-
-More advanced database configurations can be specified using -dbproperties
-option, allowing you to take full control over the database used. This takes a
-second argument, the filename of the properties file, for which the following
-example contains the default settings:
-
-in_memory = true
-provenance = false
-connector = derby
-port = 1527
-dialect = org.hibernate.dialect.DerbyDialect
-start_derby = false
-driver = org.apache.derby.jdbc.EmbeddedDriver
-jdbcuri = jdbc:derby:t2-database;create=true;upgrade=true
-
-Note that when using -dbproperties together with other options, the other
-options take precedence.
-
--cmdir option lets you specify an absolute path to a directory where
-Credential Manager's files (keystore and truststore - containing user's
-credentials and trusted certificates for accessing secure services) are stored.
-If not specified and the workflow requires access to these files, Taverna will
-try to find them in the default location in <TAVERNA_HOME>/security somewhere
-inside user's home directory (depending on the platform).
-
--cmpassword option can be used to tell Taverna to expect the password for the
-Credential Manager on standard input. If the password is not piped in, Taverna
-will prompt you for it in the terminal and block until it is entered. Do not
-enter your password in the command line! If -cmpassword option is not specified
-and -cmdir option is used, Taverna will try to find the password in a special
-file password.txt in the directory specified with -cmdir option.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java
----------------------------------------------------------------------
diff --git a/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java b/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java
deleted file mode 100644
index 3e1d0f4..0000000
--- a/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java
+++ /dev/null
@@ -1,267 +0,0 @@
-package uk.org.taverna.commandline;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
-import net.sf.taverna.t2.commandline.options.CommandLineOptions;
-
-import org.junit.Test;
-
-public class TestCommandLineOptionsHandler {
-
- @Test
- public void testWorkflowName() throws Exception {
- CommandLineOptions handler = new CommandLineOptionsImpl(
- new String[] { "myworkflow.t2flow" });
- assertEquals("myworkflow.t2flow", handler.getWorkflow());
- }
-
- @Test
- public void shouldShowHelp() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(
- new String[] { "-help" });
- assertTrue(options.askedForHelp());
- options = new CommandLineOptionsImpl(
- new String[] {});
- assertTrue(options.askedForHelp());
- options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
- assertFalse(options.askedForHelp());
- }
-
- @Test
- public void getWorkflow() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(
- new String[] { "-help" });
- assertNull(options.getWorkflow());
- options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
- assertEquals("myworkflow.t2flow", options.getWorkflow());
- }
-
- @Test(expected = InvalidOptionException.class)
- public void cannotProvideInputFileAndInputDoc() throws Exception {
- new CommandLineOptionsImpl(new String[] { "-inputfile", "fred", "fred.txt",
- "-inputdoc", "myworkflow.t2flow" });
- }
-
- @Test(expected = InvalidOptionException.class)
- public void cannotProvideInputValueAndInputDoc() throws Exception {
- new CommandLineOptionsImpl(new String[] { "-inputvalue", "fred", "fred.txt",
- "-inputdoc", "myworkflow.t2flow" });
- }
-
- @Test
- public void canProvideInputValueAndFileTogether() throws Exception {
- //should not be an error
- new CommandLineOptionsImpl(new String[] { "-inputvalue", "fred", "abc",
- "-inputfile","fred2","fred2.txt","myworkflow.t2flow" });
- }
-
- @Test
- public void getInputs() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-inputfile", "fred", "fred.txt", "myworkflow.t2flow" });
- assertEquals(2, options.getInputFiles().length);
- assertEquals("fred", options.getInputFiles()[0]);
- assertEquals("fred.txt", options.getInputFiles()[1]);
-
- options = new CommandLineOptionsImpl(new String[] { "-inputfile", "fred",
- "fred.txt", "-inputfile", "fred2", "fred2.txt",
- "myworkflow.t2flow" });
- assertEquals(4, options.getInputFiles().length);
- assertEquals("fred", options.getInputFiles()[0]);
- assertEquals("fred.txt", options.getInputFiles()[1]);
- assertEquals("fred2", options.getInputFiles()[2]);
- assertEquals("fred2.txt", options.getInputFiles()[3]);
-
- options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
- assertNotNull(options.getInputFiles());
- assertEquals(0, options.getInputFiles().length);
-
- }
-
- @Test
- public void hasInputValue() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-inputvalue", "fred", "abc", "myworkflow.t2flow" });
- assertTrue(options.hasInputValues());
-
- options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
- assertFalse(options.hasInputValues());
- }
-
- @Test
- public void getInputValues() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-inputvalue", "fred", "abc", "myworkflow.t2flow" });
- assertEquals(2, options.getInputValues().length);
-
- options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
- assertNotNull(options.getInputValues());
- assertEquals(0,options.getInputValues().length);
- }
-
- @Test
- public void hasInputs() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-inputfile", "fred", "fred.txt", "myworkflow.t2flow" });
- assertTrue(options.hasInputFiles());
-
- options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
- assertFalse(options.hasInputFiles());
- }
-
- @Test
- public void noWorkflowNameButStartDB() throws Exception {
- // should not throw an error
- CommandLineOptions options = new CommandLineOptionsImpl(
- new String[] { "-startdb" });
- assertTrue(options.getStartDatabase());
- assertTrue(options.getStartDatabaseOnly());
- }
-
- @Test
- public void workflowNameAndStartDB() throws Exception {
- // should not throw an error
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-startdb", "myworkflow.t2flow" });
- assertTrue(options.getStartDatabase());
- assertFalse(options.getStartDatabaseOnly());
- }
-
- @Test(expected = InvalidOptionException.class)
- public void provenanceButNoDatabase() throws Exception {
- new CommandLineOptionsImpl(new String[] { "-provenance",
- "myworkflow.t2flow" });
- }
-
- @Test(expected = InvalidOptionException.class)
- public void provenanceButNoDatabase2() throws Exception {
- new CommandLineOptionsImpl(new String[] { "-provenance", "-inmemory",
- "myworkflow.t2flow" });
- }
-
- @Test
- public void provenanceDatabase() throws Exception {
- // should be no errors
- new CommandLineOptionsImpl(new String[] { "-provenance", "-embedded",
- "myworkflow.t2flow" });
- new CommandLineOptionsImpl(new String[] { "-provenance", "-clientserver",
- "myworkflow.t2flow" });
- new CommandLineOptionsImpl(new String[] { "-provenance", "-dbproperties",
- "dbproperties.properties", "myworkflow.t2flow" });
- }
-
- @Test
- public void testHasInputDelimiter() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-inputvalue","in1","1,2,3","-inputdelimiter","in1",",","-inputdelimiter","in2",",","myworkflow.t2flow" });
- assertTrue(options.hasDelimiterFor("in1"));
- assertTrue(options.hasDelimiterFor("in2"));
- assertFalse(options.hasDelimiterFor("in3"));
- }
-
- @Test(expected = InvalidOptionException.class)
- public void testInputDelimiterInvalidWithInputDoc() throws Exception {
- new CommandLineOptionsImpl(new String[] {
- "-inputdoc","doc.xml","-inputdelimiter","in1",",","myworkflow.t2flow" });
- }
-
-
- @Test
- public void testInputDelimiter() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-inputvalue","in1","1,2,3","-inputdelimiter","in1",",","-inputdelimiter","in2","!","myworkflow.t2flow" });
- assertEquals(",",options.inputDelimiter("in1"));
- assertEquals("!",options.inputDelimiter("in2"));
- assertNull(options.inputDelimiter("in3"));
- }
-
- @Test
- public void testInMemory() throws Exception {
- CommandLineOptions handler = new CommandLineOptionsImpl(new String[] {
- "-inmemory", "myworkflow.t2flow" });
- assertTrue(handler.hasOption("inmemory"));
- }
-
- @Test
- public void testEmbedded() throws Exception {
- CommandLineOptions handler = new CommandLineOptionsImpl(new String[] {
- "-embedded", "myworkflow.t2flow" });
- assertTrue(handler.hasOption("embedded"));
- }
-
- @Test
- public void testClientServer() throws Exception {
- CommandLineOptions handler = new CommandLineOptionsImpl(new String[] {
- "-clientserver", "myworkflow.t2flow" });
- assertTrue(handler.hasOption("clientserver"));
- }
-
- @Test(expected = InvalidOptionException.class)
- public void testInvalidEmbeddedAndClientServer() throws Exception {
- new CommandLineOptionsImpl(new String[] { "-clientserver", "-embedded",
- "myworkflow.t2flow" });
- }
-
- @Test(expected = InvalidOptionException.class)
- public void testInvalidEmbeddedAndMemory() throws Exception {
- new CommandLineOptionsImpl(new String[] { "-embedded", "-inmemory",
- "myworkflow.t2flow" });
- }
-
- @Test(expected = InvalidOptionException.class)
- public void testInvalidClientServerAndInMemory() throws Exception {
- new CommandLineOptionsImpl(new String[] { "-clientserver", "-inmemory",
- "myworkflow.t2flow" });
- }
-
- @Test
- public void isInMemory() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-inmemory", "myworkflow.t2flow" });
-
- assertTrue(options.isInMemory());
- assertFalse(options.isClientServer());
- assertFalse(options.isEmbedded());
- }
-
- @Test
- public void isClientServer() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-clientserver", "myworkflow.t2flow" });
-
- assertTrue(options.isClientServer());
- assertFalse(options.isInMemory());
- assertFalse(options.isEmbedded());
- }
-
- @Test
- public void hasLogFile() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-logfile","/tmp/logging", "myworkflow.t2flow" });
-
- assertTrue(options.hasLogFile());
- assertEquals("/tmp/logging", options.getLogFile());
- }
-
- @Test(expected = InvalidOptionException.class)
- @SuppressWarnings("unused")
- public void hasLogFileNotValidWithoutWorkflow() throws Exception{
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-logfile","/tmp/logging"});
- }
-
- @Test
- public void isEmbedded() throws Exception {
- CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
- "-embedded", "myworkflow.t2flow" });
-
- assertTrue(options.isEmbedded());
- assertFalse(options.isInMemory());
- assertFalse(options.isClientServer());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/taverna-commandline-launcher/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-commandline-launcher/pom.xml b/taverna-commandline-launcher/pom.xml
new file mode 100644
index 0000000..ad8330e
--- /dev/null
+++ b/taverna-commandline-launcher/pom.xml
@@ -0,0 +1,96 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.taverna</groupId>
+ <artifactId>taverna-parent</artifactId>
+ <version>3.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>uk.org.taverna.commandline</groupId>
+ <artifactId>taverna-command-line</artifactId>
+ <version>0.1.2-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <mainClass>uk.org.taverna.commandline.TavernaCommandLine</mainClass>
+ <classpathLayoutType>custom</classpathLayoutType>
+ <customClasspathLayout>../${artifact.groupId}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</customClasspathLayout>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.taverna.t2.taverna-commandline</groupId>
+ <artifactId>taverna-commandline-api</artifactId>
+ <version>${t2.taverna-commandline.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>uk.org.taverna.osgi</groupId>
+ <artifactId>osgi-launcher</artifactId>
+ <version>${osgi.launcher.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>uk.org.taverna.configuration</groupId>
+ <artifactId>taverna-app-configuration-impl</artifactId>
+ <version>${taverna.configuration.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>com.springsource.org.apache.commons.cli</artifactId>
+ <version>${commons.cli.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>${commons.io.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.log4j</groupId>
+ <artifactId>com.springsource.org.apache.log4j</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>${osgi.equinox.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <releases />
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <id>mygrid-repository</id>
+ <name>myGrid Repository</name>
+ <url>http://www.mygrid.org.uk/maven/repository</url>
+ </repository>
+ <repository>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots />
+ <id>mygrid-snapshot-repository</id>
+ <name>myGrid Snapshot Repository</name>
+ <url>http://www.mygrid.org.uk/maven/snapshot-repository</url>
+ </repository>
+ </repositories>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java
----------------------------------------------------------------------
diff --git a/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java b/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java
new file mode 100644
index 0000000..b702e03
--- /dev/null
+++ b/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/CommandLineOptionsImpl.java
@@ -0,0 +1,445 @@
+/*******************************************************************************
+ * Copyright (C) 2007 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package uk.org.taverna.commandline;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import net.sf.taverna.t2.commandline.exceptions.ArgumentsParsingException;
+import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
+import net.sf.taverna.t2.commandline.options.CommandLineOptions;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+
+/**
+ * Handles the processing of command line arguments for enacting a workflow.
+ * This class encapsulates all command line options, and exposes them through higher-level
+ * accessors. Upon creation it checks the validity of the command line options and raises an
+ * {@link InvalidOptionException} if they are invalid.
+ *
+ * @author Stuart Owen
+ * @author David Withers
+ */
+public class CommandLineOptionsImpl implements CommandLineOptions {
+
+ private static final String OUTPUTDIR = "outputdir";
+ private static final String BUNDLE = "bundle";
+ private static final Logger logger = Logger.getLogger(CommandLineOptionsImpl.class);
+ private Options options;
+ private CommandLine commandLine;
+
+ public CommandLineOptionsImpl(String[] args) throws ArgumentsParsingException, InvalidOptionException {
+ this.options = intitialiseOptions();
+ this.commandLine = processArgs(args);
+ checkForInvalid();
+ }
+
+ @Override
+ public boolean askedForHelp() {
+ return hasOption("help") || (getArgs().length==0 && getOptions().length==0);
+ }
+
+ @Override
+ public boolean isProvenanceEnabled() {
+ return hasOption("provenance");
+ }
+
+ protected void checkForInvalid() throws InvalidOptionException {
+ if (askedForHelp()) return;
+ if (isProvenanceEnabled()
+ && !(hasOption("embedded") || hasOption("clientserver") || hasOption("dbproperties")))
+ throw new InvalidOptionException(
+ "You should be running with a database to use provenance");
+ if (isProvenanceEnabled() && hasOption("inmemory"))
+ throw new InvalidOptionException(
+ "You should be running with a database to use provenance");
+ if ((hasOption("inputfile") || hasOption("inputvalue"))
+ && hasOption("inputdoc"))
+ throw new InvalidOptionException(
+ "You can't provide both -input and -inputdoc arguments");
+
+ if (hasOption("inputdelimiter") && hasOption("inputdoc"))
+ throw new InvalidOptionException("You cannot combine the -inputdelimiter and -inputdoc arguments");
+
+ if (getArgs().length == 0
+ && !(hasOption("help") || hasOption("startdb")))
+ throw new InvalidOptionException("You must specify a workflow");
+
+ if (hasOption("inmemory") && hasOption("embedded"))
+ throw new InvalidOptionException(
+ "The options -embedded, -clientserver and -inmemory cannot be used together");
+ if (hasOption("inmemory") && hasOption("clientserver"))
+ throw new InvalidOptionException(
+ "The options -embedded, -clientserver and -inmemory cannot be used together");
+ if (hasOption("embedded") && hasOption("clientserver"))
+ throw new InvalidOptionException(
+ "The options -embedded, -clientserver and -inmemory cannot be used together");
+ }
+
+ @Override
+ public void displayHelp() {
+ boolean full = false;
+ if (hasOption("help")) full=true;
+ displayHelp(full);
+ }
+
+ @Override
+ public void displayHelp(boolean showFullText) {
+
+ HelpFormatter formatter = new HelpFormatter();
+ try {
+ formatter
+ .printHelp("executeworkflow [options] [workflow]", options);
+ if (showFullText) {
+ InputStream helpStream = CommandLineOptionsImpl.class
+ .getClassLoader().getResourceAsStream("help.txt");
+ String helpText = IOUtils.toString(helpStream);
+ System.out.println(helpText);
+ }
+
+ } catch (IOException e) {
+ logger.error("Failed to load the help document", e);
+ System.out.println("Failed to load the help document");
+ //System.exit(-1);
+ }
+ }
+
+ @Override
+ public String[] getArgs() {
+ return commandLine.getArgs();
+ }
+
+ /**
+ *
+ * @return the port that the database should run on
+ */
+ @Override
+ public String getDatabasePort() {
+ return getOptionValue("port");
+ }
+
+ /**
+ *
+ * @return a path to a properties file that contains database configuration
+ * settings
+ */
+ @Override
+ public String getDatabaseProperties() {
+ return getOptionValue("dbproperties");
+ }
+
+ /**
+ * Returns an array that alternates between a portname and path to a file
+ * containing the input values. Therefore the array will always contain an
+ * even number of elements
+ *
+ * @return an array of portname and path to files containing individual
+ * inputs.
+ */
+ @Override
+ public String[] getInputFiles() {
+ if (hasInputFiles()) {
+ return getOptionValues("inputfile");
+ } else {
+ return new String[] {};
+ }
+ }
+
+ @Override
+ public String[] getInputValues() {
+ if (hasInputValues()) {
+ return getOptionValues("inputvalue");
+ } else {
+ return new String[] {};
+ }
+ }
+
+ @Override
+ public String getLogFile() {
+ return getOptionValue("logfile");
+ }
+
+ public Option [] getOptions() {
+ return commandLine.getOptions();
+ }
+
+ private String getOptionValue(String opt) {
+ return commandLine.getOptionValue(opt);
+ }
+
+ private String[] getOptionValues(String arg0) {
+ return commandLine.getOptionValues(arg0);
+ }
+
+ /**
+ *
+ * @return the directory to write the results to
+ */
+ @Override
+ public String getOutputDirectory() {
+ return getOptionValue(OUTPUTDIR);
+ }
+
+ @Override
+ public boolean getStartDatabase() {
+ return hasOption("startdb");
+ }
+
+ /**
+ * @return the directory with Credential Manager's files
+ */
+ @Override
+ public String getCredentialManagerDir() {
+ return getOptionValue(CREDENTIAL_MANAGER_DIR_OPTION);
+ }
+
+ @Override
+ public boolean getStartDatabaseOnly() throws InvalidOptionException {
+ return (getStartDatabase() && (getWorkflow() == null));
+ }
+
+ @Override
+ public String getWorkflow() throws InvalidOptionException {
+ if (getArgs().length == 0) {
+ return null;
+ } else if (getArgs().length != 1) {
+ throw new InvalidOptionException(
+ "You should only specify one workflow file");
+ } else {
+ return getArgs()[0];
+ }
+ }
+
+ @Override
+ public boolean hasDelimiterFor(String inputName) {
+ boolean result = false;
+ if (hasOption("inputdelimiter")) {
+ String [] values = getOptionValues("inputdelimiter");
+ for (int i=0;i<values.length;i+=2) {
+ if (values[i].equals(inputName))
+ {
+ result=true;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean hasInputFiles() {
+ return hasOption("inputfile");
+ }
+
+ @Override
+ public boolean hasInputValues() {
+ return hasOption("inputvalue");
+ }
+
+ @Override
+ public boolean hasLogFile() {
+ return hasOption("logfile");
+ }
+
+ @Override
+ public boolean hasOption(String option) {
+ return commandLine.hasOption(option);
+ }
+
+ @Override
+ public String inputDelimiter(String inputName) {
+ String result = null;
+ if (hasOption("inputdelimiter")) {
+ String [] values = getOptionValues("inputdelimiter");
+ for (int i=0;i<values.length;i+=2) {
+ if (values[i].equals(inputName))
+ {
+ result=values[i+1];
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ @SuppressWarnings("static-access")
+ private Options intitialiseOptions() {
+ Option helpOption = new Option("help", "Display comprehensive help information.");
+
+ Option outputOption = OptionBuilder
+ .withArgName("directory")
+ .hasArg()
+ .withDescription(
+ "Save outputs as files in directory, default "
+ + "is to make a new directory workflowName_output.")
+ .create(OUTPUTDIR);
+
+ Option bundleOption = OptionBuilder.withArgName(BUNDLE).hasArg()
+ .withDescription("Save outputs to a new Workflow Run Bundle (zip).")
+ .create(BUNDLE);
+
+ Option logFileOption = OptionBuilder
+ .withArgName("filename")
+ .hasArg()
+ .withDescription(
+ "The logfile to which more verbose logging will be written to.")
+ .create("logfile");
+
+ Option inputdocOption = OptionBuilder.withArgName("document").hasArg()
+ .withDescription("Load inputs from a Baclava document.").create(
+ "inputdoc");
+
+ Option inputFileOption = OptionBuilder
+ .withArgName("inputname filename").hasArgs(2)
+ .withValueSeparator(' ').withDescription(
+ "Load the named input from file or URL.").create(
+ "inputfile");
+
+ Option inputValueOption = OptionBuilder.withArgName("inputname value")
+ .hasArgs(2).withValueSeparator(' ').withDescription(
+ "Directly use the value for the named input.").create(
+ "inputvalue");
+
+ Option inputDelimiterOption = OptionBuilder
+ .withArgName("inputname delimiter")
+ .hasArgs(2)
+ .withValueSeparator(' ')
+ .withDescription(
+ "Cause an inputvalue or inputfile to be split into a list according to the delimiter. The associated workflow input must be expected to receive a list.")
+ .create("inputdelimiter");
+
+ Option dbProperties = OptionBuilder.withArgName("filename").hasArg()
+ .withDescription(
+ "Load a properties file to configure the database.")
+ .create("dbproperties");
+
+ Option port = OptionBuilder
+ .withArgName("portnumber")
+ .hasArg()
+ .withDescription(
+ "The port that the database is running on. If set requested to start its own internal server, this is the start port that will be used.")
+ .create("port");
+
+ Option embedded = new Option("embedded",
+ "Connect to an embedded Derby database. This can prevent mulitple invocations.");
+ Option clientserver = new Option("clientserver",
+ "Connect as a client to a derby server instance.");
+ Option inMemOption = new Option(
+ "inmemory",
+ "Run the workflow with data stored in-memory rather than in a database (this is the default option). This can give performance inprovements, at the cost of overall memory usage.");
+ Option startDB = new Option("startdb",
+ "Automatically start an internal Derby database server.");
+ Option provenance = new Option("provenance",
+ "Generate provenance information and store it in the database.");
+
+
+ Option credentialManagerDirectory = OptionBuilder.withArgName("directory path").
+ hasArg().withDescription(
+ "Absolute path to a directory where Credential Manager's files (keystore and truststore) are located.")
+ .create(CREDENTIAL_MANAGER_DIR_OPTION);
+ Option credentialManagerPassword = new Option(CREDENTIAL_MANAGER_PASSWORD_OPTION, "Indicate that the master password for Credential Manager will be provided on standard input."); // optional password option, to be read from standard input
+
+ Options options = new Options();
+ options.addOption(helpOption);
+ options.addOption(inputFileOption);
+ options.addOption(inputValueOption);
+ options.addOption(inputDelimiterOption);
+ options.addOption(inputdocOption);
+ options.addOption(outputOption);
+ options.addOption(bundleOption);
+ options.addOption(inMemOption);
+ options.addOption(embedded);
+ options.addOption(clientserver);
+ options.addOption(dbProperties);
+ options.addOption(port);
+ options.addOption(startDB);
+ options.addOption(provenance);
+ options.addOption(logFileOption);
+ options.addOption(credentialManagerDirectory);
+ options.addOption(credentialManagerPassword);
+
+ return options;
+ }
+
+ @Override
+ public boolean isClientServer() {
+ return hasOption("clientserver");
+ }
+
+ @Override
+ public boolean isEmbedded() {
+ return hasOption("embedded");
+ }
+
+ @Override
+ public boolean isInMemory() {
+ return hasOption("inmemory");
+ }
+
+ private CommandLine processArgs(String[] args) throws ArgumentsParsingException {
+ CommandLineParser parser = new GnuParser();
+ CommandLine line = null;
+ try {
+ // parse the command line arguments
+ line = parser.parse(options, args);
+ } catch (ParseException exp) {
+ // oops, something went wrong
+// System.err.println("Taverna command line arguments' parsing failed. Reason: " + exp.getMessage());
+// System.exit(1);
+ throw new ArgumentsParsingException("Taverna command line arguments' parsing failed. Reason: " + exp.getMessage(), exp);
+ }
+ return line;
+ }
+
+ /**
+ * Save the results to a directory if -outputdir has been explicitly defined,
+ * or if -outputdoc has not been defined.
+ *
+ * @return boolean
+ */
+ @Override
+ public boolean saveResultsToDirectory() {
+ return (options.hasOption(OUTPUTDIR) || !hasSaveResultsToBundle());
+ }
+
+ @Override
+ public String saveResultsToBundle() {
+ if (! hasSaveResultsToBundle()) {
+ return null;
+ }
+ return getOptionValue(BUNDLE);
+ }
+
+ @Override
+ public boolean hasSaveResultsToBundle() {
+ return hasOption(BUNDLE);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java
----------------------------------------------------------------------
diff --git a/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java b/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java
new file mode 100644
index 0000000..a462ba3
--- /dev/null
+++ b/taverna-commandline-launcher/src/main/java/uk/org/taverna/commandline/TavernaCommandLine.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (C) 2012 The University of Manchester
+ *
+ * Modifications to the initial code base are copyright of their
+ * respective authors, or their employers as appropriate.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ ******************************************************************************/
+package uk.org.taverna.commandline;
+
+import java.io.File;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.taverna.t2.commandline.exceptions.ArgumentsParsingException;
+import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
+import net.sf.taverna.t2.commandline.options.CommandLineOptions;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+import uk.org.taverna.commons.profile.xml.jaxb.ApplicationProfile;
+import uk.org.taverna.commons.profile.xml.jaxb.BundleInfo;
+import uk.org.taverna.commons.profile.xml.jaxb.FrameworkConfiguration;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+import uk.org.taverna.configuration.app.impl.ApplicationConfigurationImpl;
+import uk.org.taverna.configuration.app.impl.Log4JConfiguration;
+import uk.org.taverna.osgi.OsgiLauncher;
+
+/**
+ * Main entry point for starting the Taverna Command Line Tool.
+ *
+ * @author David Withers
+ */
+public class TavernaCommandLine {
+
+ private static final String COMMANDLINE_BUNDLE_NAME = "net.sf.taverna.t2.taverna-commandline.common";
+
+ private static File commandlineBundle;
+
+ private static ApplicationConfiguration applicationConfiguration = new ApplicationConfigurationImpl();
+
+ private static Log4JConfiguration log4jConfiguration = new Log4JConfiguration();
+
+ /**
+ * Starts the Taverna Command Line Tool.
+ *
+ * @param args
+ * Taverna Command Line arguments
+ */
+ public static void main(final String[] args) {
+ try {
+ CommandLineOptions commandLineOptions = new CommandLineOptionsImpl(args);
+ if (commandLineOptions.askedForHelp()) {
+ commandLineOptions.displayHelp();
+ } else {
+ log4jConfiguration.setApplicationConfiguration(applicationConfiguration);
+ log4jConfiguration.prepareLog4J();
+ setDerbyPaths();
+ OsgiLauncher osgilauncher = new OsgiLauncher(getAppDirectory(), getBundleURIs());
+ setFrameworkConfiguration(osgilauncher);
+ osgilauncher.start();
+ BundleContext context = osgilauncher.getContext();
+ context.registerService("net.sf.taverna.t2.commandline.options.CommandLineOptions",
+ commandLineOptions, null);
+ osgilauncher.startServices(true);
+ osgilauncher.startBundle(osgilauncher.installBundle(commandlineBundle.toURI()));
+ }
+ } catch (ArgumentsParsingException e) {
+ System.out.println(e.getMessage());
+ } catch (InvalidOptionException e) {
+ System.out.println(e.getMessage());
+ } catch (BundleException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ /**
+ * Sets the OSGi Framework configuration.
+ *
+ * @param osgilauncher
+ */
+ private static void setFrameworkConfiguration(OsgiLauncher osgilauncher) {
+ ApplicationProfile applicationProfile = applicationConfiguration.getApplicationProfile();
+ List<FrameworkConfiguration> frameworkConfigurations = applicationProfile
+ .getFrameworkConfiguration();
+ if (!frameworkConfigurations.isEmpty()) {
+ Map<String, String> configurationMap = new HashMap<String, String>();
+ for (FrameworkConfiguration frameworkConfiguration : frameworkConfigurations) {
+ configurationMap.put(frameworkConfiguration.getName(),
+ frameworkConfiguration.getValue());
+ }
+ osgilauncher.setFrameworkConfiguration(configurationMap);
+ }
+ }
+
+ private static List<URI> getBundleURIs() {
+ List<URI> bundleURIs = new ArrayList<URI>();
+ ApplicationProfile applicationProfile = applicationConfiguration.getApplicationProfile();
+ File libDir = new File(applicationConfiguration.getStartupDir(), "lib");
+ if (applicationProfile != null) {
+ for (BundleInfo bundle : applicationProfile.getBundle()) {
+ File bundleFile = new File(libDir, bundle.getFileName());
+ if (bundle.getSymbolicName().equals(COMMANDLINE_BUNDLE_NAME)) {
+ commandlineBundle = bundleFile;
+ } else {
+ bundleURIs.add(bundleFile.toURI());
+ }
+ }
+ }
+ return bundleURIs;
+ }
+
+ private static File getAppDirectory() {
+ return new File(applicationConfiguration.getApplicationHomeDir().getAbsolutePath());
+ }
+
+ private static void setDerbyPaths() {
+ System.setProperty("derby.system.home", getAppDirectory().getAbsolutePath());
+ File logFile = new File(applicationConfiguration.getLogDir(), "derby.log");
+ System.setProperty("derby.stream.error.file", logFile.getAbsolutePath());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/taverna-commandline-launcher/src/main/resources/help.txt
----------------------------------------------------------------------
diff --git a/taverna-commandline-launcher/src/main/resources/help.txt b/taverna-commandline-launcher/src/main/resources/help.txt
new file mode 100644
index 0000000..fb082cc
--- /dev/null
+++ b/taverna-commandline-launcher/src/main/resources/help.txt
@@ -0,0 +1,87 @@
+By default, the workflow is executed using the -inmemory option, and the
+results are written out to a directory named after the workflow name.
+
+If this directory already exists then a new directory is created, and
+appended with _<n>, where n is incremented to the next available index.
+
+Results are written out to files named after the output port for that result.
+If a result is composed of lists, then a directory is created for the output
+port and individual list items are named after the list element index (with 1
+being the first index). The the output is the result of an error, the filename
+is appended with '.error'.
+
+You can provide your own output directory with the -outputdir option. There
+will be an error if the directory already exists.
+
+You can also record your results to a Baclava document using -outputdoc
+option. The document will be overwritten if it already exists.
+
+Inputs can be provided in three ways. Both -inputfile and -inputvalue options
+can be used together; -inputdoc option must be used on its own. -inputfile and
+-inputvalue options both take two additional arguments, the name of the port
+for the input, and either a file containing the input data, or the input value
+itself respectively.
+
+If one of more of your workflow inputs is a list, you can create a list
+input by using the -inputdelimiter option, which may be used with either
+-inputfile or -inputvalue. This option takes two parameters - an input name
+and the delimiter by which to split the input into a list.
+
+The delimiter may be a simple character, such as a comma or a new-line
+character, or a regular expression. The input string, or file, will then be
+converted into a list being split by the delimiter specified. Make sure to
+put the delimiter character in quotes as it may be interpreted by the shell
+as a special character, e.g. ;.
+
+If a list of greater depth (i.e. a list or lists or deeper) is required then
+you will need to use the -inputdoc option. However, if you provide an input
+of lower depth to that required, then it will automatically be wrapped in one
+or more lists up to the required depth. Providing an input of greater depth
+than that required will result in an error.
+
+If a workflow has a high memory requirement, then it may be better to run it
+using a database to store data rather than storing it in memory, which is the
+default option. There are three options for using a database:
+
+-embedded option, runs with an embedded database. This is slightly faster than
+the -clientserver option (below), but has the limitation that only one
+executeworkflow script may be executed simultaneously.
+
+-clientserver option allows the workflow to be executed backed by the database
+running as a server. By default a database is not started for you, but may be
+started using -startdb option.
+
+-startdb option starts a database. It may be used without providing a workflow
+to allow a database to be started separately, allowing multiple simultaneous
+executeworkflow script runs.
+
+More advanced database configurations can be specified using -dbproperties
+option, allowing you to take full control over the database used. This takes a
+second argument, the filename of the properties file, for which the following
+example contains the default settings:
+
+in_memory = true
+provenance = false
+connector = derby
+port = 1527
+dialect = org.hibernate.dialect.DerbyDialect
+start_derby = false
+driver = org.apache.derby.jdbc.EmbeddedDriver
+jdbcuri = jdbc:derby:t2-database;create=true;upgrade=true
+
+Note that when using -dbproperties together with other options, the other
+options take precedence.
+
+-cmdir option lets you specify an absolute path to a directory where
+Credential Manager's files (keystore and truststore - containing user's
+credentials and trusted certificates for accessing secure services) are stored.
+If not specified and the workflow requires access to these files, Taverna will
+try to find them in the default location in <TAVERNA_HOME>/security somewhere
+inside user's home directory (depending on the platform).
+
+-cmpassword option can be used to tell Taverna to expect the password for the
+Credential Manager on standard input. If the password is not piped in, Taverna
+will prompt you for it in the terminal and block until it is entered. Do not
+enter your password in the command line! If -cmpassword option is not specified
+and -cmdir option is used, Taverna will try to find the password in a special
+file password.txt in the directory specified with -cmdir option.
http://git-wip-us.apache.org/repos/asf/incubator-taverna-commandline/blob/a8e6b3ed/taverna-commandline-launcher/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java
----------------------------------------------------------------------
diff --git a/taverna-commandline-launcher/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java b/taverna-commandline-launcher/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java
new file mode 100644
index 0000000..3e1d0f4
--- /dev/null
+++ b/taverna-commandline-launcher/src/test/java/uk/org/taverna/commandline/TestCommandLineOptionsHandler.java
@@ -0,0 +1,267 @@
+package uk.org.taverna.commandline;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import net.sf.taverna.t2.commandline.exceptions.InvalidOptionException;
+import net.sf.taverna.t2.commandline.options.CommandLineOptions;
+
+import org.junit.Test;
+
+public class TestCommandLineOptionsHandler {
+
+ @Test
+ public void testWorkflowName() throws Exception {
+ CommandLineOptions handler = new CommandLineOptionsImpl(
+ new String[] { "myworkflow.t2flow" });
+ assertEquals("myworkflow.t2flow", handler.getWorkflow());
+ }
+
+ @Test
+ public void shouldShowHelp() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(
+ new String[] { "-help" });
+ assertTrue(options.askedForHelp());
+ options = new CommandLineOptionsImpl(
+ new String[] {});
+ assertTrue(options.askedForHelp());
+ options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
+ assertFalse(options.askedForHelp());
+ }
+
+ @Test
+ public void getWorkflow() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(
+ new String[] { "-help" });
+ assertNull(options.getWorkflow());
+ options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
+ assertEquals("myworkflow.t2flow", options.getWorkflow());
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void cannotProvideInputFileAndInputDoc() throws Exception {
+ new CommandLineOptionsImpl(new String[] { "-inputfile", "fred", "fred.txt",
+ "-inputdoc", "myworkflow.t2flow" });
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void cannotProvideInputValueAndInputDoc() throws Exception {
+ new CommandLineOptionsImpl(new String[] { "-inputvalue", "fred", "fred.txt",
+ "-inputdoc", "myworkflow.t2flow" });
+ }
+
+ @Test
+ public void canProvideInputValueAndFileTogether() throws Exception {
+ //should not be an error
+ new CommandLineOptionsImpl(new String[] { "-inputvalue", "fred", "abc",
+ "-inputfile","fred2","fred2.txt","myworkflow.t2flow" });
+ }
+
+ @Test
+ public void getInputs() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-inputfile", "fred", "fred.txt", "myworkflow.t2flow" });
+ assertEquals(2, options.getInputFiles().length);
+ assertEquals("fred", options.getInputFiles()[0]);
+ assertEquals("fred.txt", options.getInputFiles()[1]);
+
+ options = new CommandLineOptionsImpl(new String[] { "-inputfile", "fred",
+ "fred.txt", "-inputfile", "fred2", "fred2.txt",
+ "myworkflow.t2flow" });
+ assertEquals(4, options.getInputFiles().length);
+ assertEquals("fred", options.getInputFiles()[0]);
+ assertEquals("fred.txt", options.getInputFiles()[1]);
+ assertEquals("fred2", options.getInputFiles()[2]);
+ assertEquals("fred2.txt", options.getInputFiles()[3]);
+
+ options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
+ assertNotNull(options.getInputFiles());
+ assertEquals(0, options.getInputFiles().length);
+
+ }
+
+ @Test
+ public void hasInputValue() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-inputvalue", "fred", "abc", "myworkflow.t2flow" });
+ assertTrue(options.hasInputValues());
+
+ options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
+ assertFalse(options.hasInputValues());
+ }
+
+ @Test
+ public void getInputValues() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-inputvalue", "fred", "abc", "myworkflow.t2flow" });
+ assertEquals(2, options.getInputValues().length);
+
+ options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
+ assertNotNull(options.getInputValues());
+ assertEquals(0,options.getInputValues().length);
+ }
+
+ @Test
+ public void hasInputs() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-inputfile", "fred", "fred.txt", "myworkflow.t2flow" });
+ assertTrue(options.hasInputFiles());
+
+ options = new CommandLineOptionsImpl(new String[] { "myworkflow.t2flow" });
+ assertFalse(options.hasInputFiles());
+ }
+
+ @Test
+ public void noWorkflowNameButStartDB() throws Exception {
+ // should not throw an error
+ CommandLineOptions options = new CommandLineOptionsImpl(
+ new String[] { "-startdb" });
+ assertTrue(options.getStartDatabase());
+ assertTrue(options.getStartDatabaseOnly());
+ }
+
+ @Test
+ public void workflowNameAndStartDB() throws Exception {
+ // should not throw an error
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-startdb", "myworkflow.t2flow" });
+ assertTrue(options.getStartDatabase());
+ assertFalse(options.getStartDatabaseOnly());
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void provenanceButNoDatabase() throws Exception {
+ new CommandLineOptionsImpl(new String[] { "-provenance",
+ "myworkflow.t2flow" });
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void provenanceButNoDatabase2() throws Exception {
+ new CommandLineOptionsImpl(new String[] { "-provenance", "-inmemory",
+ "myworkflow.t2flow" });
+ }
+
+ @Test
+ public void provenanceDatabase() throws Exception {
+ // should be no errors
+ new CommandLineOptionsImpl(new String[] { "-provenance", "-embedded",
+ "myworkflow.t2flow" });
+ new CommandLineOptionsImpl(new String[] { "-provenance", "-clientserver",
+ "myworkflow.t2flow" });
+ new CommandLineOptionsImpl(new String[] { "-provenance", "-dbproperties",
+ "dbproperties.properties", "myworkflow.t2flow" });
+ }
+
+ @Test
+ public void testHasInputDelimiter() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-inputvalue","in1","1,2,3","-inputdelimiter","in1",",","-inputdelimiter","in2",",","myworkflow.t2flow" });
+ assertTrue(options.hasDelimiterFor("in1"));
+ assertTrue(options.hasDelimiterFor("in2"));
+ assertFalse(options.hasDelimiterFor("in3"));
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void testInputDelimiterInvalidWithInputDoc() throws Exception {
+ new CommandLineOptionsImpl(new String[] {
+ "-inputdoc","doc.xml","-inputdelimiter","in1",",","myworkflow.t2flow" });
+ }
+
+
+ @Test
+ public void testInputDelimiter() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-inputvalue","in1","1,2,3","-inputdelimiter","in1",",","-inputdelimiter","in2","!","myworkflow.t2flow" });
+ assertEquals(",",options.inputDelimiter("in1"));
+ assertEquals("!",options.inputDelimiter("in2"));
+ assertNull(options.inputDelimiter("in3"));
+ }
+
+ @Test
+ public void testInMemory() throws Exception {
+ CommandLineOptions handler = new CommandLineOptionsImpl(new String[] {
+ "-inmemory", "myworkflow.t2flow" });
+ assertTrue(handler.hasOption("inmemory"));
+ }
+
+ @Test
+ public void testEmbedded() throws Exception {
+ CommandLineOptions handler = new CommandLineOptionsImpl(new String[] {
+ "-embedded", "myworkflow.t2flow" });
+ assertTrue(handler.hasOption("embedded"));
+ }
+
+ @Test
+ public void testClientServer() throws Exception {
+ CommandLineOptions handler = new CommandLineOptionsImpl(new String[] {
+ "-clientserver", "myworkflow.t2flow" });
+ assertTrue(handler.hasOption("clientserver"));
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void testInvalidEmbeddedAndClientServer() throws Exception {
+ new CommandLineOptionsImpl(new String[] { "-clientserver", "-embedded",
+ "myworkflow.t2flow" });
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void testInvalidEmbeddedAndMemory() throws Exception {
+ new CommandLineOptionsImpl(new String[] { "-embedded", "-inmemory",
+ "myworkflow.t2flow" });
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ public void testInvalidClientServerAndInMemory() throws Exception {
+ new CommandLineOptionsImpl(new String[] { "-clientserver", "-inmemory",
+ "myworkflow.t2flow" });
+ }
+
+ @Test
+ public void isInMemory() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-inmemory", "myworkflow.t2flow" });
+
+ assertTrue(options.isInMemory());
+ assertFalse(options.isClientServer());
+ assertFalse(options.isEmbedded());
+ }
+
+ @Test
+ public void isClientServer() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-clientserver", "myworkflow.t2flow" });
+
+ assertTrue(options.isClientServer());
+ assertFalse(options.isInMemory());
+ assertFalse(options.isEmbedded());
+ }
+
+ @Test
+ public void hasLogFile() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-logfile","/tmp/logging", "myworkflow.t2flow" });
+
+ assertTrue(options.hasLogFile());
+ assertEquals("/tmp/logging", options.getLogFile());
+ }
+
+ @Test(expected = InvalidOptionException.class)
+ @SuppressWarnings("unused")
+ public void hasLogFileNotValidWithoutWorkflow() throws Exception{
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-logfile","/tmp/logging"});
+ }
+
+ @Test
+ public void isEmbedded() throws Exception {
+ CommandLineOptions options = new CommandLineOptionsImpl(new String[] {
+ "-embedded", "myworkflow.t2flow" });
+
+ assertTrue(options.isEmbedded());
+ assertFalse(options.isInMemory());
+ assertFalse(options.isClientServer());
+ }
+
+}