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

Commit 0f150a8

Browse files
authored
Merge pull request #34 from mathworks/gecko-280753_copy_for_custom_option
Scratch file copy operation restricted to Automatic mode only.
2 parents d117d3f + a178b63 commit 0f150a8

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class MatlabBuilder extends Builder implements SimpleBuildStep {
5959
"Builder.matlab.runner.target.file.name";
6060
private static final String MATLAB_RUNNER_RESOURCE =
6161
"com/mathworks/ci/MatlabBuilder/runMatlabTests.m";
62+
private static final String AUTOMATIC_OPTION = "RunTestsAutomaticallyOption";
6263

6364

6465
@DataBoundConstructor
@@ -408,9 +409,13 @@ private synchronized int execMatlabCommand(Run<?, ?> build, FilePath workspace,
408409
TaskListener listener, boolean isLinuxLauncher)
409410
throws IOException, InterruptedException {
410411
setEnv(build.getEnvironment(listener));
411-
//Copy MATLAB scratch file into the workspace
412-
copyMatlabScratchFileInWorkspace(MATLAB_RUNNER_RESOURCE, MATLAB_RUNNER_TARGET_FILE,
413-
workspace, getClass().getClassLoader());
412+
final String testRunMode = this.getTestRunTypeList().getDescriptor().getId();
413+
414+
// Copy MATLAB scratch file into the workspace only if Automatic option is selected.
415+
if (testRunMode.contains(AUTOMATIC_OPTION)) {
416+
copyMatlabScratchFileInWorkspace(MATLAB_RUNNER_RESOURCE, MATLAB_RUNNER_TARGET_FILE,
417+
workspace, getClass().getClassLoader());
418+
}
414419
ProcStarter matlabLauncher;
415420
try {
416421
MatlabReleaseInfo rel = new MatlabReleaseInfo(getLocalMatlab());
@@ -429,11 +434,10 @@ private synchronized int execMatlabCommand(Run<?, ?> build, FilePath workspace,
429434
}
430435

431436
public List<String> constructMatlabCommandWithBatch() {
432-
final String testRunMode = this.getTestRunTypeList().getDescriptor().getDisplayName();
437+
final String testRunMode = this.getTestRunTypeList().getDescriptor().getId();
433438
final String runCommand;
434439
final List<String> matlabDefaultArgs;
435-
if (!testRunMode.equalsIgnoreCase(
436-
Message.getValue("builder.matlab.customcommandoption.display.name"))) {
440+
if (testRunMode.contains(AUTOMATIC_OPTION)) {
437441
String matlabFunctionName =
438442
FilenameUtils.removeExtension(Message.getValue(MATLAB_RUNNER_TARGET_FILE));
439443
runCommand = "exit(" + matlabFunctionName + "("
@@ -481,9 +485,8 @@ private String[] getPostRunnerSwitches() {
481485

482486
private String[] getRunnerSwitch() {
483487
final String runCommand;
484-
final String testRunMode = this.getTestRunTypeList().getDescriptor().getDisplayName();
485-
if (!testRunMode.equalsIgnoreCase(
486-
Message.getValue("builder.matlab.customcommandoption.display.name"))) {
488+
final String testRunMode = this.getTestRunTypeList().getDescriptor().getId();
489+
if (testRunMode.contains(AUTOMATIC_OPTION)) {
487490
String matlabFunctionName =
488491
FilenameUtils.removeExtension(Message.getValue(MATLAB_RUNNER_TARGET_FILE));
489492
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)