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

Commit 5b284ba

Browse files
author
Nikhil Bhoski
committed
Updated review comments
1 parent d5d8164 commit 5b284ba

File tree

11 files changed

+114
-90
lines changed

11 files changed

+114
-90
lines changed

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@
5353
<url>http://github.com/jenkinsci/matlab-plugin</url>
5454
<tag>HEAD</tag>
5555
</scm>
56-
<dependencyManagement>
57-
<dependencies>
58-
<dependency>
59-
<groupId>io.jenkins.tools.bom</groupId>
60-
<artifactId>bom-2.164.x</artifactId>
61-
<version>4</version>
62-
<scope>import</scope>
63-
<type>pom</type>
64-
</dependency>
65-
</dependencies>
66-
</dependencyManagement>
56+
<dependencyManagement>
57+
<dependencies>
58+
<dependency>
59+
<groupId>io.jenkins.tools.bom</groupId>
60+
<artifactId>bom-2.164.x</artifactId>
61+
<version>4</version>
62+
<scope>import</scope>
63+
<type>pom</type>
64+
</dependency>
65+
</dependencies>
66+
</dependencyManagement>
6767
<dependencies>
6868

6969
<!-- Pipeline Step dependencies -->

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

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,26 @@
1818
public class MatlabStepExecution extends StepExecution implements MatlabBuild {
1919
private static final long serialVersionUID = 1L;
2020
private String command;
21-
private EnvVars env;
22-
private boolean copyScratchFile;
2321

2422

25-
public MatlabStepExecution(StepContext context, String command, boolean copyScratchFile) {
23+
public MatlabStepExecution(StepContext context, String command) {
2624
super(context);
2725
this.command = command;
28-
this.copyScratchFile = copyScratchFile;
2926
}
3027

3128
private String getCommand() {
32-
return this.env == null ? getMatlabCommand() : this.env.expand(getMatlabCommand());
33-
}
34-
35-
private String getMatlabCommand() {
3629
return this.command;
3730
}
3831

39-
private void setEnv(EnvVars env) {
40-
this.env = env;
41-
}
42-
43-
private EnvVars getEnv() {
44-
return this.env;
45-
}
46-
4732
@Override
4833
public boolean start() throws Exception {
4934
Launcher launcher = getContext().get(Launcher.class);
5035
FilePath workspace = getContext().get(FilePath.class);
5136
TaskListener listener = getContext().get(TaskListener.class);
5237
EnvVars env = getContext().get(EnvVars.class);
53-
setEnv(env);
38+
5439

55-
int res = execMatlabCommand(workspace, launcher, listener, getEnv());
40+
int res = execMatlabCommand(workspace, launcher, listener, env);
5641
if (res == 0) {
5742
getContext().setResult(Result.SUCCESS);
5843
} else {
@@ -75,14 +60,8 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
7560
ProcStarter matlabLauncher;
7661
try {
7762
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
78-
getCommand(), uniqueTmpFldrName);
63+
envVars.expand(getCommand()), uniqueTmpFldrName);
7964

80-
// Copy MATLAB scratch file into the workspace if required.
81-
if(this.copyScratchFile) {
82-
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
83-
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
84-
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
85-
}
8665

8766
return matlabLauncher.join();
8867
} catch (Exception e) {

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2019-2020 The MathWorks, Inc.
4+
* Copyright 2020 The MathWorks, Inc.
55
*
66
*/
77

@@ -22,22 +22,21 @@
2222
public class RunMatlabCommandStep extends Step {
2323

2424
private EnvVars env;
25-
private String matlabCommand;
26-
private static boolean COPY_SCRATCH_FILE = false;
25+
private String command;
2726

2827
@DataBoundConstructor
29-
public RunMatlabCommandStep(String matlabCommand) {
30-
this.matlabCommand = matlabCommand;
28+
public RunMatlabCommandStep(String command) {
29+
this.command = command;
3130

3231
}
3332

3433

35-
public String getMatlabCommand() {
36-
return this.matlabCommand;
34+
public String getCommand() {
35+
return this.command;
3736
}
3837

39-
private String getCommand() {
40-
return this.env == null ? getMatlabCommand() : this.env.expand(getMatlabCommand());
38+
private String getMatlabCommand() {
39+
return this.env == null ? getCommand() : this.env.expand(getCommand());
4140
}
4241

4342
public void setEnv(EnvVars env) {
@@ -50,7 +49,7 @@ public EnvVars getEnv() {
5049

5150
@Override
5251
public StepExecution start(StepContext context) throws Exception {
53-
return new MatlabStepExecution(context, getCommand(), COPY_SCRATCH_FILE);
52+
return new MatlabStepExecution(context, getMatlabCommand());
5453
}
5554

5655
@Extension

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

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.mathworks.ci;
22

3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
36
/**
4-
* Copyright 2019-2020 The MathWorks, Inc.
7+
* Copyright 2020 The MathWorks, Inc.
58
*
69
*/
710

@@ -27,7 +30,7 @@
2730

2831
public class RunMatlabTestsStep extends Step {
2932

30-
private String testResultsPdf;
33+
private String testResultsPDF;
3134
private String testResultsTAP;
3235
private String testResultsJUnit;
3336
private String codeCoverageCobertura;
@@ -39,7 +42,6 @@ public class RunMatlabTestsStep extends Step {
3942
private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath";
4043
private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath";
4144
private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath";
42-
private static boolean COPY_SCRATCH_FILE = true;
4345

4446
@DataBoundConstructor
4547
public RunMatlabTestsStep() {
@@ -55,13 +57,13 @@ public void setTestResultsTAP(String testResultsTAP) {
5557
this.testResultsTAP = testResultsTAP;
5658
}
5759

58-
public String getTestResultsPdf() {
59-
return testResultsPdf;
60+
public String getTestResultsPDF() {
61+
return testResultsPDF;
6062
}
6163

6264
@DataBoundSetter
63-
public void setTestResultsPdf(String testResultsPdf) {
64-
this.testResultsPdf = testResultsPdf;
65+
public void setTestResultsPDF(String testResultsPDF) {
66+
this.testResultsPDF = testResultsPDF;
6567
}
6668

6769
public String getTestResultsJUnit() {
@@ -104,8 +106,14 @@ public void setModelCoverageCobertura(String modelCoverageCobertura) {
104106

105107
@Override
106108
public StepExecution start(StepContext context) throws Exception {
107-
108-
return new MatlabStepExecution(context,constructCommandForTest(getInputArgs()), COPY_SCRATCH_FILE);
109+
Launcher launcher = context.get(Launcher.class);
110+
FilePath workspace = context.get(FilePath.class);
111+
112+
//Copy Scratch file needed to run MATLAB tests in workspace
113+
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
114+
copyScratchFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
115+
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
116+
return new MatlabStepExecution(context,constructCommandForTest(getInputArgs()));
109117
}
110118

111119
@Extension
@@ -150,12 +158,31 @@ private String getInputArgs() {
150158

151159
private Map<String, String> getMatlabArgs() {
152160
final Map<String, String> args = new HashMap<String, String>();
153-
args.put(PDF_REPORT_PATH, getTestResultsPdf());
154-
args.put(TAP_RESULTS_PATH, getTestResultsTAP());
155-
args.put(JUNIT_RESULTS_PATH, getTestResultsJUnit());
156-
args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest());
157-
args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura());
158-
args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura());
161+
args.put(PDF_REPORT_PATH,
162+
getTestResultsPDF() == null ? null : getTestResultsPDF().replaceAll("'", "''"));
163+
args.put(TAP_RESULTS_PATH,
164+
getTestResultsTAP() == null ? null : getTestResultsTAP().replaceAll("'", "''"));
165+
args.put(JUNIT_RESULTS_PATH,
166+
getTestResultsJUnit() == null ? null : getTestResultsJUnit().replaceAll("'", "''"));
167+
args.put(STM_RESULTS_PATH, getTestResultsSimulinkTest() == null ? null
168+
: getTestResultsSimulinkTest().replaceAll("'", "''"));
169+
args.put(COBERTURA_CODE_COVERAGE_PATH, getCodeCoverageCobertura() == null ? null
170+
: getCodeCoverageCobertura().replaceAll("'", "''"));
171+
args.put(COBERTURA_MODEL_COVERAGE_PATH, getModelCoverageCobertura() == null ? null
172+
: getModelCoverageCobertura().replaceAll("'", "''"));
159173
return args;
160174
}
175+
176+
/*
177+
* Method to copy given file from source to target node specific workspace.
178+
*/
179+
private void copyScratchFileInWorkspace(String sourceFile, String targetFile, FilePath targetWorkspace)
180+
throws IOException, InterruptedException {
181+
final ClassLoader classLoader = getClass().getClassLoader();
182+
FilePath targetFilePath = new FilePath(targetWorkspace, targetFile);
183+
InputStream in = classLoader.getResourceAsStream(sourceFile);
184+
targetFilePath.copyFrom(in);
185+
// set executable permission
186+
targetFilePath.chmod(0755);
187+
}
161188
}

src/main/resources/com/mathworks/ci/RunMatlabCommandStep/config.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33

4-
<f:entry title="Command" field="matlabCommand">
4+
<f:entry field="command">
55
<f:textbox/>
66
</f:entry>
77

src/main/resources/com/mathworks/ci/RunMatlabTestsStep/config.jelly

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33

4-
<f:entry title="Pdf Report" field="testResultsPdf">
4+
<f:entry field="testResultsPDF">
55
<f:textbox/>
66
</f:entry>
77

8-
<f:entry title="TAP report" field="testResultsTAP">
8+
<f:entry field="testResultsTAP">
99
<f:textbox/>
1010
</f:entry>
1111

12-
<f:entry title="Junit report" field="testResultsJUnit">
12+
<f:entry field="testResultsJUnit">
1313
<f:textbox/>
1414
</f:entry>
1515

16-
<f:entry title="Cobertura code coverage" field="codeCoverageCobertura">
16+
<f:entry field="codeCoverageCobertura">
1717
<f:textbox/>
1818
</f:entry>
1919

20-
<f:entry title="Simulink Test report" field="testResultsSimulinkTest">
20+
<f:entry field="testResultsSimulinkTest">
2121
<f:textbox/>
2222
</f:entry>
2323

24-
<f:entry title="Model coverage report" field="modelCoverageCobertura">
24+
<f:entry field="modelCoverageCobertura">
2525
<f:textbox/>
2626
</f:entry>
2727

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.mathworks.ci;
22
/**
3-
* Copyright 2019-2020 The MathWorks, Inc.
3+
* Copyright 2020 The MathWorks, Inc.
44
*
55
*/
66

@@ -39,7 +39,7 @@ public void testSetup() throws IOException {
3939
public void verifyMATLABPathNotSet() throws Exception {
4040
project.setDefinition(
4141
new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n"
42-
+ "runMATLABCommand(matlabCommand: 'pwd')}", true));
42+
+ "runMATLABCommand(command: 'pwd')}", true));
4343
WorkflowRun build = project.scheduleBuild2(0).get();
4444
j.assertLogContains("MATLAB_ROOT", build);
4545
}
@@ -53,7 +53,7 @@ public void verifyMATLABPathNotSet() throws Exception {
5353
public void verifyMATLABPathSet() throws Exception {
5454
project.setDefinition(
5555
new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n"
56-
+ "testMATLABCommand(matlabCommand: 'pwd')}", true));
56+
+ "testMATLABCommand(command: 'pwd')}", true));
5757
WorkflowRun build = project.scheduleBuild2(0).get();
5858
j.assertLogContains("tester_started", build);
5959
}
@@ -68,7 +68,7 @@ public void verifyPipelineOnSlave() throws Exception {
6868
DumbSlave s = j.createOnlineSlave();
6969
project.setDefinition(new CpsFlowDefinition(
7070
"node('!master') { writeFile text: 'worksapce', file: 'test.txt'\n"
71-
+ "testMATLABCommand(matlabCommand: 'pwd')}",
71+
+ "testMATLABCommand(command: 'pwd')}",
7272
true));
7373

7474
s.getWorkspaceFor(project);
@@ -86,7 +86,7 @@ public void verifyPipelineOnSlave() throws Exception {
8686
public void verifyCommandSameAsScript() throws Exception {
8787
project.setDefinition(
8888
new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n"
89-
+ "runMATLABCommand(matlabCommand: 'pwd')}", true));
89+
+ "runMATLABCommand(command: 'pwd')}", true));
9090

9191
WorkflowRun build = project.scheduleBuild2(0).get();
9292
j.assertLogContains("pwd", build);
@@ -103,7 +103,7 @@ public void verifyMatrixBuild() throws Exception {
103103
new CpsFlowDefinition("node { writeFile text: 'worksapce', file: 'test.txt'\n"
104104
+ "matrix {\n" + "agent any\n" + "axes {\n" + "axis {\n" + "name: 'CMD'\n"
105105
+ "values: 'pwd','ver'\n }}\n"
106-
+ "runMATLABCommand(matlabCommand: '${CMD}')}}", true));
106+
+ "runMATLABCommand(command: '${CMD}')}}", true));
107107

108108
WorkflowRun build = project.scheduleBuild2(0).get();
109109
j.assertLogContains("pwd", build);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2019-2020 The MathWorks, Inc.
4+
* Copyright 2020 The MathWorks, Inc.
55
*
66
*/
77

@@ -20,14 +20,14 @@
2020

2121
public class RunMatlabCommandStepTester extends RunMatlabCommandStep {
2222
@DataBoundConstructor
23-
public RunMatlabCommandStepTester(String matlabCommand) {
24-
super(matlabCommand);
23+
public RunMatlabCommandStepTester(String command) {
24+
super(command);
2525
}
2626

2727
@Override
2828
public StepExecution start(StepContext context) throws Exception {
2929

30-
return new TestStepExecution(context,this.getMatlabCommand(), false);
30+
return new TestStepExecution(context,this.getCommand());
3131
}
3232

3333
@Extension

0 commit comments

Comments
 (0)