Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 0c2a9ba

Browse files
author
Nikhil Bhoski
committed
final changes for both Step execution
1 parent 669a97d commit 0c2a9ba

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

src/main/java/com/mathworks/ci/MatlabCommandStepExecution.java renamed to src/main/java/com/mathworks/ci/MatlabStepExecution.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import hudson.model.Result;
1111
import hudson.model.TaskListener;
1212

13-
public class MatlabCommandStepExecution extends StepExecution implements MatlabBuild {
13+
public class MatlabStepExecution extends StepExecution implements MatlabBuild {
1414
private static final long serialVersionUID = 1L;
1515
private String command;
1616
private EnvVars env;
1717
private boolean copyScratchFile;
1818

1919

20-
public MatlabCommandStepExecution(StepContext context, String command, boolean copyScratchFile) {
20+
public MatlabStepExecution(StepContext context, String command, boolean copyScratchFile) {
2121
super(context);
2222
this.command = command;
2323
this.copyScratchFile = copyScratchFile;
@@ -72,11 +72,13 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
7272
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
7373
getCommand(), uniqueTmpFldrName);
7474

75-
// Copy MATLAB scratch file into the workspace.
76-
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
77-
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
78-
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
79-
75+
// Copy MATLAB scratch file into the workspace if required.
76+
if(this.copyScratchFile) {
77+
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
78+
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
79+
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
80+
}
81+
8082
return matlabLauncher.join();
8183
} catch (Exception e) {
8284
listener.getLogger().println(e.getMessage());

src/main/java/com/mathworks/ci/MatlabTestStepExecution.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/com/mathworks/ci/RunMatlabCommandStep.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class RunMatlabCommandStep extends Step {
1818

1919
private EnvVars env;
2020
private String matlabCommand;
21+
private static boolean COPY_SCRATCH_FILE = false;
2122

2223
@DataBoundConstructor
2324
public RunMatlabCommandStep(String command) {
@@ -44,7 +45,7 @@ public EnvVars getEnv() {
4445

4546
@Override
4647
public StepExecution start(StepContext context) throws Exception {
47-
return new MatlabCommandStepExecution(context, getCommand(), true);
48+
return new MatlabStepExecution(context, getCommand(), COPY_SCRATCH_FILE);
4849
}
4950

5051
@Extension

src/main/java/com/mathworks/ci/RunMatlabTestsStep.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import java.util.Arrays;
55
import java.util.List;
66
import java.util.Set;
7+
import org.apache.commons.io.FilenameUtils;
78
import org.jenkinsci.plugins.workflow.steps.Step;
89
import org.jenkinsci.plugins.workflow.steps.StepContext;
910
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
1011
import org.jenkinsci.plugins.workflow.steps.StepExecution;
1112
import org.kohsuke.stapler.DataBoundConstructor;
1213
import org.kohsuke.stapler.DataBoundSetter;
1314
import com.google.common.collect.ImmutableSet;
15+
import com.mathworks.ci.RunMatlabTestsBuilder.PdfArtifact;
1416
import hudson.EnvVars;
1517
import hudson.Extension;
1618
import hudson.FilePath;
@@ -26,7 +28,14 @@ public class RunMatlabTestsStep extends Step {
2628
private String codeCoverageCobertura;
2729
private String testResultsSimulinkTest;
2830
private String modelCoverageCobertura;
29-
31+
private static final String PDF_REPORT_PATH = "'PDFReportPath'";
32+
private static final String TAP_RESULTS_PATH = "'TAPResultsPath'";
33+
private static final String JUNIT_RESULTS_PATH = "'JUnitResultsPath'";
34+
private static final String COBERTURA_CODE_COVERAGE_PATH = "'CoberturaCodeCoveragePath'";
35+
private static final String STM_RESULTS_PATH = "'SimulinkTestResultsPath'";
36+
private static final String COBERTURA_MODEL_COVERAGE_PATH = "'CoberturaModelCoveragePath'";
37+
private static boolean COPY_SCRATCH_FILE = true;
38+
3039
@DataBoundConstructor
3140
public RunMatlabTestsStep() {
3241

@@ -91,7 +100,7 @@ public void setModelCoverageCobertura(String modelCoverageCobertura) {
91100
@Override
92101
public StepExecution start(StepContext context) throws Exception {
93102

94-
return new MatlabCommandStepExecution(context,getInputArgs(), true);
103+
return new MatlabStepExecution(context,constructCommandForTest(getInputArgs()), COPY_SCRATCH_FILE);
95104
}
96105

97106
@Extension
@@ -109,21 +118,29 @@ public String getFunctionName() {
109118
}
110119
}
111120

121+
public String constructCommandForTest(String inputArguments) {
122+
final String matlabFunctionName =
123+
FilenameUtils.removeExtension(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE);
124+
final String runCommand = "exit(" + matlabFunctionName + "(" + inputArguments + "))";
125+
return runCommand;
126+
}
127+
128+
112129
private String getInputArgs() {
113130
List<String> inputArgs = new ArrayList<>();
114-
addInputArgs(MatlabBuilderConstants.PDF_REPORT_PATH, getTestResultsPdf(),inputArgs);
115-
addInputArgs(MatlabBuilderConstants.TAP_RESULTS_PATH, getTestResultsTAP(), inputArgs);
116-
addInputArgs(MatlabBuilderConstants.JUNIT_RESULTS_PATH, getTestResultsJUnit(), inputArgs);
117-
addInputArgs(MatlabBuilderConstants.STM_RESULTS_PATH, getTestResultsSimulinkTest(), inputArgs);
118-
addInputArgs(MatlabBuilderConstants.COBERTURA_CODE_COVERAGE_PATH,
131+
addInputArgs(PDF_REPORT_PATH, getTestResultsPdf(),inputArgs);
132+
addInputArgs(TAP_RESULTS_PATH, getTestResultsTAP(), inputArgs);
133+
addInputArgs(JUNIT_RESULTS_PATH, getTestResultsJUnit(), inputArgs);
134+
addInputArgs(STM_RESULTS_PATH, getTestResultsSimulinkTest(), inputArgs);
135+
addInputArgs(COBERTURA_CODE_COVERAGE_PATH,
119136
getCodeCoverageCobertura(), inputArgs);
120-
addInputArgs(MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE_PATH,
137+
addInputArgs(COBERTURA_MODEL_COVERAGE_PATH,
121138
getModelCoverageCobertura(), inputArgs);
122139

123140
if (inputArgs.isEmpty()) {
124141
return "";
125-
}
126-
142+
}
143+
127144
return String.join(",", inputArgs);
128145
}
129146

@@ -132,5 +149,4 @@ private void addInputArgs(String reportName, String reportPath, List<String> inp
132149
inputArgs.add(reportName + "," + "'" + reportPath + "'");
133150
}
134151
}
135-
136152
}

0 commit comments

Comments
 (0)