Diff
Modified: trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/classic/Silk4TestBuilder.java (40670 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/classic/Silk4TestBuilder.java 2012-07-17 17:13:08 UTC (rev 40670)
+++ trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/classic/Silk4TestBuilder.java 2012-07-18 10:53:48 UTC (rev 40671)
@@ -83,7 +83,7 @@
return true;
}
- if (!Utils.cleanupWorkspace(build.getWorkspace(), build.getTimestamp())) {
+ if (!Utils.cleanupWorkspace(launcher, build.getWorkspace().getRemote(), build.getTimestamp())) {
build.setResult(Result.FAILURE);
listener.error("[SilkTest Classic] Deleting the result folder failed.");
LOGGER.severe("Deleting result folder failed.");
Modified: trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/common/Utils.java (40670 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/common/Utils.java 2012-07-17 17:13:08 UTC (rev 40670)
+++ trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/common/Utils.java 2012-07-18 10:53:48 UTC (rev 40671)
@@ -1,8 +1,9 @@
package org.jenkins.plugins.silktestsuite.common;
-import hudson.FilePath;
+import hudson.Launcher;
+import hudson.remoting.Callable;
-import java.io.IOException;
+import java.io.File;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -10,15 +11,29 @@
public class Utils {
private static final Logger LOGGER = Logger.getLogger("org.jenkins.plugins.silktestsuite.common");
- public static boolean cleanupWorkspace(final FilePath workspace, final Calendar startTime)
- throws InterruptedException {
+ public static boolean cleanupWorkspace(final Launcher launcher, final String workspace, final Calendar startTime) {
try {
- final FilePath resultDir = new FilePath(workspace, "SilkTestResults");
- if (!resultDir.exists() || (resultDir.lastModified() < startTime.getTimeInMillis())) {
- resultDir.deleteRecursive();
- }
- return true;
- } catch (final IOException e) {
+ return launcher.getChannel().call(new Callable<Boolean, Throwable>() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Boolean call() {
+ final File resultDir = new File(workspace, "SilkTestResults");
+ deleteRecursive(resultDir);
+ return true;
+ }
+
+ private void deleteRecursive(File file) {
+ if (file.isFile() && (file.lastModified() < startTime.getTimeInMillis()))
+ file.delete();
+ else {
+ for (File f : file.listFiles()) {
+ deleteRecursive(f);
+ }
+ }
+ }
+ });
+ } catch (Throwable e) {
LOGGER.log(Level.SEVERE, "Deleting the result folder failed.", e);
return false;
}
Added: trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/STWCOMExecution.java (0 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/STWCOMExecution.java (rev 0)
+++ trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/STWCOMExecution.java 2012-07-18 10:53:48 UTC (rev 40671)
@@ -0,0 +1,197 @@
+package org.jenkins.plugins.silktestsuite.workbench;
+
+import hudson.model.BuildListener;
+import hudson.model.Result;
+import hudson.remoting.Callable;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+
+import com.borland.silktest.workbench.generated.ClassFactory;
+import com.borland.silktest.workbench.generated.ISTWApp;
+import com.borland.silktest.workbench.generated.ISTWDotNETScripts;
+import com.borland.silktest.workbench.generated.ISTWExecutionResult;
+import com.borland.silktest.workbench.generated.ISTWProjects;
+import com.borland.silktest.workbench.generated.ISTWResult;
+import com.borland.silktest.workbench.generated.ISTWVisualTests;
+import com4j.ComException;
+import com4j.Holder;
+
+public class STWCOMExecution implements Callable<Result, RuntimeException> {
+ private static final int WAIT_FOR_STWIDLE_TIMEOUT = 1000;
+
+ private static final long serialVersionUID = 1L;
+ private String user;
+ private String password;
+ private String dsn;
+ private String projectsCsv;
+ private String namesCsv;
+ private String playbackenv;
+ private String workspace;
+
+ private BuildListener listener;
+
+ public STWCOMExecution(String user, String password, String dsn, String projectsCsv, String namesCsv, String playbackenv, String workspace, BuildListener listener) {
+ this.user = user;
+ this.password = password;
+ this.dsn = dsn;
+ this.projectsCsv = projectsCsv;
+ this.namesCsv = namesCsv;
+ this.playbackenv = playbackenv;
+ this.workspace = workspace;
+ this.listener = listener;
+ }
+
+
+ @Override
+ public Result call() throws RuntimeException {
+ final ISTWApp stWorkbench = login(listener);
+ if (stWorkbench == null) {
+ return Result.FAILURE;
+ }
+
+ final List<String> projectNames = new ArrayList<String>();
+ final ISTWProjects projects = stWorkbench.projects();
+ if (StringUtils.isEmpty(projectsCsv)) {
+ for (int i = 1; i <= projects.count(); i++) {
+ projectNames.add(projects.item(i).name());
+ }
+ } else
+ Collections.addAll(projectNames, StringUtils.splitByWholeSeparator(projectsCsv, ","));
+
+ Result result = Result.NOT_BUILT;
+ for (final String projectName : projectNames) {
+ final List<String> testNames = new ArrayList<String>();
+ listTestsForExecution(projectNames, projects, projectName, testNames);
+
+ for (final String name : testNames) {
+ final String normalizedTestName = StringUtils.chomp(name);
+ listener.getLogger().println(
+ MessageFormat.format("[SilkTest Workbench] Execute test {0} in project {1}.", normalizedTestName,
+ projectName));
+ try {
+ executeTest(stWorkbench, projectName, normalizedTestName);
+ result = result.combine(writeResult(new File(workspace), stWorkbench));
+ } catch (final ComException e) {
+ throw new RuntimeException(String.format("[SilkTest Workbench] Execute test %s in project %s failed. Please verify if the configuration is correct.",normalizedTestName, projectName), e);
+ } catch (final IOException e) {
+ throw new RuntimeException(String.format("[SilkTest Workbench] Writting the result of test %s failed because of %s.",
+ normalizedTestName, e.getLocalizedMessage()), e);
+ }
+ }
+ }
+
+ return result;
+ }
+
+
+ private ISTWApp login(final BuildListener listener) {
+ ISTWApp stWorkbench = null;
+ try {
+ stWorkbench = ClassFactory.createSTWApp();
+ if (!stWorkbench.login(user, password, dsn, Boolean.TRUE, Boolean.FALSE)) {
+ listener.error("[SilkTest Workbench] Log-in at SilkTest Workbench failed.");
+ stWorkbench = null;
+ }
+ } catch (final Exception e) {
+ listener
+ .error("[SilkTest Workbench] Cannot find SilkTest Workbench. Verify if the installation is completed successfully.");
+ }
+ return stWorkbench;
+ }
+
+ private void listTestsForExecution(final List<String> projectNames, final ISTWProjects projects,
+ final String projectName, final List<String> testNames) {
+ if ((projectNames.size() == 1) && !StringUtils.isEmpty(namesCsv)) {
+ Collections.addAll(testNames, StringUtils.splitByWholeSeparator(namesCsv, ","));
+ } else {
+ final ISTWDotNETScripts dotNETScripts = projects.item(projectName).dotNETScripts();
+ final ISTWVisualTests visualTests = projects.item(projectName).visualTests();
+ for (int i = 1; i <= dotNETScripts.count(); i++) {
+ testNames.add(dotNETScripts.item(i).name());
+ }
+ for (int i = 1; i <= visualTests.count(); i++) {
+ testNames.add(visualTests.item(i).name());
+ }
+ }
+ }
+
+ private void executeTest(final ISTWApp stWorkbench, final String projectName, final String normalizedTestName) {
+ stWorkbench.execute(projectName, normalizedTestName, null, null, playbackenv);
+
+ try {
+ while (stWorkbench.playbackInProgress()) {
+ Thread.sleep(WAIT_FOR_STWIDLE_TIMEOUT);
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Result writeResult(final File workspace, final ISTWApp stWorkbench)
+ throws IOException {
+ final ISTWExecutionResult lastResult = stWorkbench.lastResult();
+ final ISTWResult resultObject = lastResult.resultObject();
+ writeResultFile(workspace, resultObject);
+ Result result = lastTestResult(lastResult);
+
+ if (result.isWorseThan(Result.SUCCESS)) {
+ writeErrorScreen(workspace, resultObject);
+ }
+ return result;
+ }
+
+ private void writeResultFile(final File workspace, final ISTWResult lastResult) throws IOException {
+ final File workbenchResults = createResultFolders(workspace);
+ final File result = new File(workbenchResults, lastResult.name() + "_" + lastResult.assetID() + ".xml");
+
+ final Holder<String> xmlFileName = new Holder<String>();
+ lastResult.getXML(lastResult.currentVersion(), 1, xmlFileName, null);
+ new File(xmlFileName.value).renameTo(result);
+ }
+
+ private void writeErrorScreen(final File workspace, final ISTWResult lastResult) throws IOException {
+ final File workbenchResults = createResultFolders(workspace);
+ final File errorScreen = new File(workbenchResults, lastResult.name() + "_" + lastResult.assetID() + ".png");
+ final Holder<String> errorScreenFileName = new Holder<String>();
+ lastResult.getErrorScreen(lastResult.currentVersion(), errorScreenFileName);
+ new File(errorScreenFileName.value).renameTo(errorScreen);
+ }
+
+ private Result lastTestResult(final ISTWExecutionResult lastResult) {
+ final int passCriteria = lastResult.verificationPassCriteria();
+ final int executed = lastResult.verificationsExecuted();
+ final int passed = lastResult.verificationsPassed();
+ if (!StringUtils.isEmpty(lastResult.playbackErrorString())) {
+ return Result.FAILURE;
+ }
+
+ if (executed <= 0) {
+ return Result.SUCCESS; // no verifications in the test
+ }
+ if (passCriteria <= ((passed * 100) / executed)) {
+ return Result.SUCCESS;
+ } else {
+ return Result.UNSTABLE;
+ }
+ }
+
+ private File createResultFolders(final File workspace) throws IOException {
+ final File silktestResultRoot = new File(workspace, "SilkTestResults");
+ if (!silktestResultRoot.exists()) {
+ silktestResultRoot.mkdirs();
+ }
+
+ final File workbenchResults = new File(silktestResultRoot, "Workbench");
+ if (!workbenchResults.exists()) {
+ workbenchResults.mkdirs();
+ }
+ return workbenchResults;
+ }
+}
Deleted: trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchBuilder.java (40670 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchBuilder.java 2012-07-17 17:13:08 UTC (rev 40670)
+++ trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchBuilder.java 2012-07-18 10:53:48 UTC (rev 40671)
@@ -1,319 +0,0 @@
-package org.jenkins.plugins.silktestsuite.workbench;
-
-import hudson.FilePath;
-import hudson.Functions;
-import hudson.Launcher;
-import hudson.Proc;
-import hudson.Launcher.ProcStarter;
-import hudson.model.BuildListener;
-import hudson.model.Result;
-import hudson.model.AbstractBuild;
-import hudson.tasks.Builder;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.commons.lang.StringUtils;
-import org.jenkins.plugins.silktestsuite.common.RemoteEnvironmentVariables;
-import org.jenkins.plugins.silktestsuite.common.Utils;
-import org.kohsuke.stapler.DataBoundConstructor;
-
-import com.borland.silktest.workbench.generated.ClassFactory;
-import com.borland.silktest.workbench.generated.ISTWApp;
-import com.borland.silktest.workbench.generated.ISTWDotNETScripts;
-import com.borland.silktest.workbench.generated.ISTWExecutionResult;
-import com.borland.silktest.workbench.generated.ISTWProjects;
-import com.borland.silktest.workbench.generated.ISTWResult;
-import com.borland.silktest.workbench.generated.ISTWVisualTests;
-import com.google.common.base.Strings;
-
-import com4j.ComException;
-import com4j.Holder;
-
-public class SilkTestWorkbenchBuilder extends Builder {
- private static final int WAIT_FOR_STWIDLE_TIMEOUT = 1000;
- private static final Logger LOGGER = Logger.getLogger("org.jenkins.plugins.silktestsuite.workbench");
-
- private final String user;
- private final String password;
- private final String dsn;
- private final String projectsCsv;
- private final String namesCsv;
- private final String playbackenv;
-
- @DataBoundConstructor
- public SilkTestWorkbenchBuilder(final String user, final String password, final String dsn, final String projectsCsv,
- final String playbackenv, final String namesCsv) {
- this.user = user;
- this.password = password;
- this.dsn = dsn;
- this.projectsCsv = projectsCsv;
- this.playbackenv = StringUtils.isEmpty(playbackenv) ? "System Defaults" : playbackenv;
- this.namesCsv = namesCsv;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getUser() {
- return user;
- }
-
- public String getDsn() {
- return dsn;
- }
-
- public String getProjectsCsv() {
- return projectsCsv;
- }
-
- public String getNamesCsv() {
- return namesCsv;
- }
-
- @Override
- public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
- throws InterruptedException, IOException {
- if (!Functions.isWindows()) {
- listener.error("Only available on Windows systems.");
- LOGGER.severe("This operation system is not supported with SilkTest.");
- build.setResult(Result.ABORTED);
- return true;
- }
-
- if (!Utils.cleanupWorkspace(build.getWorkspace(), build.getTimestamp())) {
- listener.error("[SilkTest Workbench] Deleting the result folder failed.");
- build.setResult(Result.FAILURE);
- return false;
- }
-
- FilePath resultPath = createResultFolders(build.getWorkspace());
- String resultFileName = calculateResultName(dsn, projectsCsv, namesCsv);
- FilePath resultFile = new FilePath(resultPath, resultFileName+".txt");
- Map<String,String> environment = launcher.getChannel().call(new RemoteEnvironmentVariables());
- List<String> cmd = createCommandLine(environment, resultFile.getRemote());
- ProcStarter silktestworkbench = launcher.launch().cmds(cmd).stdout(listener.getLogger());
- Proc launch = launcher.launch(silktestworkbench);
- int exitCode = launch.join();
- Result result = exitCode == 0 ? Result.SUCCESS : Result.UNSTABLE;
-
- FilePath junitResultFile = new FilePath(resultPath, resultFileName+".xml");
- new STWTestResultConverter().convert(resultFile, junitResultFile);
-
-// final ISTWApp stWorkbench = login(build, listener);
-// if (stWorkbench == null) {
-// build.setResult(Result.FAILURE);
-// return false;
-// }
-//
-// final List<String> projectNames = new ArrayList<String>();
-// final ISTWProjects projects = stWorkbench.projects();
-// if (StringUtils.isEmpty(projectsCsv)) {
-// for (int i = 1; i <= projects.count(); i++) {
-// projectNames.add(projects.item(i).name());
-// }
-// } else {
-// Collections.addAll(projectNames, StringUtils.splitByWholeSeparator(projectsCsv, ","));
-// }
-//
-// Result result = build.getResult() == null ? Result.SUCCESS : build.getResult();
-// for (final String projectName : projectNames) {
-// final List<String> testNames = new ArrayList<String>();
-// listTestsForExecution(projectNames, projects, projectName, testNames);
-//
-// for (final String name : testNames) {
-// final String normalizedTestName = StringUtils.chomp(name);
-// listener.getLogger().println(
-// MessageFormat.format("[SilkTest Workbench] Execute test {0} in project {1}.", normalizedTestName,
-// projectName));
-// try {
-// executeTest(stWorkbench, projectName, normalizedTestName);
-// result = writeResult(build, stWorkbench, result);
-// } catch (final ComException e) {
-// listener
-// .error(
-// "[SilkTest Workbench] Execute test %s in project %s failed. Please verify if the configuration is correct.",
-// normalizedTestName, projectName);
-// LOGGER.log(Level.SEVERE, "SilkTest Workbench execution failed.", e);
-// result = result.combine(Result.FAILURE);
-// } catch (final IOException e) {
-// listener.error("[SilkTest Workbench] Writting the result of test %s failed because of %s.",
-// normalizedTestName, e.getLocalizedMessage());
-// LOGGER.log(Level.SEVERE, "Writting result for SilkTest Workbench execution failed.", e);
-// result = result.combine(Result.FAILURE);
-// }
-// LOGGER.fine("New result :" + result.toString());
-// }
-// }
- build.setResult(result);
-
- return result.isBetterThan(Result.FAILURE);
- }
-
- private String calculateResultName(String dsn2, String projectsCsv2, String namesCsv2) {
- return "xy";
- }
-
- private List<String> createCommandLine(Map<String, String> environment, String resultPath) {
- String oaHome = environment.get("OPEN_AGENT_HOME");
- List<String> cli = new ArrayList<String>();
- cli.add(oaHome+"/gui/stw.exe");
- cli.add("-u");
- cli.add(this.user);
- cli.add("-p");
- cli.add(password);
- cli.add("-d");
- cli.add(dsn);
- cli.add("-o");
- cli.add(resultPath);
- if (!Strings.isNullOrEmpty(projectsCsv)) {
- cli.add("-r");
- cli.add(projectsCsv); // FIXME: allows only one project
- }
- if (!Strings.isNullOrEmpty(namesCsv)) {
- cli.add("-s");
- cli.add(namesCsv); // FIXME: allows only one script name
- }
- if (!Strings.isNullOrEmpty(playbackenv)) {
- cli.add("-e");
- cli.add(playbackenv);
- }
-
- return cli;
- }
-
-// private Result writeResult(final AbstractBuild<?, ?> build, final ISTWApp stWorkbench, Result result)
-// throws IOException, InterruptedException {
-// final ISTWExecutionResult lastResult = stWorkbench.lastResult();
-// final ISTWResult resultObject = lastResult.resultObject();
-// writeResultFile(build.getWorkspace(), resultObject);
-// result = result.combine(lastTestResult(lastResult)); // FIXME: after executed test
-// // lastResult.verificationsExecuted(); returns 0, do we
-// // need a delay?
-// if (result.isWorseThan(Result.SUCCESS)) {
-// writeErrorScreen(new FilePath(build.getRootDir()), resultObject);
-// }
-// return result;
-// }
-//
-// private void executeTest(final ISTWApp stWorkbench, final String projectName, final String normalizedTestName)
-// throws InterruptedException {
-// stWorkbench.execute(projectName, normalizedTestName, null, null, playbackenv);
-//
-// while (stWorkbench.playbackInProgress()) {
-// Thread.sleep(WAIT_FOR_STWIDLE_TIMEOUT);
-// }
-// }
-//
-// private void listTestsForExecution(final List<String> projectNames, final ISTWProjects projects,
-// final String projectName, final List<String> testNames) {
-// if ((projectNames.size() == 1) && !StringUtils.isEmpty(namesCsv)) {
-// Collections.addAll(testNames, StringUtils.splitByWholeSeparator(namesCsv, ","));
-// } else {
-// final ISTWDotNETScripts dotNETScripts = projects.item(projectName).dotNETScripts();
-// final ISTWVisualTests visualTests = projects.item(projectName).visualTests();
-// for (int i = 1; i <= dotNETScripts.count(); i++) {
-// testNames.add(dotNETScripts.item(i).name());
-// }
-// for (int i = 1; i <= visualTests.count(); i++) {
-// testNames.add(visualTests.item(i).name());
-// }
-// }
-// }
-
-// private ISTWApp login(final AbstractBuild<?, ?> build, final BuildListener listener) {
-// ISTWApp stWorkbench = null;
-// try {
-// stWorkbench = ClassFactory.createSTWApp();
-// if (!stWorkbench.login(user, password, dsn, Boolean.TRUE, Boolean.FALSE)) {
-// listener.error("[SilkTest Workbench] Log-in at SilkTest Workbench failed.");
-// LOGGER.warning("log in to Silktest Workbench failed.");
-// build.setResult(Result.FAILURE);
-// stWorkbench = null;
-// }
-// } catch (final Exception e) {
-// listener
-// .error("[SilkTest Workbench] Cannot find SilkTest Workbench. Verify if the installation is completed successfully.");
-// LOGGER.log(Level.SEVERE, "SilkTEst Workbench is not installed.", e);
-// build.setResult(Result.FAILURE);
-// }
-// return stWorkbench;
-// }
-//
-// private Result lastTestResult(final ISTWExecutionResult lastResult) {
-// final int passCriteria = lastResult.verificationPassCriteria();
-// final int executed = lastResult.verificationsExecuted();
-// final int passed = lastResult.verificationsPassed();
-// if (!StringUtils.isEmpty(lastResult.playbackErrorString())) {
-// return Result.FAILURE;
-// }
-//
-// if (executed <= 0) {
-// return Result.SUCCESS; // no verifications in the test
-// }
-// if (passCriteria <= ((passed * 100) / executed)) {
-// return Result.SUCCESS;
-// } else {
-// return Result.UNSTABLE;
-// }
-// }
-//
-// private void writeResultFile(final FilePath filePath, final ISTWResult lastResult) throws IOException,
-// InterruptedException {
-// final FilePath workbenchResults = createResultFolders(filePath);
-// final FilePath result = new FilePath(workbenchResults, lastResult.name() + "_" + lastResult.assetID() + ".xml");
-//
-// final Holder<String> xmlFileName = new Holder<String>();
-// lastResult.getXML(lastResult.currentVersion(), 1, xmlFileName, null);
-// moveFileToDestination(result, xmlFileName.value);
-// }
-//
-// private void writeErrorScreen(final FilePath filePath, final ISTWResult lastResult) throws IOException,
-// InterruptedException {
-// final FilePath workbenchResults = createResultFolders(filePath);
-// final FilePath errorScreen = new FilePath(workbenchResults, lastResult.name() + "_" + lastResult.assetID() + ".png");
-// final Holder<String> errorScreenFileName = new Holder<String>();
-// lastResult.getErrorScreen(lastResult.currentVersion(), errorScreenFileName);
-// moveFileToDestination(errorScreen, errorScreenFileName.value);
-// }
-
- private FilePath createResultFolders(final FilePath filePath) throws IOException, InterruptedException {
- final FilePath silktestResultRoot = new FilePath(filePath, "SilkTestResults");
- if (!silktestResultRoot.exists()) {
- silktestResultRoot.mkdirs();
- }
-
- final FilePath workbenchResults = new FilePath(silktestResultRoot, "Workbench");
- if (!workbenchResults.exists()) {
- workbenchResults.mkdirs();
- }
- return workbenchResults;
- }
-
-// private void moveFileToDestination(final FilePath result, final String fileName) throws FileNotFoundException,
-// IOException, InterruptedException {
-// InputStream is = null;
-// try {
-// final File source = new File(fileName);
-// is = new FileInputStream(source);
-// result.copyFrom(is);
-// source.delete();
-// } finally {
-// if (is != null) {
-// is.close();
-// }
-// }
-// }
-}
Copied: trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder.java (from rev 40670, trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchBuilder.java) (0 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder.java (rev 0)
+++ trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder.java 2012-07-18 10:53:48 UTC (rev 40671)
@@ -0,0 +1,146 @@
+package org.jenkins.plugins.silktestsuite.workbench;
+
+import hudson.FilePath;
+import hudson.Functions;
+import hudson.Launcher;
+import hudson.Launcher.ProcStarter;
+import hudson.Proc;
+import hudson.model.BuildListener;
+import hudson.model.Result;
+import hudson.model.AbstractBuild;
+import hudson.tasks.Builder;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.apache.commons.lang.StringUtils;
+import org.jenkins.plugins.silktestsuite.common.RemoteEnvironmentVariables;
+import org.jenkins.plugins.silktestsuite.common.Utils;
+import org.kohsuke.stapler.DataBoundConstructor;
+
+import com.google.common.base.Strings;
+
+public class SilkTestWorkbenchCLIBuilder extends Builder {
+ private static final Logger LOGGER = Logger.getLogger("org.jenkins.plugins.silktestsuite.workbench");
+
+ private final String user;
+ private final String password;
+ private final String dsn;
+ private final String projectsCsv;
+ private final String namesCsv;
+ private final String playbackenv;
+
+ @DataBoundConstructor
+ public SilkTestWorkbenchCLIBuilder(final String user, final String password, final String dsn, final String projectsCsv,
+ final String playbackenv, final String namesCsv) {
+ this.user = user;
+ this.password = password;
+ this.dsn = dsn;
+ this.projectsCsv = projectsCsv;
+ this.playbackenv = StringUtils.isEmpty(playbackenv) ? "System Defaults" : playbackenv;
+ this.namesCsv = namesCsv;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getDsn() {
+ return dsn;
+ }
+
+ public String getProjectsCsv() {
+ return projectsCsv;
+ }
+
+ public String getNamesCsv() {
+ return namesCsv;
+ }
+
+ @Override
+ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
+ throws InterruptedException, IOException {
+ if (!Functions.isWindows()) {
+ listener.error("Only available on Windows systems.");
+ LOGGER.severe("This operation system is not supported with SilkTest.");
+ build.setResult(Result.ABORTED);
+ return true;
+ }
+
+ if (!Utils.cleanupWorkspace(launcher, build.getWorkspace().getRemote(), build.getTimestamp())) {
+ listener.error("[SilkTest Workbench] Deleting the result folder failed.");
+ build.setResult(Result.FAILURE);
+ return false;
+ }
+
+ FilePath resultPath = createResultFolders(build.getWorkspace());
+ String resultFileName = calculateResultName(dsn, projectsCsv, namesCsv);
+ FilePath resultFile = new FilePath(resultPath, resultFileName+".txt");
+ Map<String,String> environment = launcher.getChannel().call(new RemoteEnvironmentVariables());
+ List<String> cmd = createCommandLine(environment, resultFile.getRemote());
+ ProcStarter silktestworkbench = launcher.launch().cmds(cmd).stdout(listener.getLogger());
+ Proc launch = launcher.launch(silktestworkbench);
+ int exitCode = launch.join();
+ Result result = exitCode == 0 ? Result.SUCCESS : Result.UNSTABLE;
+
+ FilePath junitResultFile = new FilePath(resultPath, resultFileName+".xml");
+ new STWTestResultConverter().convert(resultFile, junitResultFile);
+
+ build.setResult(result);
+
+ return result.isBetterThan(Result.FAILURE);
+ }
+
+ private String calculateResultName(String dsn2, String projectsCsv2, String namesCsv2) {
+ return "xy";
+ }
+
+ private List<String> createCommandLine(Map<String, String> environment, String resultPath) {
+ String oaHome = environment.get("OPEN_AGENT_HOME");
+ List<String> cli = new ArrayList<String>();
+ cli.add(oaHome+"/gui/stw.exe");
+ cli.add("-u");
+ cli.add(this.user);
+ cli.add("-p");
+ cli.add(password);
+ cli.add("-d");
+ cli.add(dsn);
+ cli.add("-o");
+ cli.add(resultPath);
+ if (!Strings.isNullOrEmpty(projectsCsv)) {
+ cli.add("-r");
+ cli.add(projectsCsv); // FIXME: allows only one project
+ }
+ if (!Strings.isNullOrEmpty(namesCsv)) {
+ cli.add("-s");
+ cli.add(namesCsv); // FIXME: allows only one script name
+ }
+ if (!Strings.isNullOrEmpty(playbackenv)) {
+ cli.add("-e");
+ cli.add(playbackenv);
+ }
+
+ return cli;
+ }
+
+ private FilePath createResultFolders(final FilePath filePath) throws IOException, InterruptedException {
+ final FilePath silktestResultRoot = new FilePath(filePath, "SilkTestResults");
+ if (!silktestResultRoot.exists()) {
+ silktestResultRoot.mkdirs();
+ }
+
+ final FilePath workbenchResults = new FilePath(silktestResultRoot, "Workbench");
+ if (!workbenchResults.exists()) {
+ workbenchResults.mkdirs();
+ }
+ return workbenchResults;
+ }
+
+}
Added: trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCOMBuilder.java (0 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCOMBuilder.java (rev 0)
+++ trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCOMBuilder.java 2012-07-18 10:53:48 UTC (rev 40671)
@@ -0,0 +1,102 @@
+package org.jenkins.plugins.silktestsuite.workbench;
+
+import hudson.Functions;
+import hudson.Launcher;
+import hudson.model.BuildListener;
+import hudson.model.Result;
+import hudson.model.AbstractBuild;
+import hudson.remoting.Callable;
+import hudson.tasks.Builder;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.commons.lang.StringUtils;
+import org.jenkins.plugins.silktestsuite.common.Utils;
+import org.kohsuke.stapler.DataBoundConstructor;
+
+public class SilkTestWorkbenchCOMBuilder extends Builder {
+ private static final Logger LOGGER = Logger.getLogger("org.jenkins.plugins.silktestsuite.workbench");
+
+ private final String user;
+ private final String password;
+ private final String dsn;
+ private final String projectsCsv;
+ private final String namesCsv;
+ private final String playbackenv;
+
+ @DataBoundConstructor
+ public SilkTestWorkbenchCOMBuilder(final String user, final String password, final String dsn, final String projectsCsv,
+ final String playbackenv, final String namesCsv) {
+ this.user = user;
+ this.password = password;
+ this.dsn = dsn;
+ this.projectsCsv = projectsCsv;
+ this.playbackenv = StringUtils.isEmpty(playbackenv) ? "System Defaults" : playbackenv;
+ this.namesCsv = namesCsv;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public String getDsn() {
+ return dsn;
+ }
+
+ public String getProjectsCsv() {
+ return projectsCsv;
+ }
+
+ public String getNamesCsv() {
+ return namesCsv;
+ }
+
+ @Override
+ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
+ throws InterruptedException, IOException {
+
+// boolean windowsOS = launcher.getChannel().call(new Callable<Boolean, RuntimeException>() {
+// private static final long serialVersionUID = 1L;
+//
+// @Override
+// public Boolean call() throws RuntimeException {
+// return true;
+// }
+// });
+//
+// if (!windowsOS) {
+// listener.error("Only available on Windows systems.");
+// LOGGER.severe("This operation system is not supported with SilkTest.");
+// build.setResult(Result.ABORTED);
+// return true;
+// }
+
+ final String workspace = build.getWorkspace().getRemote();
+ if (!Utils.cleanupWorkspace(launcher, workspace, build.getTimestamp())) {
+ listener.error("[SilkTest Workbench] Deleting the result folder failed.");
+ build.setResult(Result.FAILURE);
+ return false;
+ }
+
+ Result result;
+ try {
+ result = launcher.getChannel().call(new STWCOMExecution(user, password, dsn, projectsCsv, namesCsv, playbackenv, workspace, listener));
+ } catch (RuntimeException e) {
+ LOGGER.log(Level.SEVERE, e.getMessage(), e);
+ result = Result.FAILURE;
+ }
+
+ result = build.getResult() == null ? result : build.getResult().combine(result);
+ build.setResult(result);
+
+ return result.isBetterThan(Result.FAILURE);
+ }
+
+
+}
Modified: trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchDescriptor.java (40670 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchDescriptor.java 2012-07-17 17:13:08 UTC (rev 40670)
+++ trunk/hudson/plugins/silktestsuite/src/main/java/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchDescriptor.java 2012-07-18 10:53:48 UTC (rev 40671)
@@ -23,7 +23,7 @@
private static final Logger LOGGER = Logger.getLogger("org.jenkins.plugins.silktestsuite.visualtest");
public SilkTestWorkbenchDescriptor() {
- super(SilkTestWorkbenchBuilder.class);
+ super(SilkTestWorkbenchCOMBuilder.class);
load();
}
Added: trunk/hudson/plugins/silktestsuite/src/main/resources/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder/config.jelly (0 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/resources/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder/config.jelly (rev 0)
+++ trunk/hudson/plugins/silktestsuite/src/main/resources/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder/config.jelly 2012-07-18 10:53:48 UTC (rev 40671)
@@ -0,0 +1,26 @@
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+ <st:documentation>
+ Executes a VisualTest or a VB.net TestScript with Borland SilkTest Workbench
+ <st:attribute name="user" use="required"/>
+ <st:attribute name="password" use="required"/>
+ <st:attribute name="dsn" use="required"/>
+ </st:documentation>
+ <f:entry title="User:">
+ <f:textbox field="user" value="${instance.user}" />
+ </f:entry>
+ <f:entry title="Password:">
+ <f:password field="password" value="${instance.password}" />
+ </f:entry>
+ <f:entry title="Data Source Name:">
+ <f:textbox field="dsn" value="${instance.dsn}" />
+ </f:entry>
+ <f:entry title="Project name(s):">
+ <f:textbox field="projectsCsv" value="${instance.projectsCsv}" />
+ </f:entry>
+ <f:entry title="Test name(s):">
+ <f:textbox field="namesCsv" value="${instance.namesCsv}" />
+ </f:entry>
+ <f:entry title="Playback Environment Settings">
+ <f:textbox field="playbackenv" value="${instance.playbackenv}" />
+ </f:entry>
+</j:jelly>
\ No newline at end of file
Added: trunk/hudson/plugins/silktestsuite/src/main/resources/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder/global.jelly (0 => 40671)
--- trunk/hudson/plugins/silktestsuite/src/main/resources/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder/global.jelly (rev 0)
+++ trunk/hudson/plugins/silktestsuite/src/main/resources/org/jenkins/plugins/silktestsuite/workbench/SilkTestWorkbenchCLIBuilder/global.jelly 2012-07-18 10:53:48 UTC (rev 40671)
@@ -0,0 +1,2 @@
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+</j:jelly>
\ No newline at end of file