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

Commit bfe2c4b

Browse files
committed
Scratch file copy operation restricted to Automatic mode only.
1 parent d117d3f commit bfe2c4b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

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

104108
@Extension
105109
public static class MatlabDescriptor extends BuildStepDescriptor<Builder> {
@@ -408,9 +412,7 @@ private synchronized int execMatlabCommand(Run<?, ?> build, FilePath workspace,
408412
TaskListener listener, boolean isLinuxLauncher)
409413
throws IOException, InterruptedException {
410414
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());
415+
setWorkspace(workspace);
414416
ProcStarter matlabLauncher;
415417
try {
416418
MatlabReleaseInfo rel = new MatlabReleaseInfo(getLocalMatlab());
@@ -428,12 +430,16 @@ private synchronized int execMatlabCommand(Run<?, ?> build, FilePath workspace,
428430
return matlabLauncher.join();
429431
}
430432

431-
public List<String> constructMatlabCommandWithBatch() {
433+
public List<String> constructMatlabCommandWithBatch() throws IOException, InterruptedException {
432434
final String testRunMode = this.getTestRunTypeList().getDescriptor().getDisplayName();
433435
final String runCommand;
434436
final List<String> matlabDefaultArgs;
435437
if (!testRunMode.equalsIgnoreCase(
436438
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());
437443
String matlabFunctionName =
438444
FilenameUtils.removeExtension(Message.getValue(MATLAB_RUNNER_TARGET_FILE));
439445
runCommand = "exit(" + matlabFunctionName + "("
@@ -452,7 +458,7 @@ public List<String> constructMatlabCommandWithBatch() {
452458
return matlabDefaultArgs;
453459
}
454460

455-
public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) {
461+
public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) throws IOException, InterruptedException {
456462
final List<String> matlabDefaultArgs = new ArrayList<String>();
457463
Collections.addAll(matlabDefaultArgs, getPreRunnerSwitches());
458464
if (!isLinuxLauncher) {
@@ -479,11 +485,15 @@ private String[] getPostRunnerSwitches() {
479485
return postRunnerSwitch;
480486
}
481487

482-
private String[] getRunnerSwitch() {
488+
private String[] getRunnerSwitch() throws IOException, InterruptedException {
483489
final String runCommand;
484490
final String testRunMode = this.getTestRunTypeList().getDescriptor().getDisplayName();
485491
if (!testRunMode.equalsIgnoreCase(
486492
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());
487497
String matlabFunctionName =
488498
FilenameUtils.removeExtension(Message.getValue(MATLAB_RUNNER_TARGET_FILE));
489499
runCommand = "try,exit(" + matlabFunctionName + "("

0 commit comments

Comments
 (0)