From 494608aa92c925145bfcc4604a746dd021aad4ef Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 11 May 2020 12:14:22 +0530 Subject: [PATCH 01/14] Keepng execution logic same for both steps. --- pom.xml | 15 +- .../ci/MatlabCommandStepExecution.java | 94 ++++++++++++ .../mathworks/ci/MatlabTestStepExecution.java | 5 + .../mathworks/ci/RunMatlabCommandStep.java | 66 +++++++++ .../com/mathworks/ci/RunMatlabTestsStep.java | 136 ++++++++++++++++++ src/main/resources/config.properties | 4 +- 6 files changed, 318 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java create mode 100644 src/main/java/com/mathworks/ci/MatlabTestStepExecution.java create mode 100644 src/main/java/com/mathworks/ci/RunMatlabCommandStep.java create mode 100644 src/main/java/com/mathworks/ci/RunMatlabTestsStep.java diff --git a/pom.xml b/pom.xml index d20d1d70..588a2542 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 3.4 + 3.57 matlab @@ -60,6 +60,19 @@ matrix-project 1.14 + + + + org.jenkins-ci.plugins.workflow + workflow-step-api + 2.22 + + + + org.jenkins-ci.plugins.workflow + workflow-api + 2.23 + diff --git a/src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java b/src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java new file mode 100644 index 00000000..b00275ae --- /dev/null +++ b/src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java @@ -0,0 +1,94 @@ +package com.mathworks.ci; + +import java.io.IOException; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepExecution; +import hudson.EnvVars; +import hudson.FilePath; +import hudson.Launcher; +import hudson.Launcher.ProcStarter; +import hudson.model.Result; +import hudson.model.TaskListener; + +public class MatlabCommandStepExecution extends StepExecution implements MatlabBuild { + private static final long serialVersionUID = 1L; + private String command; + private EnvVars env; + private boolean copyScratchFile; + + + public MatlabCommandStepExecution(StepContext context, String command, boolean copyScratchFile) { + super(context); + this.command = command; + this.copyScratchFile = copyScratchFile; + } + + private String getCommand() { + return this.env == null ? getMatlabCommand() : this.env.expand(getMatlabCommand()); + } + + private String getMatlabCommand() { + return this.command; + } + + private void setEnv(EnvVars env) { + this.env = env; + } + + private EnvVars getEnv() { + return this.env; + } + + @Override + public boolean start() throws Exception { + Launcher launcher = getContext().get(Launcher.class); + FilePath workspace = getContext().get(FilePath.class); + TaskListener listener = getContext().get(TaskListener.class); + EnvVars env = getContext().get(EnvVars.class); + setEnv(env); + + int res = execMatlabCommand(workspace, launcher, listener, getEnv()); + if (res == 0) { + getContext().setResult(Result.SUCCESS); + } else { + getContext().setResult(Result.FAILURE); + } + getContext().onSuccess(true); + + //return false represents the asynchronous run. + return false; + } + + @Override + public void stop(Throwable cause) throws Exception { + getContext().onFailure(cause); + } + + private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher, + TaskListener listener, EnvVars envVars) throws IOException, InterruptedException { + final String uniqueTmpFldrName = getUniqueNameForRunnerFile(); + ProcStarter matlabLauncher; + try { + matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars, + getCommand(), uniqueTmpFldrName); + + // Copy MATLAB scratch file into the workspace. + FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote()); + copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE, + MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace); + + return matlabLauncher.join(); + } catch (Exception e) { + listener.getLogger().println(e.getMessage()); + return 1; + } finally { + // Cleanup the runner File from tmp directory + FilePath matlabRunnerScript = + getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace); + if (matlabRunnerScript.exists()) { + matlabRunnerScript.deleteRecursive(); + } + } + + } +} diff --git a/src/main/java/com/mathworks/ci/MatlabTestStepExecution.java b/src/main/java/com/mathworks/ci/MatlabTestStepExecution.java new file mode 100644 index 00000000..51a897e6 --- /dev/null +++ b/src/main/java/com/mathworks/ci/MatlabTestStepExecution.java @@ -0,0 +1,5 @@ +package com.mathworks.ci; + +public class MatlabTestStepExecution { + +} diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java new file mode 100644 index 00000000..e89f9acc --- /dev/null +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java @@ -0,0 +1,66 @@ +package com.mathworks.ci; + +import java.util.Set; +import org.jenkinsci.plugins.workflow.steps.Step; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; +import org.jenkinsci.plugins.workflow.steps.StepExecution; +import org.kohsuke.stapler.DataBoundConstructor; +import com.google.common.collect.ImmutableSet; +import hudson.EnvVars; +import hudson.Extension; +import hudson.FilePath; +import hudson.Launcher; +import hudson.model.Run; +import hudson.model.TaskListener; + +public class RunMatlabCommandStep extends Step { + + private EnvVars env; + private String matlabCommand; + + @DataBoundConstructor + public RunMatlabCommandStep(String command) { + this.matlabCommand = command; + + } + + + public String getMatlabCommand() { + return this.matlabCommand; + } + + private String getCommand() { + return this.env == null ? getMatlabCommand() : this.env.expand(getMatlabCommand()); + } + + public void setEnv(EnvVars env) { + this.env = env; + } + + public EnvVars getEnv() { + return this.env; + } + + @Override + public StepExecution start(StepContext context) throws Exception { + return new MatlabCommandStepExecution(context, getCommand(), true); + } + + @Extension + public static class CommandStepDescriptor extends StepDescriptor { + + @Override + public Set> getRequiredContext() { + return ImmutableSet.of(TaskListener.class, FilePath.class, Launcher.class, + EnvVars.class, Run.class); + } + + @Override + public String getFunctionName() { + return Message.getValue("matlab.command.build.step.name"); + } + } +} + + diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java new file mode 100644 index 00000000..9b45749b --- /dev/null +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -0,0 +1,136 @@ +package com.mathworks.ci; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import org.jenkinsci.plugins.workflow.steps.Step; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; +import org.jenkinsci.plugins.workflow.steps.StepExecution; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; +import com.google.common.collect.ImmutableSet; +import hudson.EnvVars; +import hudson.Extension; +import hudson.FilePath; +import hudson.Launcher; +import hudson.model.Run; +import hudson.model.TaskListener; + +public class RunMatlabTestsStep extends Step { + + private String testResultsPdf; + private String testResultsTAP; + private String testResultsJUnit; + private String codeCoverageCobertura; + private String testResultsSimulinkTest; + private String modelCoverageCobertura; + + @DataBoundConstructor + public RunMatlabTestsStep() { + + } + + public String getTestResultsTAP() { + return testResultsTAP; + } + + @DataBoundSetter + public void setTestResultsTAP(String testResultsTAP) { + this.testResultsTAP = testResultsTAP; + } + + public String getTestResultsPdf() { + return testResultsPdf; + } + + @DataBoundSetter + public void setTestResultsPdf(String testResultsPdf) { + this.testResultsPdf = testResultsPdf; + } + + public String getTestResultsJUnit() { + return testResultsJUnit; + } + + @DataBoundSetter + public void setTestResultsJUnit(String testResultsJUnit) { + this.testResultsJUnit = testResultsJUnit; + } + + public String getCodeCoverageCobertura() { + return codeCoverageCobertura; + } + + @DataBoundSetter + public void setCodeCoverageCobertura(String codeCoverageCobertura) { + this.codeCoverageCobertura = codeCoverageCobertura; + } + + public String getTestResultsSimulinkTest() { + return testResultsSimulinkTest; + } + + @DataBoundSetter + public void setTestResultsSimulinkTest(String testResultsSimulinkTest) { + this.testResultsSimulinkTest = testResultsSimulinkTest; + } + + public String getModelCoverageCobertura() { + return modelCoverageCobertura; + } + + + @DataBoundSetter + public void setModelCoverageCobertura(String modelCoverageCobertura) { + this.modelCoverageCobertura = modelCoverageCobertura; + } + + + @Override + public StepExecution start(StepContext context) throws Exception { + + return new MatlabCommandStepExecution(context,getInputArgs(), true); + } + + @Extension + public static class CommandStepDescriptor extends StepDescriptor { + + @Override + public Set> getRequiredContext() { + return ImmutableSet.of(TaskListener.class, FilePath.class, Launcher.class, + EnvVars.class, Run.class); + } + + @Override + public String getFunctionName() { + return Message.getValue("matlab.tests.build.step.name"); + } + } + + private String getInputArgs() { + List inputArgs = new ArrayList<>(); + addInputArgs(MatlabBuilderConstants.PDF_REPORT_PATH, getTestResultsPdf(),inputArgs); + addInputArgs(MatlabBuilderConstants.TAP_RESULTS_PATH, getTestResultsTAP(), inputArgs); + addInputArgs(MatlabBuilderConstants.JUNIT_RESULTS_PATH, getTestResultsJUnit(), inputArgs); + addInputArgs(MatlabBuilderConstants.STM_RESULTS_PATH, getTestResultsSimulinkTest(), inputArgs); + addInputArgs(MatlabBuilderConstants.COBERTURA_CODE_COVERAGE_PATH, + getCodeCoverageCobertura(), inputArgs); + addInputArgs(MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE_PATH, + getModelCoverageCobertura(), inputArgs); + + if (inputArgs.isEmpty()) { + return ""; + } + + return String.join(",", inputArgs); + } + + private void addInputArgs(String reportName, String reportPath, List inputArgs) { + if (reportPath != null) { + inputArgs.add(reportName + "," + "'" + reportPath + "'"); + } + } + +} diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index 7cf08e48..3c9c1dd1 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -16,4 +16,6 @@ Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model cov Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release. Builder.matlab.runner.script.target.file.linux.name = run_matlab_command.sh Builder.matlab.runner.script.target.file.windows.name = run_matlab_command.bat -build.workspace.computer.not.found = Unable to access the computer for this build. \ No newline at end of file +build.workspace.computer.not.found = Unable to access the computer for this build. +matlab.command.build.step.name = runMATLABCommand +matlab.tests.build.step.name = runMATLABTests \ No newline at end of file From 0c2a9baaf3d9c751f2914d06543959f4c47df31d Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 18 May 2020 12:52:36 +0530 Subject: [PATCH 02/14] final changes for both Step execution --- ...xecution.java => MatlabStepExecution.java} | 16 ++++---- .../mathworks/ci/MatlabTestStepExecution.java | 5 --- .../mathworks/ci/RunMatlabCommandStep.java | 3 +- .../com/mathworks/ci/RunMatlabTestsStep.java | 38 +++++++++++++------ 4 files changed, 38 insertions(+), 24 deletions(-) rename src/main/java/com/mathworks/ci/{MatlabCommandStepExecution.java => MatlabStepExecution.java} (81%) delete mode 100644 src/main/java/com/mathworks/ci/MatlabTestStepExecution.java diff --git a/src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java b/src/main/java/com/mathworks/ci/MatlabStepExecution.java similarity index 81% rename from src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java rename to src/main/java/com/mathworks/ci/MatlabStepExecution.java index b00275ae..9536e478 100644 --- a/src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java +++ b/src/main/java/com/mathworks/ci/MatlabStepExecution.java @@ -10,14 +10,14 @@ import hudson.model.Result; import hudson.model.TaskListener; -public class MatlabCommandStepExecution extends StepExecution implements MatlabBuild { +public class MatlabStepExecution extends StepExecution implements MatlabBuild { private static final long serialVersionUID = 1L; private String command; private EnvVars env; private boolean copyScratchFile; - public MatlabCommandStepExecution(StepContext context, String command, boolean copyScratchFile) { + public MatlabStepExecution(StepContext context, String command, boolean copyScratchFile) { super(context); this.command = command; this.copyScratchFile = copyScratchFile; @@ -72,11 +72,13 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars, getCommand(), uniqueTmpFldrName); - // Copy MATLAB scratch file into the workspace. - FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote()); - copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE, - MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace); - + // Copy MATLAB scratch file into the workspace if required. + if(this.copyScratchFile) { + FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote()); + copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE, + MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace); + } + return matlabLauncher.join(); } catch (Exception e) { listener.getLogger().println(e.getMessage()); diff --git a/src/main/java/com/mathworks/ci/MatlabTestStepExecution.java b/src/main/java/com/mathworks/ci/MatlabTestStepExecution.java deleted file mode 100644 index 51a897e6..00000000 --- a/src/main/java/com/mathworks/ci/MatlabTestStepExecution.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.mathworks.ci; - -public class MatlabTestStepExecution { - -} diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java index e89f9acc..6a82defd 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java @@ -18,6 +18,7 @@ public class RunMatlabCommandStep extends Step { private EnvVars env; private String matlabCommand; + private static boolean COPY_SCRATCH_FILE = false; @DataBoundConstructor public RunMatlabCommandStep(String command) { @@ -44,7 +45,7 @@ public EnvVars getEnv() { @Override public StepExecution start(StepContext context) throws Exception { - return new MatlabCommandStepExecution(context, getCommand(), true); + return new MatlabStepExecution(context, getCommand(), COPY_SCRATCH_FILE); } @Extension diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java index 9b45749b..e03f5a05 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.List; import java.util.Set; +import org.apache.commons.io.FilenameUtils; import org.jenkinsci.plugins.workflow.steps.Step; import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jenkinsci.plugins.workflow.steps.StepDescriptor; @@ -11,6 +12,7 @@ import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import com.google.common.collect.ImmutableSet; +import com.mathworks.ci.RunMatlabTestsBuilder.PdfArtifact; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -26,7 +28,14 @@ public class RunMatlabTestsStep extends Step { private String codeCoverageCobertura; private String testResultsSimulinkTest; private String modelCoverageCobertura; - + private static final String PDF_REPORT_PATH = "'PDFReportPath'"; + private static final String TAP_RESULTS_PATH = "'TAPResultsPath'"; + private static final String JUNIT_RESULTS_PATH = "'JUnitResultsPath'"; + private static final String COBERTURA_CODE_COVERAGE_PATH = "'CoberturaCodeCoveragePath'"; + private static final String STM_RESULTS_PATH = "'SimulinkTestResultsPath'"; + private static final String COBERTURA_MODEL_COVERAGE_PATH = "'CoberturaModelCoveragePath'"; + private static boolean COPY_SCRATCH_FILE = true; + @DataBoundConstructor public RunMatlabTestsStep() { @@ -91,7 +100,7 @@ public void setModelCoverageCobertura(String modelCoverageCobertura) { @Override public StepExecution start(StepContext context) throws Exception { - return new MatlabCommandStepExecution(context,getInputArgs(), true); + return new MatlabStepExecution(context,constructCommandForTest(getInputArgs()), COPY_SCRATCH_FILE); } @Extension @@ -109,21 +118,29 @@ public String getFunctionName() { } } + public String constructCommandForTest(String inputArguments) { + final String matlabFunctionName = + FilenameUtils.removeExtension(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE); + final String runCommand = "exit(" + matlabFunctionName + "(" + inputArguments + "))"; + return runCommand; + } + + private String getInputArgs() { List inputArgs = new ArrayList<>(); - addInputArgs(MatlabBuilderConstants.PDF_REPORT_PATH, getTestResultsPdf(),inputArgs); - addInputArgs(MatlabBuilderConstants.TAP_RESULTS_PATH, getTestResultsTAP(), inputArgs); - addInputArgs(MatlabBuilderConstants.JUNIT_RESULTS_PATH, getTestResultsJUnit(), inputArgs); - addInputArgs(MatlabBuilderConstants.STM_RESULTS_PATH, getTestResultsSimulinkTest(), inputArgs); - addInputArgs(MatlabBuilderConstants.COBERTURA_CODE_COVERAGE_PATH, + addInputArgs(PDF_REPORT_PATH, getTestResultsPdf(),inputArgs); + addInputArgs(TAP_RESULTS_PATH, getTestResultsTAP(), inputArgs); + addInputArgs(JUNIT_RESULTS_PATH, getTestResultsJUnit(), inputArgs); + addInputArgs(STM_RESULTS_PATH, getTestResultsSimulinkTest(), inputArgs); + addInputArgs(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura(), inputArgs); - addInputArgs(MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE_PATH, + addInputArgs(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura(), inputArgs); if (inputArgs.isEmpty()) { return ""; - } - + } + return String.join(",", inputArgs); } @@ -132,5 +149,4 @@ private void addInputArgs(String reportName, String reportPath, List inp inputArgs.add(reportName + "," + "'" + reportPath + "'"); } } - } From 52c4c9b01d5f1ae32091c826ec8768493bc437c0 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Mon, 18 May 2020 12:56:50 +0530 Subject: [PATCH 03/14] Added config jelly for both steps. --- .../ci/RunMatlabCommandStep/config.jelly | 8 ++++++ .../ci/RunMatlabTestsStep/config.jelly | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly create mode 100644 src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly diff --git a/src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly b/src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly new file mode 100644 index 00000000..9a0804f9 --- /dev/null +++ b/src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly b/src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly new file mode 100644 index 00000000..b67dd357 --- /dev/null +++ b/src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 5bbcb585e94005c85d4119c8e22663a43a5f1a43 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 20 May 2020 13:48:03 +0530 Subject: [PATCH 04/14] Added unit tests for pipeline --- pom.xml | 43 ++++++- .../mathworks/ci/RunMatlabCommandStep.java | 4 +- .../com/mathworks/ci/RunMatlabTestsStep.java | 14 +-- .../ci/RunMatlabCommandStepTest.java | 109 ++++++++++++++++++ .../ci/RunMatlabCommandStepTester.java | 43 +++++++ .../mathworks/ci/RunMatlabTestsStepTest.java | 92 +++++++++++++++ .../ci/RunMatlabTestsStepTester.java | 58 ++++++++++ .../com/mathworks/ci/TestStepExecution.java | 48 ++++++++ .../resources/run_matlab_command_test.bat | 8 ++ src/test/resources/run_matlab_command_test.sh | 6 + 10 files changed, 411 insertions(+), 14 deletions(-) create mode 100644 src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java create mode 100644 src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java create mode 100644 src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java create mode 100644 src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java create mode 100644 src/test/java/com/mathworks/ci/TestStepExecution.java create mode 100644 src/test/resources/run_matlab_command_test.bat create mode 100644 src/test/resources/run_matlab_command_test.sh diff --git a/pom.xml b/pom.xml index 588a2542..ab77cc6d 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 2.7.3 + 2.164.3 8 @@ -52,26 +52,59 @@ http://github.com/jenkinsci/matlab-plugin HEAD - + + + + io.jenkins.tools.bom + bom-2.164.x + 4 + import + pom + + + + org.jenkins-ci.plugins matrix-project - 1.14 + org.jenkins-ci.plugins.workflow workflow-step-api - 2.22 + org.jenkins-ci.plugins.workflow workflow-api - 2.23 + + + + + + org.jenkins-ci.plugins.workflow + workflow-basic-steps + test + + + org.jenkins-ci.plugins.workflow + workflow-cps + test + + + org.jenkins-ci.plugins.workflow + workflow-durable-task-step + test + + + org.jenkins-ci.plugins.workflow + workflow-job + test diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java index 6a82defd..f3215926 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java @@ -21,8 +21,8 @@ public class RunMatlabCommandStep extends Step { private static boolean COPY_SCRATCH_FILE = false; @DataBoundConstructor - public RunMatlabCommandStep(String command) { - this.matlabCommand = command; + public RunMatlabCommandStep(String matlabCommand) { + this.matlabCommand = matlabCommand; } diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java index e03f5a05..7d77d1dd 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -28,12 +28,12 @@ public class RunMatlabTestsStep extends Step { private String codeCoverageCobertura; private String testResultsSimulinkTest; private String modelCoverageCobertura; - private static final String PDF_REPORT_PATH = "'PDFReportPath'"; - private static final String TAP_RESULTS_PATH = "'TAPResultsPath'"; - private static final String JUNIT_RESULTS_PATH = "'JUnitResultsPath'"; - private static final String COBERTURA_CODE_COVERAGE_PATH = "'CoberturaCodeCoveragePath'"; - private static final String STM_RESULTS_PATH = "'SimulinkTestResultsPath'"; - private static final String COBERTURA_MODEL_COVERAGE_PATH = "'CoberturaModelCoveragePath'"; + private static final String PDF_REPORT_PATH = "PDFReportPath"; + private static final String TAP_RESULTS_PATH = "TAPResultsPath"; + private static final String JUNIT_RESULTS_PATH = "JUnitResultsPath"; + private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath"; + private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath"; + private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath"; private static boolean COPY_SCRATCH_FILE = true; @DataBoundConstructor @@ -146,7 +146,7 @@ private String getInputArgs() { private void addInputArgs(String reportName, String reportPath, List inputArgs) { if (reportPath != null) { - inputArgs.add(reportName + "," + "'" + reportPath + "'"); + inputArgs.add("'" + reportName + "'" + "," + "'" + reportPath + "'"); } } } diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java new file mode 100644 index 00000000..41736333 --- /dev/null +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -0,0 +1,109 @@ +package com.mathworks.ci; + +import java.io.IOException; +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.jenkinsci.plugins.workflow.job.WorkflowRun; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; +import hudson.FilePath; +import hudson.slaves.DumbSlave; + +public class RunMatlabCommandStepTest { + + + private WorkflowJob project; + + + + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Before + public void testSetup() throws IOException { + this.project = j.createProject(WorkflowJob.class); + } + + + /* + * Verify when MATLAB is not in PATH variable. + */ + + @Test + public void verifyMATLABPathNotSet() throws Exception { + project.setDefinition( + new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" + + "runMATLABCommand(matlabCommand: 'pwd')}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("MATLAB_ROOT", build); + } + + /* + * Verify MATLAB is invoked when valid MATLAB is in PATH. + * + */ + + @Test + public void verifyMATLABPathSet() throws Exception { + project.setDefinition( + new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" + + "testMATLABCommand(matlabCommand: 'pwd')}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("tester_started", build); + } + + /* + * Verify Pipeline script runs on Slave with valid MATLAB + * + */ + + @Test + public void verifyPipelineOnSlave() throws Exception { + DumbSlave s = j.createOnlineSlave(); + project.setDefinition(new CpsFlowDefinition( + "node('!master') { writeFile text: 'worksapce', file: 'test.txt'\n" + + "testMATLABCommand(matlabCommand: 'pwd')}", + true)); + + s.getWorkspaceFor(project); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("tester_started", build); + } + + /* + * Verify appropriate command is invoked as in pipeline script + * + */ + + @Test + public void verifyCommandSamAsScript() throws Exception { + DumbSlave s = j.createOnlineSlave(); + project.setDefinition( + new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" + + "runMATLABCommand(matlabCommand: 'pwd')}", true)); + + s.getWorkspaceFor(project); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("pwd", build); + } + + /* + * Verify script can run Matrix build + * + */ + + @Test + public void verifyMatrixBuild() throws Exception { + project.setDefinition( + new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" + + "matrix {\n" + "agent any\n" + "axes {\n" + "axis {\n" + "name: 'CMD'\n" + + "values: 'pwd','ver'\n }}\n" + + "runMATLABCommand(matlabCommand: '${CMD}')}}", true)); + + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("pwd", build); + j.assertLogContains("ver", build); + } +} diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java new file mode 100644 index 00000000..dffe4ec6 --- /dev/null +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java @@ -0,0 +1,43 @@ +package com.mathworks.ci; + +import java.util.Set; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; +import org.jenkinsci.plugins.workflow.steps.StepExecution; +import org.kohsuke.stapler.DataBoundConstructor; +import com.google.common.collect.ImmutableSet; +import hudson.EnvVars; +import hudson.Extension; +import hudson.FilePath; +import hudson.Launcher; +import hudson.model.Run; +import hudson.model.TaskListener; + +public class RunMatlabCommandStepTester extends RunMatlabCommandStep { + @DataBoundConstructor + public RunMatlabCommandStepTester(String matlabCommand) { + super(matlabCommand); + } + + @Override + public StepExecution start(StepContext context) throws Exception { + + return new TestStepExecution(context,this.getMatlabCommand(), false); + } + + @Extension + public static class CommandStepTestDescriptor extends StepDescriptor { + + @Override + public Set> getRequiredContext() { + return ImmutableSet.of(TaskListener.class, FilePath.class, Launcher.class, + EnvVars.class, Run.class); + } + + @Override + public String getFunctionName() { + return "testMATLABCommand"; + } + } + +} diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java new file mode 100644 index 00000000..f2666406 --- /dev/null +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -0,0 +1,92 @@ +package com.mathworks.ci; + +import java.io.IOException; +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.jenkinsci.plugins.workflow.job.WorkflowRun; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; +import hudson.slaves.DumbSlave; + +public class RunMatlabTestsStepTest { + + private WorkflowJob project; + + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Before + public void testSetup() throws IOException { + this.project = j.createProject(WorkflowJob.class); + } + + + /* + * Verify when MATLAB Path is not set + */ + @Test + public void verifyMATLABPathNotSet() throws Exception { + project.setDefinition(new CpsFlowDefinition( + "node {runMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("MATLAB_ROOT", build); + } + + + /* + * VErify when MATLAB PATH is set. + */ + + @Test + public void verifyMATLABPathSet() throws Exception { + project.setDefinition(new CpsFlowDefinition( + "node {testMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("tester_started", build); + } + + /* + * Verify Pipeline runs on slave node + */ + + @Test + public void verifyOnslave() throws Exception { + DumbSlave s = j.createOnlineSlave(); + project.setDefinition(new CpsFlowDefinition( + "node('!master') {testMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + s.getWorkspaceFor(project); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("tester_started", build); + } + + /* + * Verify artifact path is correct. + */ + + @Test + public void verifyArtifactPath() throws Exception { + project.setDefinition(new CpsFlowDefinition( + "node {runMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("'PDFReportPath','myresult/result.pdf'", build); + } + + /* + * Verify Artifact is not sent as parameter if not selected in script. + */ + + @Test + public void verifyArtifactParameters() throws Exception { + project.setDefinition(new CpsFlowDefinition( + "node {runMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("'PDFReportPath','myresult/result.pdf'", build); + j.assertLogNotContains("TAPResultsPath", build); + j.assertLogNotContains("JUnitResultsPath", build); + j.assertLogNotContains("CoberturaCodeCoveragePath", build); + j.assertLogNotContains("SimulinkTestResultsPath", build); + j.assertLogNotContains("CoberturaModelCoveragePath", build); + } +} diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java new file mode 100644 index 00000000..9fe93dfb --- /dev/null +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java @@ -0,0 +1,58 @@ +package com.mathworks.ci; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import org.jenkinsci.plugins.workflow.steps.StepDescriptor; +import org.jenkinsci.plugins.workflow.steps.StepExecution; +import org.kohsuke.stapler.DataBoundConstructor; +import com.google.common.collect.ImmutableSet; +import com.kenai.jffi.Array; +import hudson.EnvVars; +import hudson.Extension; +import hudson.FilePath; +import hudson.Launcher; +import hudson.model.Run; +import hudson.model.TaskListener; + +public class RunMatlabTestsStepTester extends RunMatlabTestsStep { + + + @DataBoundConstructor + public RunMatlabTestsStepTester() { + + } + + @Override + public StepExecution start(StepContext context) throws Exception { + + return new TestStepExecution(context,constructCommandForTest(getInputArgs()), true); + } + + @Extension + public static class CommandStepTestDescriptor extends StepDescriptor { + + @Override + public Set> getRequiredContext() { + return ImmutableSet.of(TaskListener.class, FilePath.class, Launcher.class, + EnvVars.class, Run.class); + } + + @Override + public String getFunctionName() { + return "testMATLABTests"; + } + } + + public String getInputArgs() { + List args = Arrays.asList(getTestResultsPdf(), getTestResultsTAP(), + getTestResultsJUnit(), getTestResultsSimulinkTest(), getCodeCoverageCobertura(), + getModelCoverageCobertura()); + + return String.join(",", args); + } + +} diff --git a/src/test/java/com/mathworks/ci/TestStepExecution.java b/src/test/java/com/mathworks/ci/TestStepExecution.java new file mode 100644 index 00000000..16167b1c --- /dev/null +++ b/src/test/java/com/mathworks/ci/TestStepExecution.java @@ -0,0 +1,48 @@ +package com.mathworks.ci; + +import java.io.IOException; +import org.jenkinsci.plugins.workflow.steps.StepContext; +import hudson.EnvVars; +import hudson.FilePath; +import hudson.Launcher; +import hudson.Launcher.ProcStarter; +import hudson.model.TaskListener; + +public class TestStepExecution extends MatlabStepExecution{ + + public TestStepExecution(StepContext context, String command, boolean copyScratchFile) { + super(context, command, copyScratchFile); + + } + + @Override + public ProcStarter getProcessToRunMatlabCommand(FilePath workspace, Launcher launcher, + TaskListener listener, EnvVars envVars, String matlabCommand, String uniqueName) + throws IOException, InterruptedException { + // Get node specific tmp directory to copy matlab runner script + String tmpDir = getNodeSpecificTmpFolderPath(workspace); + FilePath targetWorkspace = new FilePath(launcher.getChannel(), tmpDir); + ProcStarter matlabLauncher; + if (launcher.isUnix()) { + final String runnerScriptName = uniqueName + "/run_matlab_command_test.sh"; + matlabLauncher = launcher.launch().pwd(workspace).envs(envVars) + .cmds(tmpDir + "/" + runnerScriptName, matlabCommand).stdout(listener); + + // Copy runner .sh for linux platform in workspace. + copyFileInWorkspace("run_matlab_command_test.sh", runnerScriptName, + targetWorkspace); + } else { + final String runnerScriptName = uniqueName + "\\run_matlab_command_test.bat"; + launcher = launcher.decorateByPrefix("cmd.exe", "/C"); + matlabLauncher = launcher.launch().pwd(workspace).envs(envVars) + .cmds(tmpDir + "\\" + runnerScriptName, "\"" + matlabCommand + "\"") + .stdout(listener); + // Copy runner.bat for Windows platform in workspace. + copyFileInWorkspace("run_matlab_command_test.bat", runnerScriptName, + targetWorkspace); + } + return matlabLauncher; + } + + +} diff --git a/src/test/resources/run_matlab_command_test.bat b/src/test/resources/run_matlab_command_test.bat new file mode 100644 index 00000000..24448500 --- /dev/null +++ b/src/test/resources/run_matlab_command_test.bat @@ -0,0 +1,8 @@ +rem Copyright 2018 The MathWorks, Inc. + +echo off + +set "arg1=%~1" + + +echo "%arg1%" diff --git a/src/test/resources/run_matlab_command_test.sh b/src/test/resources/run_matlab_command_test.sh new file mode 100644 index 00000000..749a2345 --- /dev/null +++ b/src/test/resources/run_matlab_command_test.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +#Copyright 2018 The MathWorks, Inc. + +echo "tester_started" +echo $1 From c8372859069cff400ad1331b1ca9cd0bd9f283ed Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 20 May 2020 16:44:29 +0530 Subject: [PATCH 05/14] Tests modified and copyright added. --- .../com/mathworks/ci/MatlabStepExecution.java | 5 ++ .../mathworks/ci/RunMatlabCommandStep.java | 5 ++ .../com/mathworks/ci/RunMatlabTestsStep.java | 49 +++++++++++-------- .../ci/RunMatlabCommandStepTest.java | 4 ++ .../ci/RunMatlabCommandStepTester.java | 5 ++ .../mathworks/ci/RunMatlabTestsStepTest.java | 23 +++++++++ .../ci/RunMatlabTestsStepTester.java | 5 ++ .../com/mathworks/ci/TestStepExecution.java | 18 +++---- .../resources/run_matlab_command_test.bat | 2 +- src/test/resources/run_matlab_command_test.sh | 2 +- 10 files changed, 87 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/mathworks/ci/MatlabStepExecution.java b/src/main/java/com/mathworks/ci/MatlabStepExecution.java index 9536e478..9a21d394 100644 --- a/src/main/java/com/mathworks/ci/MatlabStepExecution.java +++ b/src/main/java/com/mathworks/ci/MatlabStepExecution.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ + import java.io.IOException; import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jenkinsci.plugins.workflow.steps.StepExecution; diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java index f3215926..69b771c3 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ + import java.util.Set; import org.jenkinsci.plugins.workflow.steps.Step; import org.jenkinsci.plugins.workflow.steps.StepContext; diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java index 7d77d1dd..a34c0b1e 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -1,8 +1,14 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ + import java.util.ArrayList; -import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.commons.io.FilenameUtils; import org.jenkinsci.plugins.workflow.steps.Step; @@ -12,7 +18,6 @@ import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import com.google.common.collect.ImmutableSet; -import com.mathworks.ci.RunMatlabTestsBuilder.PdfArtifact; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -127,26 +132,30 @@ public String constructCommandForTest(String inputArguments) { private String getInputArgs() { - List inputArgs = new ArrayList<>(); - addInputArgs(PDF_REPORT_PATH, getTestResultsPdf(),inputArgs); - addInputArgs(TAP_RESULTS_PATH, getTestResultsTAP(), inputArgs); - addInputArgs(JUNIT_RESULTS_PATH, getTestResultsJUnit(), inputArgs); - addInputArgs(STM_RESULTS_PATH, getTestResultsSimulinkTest(), inputArgs); - addInputArgs(COBERTURA_CODE_COVERAGE_PATH, - getCodeCoverageCobertura(), inputArgs); - addInputArgs(COBERTURA_MODEL_COVERAGE_PATH, - getModelCoverageCobertura(), inputArgs); - + final List inputArgs = new ArrayList<>(); + final Map args = getMatlabArgs(); + + args.forEach((key, val) -> { + if (val != null) { + inputArgs.add("'" + key + "'" + "," + "'" + val + "'"); + } + }); + if (inputArgs.isEmpty()) { - return ""; - } - - return String.join(",", inputArgs); + return ""; + } + + return String.join(",", inputArgs); } - private void addInputArgs(String reportName, String reportPath, List inputArgs) { - if (reportPath != null) { - inputArgs.add("'" + reportName + "'" + "," + "'" + reportPath + "'"); - } + private Map getMatlabArgs() { + final Map args = new HashMap(); + args.put(PDF_REPORT_PATH, getTestResultsPdf()); + args.put(TAP_RESULTS_PATH, getTestResultsTAP()); + args.put(JUNIT_RESULTS_PATH, getTestResultsJUnit()); + args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest()); + args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura()); + args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura()); + return args; } } diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java index 41736333..81d1dbd2 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -1,4 +1,8 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ import java.io.IOException; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java index dffe4ec6..a08c978b 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ + import java.util.Set; import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jenkinsci.plugins.workflow.steps.StepDescriptor; diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java index f2666406..9f98e19f 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ + import java.io.IOException; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; @@ -89,4 +94,22 @@ public void verifyArtifactParameters() throws Exception { j.assertLogNotContains("SimulinkTestResultsPath", build); j.assertLogNotContains("CoberturaModelCoveragePath", build); } + + /* + * Verify runMatlabTests runs with empty parameters when nothing no artifact selected + */ + + @Test + public void verifyEmptyParameter() throws Exception { + project.setDefinition(new CpsFlowDefinition( + "node {runMATLABTests()}", true)); + WorkflowRun build = project.scheduleBuild2(0).get(); + j.assertLogContains("runMatlabTests()", build); + j.assertLogNotContains("PDFReportPath", build); + j.assertLogNotContains("TAPResultsPath", build); + j.assertLogNotContains("JUnitResultsPath", build); + j.assertLogNotContains("CoberturaCodeCoveragePath", build); + j.assertLogNotContains("SimulinkTestResultsPath", build); + j.assertLogNotContains("CoberturaModelCoveragePath", build); + } } diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java index 9fe93dfb..7ef0d7cd 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java @@ -1,5 +1,10 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; diff --git a/src/test/java/com/mathworks/ci/TestStepExecution.java b/src/test/java/com/mathworks/ci/TestStepExecution.java index 16167b1c..415db3ef 100644 --- a/src/test/java/com/mathworks/ci/TestStepExecution.java +++ b/src/test/java/com/mathworks/ci/TestStepExecution.java @@ -1,4 +1,8 @@ package com.mathworks.ci; +/** + * Copyright 2019-2020 The MathWorks, Inc. + * + */ import java.io.IOException; import org.jenkinsci.plugins.workflow.steps.StepContext; @@ -8,13 +12,13 @@ import hudson.Launcher.ProcStarter; import hudson.model.TaskListener; -public class TestStepExecution extends MatlabStepExecution{ +public class TestStepExecution extends MatlabStepExecution { public TestStepExecution(StepContext context, String command, boolean copyScratchFile) { super(context, command, copyScratchFile); - + } - + @Override public ProcStarter getProcessToRunMatlabCommand(FilePath workspace, Launcher launcher, TaskListener listener, EnvVars envVars, String matlabCommand, String uniqueName) @@ -29,8 +33,7 @@ public ProcStarter getProcessToRunMatlabCommand(FilePath workspace, Launcher lau .cmds(tmpDir + "/" + runnerScriptName, matlabCommand).stdout(listener); // Copy runner .sh for linux platform in workspace. - copyFileInWorkspace("run_matlab_command_test.sh", runnerScriptName, - targetWorkspace); + copyFileInWorkspace("run_matlab_command_test.sh", runnerScriptName, targetWorkspace); } else { final String runnerScriptName = uniqueName + "\\run_matlab_command_test.bat"; launcher = launcher.decorateByPrefix("cmd.exe", "/C"); @@ -38,11 +41,8 @@ public ProcStarter getProcessToRunMatlabCommand(FilePath workspace, Launcher lau .cmds(tmpDir + "\\" + runnerScriptName, "\"" + matlabCommand + "\"") .stdout(listener); // Copy runner.bat for Windows platform in workspace. - copyFileInWorkspace("run_matlab_command_test.bat", runnerScriptName, - targetWorkspace); + copyFileInWorkspace("run_matlab_command_test.bat", runnerScriptName, targetWorkspace); } return matlabLauncher; } - - } diff --git a/src/test/resources/run_matlab_command_test.bat b/src/test/resources/run_matlab_command_test.bat index 24448500..d0100a33 100644 --- a/src/test/resources/run_matlab_command_test.bat +++ b/src/test/resources/run_matlab_command_test.bat @@ -1,4 +1,4 @@ -rem Copyright 2018 The MathWorks, Inc. +rem Copyright 2020 The MathWorks, Inc. echo off diff --git a/src/test/resources/run_matlab_command_test.sh b/src/test/resources/run_matlab_command_test.sh index 749a2345..1d0ddcaa 100644 --- a/src/test/resources/run_matlab_command_test.sh +++ b/src/test/resources/run_matlab_command_test.sh @@ -1,6 +1,6 @@ #!/bin/bash -#Copyright 2018 The MathWorks, Inc. +#Copyright 2020 The MathWorks, Inc. echo "tester_started" echo $1 From cb001d8bfdd4f9782c9183d4394a669eafb7d962 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 20 May 2020 17:13:30 +0530 Subject: [PATCH 06/14] Updated pom with compatibility tag. --- pom.xml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index ab77cc6d..94bbc6ae 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ 2.164.3 8 + 3.0.0 MATLAB Plugin @@ -64,26 +65,23 @@ - - - - org.jenkins-ci.plugins - matrix-project - - + + + + + org.jenkins-ci.plugins + matrix-project + - org.jenkins-ci.plugins.workflow workflow-step-api - - org.jenkins-ci.plugins.workflow workflow-api - + From d5d816491f8b1435f0ba552c77d3b170532dc923 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 21 May 2020 12:04:54 +0530 Subject: [PATCH 07/14] Fixed test failure --- .../java/com/mathworks/ci/RunMatlabCommandStepTest.java | 7 +++---- src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java | 2 +- src/test/resources/run_matlab_command_test.bat | 3 +-- src/test/resources/run_matlab_command_test.sh | 0 4 files changed, 5 insertions(+), 7 deletions(-) mode change 100644 => 100755 src/test/resources/run_matlab_command_test.bat mode change 100644 => 100755 src/test/resources/run_matlab_command_test.sh diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java index 81d1dbd2..f3881e8e 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -73,7 +73,8 @@ public void verifyPipelineOnSlave() throws Exception { s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); - j.assertLogContains("tester_started", build); + + j.assertBuildStatusSuccess(build); } /* @@ -82,13 +83,11 @@ public void verifyPipelineOnSlave() throws Exception { */ @Test - public void verifyCommandSamAsScript() throws Exception { - DumbSlave s = j.createOnlineSlave(); + public void verifyCommandSameAsScript() throws Exception { project.setDefinition( new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" + "runMATLABCommand(matlabCommand: 'pwd')}", true)); - s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("pwd", build); } diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java index 9f98e19f..110b5fce 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -63,7 +63,7 @@ public void verifyOnslave() throws Exception { "node('!master') {testMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); - j.assertLogContains("tester_started", build); + j.assertBuildStatusSuccess(build); } /* diff --git a/src/test/resources/run_matlab_command_test.bat b/src/test/resources/run_matlab_command_test.bat old mode 100644 new mode 100755 index d0100a33..f17d2e8a --- a/src/test/resources/run_matlab_command_test.bat +++ b/src/test/resources/run_matlab_command_test.bat @@ -1,8 +1,7 @@ rem Copyright 2020 The MathWorks, Inc. -echo off +echo "tester_started" set "arg1=%~1" - echo "%arg1%" diff --git a/src/test/resources/run_matlab_command_test.sh b/src/test/resources/run_matlab_command_test.sh old mode 100644 new mode 100755 From 5b284babdae5db739dd7b1b4191128f5d123a39f Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 21 May 2020 17:53:47 +0530 Subject: [PATCH 08/14] Updated review comments --- pom.xml | 22 +++---- .../com/mathworks/ci/MatlabStepExecution.java | 29 ++-------- .../mathworks/ci/RunMatlabCommandStep.java | 19 +++---- .../com/mathworks/ci/RunMatlabTestsStep.java | 57 ++++++++++++++----- .../ci/RunMatlabCommandStep/config.jelly | 2 +- .../ci/RunMatlabTestsStep/config.jelly | 12 ++-- .../ci/RunMatlabCommandStepTest.java | 12 ++-- .../ci/RunMatlabCommandStepTester.java | 8 +-- .../mathworks/ci/RunMatlabTestsStepTest.java | 12 ++-- .../ci/RunMatlabTestsStepTester.java | 25 +++++++- .../com/mathworks/ci/TestStepExecution.java | 6 +- 11 files changed, 114 insertions(+), 90 deletions(-) diff --git a/pom.xml b/pom.xml index 94bbc6ae..98b0fe83 100644 --- a/pom.xml +++ b/pom.xml @@ -53,17 +53,17 @@ http://github.com/jenkinsci/matlab-plugin HEAD - - - - io.jenkins.tools.bom - bom-2.164.x - 4 - import - pom - - - + + + + io.jenkins.tools.bom + bom-2.164.x + 4 + import + pom + + + diff --git a/src/main/java/com/mathworks/ci/MatlabStepExecution.java b/src/main/java/com/mathworks/ci/MatlabStepExecution.java index 9a21d394..cfede100 100644 --- a/src/main/java/com/mathworks/ci/MatlabStepExecution.java +++ b/src/main/java/com/mathworks/ci/MatlabStepExecution.java @@ -18,41 +18,26 @@ public class MatlabStepExecution extends StepExecution implements MatlabBuild { private static final long serialVersionUID = 1L; private String command; - private EnvVars env; - private boolean copyScratchFile; - public MatlabStepExecution(StepContext context, String command, boolean copyScratchFile) { + public MatlabStepExecution(StepContext context, String command) { super(context); this.command = command; - this.copyScratchFile = copyScratchFile; } private String getCommand() { - return this.env == null ? getMatlabCommand() : this.env.expand(getMatlabCommand()); - } - - private String getMatlabCommand() { return this.command; } - private void setEnv(EnvVars env) { - this.env = env; - } - - private EnvVars getEnv() { - return this.env; - } - @Override public boolean start() throws Exception { Launcher launcher = getContext().get(Launcher.class); FilePath workspace = getContext().get(FilePath.class); TaskListener listener = getContext().get(TaskListener.class); EnvVars env = getContext().get(EnvVars.class); - setEnv(env); + - int res = execMatlabCommand(workspace, launcher, listener, getEnv()); + int res = execMatlabCommand(workspace, launcher, listener, env); if (res == 0) { getContext().setResult(Result.SUCCESS); } else { @@ -75,14 +60,8 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher ProcStarter matlabLauncher; try { matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars, - getCommand(), uniqueTmpFldrName); + envVars.expand(getCommand()), uniqueTmpFldrName); - // Copy MATLAB scratch file into the workspace if required. - if(this.copyScratchFile) { - FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote()); - copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE, - MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace); - } return matlabLauncher.join(); } catch (Exception e) { diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java index 69b771c3..b7486852 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java @@ -1,7 +1,7 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ @@ -22,22 +22,21 @@ public class RunMatlabCommandStep extends Step { private EnvVars env; - private String matlabCommand; - private static boolean COPY_SCRATCH_FILE = false; + private String command; @DataBoundConstructor - public RunMatlabCommandStep(String matlabCommand) { - this.matlabCommand = matlabCommand; + public RunMatlabCommandStep(String command) { + this.command = command; } - public String getMatlabCommand() { - return this.matlabCommand; + public String getCommand() { + return this.command; } - private String getCommand() { - return this.env == null ? getMatlabCommand() : this.env.expand(getMatlabCommand()); + private String getMatlabCommand() { + return this.env == null ? getCommand() : this.env.expand(getCommand()); } public void setEnv(EnvVars env) { @@ -50,7 +49,7 @@ public EnvVars getEnv() { @Override public StepExecution start(StepContext context) throws Exception { - return new MatlabStepExecution(context, getCommand(), COPY_SCRATCH_FILE); + return new MatlabStepExecution(context, getMatlabCommand()); } @Extension diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java index a34c0b1e..a9a835bd 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -1,7 +1,10 @@ package com.mathworks.ci; +import java.io.IOException; +import java.io.InputStream; + /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ @@ -27,7 +30,7 @@ public class RunMatlabTestsStep extends Step { - private String testResultsPdf; + private String testResultsPDF; private String testResultsTAP; private String testResultsJUnit; private String codeCoverageCobertura; @@ -39,7 +42,6 @@ public class RunMatlabTestsStep extends Step { private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath"; private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath"; private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath"; - private static boolean COPY_SCRATCH_FILE = true; @DataBoundConstructor public RunMatlabTestsStep() { @@ -55,13 +57,13 @@ public void setTestResultsTAP(String testResultsTAP) { this.testResultsTAP = testResultsTAP; } - public String getTestResultsPdf() { - return testResultsPdf; + public String getTestResultsPDF() { + return testResultsPDF; } @DataBoundSetter - public void setTestResultsPdf(String testResultsPdf) { - this.testResultsPdf = testResultsPdf; + public void setTestResultsPDF(String testResultsPDF) { + this.testResultsPDF = testResultsPDF; } public String getTestResultsJUnit() { @@ -104,8 +106,14 @@ public void setModelCoverageCobertura(String modelCoverageCobertura) { @Override public StepExecution start(StepContext context) throws Exception { - - return new MatlabStepExecution(context,constructCommandForTest(getInputArgs()), COPY_SCRATCH_FILE); + Launcher launcher = context.get(Launcher.class); + FilePath workspace = context.get(FilePath.class); + + //Copy Scratch file needed to run MATLAB tests in workspace + FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote()); + copyScratchFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE, + MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace); + return new MatlabStepExecution(context,constructCommandForTest(getInputArgs())); } @Extension @@ -150,12 +158,31 @@ private String getInputArgs() { private Map getMatlabArgs() { final Map args = new HashMap(); - args.put(PDF_REPORT_PATH, getTestResultsPdf()); - args.put(TAP_RESULTS_PATH, getTestResultsTAP()); - args.put(JUNIT_RESULTS_PATH, getTestResultsJUnit()); - args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest()); - args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura()); - args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura()); + args.put(PDF_REPORT_PATH, + getTestResultsPDF() == null ? null : getTestResultsPDF().replaceAll("'", "''")); + args.put(TAP_RESULTS_PATH, + getTestResultsTAP() == null ? null : getTestResultsTAP().replaceAll("'", "''")); + args.put(JUNIT_RESULTS_PATH, + getTestResultsJUnit() == null ? null : getTestResultsJUnit().replaceAll("'", "''")); + args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest() == null ? null + : getTestResultsSimulinkTest().replaceAll("'", "''")); + args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura() == null ? null + : getCodeCoverageCobertura().replaceAll("'", "''")); + args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura() == null ? null + : getModelCoverageCobertura().replaceAll("'", "''")); return args; } + + /* + * Method to copy given file from source to target node specific workspace. + */ + private void copyScratchFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace) + throws IOException, InterruptedException { + final ClassLoader classLoader = getClass().getClassLoader(); + FilePath targetFilePath = new FilePath(targetWorkspace, targetFile); + InputStream in = classLoader.getResourceAsStream(sourceFile); + targetFilePath.copyFrom(in); + // set executable permission + targetFilePath.chmod(0755); + } } diff --git a/src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly b/src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly index 9a0804f9..28414b78 100644 --- a/src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly +++ b/src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly @@ -1,7 +1,7 @@ - + diff --git a/src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly b/src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly index b67dd357..564268fd 100644 --- a/src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly +++ b/src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly @@ -1,27 +1,27 @@ - + - + - + - + - + - + diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java index f3881e8e..3fbf379c 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -1,6 +1,6 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ @@ -39,7 +39,7 @@ public void testSetup() throws IOException { public void verifyMATLABPathNotSet() throws Exception { project.setDefinition( new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" - + "runMATLABCommand(matlabCommand: 'pwd')}", true)); + + "runMATLABCommand(command: 'pwd')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("MATLAB_ROOT", build); } @@ -53,7 +53,7 @@ public void verifyMATLABPathNotSet() throws Exception { public void verifyMATLABPathSet() throws Exception { project.setDefinition( new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" - + "testMATLABCommand(matlabCommand: 'pwd')}", true)); + + "testMATLABCommand(command: 'pwd')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("tester_started", build); } @@ -68,7 +68,7 @@ public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition(new CpsFlowDefinition( "node('!master') { writeFile text: 'worksapce', file: 'test.txt'\n" - + "testMATLABCommand(matlabCommand: 'pwd')}", + + "testMATLABCommand(command: 'pwd')}", true)); s.getWorkspaceFor(project); @@ -86,7 +86,7 @@ public void verifyPipelineOnSlave() throws Exception { public void verifyCommandSameAsScript() throws Exception { project.setDefinition( new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" - + "runMATLABCommand(matlabCommand: 'pwd')}", true)); + + "runMATLABCommand(command: 'pwd')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("pwd", build); @@ -103,7 +103,7 @@ public void verifyMatrixBuild() throws Exception { new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" + "matrix {\n" + "agent any\n" + "axes {\n" + "axis {\n" + "name: 'CMD'\n" + "values: 'pwd','ver'\n }}\n" - + "runMATLABCommand(matlabCommand: '${CMD}')}}", true)); + + "runMATLABCommand(command: '${CMD}')}}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("pwd", build); diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java index a08c978b..ed51a0ae 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTester.java @@ -1,7 +1,7 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ @@ -20,14 +20,14 @@ public class RunMatlabCommandStepTester extends RunMatlabCommandStep { @DataBoundConstructor - public RunMatlabCommandStepTester(String matlabCommand) { - super(matlabCommand); + public RunMatlabCommandStepTester(String command) { + super(command); } @Override public StepExecution start(StepContext context) throws Exception { - return new TestStepExecution(context,this.getMatlabCommand(), false); + return new TestStepExecution(context,this.getCommand()); } @Extension diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java index 110b5fce..6501ea2f 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTest.java @@ -1,7 +1,7 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ @@ -34,7 +34,7 @@ public void testSetup() throws IOException { @Test public void verifyMATLABPathNotSet() throws Exception { project.setDefinition(new CpsFlowDefinition( - "node {runMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + "node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("MATLAB_ROOT", build); } @@ -47,7 +47,7 @@ public void verifyMATLABPathNotSet() throws Exception { @Test public void verifyMATLABPathSet() throws Exception { project.setDefinition(new CpsFlowDefinition( - "node {testMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + "node {testMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("tester_started", build); } @@ -60,7 +60,7 @@ public void verifyMATLABPathSet() throws Exception { public void verifyOnslave() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition(new CpsFlowDefinition( - "node('!master') {testMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + "node('!master') {testMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); s.getWorkspaceFor(project); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertBuildStatusSuccess(build); @@ -73,7 +73,7 @@ public void verifyOnslave() throws Exception { @Test public void verifyArtifactPath() throws Exception { project.setDefinition(new CpsFlowDefinition( - "node {runMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + "node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("'PDFReportPath','myresult/result.pdf'", build); } @@ -85,7 +85,7 @@ public void verifyArtifactPath() throws Exception { @Test public void verifyArtifactParameters() throws Exception { project.setDefinition(new CpsFlowDefinition( - "node {runMATLABTests(testResultsPdf:'myresult/result.pdf')}", true)); + "node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("'PDFReportPath','myresult/result.pdf'", build); j.assertLogNotContains("TAPResultsPath", build); diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java index 7ef0d7cd..11c02596 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java @@ -1,7 +1,10 @@ package com.mathworks.ci; +import java.io.IOException; +import java.io.InputStream; + /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ @@ -33,8 +36,14 @@ public RunMatlabTestsStepTester() { @Override public StepExecution start(StepContext context) throws Exception { + Launcher launcher = context.get(Launcher.class); + FilePath workspace = context.get(FilePath.class); - return new TestStepExecution(context,constructCommandForTest(getInputArgs()), true); + //Copy Scratch file needed to run MATLAB tests in workspace + FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote()); + copyScratchFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE, + MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace); + return new TestStepExecution(context,constructCommandForTest(getInputArgs())); } @Extension @@ -53,11 +62,21 @@ public String getFunctionName() { } public String getInputArgs() { - List args = Arrays.asList(getTestResultsPdf(), getTestResultsTAP(), + List args = Arrays.asList(getTestResultsPDF(), getTestResultsTAP(), getTestResultsJUnit(), getTestResultsSimulinkTest(), getCodeCoverageCobertura(), getModelCoverageCobertura()); return String.join(",", args); } + + private void copyScratchFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace) + throws IOException, InterruptedException { + final ClassLoader classLoader = getClass().getClassLoader(); + FilePath targetFilePath = new FilePath(targetWorkspace, targetFile); + InputStream in = classLoader.getResourceAsStream(sourceFile); + targetFilePath.copyFrom(in); + // set executable permission + targetFilePath.chmod(0755); + } } diff --git a/src/test/java/com/mathworks/ci/TestStepExecution.java b/src/test/java/com/mathworks/ci/TestStepExecution.java index 415db3ef..aa840f6c 100644 --- a/src/test/java/com/mathworks/ci/TestStepExecution.java +++ b/src/test/java/com/mathworks/ci/TestStepExecution.java @@ -1,6 +1,6 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ @@ -14,8 +14,8 @@ public class TestStepExecution extends MatlabStepExecution { - public TestStepExecution(StepContext context, String command, boolean copyScratchFile) { - super(context, command, copyScratchFile); + public TestStepExecution(StepContext context, String command) { + super(context, command); } From a03b5a9d469c7cde65497cd6fb3beac0c1454645 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Thu, 21 May 2020 18:22:33 +0530 Subject: [PATCH 09/14] Updated the escape logic for single quotes --- .../com/mathworks/ci/RunMatlabTestsStep.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java index a9a835bd..90bccc99 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -145,7 +145,7 @@ private String getInputArgs() { args.forEach((key, val) -> { if (val != null) { - inputArgs.add("'" + key + "'" + "," + "'" + val + "'"); + inputArgs.add("'" + key + "'" + "," + "'" + val.replaceAll("'", "''") + "'"); } }); @@ -158,18 +158,12 @@ private String getInputArgs() { private Map getMatlabArgs() { final Map args = new HashMap(); - args.put(PDF_REPORT_PATH, - getTestResultsPDF() == null ? null : getTestResultsPDF().replaceAll("'", "''")); - args.put(TAP_RESULTS_PATH, - getTestResultsTAP() == null ? null : getTestResultsTAP().replaceAll("'", "''")); - args.put(JUNIT_RESULTS_PATH, - getTestResultsJUnit() == null ? null : getTestResultsJUnit().replaceAll("'", "''")); - args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest() == null ? null - : getTestResultsSimulinkTest().replaceAll("'", "''")); - args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura() == null ? null - : getCodeCoverageCobertura().replaceAll("'", "''")); - args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura() == null ? null - : getModelCoverageCobertura().replaceAll("'", "''")); + args.put(PDF_REPORT_PATH,getTestResultsPDF()); + args.put(TAP_RESULTS_PATH,getTestResultsTAP()); + args.put(JUNIT_RESULTS_PATH,getTestResultsJUnit()); + args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest()); + args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura()); + args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura()); return args; } From 694aff0792d7a1d54f3075e0a585ec7adcb60e8f Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 22 May 2020 10:58:32 +0530 Subject: [PATCH 10/14] Updated Copyright year in the file. --- src/main/java/com/mathworks/ci/MatlabStepExecution.java | 2 +- src/main/java/com/mathworks/ci/RunMatlabTestsStep.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mathworks/ci/MatlabStepExecution.java b/src/main/java/com/mathworks/ci/MatlabStepExecution.java index cfede100..d408b7cd 100644 --- a/src/main/java/com/mathworks/ci/MatlabStepExecution.java +++ b/src/main/java/com/mathworks/ci/MatlabStepExecution.java @@ -1,7 +1,7 @@ package com.mathworks.ci; /** - * Copyright 2019-2020 The MathWorks, Inc. + * Copyright 2020 The MathWorks, Inc. * */ diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java index 90bccc99..354b285a 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -1,5 +1,8 @@ package com.mathworks.ci; - +/** + * Copyright 2020 The MathWorks, Inc. + * + */ import java.io.IOException; import java.io.InputStream; From 2e389e8976664a7a6cbacfa075a91f91559f209c Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Tue, 26 May 2020 17:01:46 +0530 Subject: [PATCH 11/14] Removed version compatibility from pom. --- pom.xml | 1 - .../com/mathworks/ci/RunMatlabCommandStep.java | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 98b0fe83..0787fe2a 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,6 @@ 2.164.3 8 - 3.0.0 MATLAB Plugin diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java index b7486852..1efea39c 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java @@ -35,21 +35,9 @@ public String getCommand() { return this.command; } - private String getMatlabCommand() { - return this.env == null ? getCommand() : this.env.expand(getCommand()); - } - - public void setEnv(EnvVars env) { - this.env = env; - } - - public EnvVars getEnv() { - return this.env; - } - @Override public StepExecution start(StepContext context) throws Exception { - return new MatlabStepExecution(context, getMatlabCommand()); + return new MatlabStepExecution(context, getCommand()); } @Extension From a62b9ccc3bddb07fd3275671be662897a3c92f36 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Wed, 27 May 2020 16:22:57 +0530 Subject: [PATCH 12/14] Updated review comments. --- .../com/mathworks/ci/MatlabStepExecution.java | 28 +++++------ .../mathworks/ci/RunMatlabCommandStep.java | 3 +- .../com/mathworks/ci/RunMatlabTestsStep.java | 21 ++++---- .../ci/RunMatlabTestsStepTester.java | 48 ++++++++----------- 4 files changed, 41 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/mathworks/ci/MatlabStepExecution.java b/src/main/java/com/mathworks/ci/MatlabStepExecution.java index d408b7cd..1c7a31ea 100644 --- a/src/main/java/com/mathworks/ci/MatlabStepExecution.java +++ b/src/main/java/com/mathworks/ci/MatlabStepExecution.java @@ -16,7 +16,9 @@ import hudson.model.TaskListener; public class MatlabStepExecution extends StepExecution implements MatlabBuild { - private static final long serialVersionUID = 1L; + + private static final long serialVersionUID = 6704588180717665100L; + private String command; @@ -31,18 +33,15 @@ private String getCommand() { @Override public boolean start() throws Exception { - Launcher launcher = getContext().get(Launcher.class); - FilePath workspace = getContext().get(FilePath.class); - TaskListener listener = getContext().get(TaskListener.class); - EnvVars env = getContext().get(EnvVars.class); + final Launcher launcher = getContext().get(Launcher.class); + final FilePath workspace = getContext().get(FilePath.class); + final TaskListener listener = getContext().get(TaskListener.class); + final EnvVars env = getContext().get(EnvVars.class); - int res = execMatlabCommand(workspace, launcher, listener, env); - if (res == 0) { - getContext().setResult(Result.SUCCESS); - } else { - getContext().setResult(Result.FAILURE); - } + + getContext().setResult((res == 0) ? Result.SUCCESS : Result.FAILURE); + getContext().onSuccess(true); //return false represents the asynchronous run. @@ -56,10 +55,9 @@ public void stop(Throwable cause) throws Exception { private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher, TaskListener listener, EnvVars envVars) throws IOException, InterruptedException { - final String uniqueTmpFldrName = getUniqueNameForRunnerFile(); - ProcStarter matlabLauncher; + final String uniqueTmpFldrName = getUniqueNameForRunnerFile(); try { - matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars, + ProcStarter matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars, envVars.expand(getCommand()), uniqueTmpFldrName); @@ -69,7 +67,7 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher return 1; } finally { // Cleanup the runner File from tmp directory - FilePath matlabRunnerScript = + final FilePath matlabRunnerScript = getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace); if (matlabRunnerScript.exists()) { matlabRunnerScript.deleteRecursive(); diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java index 1efea39c..3b388185 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandStep.java @@ -21,13 +21,12 @@ public class RunMatlabCommandStep extends Step { - private EnvVars env; + private String command; @DataBoundConstructor public RunMatlabCommandStep(String command) { this.command = command; - } diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java index 354b285a..603b8d9f 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsStep.java @@ -39,12 +39,7 @@ public class RunMatlabTestsStep extends Step { private String codeCoverageCobertura; private String testResultsSimulinkTest; private String modelCoverageCobertura; - private static final String PDF_REPORT_PATH = "PDFReportPath"; - private static final String TAP_RESULTS_PATH = "TAPResultsPath"; - private static final String JUNIT_RESULTS_PATH = "JUnitResultsPath"; - private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath"; - private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath"; - private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath"; + @DataBoundConstructor public RunMatlabTestsStep() { @@ -120,7 +115,7 @@ public StepExecution start(StepContext context) throws Exception { } @Extension - public static class CommandStepDescriptor extends StepDescriptor { + public static class RunTestsStepDescriptor extends StepDescriptor { @Override public Set> getRequiredContext() { @@ -161,12 +156,12 @@ private String getInputArgs() { private Map getMatlabArgs() { final Map args = new HashMap(); - args.put(PDF_REPORT_PATH,getTestResultsPDF()); - args.put(TAP_RESULTS_PATH,getTestResultsTAP()); - args.put(JUNIT_RESULTS_PATH,getTestResultsJUnit()); - args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest()); - args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura()); - args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura()); + args.put("PDFReportPath", getTestResultsPDF()); + args.put("TAPResultsPath", getTestResultsTAP()); + args.put("JUnitResultsPath", getTestResultsJUnit()); + args.put("SimulinkTestResultsPath", getTestResultsSimulinkTest()); + args.put("CoberturaCodeCoveragePath", getCodeCoverageCobertura()); + args.put("CoberturaModelCoveragePath", getModelCoverageCobertura()); return args; } diff --git a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java index 11c02596..60a38311 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java +++ b/src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java @@ -2,15 +2,7 @@ import java.io.IOException; import java.io.InputStream; - -/** - * Copyright 2020 The MathWorks, Inc. - * - */ - -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Set; import org.jenkinsci.plugins.workflow.steps.StepContext; @@ -18,7 +10,6 @@ import org.jenkinsci.plugins.workflow.steps.StepExecution; import org.kohsuke.stapler.DataBoundConstructor; import com.google.common.collect.ImmutableSet; -import com.kenai.jffi.Array; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -27,25 +18,35 @@ import hudson.model.TaskListener; public class RunMatlabTestsStepTester extends RunMatlabTestsStep { - - + + @DataBoundConstructor public RunMatlabTestsStepTester() { - + } - + @Override public StepExecution start(StepContext context) throws Exception { Launcher launcher = context.get(Launcher.class); FilePath workspace = context.get(FilePath.class); - - //Copy Scratch file needed to run MATLAB tests in workspace + + // Copy Scratch file needed to run MATLAB tests in workspace FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote()); copyScratchFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE, MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace); - return new TestStepExecution(context,constructCommandForTest(getInputArgs())); + return new TestStepExecution(context, constructCommandForTest(getInputArgs())); } - + + private void copyScratchFileInWorkspace(String sourceFile, String targetFile, + FilePath targetWorkspace) throws IOException, InterruptedException { + final ClassLoader classLoader = getClass().getClassLoader(); + FilePath targetFilePath = new FilePath(targetWorkspace, targetFile); + InputStream in = classLoader.getResourceAsStream(sourceFile); + targetFilePath.copyFrom(in); + // set executable permission + targetFilePath.chmod(0755); + } + @Extension public static class CommandStepTestDescriptor extends StepDescriptor { @@ -60,7 +61,7 @@ public String getFunctionName() { return "testMATLABTests"; } } - + public String getInputArgs() { List args = Arrays.asList(getTestResultsPDF(), getTestResultsTAP(), getTestResultsJUnit(), getTestResultsSimulinkTest(), getCodeCoverageCobertura(), @@ -68,15 +69,4 @@ public String getInputArgs() { return String.join(",", args); } - - private void copyScratchFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace) - throws IOException, InterruptedException { - final ClassLoader classLoader = getClass().getClassLoader(); - FilePath targetFilePath = new FilePath(targetWorkspace, targetFile); - InputStream in = classLoader.getResourceAsStream(sourceFile); - targetFilePath.copyFrom(in); - // set executable permission - targetFilePath.chmod(0755); - } - } From c0680e396de8dc042201003cd8a89d9b2ea9bfa0 Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 29 May 2020 00:34:02 +0530 Subject: [PATCH 13/14] Verifying if workspace exists for runMATLABCommand step --- .../com/mathworks/ci/MatlabStepExecution.java | 4 ++++ .../ci/RunMatlabCommandStepTest.java | 21 +++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/mathworks/ci/MatlabStepExecution.java b/src/main/java/com/mathworks/ci/MatlabStepExecution.java index 1c7a31ea..dfffe258 100644 --- a/src/main/java/com/mathworks/ci/MatlabStepExecution.java +++ b/src/main/java/com/mathworks/ci/MatlabStepExecution.java @@ -38,6 +38,10 @@ public boolean start() throws Exception { final TaskListener listener = getContext().get(TaskListener.class); final EnvVars env = getContext().get(EnvVars.class); + //Make sure the Workspace exists before run + + workspace.mkdirs(); + int res = execMatlabCommand(workspace, launcher, listener, env); getContext().setResult((res == 0) ? Result.SUCCESS : Result.FAILURE); diff --git a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java index 3fbf379c..36fe579c 100644 --- a/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java +++ b/src/test/java/com/mathworks/ci/RunMatlabCommandStepTest.java @@ -38,8 +38,7 @@ public void testSetup() throws IOException { @Test public void verifyMATLABPathNotSet() throws Exception { project.setDefinition( - new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" - + "runMATLABCommand(command: 'pwd')}", true)); + new CpsFlowDefinition("node { runMATLABCommand(command: 'pwd')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("MATLAB_ROOT", build); } @@ -52,8 +51,7 @@ public void verifyMATLABPathNotSet() throws Exception { @Test public void verifyMATLABPathSet() throws Exception { project.setDefinition( - new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" - + "testMATLABCommand(command: 'pwd')}", true)); + new CpsFlowDefinition("node { testMATLABCommand(command: 'pwd')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("tester_started", build); } @@ -67,8 +65,7 @@ public void verifyMATLABPathSet() throws Exception { public void verifyPipelineOnSlave() throws Exception { DumbSlave s = j.createOnlineSlave(); project.setDefinition(new CpsFlowDefinition( - "node('!master') { writeFile text: 'worksapce', file: 'test.txt'\n" - + "testMATLABCommand(command: 'pwd')}", + "node('!master') { testMATLABCommand(command: 'pwd')}", true)); s.getWorkspaceFor(project); @@ -85,8 +82,7 @@ public void verifyPipelineOnSlave() throws Exception { @Test public void verifyCommandSameAsScript() throws Exception { project.setDefinition( - new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" - + "runMATLABCommand(command: 'pwd')}", true)); + new CpsFlowDefinition("node { runMATLABCommand(command: 'pwd')}", true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("pwd", build); @@ -99,11 +95,10 @@ public void verifyCommandSameAsScript() throws Exception { @Test public void verifyMatrixBuild() throws Exception { - project.setDefinition( - new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n" - + "matrix {\n" + "agent any\n" + "axes {\n" + "axis {\n" + "name: 'CMD'\n" - + "values: 'pwd','ver'\n }}\n" - + "runMATLABCommand(command: '${CMD}')}}", true)); + project.setDefinition(new CpsFlowDefinition( + "node { matrix {\n" + "agent any\n" + "axes {\n" + "axis {\n" + "name: 'CMD'\n" + + "values: 'pwd','ver'\n }}\n" + "runMATLABCommand(command: '${CMD}')}}", + true)); WorkflowRun build = project.scheduleBuild2(0).get(); j.assertLogContains("pwd", build); From d10a5c3e02ea53d36fd57dde5922711af03100fc Mon Sep 17 00:00:00 2001 From: Nikhil Bhoski Date: Fri, 12 Jun 2020 18:26:20 +0530 Subject: [PATCH 14/14] Removed old symbols for pipeline steps. --- src/main/java/com/mathworks/ci/RunMatlabCommandBuilder.java | 2 +- src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java | 2 +- .../java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mathworks/ci/RunMatlabCommandBuilder.java b/src/main/java/com/mathworks/ci/RunMatlabCommandBuilder.java index 9dbcf410..da289bfa 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabCommandBuilder.java +++ b/src/main/java/com/mathworks/ci/RunMatlabCommandBuilder.java @@ -61,7 +61,7 @@ private EnvVars getEnv() { return this.env; } - @Symbol("RunMatlabCommand") + @Extension public static class RunMatlabCommandDescriptor extends BuildStepDescriptor { diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java b/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java index 93840829..3c4a8ee3 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java @@ -185,7 +185,7 @@ protected Object readResolve() { } - @Symbol("RunMatlabTests") + @Extension public static class RunMatlabTestsDescriptor extends BuildStepDescriptor { diff --git a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java index cf6a2eb0..b5a2702d 100644 --- a/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java +++ b/src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java @@ -56,7 +56,7 @@ private void setEnv(EnvVars env) { this.env = env; } - @Symbol("Matlab") + @Extension public static final class UseMatlabVersionDescriptor extends BuildWrapperDescriptor {