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

Commit f238628

Browse files
committed
Updated review commentsUpdated review comments
1 parent bfe2c4b commit f238628

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class MatlabBuilder extends Builder implements SimpleBuildStep {
5555
private TestRunTypeList testRunTypeList;
5656
private String matlabRoot;
5757
private EnvVars env;
58-
private FilePath workspace;
5958
private static final String MATLAB_RUNNER_TARGET_FILE =
6059
"Builder.matlab.runner.target.file.name";
6160
private static final String MATLAB_RUNNER_RESOURCE =
@@ -101,9 +100,6 @@ private String getCustomMatlabCommand() {
101100
private void setEnv(EnvVars env) {
102101
this.env = env;
103102
}
104-
private void setWorkspace(FilePath workspace) {
105-
this.workspace = workspace;
106-
}
107103

108104
@Extension
109105
public static class MatlabDescriptor extends BuildStepDescriptor<Builder> {
@@ -412,7 +408,14 @@ private synchronized int execMatlabCommand(Run<?, ?> build, FilePath workspace,
412408
TaskListener listener, boolean isLinuxLauncher)
413409
throws IOException, InterruptedException {
414410
setEnv(build.getEnvironment(listener));
415-
setWorkspace(workspace);
411+
final String testRunMode = this.getTestRunTypeList().getDescriptor().getDisplayName();
412+
413+
// Copy MATLAB scratch file into the workspace only if Automatic option is selected.
414+
if (!testRunMode.equalsIgnoreCase(
415+
Message.getValue("builder.matlab.customcommandoption.display.name"))) {
416+
copyMatlabScratchFileInWorkspace(MATLAB_RUNNER_RESOURCE, MATLAB_RUNNER_TARGET_FILE,
417+
workspace, getClass().getClassLoader());
418+
}
416419
ProcStarter matlabLauncher;
417420
try {
418421
MatlabReleaseInfo rel = new MatlabReleaseInfo(getLocalMatlab());
@@ -430,16 +433,12 @@ private synchronized int execMatlabCommand(Run<?, ?> build, FilePath workspace,
430433
return matlabLauncher.join();
431434
}
432435

433-
public List<String> constructMatlabCommandWithBatch() throws IOException, InterruptedException {
436+
public List<String> constructMatlabCommandWithBatch() {
434437
final String testRunMode = this.getTestRunTypeList().getDescriptor().getDisplayName();
435438
final String runCommand;
436439
final List<String> matlabDefaultArgs;
437440
if (!testRunMode.equalsIgnoreCase(
438441
Message.getValue("builder.matlab.customcommandoption.display.name"))) {
439-
440-
//Copy MATLAB scratch file into the workspace only if Automatic option is selected.
441-
copyMatlabScratchFileInWorkspace(MATLAB_RUNNER_RESOURCE, MATLAB_RUNNER_TARGET_FILE,
442-
this.workspace, getClass().getClassLoader());
443442
String matlabFunctionName =
444443
FilenameUtils.removeExtension(Message.getValue(MATLAB_RUNNER_TARGET_FILE));
445444
runCommand = "exit(" + matlabFunctionName + "("
@@ -458,7 +457,7 @@ public List<String> constructMatlabCommandWithBatch() throws IOException, Interr
458457
return matlabDefaultArgs;
459458
}
460459

461-
public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) throws IOException, InterruptedException {
460+
public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) {
462461
final List<String> matlabDefaultArgs = new ArrayList<String>();
463462
Collections.addAll(matlabDefaultArgs, getPreRunnerSwitches());
464463
if (!isLinuxLauncher) {
@@ -485,15 +484,11 @@ private String[] getPostRunnerSwitches() {
485484
return postRunnerSwitch;
486485
}
487486

488-
private String[] getRunnerSwitch() throws IOException, InterruptedException {
487+
private String[] getRunnerSwitch() {
489488
final String runCommand;
490489
final String testRunMode = this.getTestRunTypeList().getDescriptor().getDisplayName();
491490
if (!testRunMode.equalsIgnoreCase(
492491
Message.getValue("builder.matlab.customcommandoption.display.name"))) {
493-
494-
//Copy MATLAB scratch file into the workspace only if Automatic option is selected.
495-
copyMatlabScratchFileInWorkspace(MATLAB_RUNNER_RESOURCE, MATLAB_RUNNER_TARGET_FILE,
496-
this.workspace, getClass().getClassLoader());
497492
String matlabFunctionName =
498493
FilenameUtils.removeExtension(Message.getValue(MATLAB_RUNNER_TARGET_FILE));
499494
runCommand = "try,exit(" + matlabFunctionName + "("

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,8 @@ public void verifyBuilderFailsForInvalidMATLABPath() throws Exception {
187187
public void verifyBuildFailureWhenMatlabException() throws Exception {
188188
MatlabBuilderTester tester = new MatlabBuilderTester(getMatlabroot("R2018b"),
189189
matlabExecutorAbsolutePath, "-positiveFail");
190-
// tester.setFailBuildIfTestFailureCheckBox(false);
190+
tester.setTestRunTypeList(new RunTestsAutomaticallyOption());
191191
project.getBuildersList().add(tester);
192-
193192
FreeStyleBuild build = project.scheduleBuild2(0).get();
194193
jenkins.assertBuildStatus(Result.FAILURE, build);
195194
}
@@ -202,6 +201,7 @@ public void verifyBuildFailureWhenMatlabException() throws Exception {
202201
public void verifyMatlabInvokedWithValidExecutable() throws Exception {
203202
MatlabBuilderTester tester = new MatlabBuilderTester(getMatlabroot("R2018b"),
204203
matlabExecutorAbsolutePath, "-positive");
204+
tester.setTestRunTypeList(new RunTestsAutomaticallyOption());
205205
project.getBuildersList().add(tester);
206206
FreeStyleBuild build = project.scheduleBuild2(0).get();
207207
jenkins.assertBuildStatus(Result.SUCCESS, build);
@@ -218,7 +218,7 @@ public void verifyMatlabPointsToValidExecutable() throws Exception {
218218
MatlabBuilderTester tester = new MatlabBuilderTester(getMatlabroot("R2018b"),
219219
matlabExecutorAbsolutePath, "-positive");
220220
project.getBuildersList().add(tester);
221-
221+
tester.setTestRunTypeList(new RunTestsAutomaticallyOption());
222222
FreeStyleBuild build = project.scheduleBuild2(0).get();
223223
jenkins.assertBuildStatus(Result.SUCCESS, build);
224224
jenkins.assertLogContains(matlabExecutorAbsolutePath, build);
@@ -301,6 +301,32 @@ public void verifyRunTestAutomaticallyIsDefault() throws Exception {
301301
jenkins.assertLogContains("true,true,true", build);
302302
}
303303

304+
/*
305+
* Test to verify if MATALB scratch file is generated in workspace for Automatic option.
306+
*/
307+
@Test
308+
public void verifyMATLABscratchFileGeneratedForAutomaticOption() throws Exception {
309+
this.matlabBuilder.setMatlabRoot(getMatlabroot("R2018b"));
310+
this.matlabBuilder.setTestRunTypeList(new RunTestsAutomaticallyOption());
311+
project.getBuildersList().add(this.matlabBuilder);
312+
FreeStyleBuild build = project.scheduleBuild2(0).get();
313+
File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m");
314+
Assert.assertTrue(matlabRunner.exists());
315+
}
316+
317+
/*
318+
* Test to verify if MATALB scratch file is not generated in workspace for Custom option.
319+
*/
320+
@Test
321+
public void verifyMATLABscratchFileGeneratedForCustomOption() throws Exception {
322+
this.matlabBuilder.setMatlabRoot(getMatlabroot("R2018b"));
323+
this.matlabBuilder.setTestRunTypeList(new RunTestsWithCustomCommandOption());
324+
project.getBuildersList().add(this.matlabBuilder);
325+
FreeStyleBuild build = project.scheduleBuild2(0).get();
326+
File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m");
327+
Assert.assertFalse(matlabRunner.exists());
328+
}
329+
304330
/*
305331
* Test to verify default value of getStringByName() when Automatic test mode.
306332
*/

0 commit comments

Comments
 (0)