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:05 UTC
[45/70] [abbrv] incubator-taverna-common-activities git commit:
taverna-beanshell-activity/
taverna-beanshell-activity/
Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/24f293c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/24f293c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/24f293c8
Branch: refs/heads/master
Commit: 24f293c8098bc4abe7a80b6df6cadcd2951ae155
Parents: 0c3f2dc
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Tue Jan 13 13:39:56 2015 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Tue Jan 13 13:39:56 2015 +0000
----------------------------------------------------------------------
.gitignore | 24 --
.travis.yml | 1 -
README.md | 3 -
pom.xml | 91 -------
.../activities/beanshell/BeanshellActivity.java | 251 -------------------
.../BeanshellActivityConfigurationBean.java | 86 -------
.../beanshell/BeanshellActivityFactory.java | 79 ------
.../BeanshellActivityHealthChecker.java | 111 --------
.../t2/activities/beanshell/package.html | 3 -
...averna.t2.workflowmodel.health.HealthChecker | 1 -
.../spring/beanshell-activity-context-osgi.xml | 15 --
.../spring/beanshell-activity-context.xml | 12 -
src/main/resources/schema.json | 21 --
.../beanshell/BeanshellActivityFactoryTest.java | 64 -----
.../BeanshellActivityHealthCheckerTest.java | 173 -------------
.../beanshell/BeanshellActivityTest.java | 86 -------
taverna-beanshell-activity/pom.xml | 91 +++++++
.../activities/beanshell/BeanshellActivity.java | 251 +++++++++++++++++++
.../BeanshellActivityConfigurationBean.java | 86 +++++++
.../beanshell/BeanshellActivityFactory.java | 79 ++++++
.../BeanshellActivityHealthChecker.java | 111 ++++++++
.../t2/activities/beanshell/package.html | 3 +
...averna.t2.workflowmodel.health.HealthChecker | 1 +
.../spring/beanshell-activity-context-osgi.xml | 15 ++
.../spring/beanshell-activity-context.xml | 12 +
.../src/main/resources/schema.json | 21 ++
.../beanshell/BeanshellActivityFactoryTest.java | 64 +++++
.../BeanshellActivityHealthCheckerTest.java | 173 +++++++++++++
.../beanshell/BeanshellActivityTest.java | 86 +++++++
29 files changed, 993 insertions(+), 1021 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/.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-common-activities/blob/24f293c8/.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-common-activities/blob/24f293c8/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
deleted file mode 100644
index f5179c7..0000000
--- a/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-Taverna Workflow system Beanshell Activity: data model and execution implementation
-
-This code was previously hosted at http://taverna.googlecode.com/svn/taverna/engine/net.sf.taverna.t2.activities/
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
deleted file mode 100644
index f95b03e..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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/maven-v4_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>net.sf.taverna.t2.activities</groupId>
- <artifactId>beanshell-activity</artifactId>
- <packaging>bundle</packaging>
- <version>2.0.1-SNAPSHOT</version>
- <name>Taverna 2 Beanshell Activity</name>
- <dependencies>
- <dependency>
- <groupId>net.sf.taverna.t2.core</groupId>
- <artifactId>reference-api</artifactId>
- <version>${t2.core.version}</version>
- </dependency>
- <dependency>
- <groupId>net.sf.taverna.t2.core</groupId>
- <artifactId>workflowmodel-api</artifactId>
- <version>${t2.core.version}</version>
- </dependency>
- <dependency>
- <groupId>net.sf.taverna.t2.activities</groupId>
- <artifactId>dependency-activity</artifactId>
- <version>${t2.activities.version}</version>
- </dependency>
- <dependency>
- <groupId>uk.org.taverna.configuration</groupId>
- <artifactId>taverna-app-configuration-api</artifactId>
- <version>${taverna.configuration.version}</version>
- </dependency>
- <dependency>
- <groupId>org.beanshell</groupId>
- <artifactId>com.springsource.bsh</artifactId>
- <version>${bsh.version}</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.2.2</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>net.sf.taverna.t2.activities</groupId>
- <artifactId>activity-test-utils</artifactId>
- <version>${t2.activities.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>net.sf.taverna.t2.core</groupId>
- <artifactId>workflowmodel-impl</artifactId>
- <version>${t2.core.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>
- <scm>
- <connection>scm:git:https://github.com/taverna/taverna-beanshell-activity.git</connection>
- <developerConnection>scm:git:ssh://git@github.com/taverna/taverna-beanshell-activity.git</developerConnection>
- <url>https://github.com/taverna/taverna-beanshell-activity/</url>
- <tag>HEAD</tag>
- </scm>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java b/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java
deleted file mode 100644
index 134d3fe..0000000
--- a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java
+++ /dev/null
@@ -1,251 +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 net.sf.taverna.t2.activities.beanshell;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import net.sf.taverna.t2.activities.dependencyactivity.AbstractAsynchronousDependencyActivity;
-import net.sf.taverna.t2.reference.ErrorDocumentService;
-import net.sf.taverna.t2.reference.ReferenceService;
-import net.sf.taverna.t2.reference.ReferenceServiceException;
-import net.sf.taverna.t2.reference.T2Reference;
-import net.sf.taverna.t2.workflowmodel.OutputPort;
-import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
-import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
-
-import org.apache.log4j.Logger;
-
-import uk.org.taverna.configuration.app.ApplicationConfiguration;
-import bsh.EvalError;
-import bsh.Interpreter;
-import bsh.TargetError;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-/**
- * An Activity providing Beanshell functionality.
- *
- * @author David Withers
- * @author Stuart Owen
- * @author Alex Nenadic
- */
-public class BeanshellActivity extends AbstractAsynchronousDependencyActivity {
-
- public static final String URI = "http://ns.taverna.org.uk/2010/activity/beanshell";
-
- protected BeanshellActivityConfigurationBean configurationBean;
-
- private static Logger logger = Logger.getLogger(BeanshellActivity.class);
-
- private Interpreter interpreter;
-
- private static String CLEAR_COMMAND = "clear();";
-
- private JsonNode json;
-
- public BeanshellActivity(ApplicationConfiguration applicationConfiguration) {
- super(applicationConfiguration);
- createInterpreter();
- }
-
- @Override
- public JsonNode getConfiguration() {
- return json;
- }
-
- @Override
- public void configure(JsonNode json) {
- this.json = json;
- checkGranularDepths();
- }
-
- /**
- * Creates the interpreter required to run the beanshell script, and assigns
- * the correct classloader setting according to the
- */
- private void createInterpreter() {
- interpreter = new Interpreter();
- }
-
- /**
- * As the Beanshell activity currently only can output values at the
- * specified depth, the granular depths should always be equal to the actual
- * depth.
- * <p>
- * Workflow definitions created with Taverna 2.0b1 would not honour this and
- * always set the granular depth to 0.
- * <p>
- * This method modifies the granular depths to be equal to the depths.
- */
- protected void checkGranularDepths() {
- for (OutputPort outputPort : getOutputPorts()) {
- if (outputPort.getGranularDepth() != outputPort.getDepth()) {
- logger.warn("Replacing granular depth of port "
- + outputPort.getName());
- // outputPort.setGranularDepth(outputPort.getDepth());
- }
- }
- }
-
- public ActivityInputPort getInputPort(String name) {
- for (ActivityInputPort port : getInputPorts()) {
- if (port.getName().equals(name)) {
- return port;
- }
- }
- return null;
- }
-
- private void clearInterpreter() {
- try {
- interpreter.eval(CLEAR_COMMAND);
- } catch (EvalError e) {
- logger.error("Could not clear the interpreter", e);
- }
- }
-
- @Override
- public void executeAsynch(final Map<String, T2Reference> data,
- final AsynchronousActivityCallback callback) {
- callback.requestRun(new Runnable() {
-
- public void run() {
-
- // Workflow run identifier (needed when classloader sharing is
- // set to 'workflow').
- String procID = callback.getParentProcessIdentifier();
- String workflowRunID;
- if (procID.contains(":")) {
- workflowRunID = procID.substring(0, procID.indexOf(':'));
- } else {
- workflowRunID = procID; // for tests, will be an empty
- // string
- }
-
- synchronized (interpreter) {
-
- // Configure the classloader for executing the Beanshell
- if (classLoader == null) {
- try {
- classLoader = findClassLoader(json, workflowRunID);
- interpreter.setClassLoader(classLoader);
- } catch (RuntimeException rex) {
- String message = "Unable to obtain the classloader for Beanshell service";
- callback.fail(message, rex);
- return;
- }
- }
-
- ReferenceService referenceService = callback.getContext()
- .getReferenceService();
-
- Map<String, T2Reference> outputData = new HashMap<String, T2Reference>();
-
- clearInterpreter();
- try {
- // set inputs
- for (String inputName : data.keySet()) {
- ActivityInputPort inputPort = getInputPort(inputName);
- Object input = referenceService.renderIdentifier(
- data.get(inputName),
- inputPort.getTranslatedElementClass(),
- callback.getContext());
- inputName = sanatisePortName(inputName);
- interpreter.set(inputName, input);
- }
- // run
- interpreter.eval(json.get("script").asText());
- // get outputs
- for (OutputPort outputPort : getOutputPorts()) {
- String name = outputPort.getName();
- Object value = interpreter.get(name);
- if (value == null) {
- ErrorDocumentService errorDocService = referenceService
- .getErrorDocumentService();
- value = errorDocService.registerError(
- "No value produced for output variable "
- + name, outputPort.getDepth(),
- callback.getContext());
- }
- outputData.put(name, referenceService.register(
- value, outputPort.getDepth(), true,
- callback.getContext()));
- }
- callback.receiveResult(outputData, new int[0]);
- } catch (EvalError e) {
- logger.error(e);
- try {
- int lineNumber = e.getErrorLineNumber();
-
- callback.fail("Line " + lineNumber + ": "
- + determineMessage(e));
- } catch (NullPointerException e2) {
- callback.fail(determineMessage(e));
- }
- } catch (ReferenceServiceException e) {
- callback.fail(
- "Error accessing beanshell input/output data for "
- + this, e);
- }
- clearInterpreter();
- }
- }
-
- /**
- * Removes any invalid characters from the port name. For example,
- * xml-text would become xmltext.
- *
- * @param name
- * @return
- */
- private String sanatisePortName(String name) {
- String result = name;
- if (Pattern.matches("\\w++", name) == false) {
- result = "";
- for (char c : name.toCharArray()) {
- if (Character.isLetterOrDigit(c) || c == '_') {
- result += c;
- }
- }
- }
- return result;
- }
- });
-
- }
-
- private static String determineMessage(Throwable e) {
- if (e instanceof TargetError) {
- Throwable t = ((TargetError) e).getTarget();
- if (t != null) {
- return t.getClass().getCanonicalName() + ": "
- + determineMessage(t);
- }
- }
- Throwable cause = e.getCause();
- if (cause != null) {
- return determineMessage(cause);
- }
- return e.getMessage();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java b/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java
deleted file mode 100644
index 8a5f06f..0000000
--- a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java
+++ /dev/null
@@ -1,86 +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 net.sf.taverna.t2.activities.beanshell;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import net.sf.taverna.t2.activities.dependencyactivity.DependencyActivityConfigurationBean;
-import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
-import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
-
-/**
- * A configuration bean specific to a Beanshell activity; provides details
- * about the Beanshell script and its local and artifact dependencies.
- *
- * @author Stuart Owen
- * @author David Withers
- * @author Alex Nenadic
- */
-@ConfigurationBean(uri = BeanshellActivity.URI + "#Config")
-public class BeanshellActivityConfigurationBean extends DependencyActivityConfigurationBean {
-
- private String script;
-
- public BeanshellActivityConfigurationBean() {
- super();
- this.script = "";
- }
-
- /**
- * @return the Beanshell script
- */
- public String getScript() {
- return script;
- }
-
- /**
- * @param script the Beanshell script
- */
- @ConfigurationProperty(name = "script", label = "Beanshell Script", description = "The beanshell script to be executed")
- public void setScript(String script) {
- this.script = script;
- }
-
- ///////////// From old code //////////
- @Deprecated
- private List<String> dependencies = new ArrayList<String>();
-
- /**
- * Returns the dependencies.
- *
- * @return the dependencies
- */
- public List<String> getDependencies() {
- return dependencies;
- }
-
- /**
- * Sets the dependencies.
- *
- * @param dependencies the new dependencies
- */
- public void setDependencies(List<String> dependencies) {
- this.dependencies = dependencies;
- }
- ///////////// From old code //////////
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java b/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java
deleted file mode 100644
index c1b0e5d..0000000
--- a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2010 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 net.sf.taverna.t2.activities.beanshell;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.HashSet;
-import java.util.Set;
-
-import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
-import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
-import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
-import uk.org.taverna.configuration.app.ApplicationConfiguration;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/**
- * An {@link ActivityFactory} for creating <code>BeanshellActivity</code>.
- *
- * @author David Withers
- */
-public class BeanshellActivityFactory implements ActivityFactory {
-
- private ApplicationConfiguration applicationConfiguration;
-
- @Override
- public BeanshellActivity createActivity() {
- return new BeanshellActivity(applicationConfiguration);
- }
-
- @Override
- public URI getActivityType() {
- return URI.create(BeanshellActivity.URI);
- }
-
- @Override
- public JsonNode getActivityConfigurationSchema() {
- ObjectMapper objectMapper = new ObjectMapper();
- try {
- return objectMapper.readTree(getClass().getResource("/schema.json"));
- } catch (IOException e) {
- return objectMapper.createObjectNode();
- }
- }
-
- public void setApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
- this.applicationConfiguration = applicationConfiguration;
- }
-
- @Override
- public Set<ActivityInputPort> getInputPorts(JsonNode configuration) {
- return new HashSet<>();
- }
-
- @Override
- public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration) {
- return new HashSet<>();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java b/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java
deleted file mode 100644
index 9913d77..0000000
--- a/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java
+++ /dev/null
@@ -1,111 +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 net.sf.taverna.t2.activities.beanshell;
-
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.List;
-
-import net.sf.taverna.t2.activities.dependencyactivity.AbstractAsynchronousDependencyActivity.FileExtFilter;
-import net.sf.taverna.t2.visit.VisitReport;
-import net.sf.taverna.t2.visit.VisitReport.Status;
-import net.sf.taverna.t2.workflowmodel.Processor;
-import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
-import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
-import bsh.ParseException;
-import bsh.Parser;
-
-import com.fasterxml.jackson.databind.JsonNode;
-
-public class BeanshellActivityHealthChecker implements HealthChecker<BeanshellActivity> {
-
- public boolean canVisit(Object subject) {
- return (subject!=null && subject instanceof BeanshellActivity);
- }
-
- public VisitReport visit(BeanshellActivity activity, List<Object> ancestors) {
- Object subject = (Processor) VisitReport.findAncestor(ancestors, Processor.class);
- if (subject == null) {
- // Fall back to using the activity itself as the subject of the reports
- subject = activity;
- }
- List<VisitReport> reports = new ArrayList<VisitReport>();
-
- String script = activity.getConfiguration().get("script").textValue();
- if (! script.trim().endsWith(";")) {
- /** Missing ; on last line is not allowed by Parser,
- * but is allowed by Interpreter.eval() used at runtime
- */
- script = script + ";";
- }
- Parser parser = new Parser(new StringReader(script));
- try {
- while (!parser.Line());
- reports.add(new VisitReport(HealthCheck.getInstance(), subject, "Script OK", HealthCheck.NO_PROBLEM, Status.OK));
- } catch (ParseException e) {
- VisitReport report = new VisitReport(HealthCheck.getInstance(), subject ,e.getMessage(), HealthCheck.INVALID_SCRIPT, Status.SEVERE);
- report.setProperty("exception", e);
- reports.add(report);
- }
-
- // Check if we can find all the Beanshell's dependencies
- if (activity.getConfiguration().has("localDependency")) {
- LinkedHashSet<String> localDependencies = new LinkedHashSet<>();
- for (JsonNode localDependency : activity.getConfiguration().get("localDependency")) {
- localDependencies.add(localDependency.textValue());
- }
-
- String[] jarArray = activity.libDir.list(new FileExtFilter(".jar"));
- if (jarArray != null) {
- List<String> jarFiles = Arrays.asList(jarArray); // URLs of all jars found in the lib directory
- for (String jar : localDependencies) {
- if (jarFiles.contains(jar)){
- localDependencies.remove(jar);
- }
- }
- }
- if (localDependencies.isEmpty()){ // all dependencies found
- reports.add(new VisitReport(HealthCheck.getInstance(), subject, "Beanshell dependencies found", HealthCheck.NO_PROBLEM, Status.OK));
- }
- else{
- VisitReport vr = new VisitReport(HealthCheck.getInstance(), subject, "Beanshell dependencies missing", HealthCheck.MISSING_DEPENDENCY, Status.SEVERE);
- vr.setProperty("dependencies", localDependencies);
- vr.setProperty("directory", activity.libDir);
- reports.add(vr);
- }
-
- }
- Status status = VisitReport.getWorstStatus(reports);
- VisitReport report = new VisitReport(HealthCheck.getInstance(), subject, "Beanshell report", HealthCheck.NO_PROBLEM,
- status, reports);
-
- return report;
-
- }
-
- public boolean isTimeConsuming() {
- return false;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html
----------------------------------------------------------------------
diff --git a/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html b/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html
deleted file mode 100644
index 8b6e7a5..0000000
--- a/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<body>
-Contains the activity classes required to include String constants within a DataFlow.
-</body>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker b/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
deleted file mode 100644
index 3fbf5a8..0000000
--- a/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
+++ /dev/null
@@ -1 +0,0 @@
-net.sf.taverna.t2.activities.beanshell.BeanshellActivityHealthChecker
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml b/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml
deleted file mode 100644
index b98c9e4..0000000
--- a/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/osgi
- http://www.springframework.org/schema/osgi/spring-osgi.xsd">
-
- <service ref="beanshellActivityHealthChecker" interface="net.sf.taverna.t2.workflowmodel.health.HealthChecker" />
-
- <service ref="beanshellActivityFactory" interface="net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory" />
-
- <reference id="applicationConfiguration" interface="uk.org.taverna.configuration.app.ApplicationConfiguration" />
-
-</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/resources/META-INF/spring/beanshell-activity-context.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/spring/beanshell-activity-context.xml b/src/main/resources/META-INF/spring/beanshell-activity-context.xml
deleted file mode 100644
index c6cc552..0000000
--- a/src/main/resources/META-INF/spring/beanshell-activity-context.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd">
-
- <bean id="beanshellActivityHealthChecker" class="net.sf.taverna.t2.activities.beanshell.BeanshellActivityHealthChecker" />
-
- <bean id="beanshellActivityFactory" class="net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory">
- <property name="applicationConfiguration" ref="applicationConfiguration" />
- </bean>
-
-</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/main/resources/schema.json
----------------------------------------------------------------------
diff --git a/src/main/resources/schema.json b/src/main/resources/schema.json
deleted file mode 100644
index fcf07b2..0000000
--- a/src/main/resources/schema.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "$schema": "http://json-schema.org/draft-03/schema#",
- "id": "http://ns.taverna.org.uk/2010/activity/beanshell.schema.json",
- "title": "Beanshell activity configuration",
- "type": "object",
- "extends" : "http://ns.taverna.org.uk/2010/activity/dependency.schema.json",
- "properties": {
- "@context": {
- "description": "JSON-LD context for interpreting the configuration as RDF",
- "required": true,
- "enum": ["http://ns.taverna.org.uk/2010/activity/beanshell.context.json"]
- },
- "script": {
- "title": "Beanshell Script",
- "description": "The beanshell script to be executed",
- "type": "string",
- "required": true,
- "default": ""
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java b/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java
deleted file mode 100644
index 32290ac..0000000
--- a/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2010 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 net.sf.taverna.t2.activities.beanshell;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URI;
-
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- *
- * @author David Withers
- */
-public class BeanshellActivityFactoryTest {
-
- private BeanshellActivityFactory factory;
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- factory = new BeanshellActivityFactory();
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory#createActivity()}.
- */
- @Test
- public void testCreateActivity() {
- BeanshellActivity createActivity = factory.createActivity();
- assertNotNull(createActivity);
- }
-
- /**
- * Test method for {@link net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory#getActivityType()}.
- */
- @Test
- public void testGetActivityURI() {
- assertEquals(URI.create(BeanshellActivity.URI), factory.getActivityType());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java b/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java
deleted file mode 100644
index 0b4b5ff..0000000
--- a/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java
+++ /dev/null
@@ -1,173 +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 net.sf.taverna.t2.activities.beanshell;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import net.sf.taverna.t2.activities.testutils.ActivityInvoker;
-import net.sf.taverna.t2.visit.VisitReport;
-import net.sf.taverna.t2.visit.VisitReport.Status;
-import net.sf.taverna.t2.workflowmodel.Edits;
-import net.sf.taverna.t2.workflowmodel.impl.EditsImpl;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * BeanshellActivityHealthChecker tests
- *
- * @author Stian Soiland-Reyes
- *
- */
-public class BeanshellActivityHealthCheckerTest {
-
- private Edits edits = new EditsImpl();
-
- private ObjectNode configuration;
-
- @Before
- public void setup() throws Exception {
- configuration = JsonNodeFactory.instance.objectNode();
- configuration.put("classLoaderSharing", "workflow");
- }
-
- @Test
- public void oneLinerNoSemicolon() throws Exception {
- BeanshellActivity activity = new BeanshellActivity(null);
- configuration.put("script", "a = 5+3");
- // Notice lack of ;
- activity.configure(configuration);
-
- Map<String,Object> inputs = new HashMap<String, Object>();
- Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
- ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
-
- BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
- assertTrue(healthChecker.canVisit(activity));
- ArrayList<Object> ancestors = new ArrayList<Object>();
-
- ancestors.add(edits.createProcessor("beanie"));
- VisitReport visit = healthChecker.visit(activity, ancestors);
- assertEquals(Status.OK, visit.getStatus());
- }
-
- @Test
- public void oneLiner() throws Exception {
- BeanshellActivity activity = new BeanshellActivity(null);
- configuration.put("script", "System.out.println(\"Hello\");");
- activity.configure(configuration);
-
- Map<String,Object> inputs = new HashMap<String, Object>();
- Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
- ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
-
- BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
- assertTrue(healthChecker.canVisit(activity));
- ArrayList<Object> ancestors = new ArrayList<Object>();
-
- ancestors.add(edits.createProcessor("beanie"));
- VisitReport visit = healthChecker.visit(activity, ancestors);
- assertEquals(Status.OK, visit.getStatus());
- }
-
- @Test
- public void threeLines() throws Exception {
- BeanshellActivity activity = new BeanshellActivity(null);
- configuration.put("script", "if (2>1) {\n" +
- " new Integer(4);\n" +
- "}");
- activity.configure(configuration);
-
- Map<String,Object> inputs = new HashMap<String, Object>();
- Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
- ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
-
- BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
- assertTrue(healthChecker.canVisit(activity));
- ArrayList<Object> ancestors = new ArrayList<Object>();
-
- ancestors.add(edits.createProcessor("beanie"));
- VisitReport visit = healthChecker.visit(activity, ancestors);
- assertEquals(Status.OK, visit.getStatus());
-
-
-
- }
-
- @Test
- public void invalidScript() throws Exception {
- BeanshellActivity activity = new BeanshellActivity(null);
- configuration.put("script", "invalid script 5 +");
- activity.configure(configuration);
-
- Map<String,Object> inputs = new HashMap<String, Object>();
- Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
- try {
- ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
- fail("Script should not be valid");
- } catch (RuntimeException ex) {
- // expected to fail
- }
-
-
- BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
- assertTrue(healthChecker.canVisit(activity));
- ArrayList<Object> ancestors = new ArrayList<Object>();
-
- ancestors.add(edits.createProcessor("beanie"));
- VisitReport visit = healthChecker.visit(activity, ancestors);
- assertEquals(Status.SEVERE, visit.getStatus());
- }
-
- @Test
- public void strangeWhitespace() throws Exception {
- BeanshellActivity activity = new BeanshellActivity(null);
- configuration.put("script", "b = \"fish\";\n" +
- "a = 2+3\n" +
- "\n" +
- "\n" +
- " +5 ");
- // Notice lots of whitespace, but still valid
- activity.configure(configuration);
-
- Map<String,Object> inputs = new HashMap<String, Object>();
- Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
- ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
-
- BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
- assertTrue(healthChecker.canVisit(activity));
- ArrayList<Object> ancestors = new ArrayList<Object>();
-
- ancestors.add(edits.createProcessor("beanie"));
- VisitReport visit = healthChecker.visit(activity, ancestors);
- System.out.println(visit);
- assertEquals(Status.OK, visit.getStatus());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityTest.java b/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityTest.java
deleted file mode 100644
index 8d724a5..0000000
--- a/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityTest.java
+++ /dev/null
@@ -1,86 +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 net.sf.taverna.t2.activities.beanshell;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import net.sf.taverna.t2.activities.testutils.ActivityInvoker;
-import net.sf.taverna.t2.workflowmodel.AbstractPort;
-import net.sf.taverna.t2.workflowmodel.Edits;
-import net.sf.taverna.t2.workflowmodel.impl.EditsImpl;
-import net.sf.taverna.t2.workflowmodel.processor.activity.impl.ActivityInputPortImpl;
-import net.sf.taverna.t2.workflowmodel.processor.activity.impl.ActivityOutputPortImpl;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-/**
- * Beanshell Activity Tests
- * @author Stuart Owen
- *
- */
-public class BeanshellActivityTest {
-
- private ObjectNode configuration;
-
- @Before
- public void setup() throws Exception {
- configuration = JsonNodeFactory.instance.objectNode();
- configuration.put("classLoaderSharing", "workflow");
- }
-
- /**
- * Tests a simple script (String output = input + "_returned") to ensure the script is invoked correctly.
- * @throws Exception
- */
- @Test
- public void simpleScript() throws Exception {
- BeanshellActivity activity = new BeanshellActivity(null);
- Edits edits = new EditsImpl();
- edits.getAddActivityInputPortEdit(activity, new ActivityInputPortImpl("input", 0, false, null, String.class)).doEdit();
- edits.getAddActivityOutputPortEdit(activity, new ActivityOutputPortImpl("output", 0, 0)).doEdit();
-
- configuration.put("script", "String output = input + \"_returned\";");
-
- activity.configure(configuration);
- assertEquals("There should be 1 input port",1,activity.getInputPorts().size());
- assertEquals("There should be 1 output port",1,activity.getOutputPorts().size());
-
- assertEquals("The input should be called input", "input",((AbstractPort)activity.getInputPorts().toArray()[0]).getName());
- assertEquals("The output should be called output", "output",((AbstractPort)activity.getOutputPorts().toArray()[0]).getName());
-
- Map<String,Object> inputs = new HashMap<String, Object>();
- inputs.put("input", "aString");
- Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
- expectedOutputs.put("output", String.class);
-
- Map<String,Object> outputs = ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
- assertTrue("there should be an output named output",outputs.containsKey("output"));
- assertEquals("output should have the value aString_returned","aString_returned",outputs.get("output"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/pom.xml b/taverna-beanshell-activity/pom.xml
new file mode 100644
index 0000000..f95b03e
--- /dev/null
+++ b/taverna-beanshell-activity/pom.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_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>net.sf.taverna.t2.activities</groupId>
+ <artifactId>beanshell-activity</artifactId>
+ <packaging>bundle</packaging>
+ <version>2.0.1-SNAPSHOT</version>
+ <name>Taverna 2 Beanshell Activity</name>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>reference-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>workflowmodel-api</artifactId>
+ <version>${t2.core.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>dependency-activity</artifactId>
+ <version>${t2.activities.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>uk.org.taverna.configuration</groupId>
+ <artifactId>taverna-app-configuration-api</artifactId>
+ <version>${taverna.configuration.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.beanshell</groupId>
+ <artifactId>com.springsource.bsh</artifactId>
+ <version>${bsh.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.activities</groupId>
+ <artifactId>activity-test-utils</artifactId>
+ <version>${t2.activities.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.taverna.t2.core</groupId>
+ <artifactId>workflowmodel-impl</artifactId>
+ <version>${t2.core.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>
+ <scm>
+ <connection>scm:git:https://github.com/taverna/taverna-beanshell-activity.git</connection>
+ <developerConnection>scm:git:ssh://git@github.com/taverna/taverna-beanshell-activity.git</developerConnection>
+ <url>https://github.com/taverna/taverna-beanshell-activity/</url>
+ <tag>HEAD</tag>
+ </scm>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java
new file mode 100644
index 0000000..134d3fe
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivity.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * 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 net.sf.taverna.t2.activities.beanshell;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import net.sf.taverna.t2.activities.dependencyactivity.AbstractAsynchronousDependencyActivity;
+import net.sf.taverna.t2.reference.ErrorDocumentService;
+import net.sf.taverna.t2.reference.ReferenceService;
+import net.sf.taverna.t2.reference.ReferenceServiceException;
+import net.sf.taverna.t2.reference.T2Reference;
+import net.sf.taverna.t2.workflowmodel.OutputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.AsynchronousActivityCallback;
+
+import org.apache.log4j.Logger;
+
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+import bsh.EvalError;
+import bsh.Interpreter;
+import bsh.TargetError;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+/**
+ * An Activity providing Beanshell functionality.
+ *
+ * @author David Withers
+ * @author Stuart Owen
+ * @author Alex Nenadic
+ */
+public class BeanshellActivity extends AbstractAsynchronousDependencyActivity {
+
+ public static final String URI = "http://ns.taverna.org.uk/2010/activity/beanshell";
+
+ protected BeanshellActivityConfigurationBean configurationBean;
+
+ private static Logger logger = Logger.getLogger(BeanshellActivity.class);
+
+ private Interpreter interpreter;
+
+ private static String CLEAR_COMMAND = "clear();";
+
+ private JsonNode json;
+
+ public BeanshellActivity(ApplicationConfiguration applicationConfiguration) {
+ super(applicationConfiguration);
+ createInterpreter();
+ }
+
+ @Override
+ public JsonNode getConfiguration() {
+ return json;
+ }
+
+ @Override
+ public void configure(JsonNode json) {
+ this.json = json;
+ checkGranularDepths();
+ }
+
+ /**
+ * Creates the interpreter required to run the beanshell script, and assigns
+ * the correct classloader setting according to the
+ */
+ private void createInterpreter() {
+ interpreter = new Interpreter();
+ }
+
+ /**
+ * As the Beanshell activity currently only can output values at the
+ * specified depth, the granular depths should always be equal to the actual
+ * depth.
+ * <p>
+ * Workflow definitions created with Taverna 2.0b1 would not honour this and
+ * always set the granular depth to 0.
+ * <p>
+ * This method modifies the granular depths to be equal to the depths.
+ */
+ protected void checkGranularDepths() {
+ for (OutputPort outputPort : getOutputPorts()) {
+ if (outputPort.getGranularDepth() != outputPort.getDepth()) {
+ logger.warn("Replacing granular depth of port "
+ + outputPort.getName());
+ // outputPort.setGranularDepth(outputPort.getDepth());
+ }
+ }
+ }
+
+ public ActivityInputPort getInputPort(String name) {
+ for (ActivityInputPort port : getInputPorts()) {
+ if (port.getName().equals(name)) {
+ return port;
+ }
+ }
+ return null;
+ }
+
+ private void clearInterpreter() {
+ try {
+ interpreter.eval(CLEAR_COMMAND);
+ } catch (EvalError e) {
+ logger.error("Could not clear the interpreter", e);
+ }
+ }
+
+ @Override
+ public void executeAsynch(final Map<String, T2Reference> data,
+ final AsynchronousActivityCallback callback) {
+ callback.requestRun(new Runnable() {
+
+ public void run() {
+
+ // Workflow run identifier (needed when classloader sharing is
+ // set to 'workflow').
+ String procID = callback.getParentProcessIdentifier();
+ String workflowRunID;
+ if (procID.contains(":")) {
+ workflowRunID = procID.substring(0, procID.indexOf(':'));
+ } else {
+ workflowRunID = procID; // for tests, will be an empty
+ // string
+ }
+
+ synchronized (interpreter) {
+
+ // Configure the classloader for executing the Beanshell
+ if (classLoader == null) {
+ try {
+ classLoader = findClassLoader(json, workflowRunID);
+ interpreter.setClassLoader(classLoader);
+ } catch (RuntimeException rex) {
+ String message = "Unable to obtain the classloader for Beanshell service";
+ callback.fail(message, rex);
+ return;
+ }
+ }
+
+ ReferenceService referenceService = callback.getContext()
+ .getReferenceService();
+
+ Map<String, T2Reference> outputData = new HashMap<String, T2Reference>();
+
+ clearInterpreter();
+ try {
+ // set inputs
+ for (String inputName : data.keySet()) {
+ ActivityInputPort inputPort = getInputPort(inputName);
+ Object input = referenceService.renderIdentifier(
+ data.get(inputName),
+ inputPort.getTranslatedElementClass(),
+ callback.getContext());
+ inputName = sanatisePortName(inputName);
+ interpreter.set(inputName, input);
+ }
+ // run
+ interpreter.eval(json.get("script").asText());
+ // get outputs
+ for (OutputPort outputPort : getOutputPorts()) {
+ String name = outputPort.getName();
+ Object value = interpreter.get(name);
+ if (value == null) {
+ ErrorDocumentService errorDocService = referenceService
+ .getErrorDocumentService();
+ value = errorDocService.registerError(
+ "No value produced for output variable "
+ + name, outputPort.getDepth(),
+ callback.getContext());
+ }
+ outputData.put(name, referenceService.register(
+ value, outputPort.getDepth(), true,
+ callback.getContext()));
+ }
+ callback.receiveResult(outputData, new int[0]);
+ } catch (EvalError e) {
+ logger.error(e);
+ try {
+ int lineNumber = e.getErrorLineNumber();
+
+ callback.fail("Line " + lineNumber + ": "
+ + determineMessage(e));
+ } catch (NullPointerException e2) {
+ callback.fail(determineMessage(e));
+ }
+ } catch (ReferenceServiceException e) {
+ callback.fail(
+ "Error accessing beanshell input/output data for "
+ + this, e);
+ }
+ clearInterpreter();
+ }
+ }
+
+ /**
+ * Removes any invalid characters from the port name. For example,
+ * xml-text would become xmltext.
+ *
+ * @param name
+ * @return
+ */
+ private String sanatisePortName(String name) {
+ String result = name;
+ if (Pattern.matches("\\w++", name) == false) {
+ result = "";
+ for (char c : name.toCharArray()) {
+ if (Character.isLetterOrDigit(c) || c == '_') {
+ result += c;
+ }
+ }
+ }
+ return result;
+ }
+ });
+
+ }
+
+ private static String determineMessage(Throwable e) {
+ if (e instanceof TargetError) {
+ Throwable t = ((TargetError) e).getTarget();
+ if (t != null) {
+ return t.getClass().getCanonicalName() + ": "
+ + determineMessage(t);
+ }
+ }
+ Throwable cause = e.getCause();
+ if (cause != null) {
+ return determineMessage(cause);
+ }
+ return e.getMessage();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java
new file mode 100644
index 0000000..8a5f06f
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityConfigurationBean.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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 net.sf.taverna.t2.activities.beanshell;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.dependencyactivity.DependencyActivityConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationBean;
+import net.sf.taverna.t2.workflowmodel.processor.config.ConfigurationProperty;
+
+/**
+ * A configuration bean specific to a Beanshell activity; provides details
+ * about the Beanshell script and its local and artifact dependencies.
+ *
+ * @author Stuart Owen
+ * @author David Withers
+ * @author Alex Nenadic
+ */
+@ConfigurationBean(uri = BeanshellActivity.URI + "#Config")
+public class BeanshellActivityConfigurationBean extends DependencyActivityConfigurationBean {
+
+ private String script;
+
+ public BeanshellActivityConfigurationBean() {
+ super();
+ this.script = "";
+ }
+
+ /**
+ * @return the Beanshell script
+ */
+ public String getScript() {
+ return script;
+ }
+
+ /**
+ * @param script the Beanshell script
+ */
+ @ConfigurationProperty(name = "script", label = "Beanshell Script", description = "The beanshell script to be executed")
+ public void setScript(String script) {
+ this.script = script;
+ }
+
+ ///////////// From old code //////////
+ @Deprecated
+ private List<String> dependencies = new ArrayList<String>();
+
+ /**
+ * Returns the dependencies.
+ *
+ * @return the dependencies
+ */
+ public List<String> getDependencies() {
+ return dependencies;
+ }
+
+ /**
+ * Sets the dependencies.
+ *
+ * @param dependencies the new dependencies
+ */
+ public void setDependencies(List<String> dependencies) {
+ this.dependencies = dependencies;
+ }
+ ///////////// From old code //////////
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java
new file mode 100644
index 0000000..c1b0e5d
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactory.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (C) 2010 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 net.sf.taverna.t2.activities.beanshell;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityInputPort;
+import net.sf.taverna.t2.workflowmodel.processor.activity.ActivityOutputPort;
+import uk.org.taverna.configuration.app.ApplicationConfiguration;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * An {@link ActivityFactory} for creating <code>BeanshellActivity</code>.
+ *
+ * @author David Withers
+ */
+public class BeanshellActivityFactory implements ActivityFactory {
+
+ private ApplicationConfiguration applicationConfiguration;
+
+ @Override
+ public BeanshellActivity createActivity() {
+ return new BeanshellActivity(applicationConfiguration);
+ }
+
+ @Override
+ public URI getActivityType() {
+ return URI.create(BeanshellActivity.URI);
+ }
+
+ @Override
+ public JsonNode getActivityConfigurationSchema() {
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.readTree(getClass().getResource("/schema.json"));
+ } catch (IOException e) {
+ return objectMapper.createObjectNode();
+ }
+ }
+
+ public void setApplicationConfiguration(ApplicationConfiguration applicationConfiguration) {
+ this.applicationConfiguration = applicationConfiguration;
+ }
+
+ @Override
+ public Set<ActivityInputPort> getInputPorts(JsonNode configuration) {
+ return new HashSet<>();
+ }
+
+ @Override
+ public Set<ActivityOutputPort> getOutputPorts(JsonNode configuration) {
+ return new HashSet<>();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java
new file mode 100644
index 0000000..9913d77
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthChecker.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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 net.sf.taverna.t2.activities.beanshell;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import net.sf.taverna.t2.activities.dependencyactivity.AbstractAsynchronousDependencyActivity.FileExtFilter;
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+import net.sf.taverna.t2.workflowmodel.Processor;
+import net.sf.taverna.t2.workflowmodel.health.HealthCheck;
+import net.sf.taverna.t2.workflowmodel.health.HealthChecker;
+import bsh.ParseException;
+import bsh.Parser;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class BeanshellActivityHealthChecker implements HealthChecker<BeanshellActivity> {
+
+ public boolean canVisit(Object subject) {
+ return (subject!=null && subject instanceof BeanshellActivity);
+ }
+
+ public VisitReport visit(BeanshellActivity activity, List<Object> ancestors) {
+ Object subject = (Processor) VisitReport.findAncestor(ancestors, Processor.class);
+ if (subject == null) {
+ // Fall back to using the activity itself as the subject of the reports
+ subject = activity;
+ }
+ List<VisitReport> reports = new ArrayList<VisitReport>();
+
+ String script = activity.getConfiguration().get("script").textValue();
+ if (! script.trim().endsWith(";")) {
+ /** Missing ; on last line is not allowed by Parser,
+ * but is allowed by Interpreter.eval() used at runtime
+ */
+ script = script + ";";
+ }
+ Parser parser = new Parser(new StringReader(script));
+ try {
+ while (!parser.Line());
+ reports.add(new VisitReport(HealthCheck.getInstance(), subject, "Script OK", HealthCheck.NO_PROBLEM, Status.OK));
+ } catch (ParseException e) {
+ VisitReport report = new VisitReport(HealthCheck.getInstance(), subject ,e.getMessage(), HealthCheck.INVALID_SCRIPT, Status.SEVERE);
+ report.setProperty("exception", e);
+ reports.add(report);
+ }
+
+ // Check if we can find all the Beanshell's dependencies
+ if (activity.getConfiguration().has("localDependency")) {
+ LinkedHashSet<String> localDependencies = new LinkedHashSet<>();
+ for (JsonNode localDependency : activity.getConfiguration().get("localDependency")) {
+ localDependencies.add(localDependency.textValue());
+ }
+
+ String[] jarArray = activity.libDir.list(new FileExtFilter(".jar"));
+ if (jarArray != null) {
+ List<String> jarFiles = Arrays.asList(jarArray); // URLs of all jars found in the lib directory
+ for (String jar : localDependencies) {
+ if (jarFiles.contains(jar)){
+ localDependencies.remove(jar);
+ }
+ }
+ }
+ if (localDependencies.isEmpty()){ // all dependencies found
+ reports.add(new VisitReport(HealthCheck.getInstance(), subject, "Beanshell dependencies found", HealthCheck.NO_PROBLEM, Status.OK));
+ }
+ else{
+ VisitReport vr = new VisitReport(HealthCheck.getInstance(), subject, "Beanshell dependencies missing", HealthCheck.MISSING_DEPENDENCY, Status.SEVERE);
+ vr.setProperty("dependencies", localDependencies);
+ vr.setProperty("directory", activity.libDir);
+ reports.add(vr);
+ }
+
+ }
+ Status status = VisitReport.getWorstStatus(reports);
+ VisitReport report = new VisitReport(HealthCheck.getInstance(), subject, "Beanshell report", HealthCheck.NO_PROBLEM,
+ status, reports);
+
+ return report;
+
+ }
+
+ public boolean isTimeConsuming() {
+ return false;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html
new file mode 100644
index 0000000..8b6e7a5
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/java/net/sf/taverna/t2/activities/beanshell/package.html
@@ -0,0 +1,3 @@
+<body>
+Contains the activity classes required to include String constants within a DataFlow.
+</body>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker b/taverna-beanshell-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
new file mode 100644
index 0000000..3fbf5a8
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/resources/META-INF/services/net.sf.taverna.t2.workflowmodel.health.HealthChecker
@@ -0,0 +1 @@
+net.sf.taverna.t2.activities.beanshell.BeanshellActivityHealthChecker
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml b/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml
new file mode 100644
index 0000000..b98c9e4
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context-osgi.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <service ref="beanshellActivityHealthChecker" interface="net.sf.taverna.t2.workflowmodel.health.HealthChecker" />
+
+ <service ref="beanshellActivityFactory" interface="net.sf.taverna.t2.workflowmodel.processor.activity.ActivityFactory" />
+
+ <reference id="applicationConfiguration" interface="uk.org.taverna.configuration.app.ApplicationConfiguration" />
+
+</beans:beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context.xml
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context.xml b/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context.xml
new file mode 100644
index 0000000..c6cc552
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/resources/META-INF/spring/beanshell-activity-context.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="beanshellActivityHealthChecker" class="net.sf.taverna.t2.activities.beanshell.BeanshellActivityHealthChecker" />
+
+ <bean id="beanshellActivityFactory" class="net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory">
+ <property name="applicationConfiguration" ref="applicationConfiguration" />
+ </bean>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/main/resources/schema.json
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/main/resources/schema.json b/taverna-beanshell-activity/src/main/resources/schema.json
new file mode 100644
index 0000000..fcf07b2
--- /dev/null
+++ b/taverna-beanshell-activity/src/main/resources/schema.json
@@ -0,0 +1,21 @@
+{
+ "$schema": "http://json-schema.org/draft-03/schema#",
+ "id": "http://ns.taverna.org.uk/2010/activity/beanshell.schema.json",
+ "title": "Beanshell activity configuration",
+ "type": "object",
+ "extends" : "http://ns.taverna.org.uk/2010/activity/dependency.schema.json",
+ "properties": {
+ "@context": {
+ "description": "JSON-LD context for interpreting the configuration as RDF",
+ "required": true,
+ "enum": ["http://ns.taverna.org.uk/2010/activity/beanshell.context.json"]
+ },
+ "script": {
+ "title": "Beanshell Script",
+ "description": "The beanshell script to be executed",
+ "type": "string",
+ "required": true,
+ "default": ""
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java b/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java
new file mode 100644
index 0000000..32290ac
--- /dev/null
+++ b/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityFactoryTest.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (C) 2010 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 net.sf.taverna.t2.activities.beanshell;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URI;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ * @author David Withers
+ */
+public class BeanshellActivityFactoryTest {
+
+ private BeanshellActivityFactory factory;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ factory = new BeanshellActivityFactory();
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory#createActivity()}.
+ */
+ @Test
+ public void testCreateActivity() {
+ BeanshellActivity createActivity = factory.createActivity();
+ assertNotNull(createActivity);
+ }
+
+ /**
+ * Test method for {@link net.sf.taverna.t2.activities.beanshell.BeanshellActivityFactory#getActivityType()}.
+ */
+ @Test
+ public void testGetActivityURI() {
+ assertEquals(URI.create(BeanshellActivity.URI), factory.getActivityType());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/24f293c8/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java
----------------------------------------------------------------------
diff --git a/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java b/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java
new file mode 100644
index 0000000..0b4b5ff
--- /dev/null
+++ b/taverna-beanshell-activity/src/test/java/net/sf/taverna/t2/activities/beanshell/BeanshellActivityHealthCheckerTest.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * 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 net.sf.taverna.t2.activities.beanshell;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sf.taverna.t2.activities.testutils.ActivityInvoker;
+import net.sf.taverna.t2.visit.VisitReport;
+import net.sf.taverna.t2.visit.VisitReport.Status;
+import net.sf.taverna.t2.workflowmodel.Edits;
+import net.sf.taverna.t2.workflowmodel.impl.EditsImpl;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+/**
+ * BeanshellActivityHealthChecker tests
+ *
+ * @author Stian Soiland-Reyes
+ *
+ */
+public class BeanshellActivityHealthCheckerTest {
+
+ private Edits edits = new EditsImpl();
+
+ private ObjectNode configuration;
+
+ @Before
+ public void setup() throws Exception {
+ configuration = JsonNodeFactory.instance.objectNode();
+ configuration.put("classLoaderSharing", "workflow");
+ }
+
+ @Test
+ public void oneLinerNoSemicolon() throws Exception {
+ BeanshellActivity activity = new BeanshellActivity(null);
+ configuration.put("script", "a = 5+3");
+ // Notice lack of ;
+ activity.configure(configuration);
+
+ Map<String,Object> inputs = new HashMap<String, Object>();
+ Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
+ ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
+
+ BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
+ assertTrue(healthChecker.canVisit(activity));
+ ArrayList<Object> ancestors = new ArrayList<Object>();
+
+ ancestors.add(edits.createProcessor("beanie"));
+ VisitReport visit = healthChecker.visit(activity, ancestors);
+ assertEquals(Status.OK, visit.getStatus());
+ }
+
+ @Test
+ public void oneLiner() throws Exception {
+ BeanshellActivity activity = new BeanshellActivity(null);
+ configuration.put("script", "System.out.println(\"Hello\");");
+ activity.configure(configuration);
+
+ Map<String,Object> inputs = new HashMap<String, Object>();
+ Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
+ ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
+
+ BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
+ assertTrue(healthChecker.canVisit(activity));
+ ArrayList<Object> ancestors = new ArrayList<Object>();
+
+ ancestors.add(edits.createProcessor("beanie"));
+ VisitReport visit = healthChecker.visit(activity, ancestors);
+ assertEquals(Status.OK, visit.getStatus());
+ }
+
+ @Test
+ public void threeLines() throws Exception {
+ BeanshellActivity activity = new BeanshellActivity(null);
+ configuration.put("script", "if (2>1) {\n" +
+ " new Integer(4);\n" +
+ "}");
+ activity.configure(configuration);
+
+ Map<String,Object> inputs = new HashMap<String, Object>();
+ Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
+ ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
+
+ BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
+ assertTrue(healthChecker.canVisit(activity));
+ ArrayList<Object> ancestors = new ArrayList<Object>();
+
+ ancestors.add(edits.createProcessor("beanie"));
+ VisitReport visit = healthChecker.visit(activity, ancestors);
+ assertEquals(Status.OK, visit.getStatus());
+
+
+
+ }
+
+ @Test
+ public void invalidScript() throws Exception {
+ BeanshellActivity activity = new BeanshellActivity(null);
+ configuration.put("script", "invalid script 5 +");
+ activity.configure(configuration);
+
+ Map<String,Object> inputs = new HashMap<String, Object>();
+ Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
+ try {
+ ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
+ fail("Script should not be valid");
+ } catch (RuntimeException ex) {
+ // expected to fail
+ }
+
+
+ BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
+ assertTrue(healthChecker.canVisit(activity));
+ ArrayList<Object> ancestors = new ArrayList<Object>();
+
+ ancestors.add(edits.createProcessor("beanie"));
+ VisitReport visit = healthChecker.visit(activity, ancestors);
+ assertEquals(Status.SEVERE, visit.getStatus());
+ }
+
+ @Test
+ public void strangeWhitespace() throws Exception {
+ BeanshellActivity activity = new BeanshellActivity(null);
+ configuration.put("script", "b = \"fish\";\n" +
+ "a = 2+3\n" +
+ "\n" +
+ "\n" +
+ " +5 ");
+ // Notice lots of whitespace, but still valid
+ activity.configure(configuration);
+
+ Map<String,Object> inputs = new HashMap<String, Object>();
+ Map<String, Class<?>> expectedOutputs = new HashMap<String, Class<?>>();
+ ActivityInvoker.invokeAsyncActivity(activity, inputs, expectedOutputs);
+
+ BeanshellActivityHealthChecker healthChecker = new BeanshellActivityHealthChecker();
+ assertTrue(healthChecker.canVisit(activity));
+ ArrayList<Object> ancestors = new ArrayList<Object>();
+
+ ancestors.add(edits.createProcessor("beanie"));
+ VisitReport visit = healthChecker.visit(activity, ancestors);
+ System.out.println(visit);
+ assertEquals(Status.OK, visit.getStatus());
+ }
+}