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

Commit a62b9cc

Browse files
author
Nikhil Bhoski
committed
Updated review comments.
1 parent 2e389e8 commit a62b9cc

File tree

4 files changed

+41
-59
lines changed

4 files changed

+41
-59
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import hudson.model.TaskListener;
1717

1818
public class MatlabStepExecution extends StepExecution implements MatlabBuild {
19-
private static final long serialVersionUID = 1L;
19+
20+
private static final long serialVersionUID = 6704588180717665100L;
21+
2022
private String command;
2123

2224

@@ -31,18 +33,15 @@ private String getCommand() {
3133

3234
@Override
3335
public boolean start() throws Exception {
34-
Launcher launcher = getContext().get(Launcher.class);
35-
FilePath workspace = getContext().get(FilePath.class);
36-
TaskListener listener = getContext().get(TaskListener.class);
37-
EnvVars env = getContext().get(EnvVars.class);
36+
final Launcher launcher = getContext().get(Launcher.class);
37+
final FilePath workspace = getContext().get(FilePath.class);
38+
final TaskListener listener = getContext().get(TaskListener.class);
39+
final EnvVars env = getContext().get(EnvVars.class);
3840

39-
4041
int res = execMatlabCommand(workspace, launcher, listener, env);
41-
if (res == 0) {
42-
getContext().setResult(Result.SUCCESS);
43-
} else {
44-
getContext().setResult(Result.FAILURE);
45-
}
42+
43+
getContext().setResult((res == 0) ? Result.SUCCESS : Result.FAILURE);
44+
4645
getContext().onSuccess(true);
4746

4847
//return false represents the asynchronous run.
@@ -56,10 +55,9 @@ public void stop(Throwable cause) throws Exception {
5655

5756
private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher,
5857
TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
59-
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
60-
ProcStarter matlabLauncher;
58+
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
6159
try {
62-
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
60+
ProcStarter matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
6361
envVars.expand(getCommand()), uniqueTmpFldrName);
6462

6563

@@ -69,7 +67,7 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
6967
return 1;
7068
} finally {
7169
// Cleanup the runner File from tmp directory
72-
FilePath matlabRunnerScript =
70+
final FilePath matlabRunnerScript =
7371
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
7472
if (matlabRunnerScript.exists()) {
7573
matlabRunnerScript.deleteRecursive();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121

2222
public class RunMatlabCommandStep extends Step {
2323

24-
private EnvVars env;
24+
2525
private String command;
2626

2727
@DataBoundConstructor
2828
public RunMatlabCommandStep(String command) {
2929
this.command = command;
30-
3130
}
3231

3332

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public class RunMatlabTestsStep extends Step {
3939
private String codeCoverageCobertura;
4040
private String testResultsSimulinkTest;
4141
private String modelCoverageCobertura;
42-
private static final String PDF_REPORT_PATH = "PDFReportPath";
43-
private static final String TAP_RESULTS_PATH = "TAPResultsPath";
44-
private static final String JUNIT_RESULTS_PATH = "JUnitResultsPath";
45-
private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath";
46-
private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath";
47-
private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath";
42+
4843

4944
@DataBoundConstructor
5045
public RunMatlabTestsStep() {
@@ -120,7 +115,7 @@ public StepExecution start(StepContext context) throws Exception {
120115
}
121116

122117
@Extension
123-
public static class CommandStepDescriptor extends StepDescriptor {
118+
public static class RunTestsStepDescriptor extends StepDescriptor {
124119

125120
@Override
126121
public Set<? extends Class<?>> getRequiredContext() {
@@ -161,12 +156,12 @@ private String getInputArgs() {
161156

162157
private Map<String, String> getMatlabArgs() {
163158
final Map<String, String> args = new HashMap<String, String>();
164-
args.put(PDF_REPORT_PATH,getTestResultsPDF());
165-
args.put(TAP_RESULTS_PATH,getTestResultsTAP());
166-
args.put(JUNIT_RESULTS_PATH,getTestResultsJUnit());
167-
args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest());
168-
args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura());
169-
args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura());
159+
args.put("PDFReportPath", getTestResultsPDF());
160+
args.put("TAPResultsPath", getTestResultsTAP());
161+
args.put("JUnitResultsPath", getTestResultsJUnit());
162+
args.put("SimulinkTestResultsPath", getTestResultsSimulinkTest());
163+
args.put("CoberturaCodeCoveragePath", getCodeCoverageCobertura());
164+
args.put("CoberturaModelCoveragePath", getModelCoverageCobertura());
170165
return args;
171166
}
172167

src/test/java/com/mathworks/ci/RunMatlabTestsStepTester.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,14 @@
22

33
import java.io.IOException;
44
import java.io.InputStream;
5-
6-
/**
7-
* Copyright 2020 The MathWorks, Inc.
8-
*
9-
*/
10-
11-
import java.util.ArrayList;
125
import java.util.Arrays;
13-
import java.util.Collections;
146
import java.util.List;
157
import java.util.Set;
168
import org.jenkinsci.plugins.workflow.steps.StepContext;
179
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
1810
import org.jenkinsci.plugins.workflow.steps.StepExecution;
1911
import org.kohsuke.stapler.DataBoundConstructor;
2012
import com.google.common.collect.ImmutableSet;
21-
import com.kenai.jffi.Array;
2213
import hudson.EnvVars;
2314
import hudson.Extension;
2415
import hudson.FilePath;
@@ -27,25 +18,35 @@
2718
import hudson.model.TaskListener;
2819

2920
public class RunMatlabTestsStepTester extends RunMatlabTestsStep {
30-
31-
21+
22+
3223
@DataBoundConstructor
3324
public RunMatlabTestsStepTester() {
34-
25+
3526
}
36-
27+
3728
@Override
3829
public StepExecution start(StepContext context) throws Exception {
3930
Launcher launcher = context.get(Launcher.class);
4031
FilePath workspace = context.get(FilePath.class);
41-
42-
//Copy Scratch file needed to run MATLAB tests in workspace
32+
33+
// Copy Scratch file needed to run MATLAB tests in workspace
4334
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
4435
copyScratchFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
4536
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
46-
return new TestStepExecution(context,constructCommandForTest(getInputArgs()));
37+
return new TestStepExecution(context, constructCommandForTest(getInputArgs()));
4738
}
48-
39+
40+
private void copyScratchFileInWorkspace(String sourceFile, String targetFile,
41+
FilePath targetWorkspace) throws IOException, InterruptedException {
42+
final ClassLoader classLoader = getClass().getClassLoader();
43+
FilePath targetFilePath = new FilePath(targetWorkspace, targetFile);
44+
InputStream in = classLoader.getResourceAsStream(sourceFile);
45+
targetFilePath.copyFrom(in);
46+
// set executable permission
47+
targetFilePath.chmod(0755);
48+
}
49+
4950
@Extension
5051
public static class CommandStepTestDescriptor extends StepDescriptor {
5152

@@ -60,23 +61,12 @@ public String getFunctionName() {
6061
return "testMATLABTests";
6162
}
6263
}
63-
64+
6465
public String getInputArgs() {
6566
List<String> args = Arrays.asList(getTestResultsPDF(), getTestResultsTAP(),
6667
getTestResultsJUnit(), getTestResultsSimulinkTest(), getCodeCoverageCobertura(),
6768
getModelCoverageCobertura());
6869

6970
return String.join(",", args);
7071
}
71-
72-
private void copyScratchFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace)
73-
throws IOException, InterruptedException {
74-
final ClassLoader classLoader = getClass().getClassLoader();
75-
FilePath targetFilePath = new FilePath(targetWorkspace, targetFile);
76-
InputStream in = classLoader.getResourceAsStream(sourceFile);
77-
targetFilePath.copyFrom(in);
78-
// set executable permission
79-
targetFilePath.chmod(0755);
80-
}
81-
8272
}

0 commit comments

Comments
 (0)