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

Commit b66a25d

Browse files
author
Nikhil Bhoski
committed
Updates as per review comments
1 parent 1daefbb commit b66a25d

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,33 @@ public interface MatlabBuild {
2222
* This Method decorates the launcher with MATLAB command provided and returns the Process
2323
* object to launch MATLAB with appropriate startup options like -r or -batch
2424
*
25-
* @param matlabLauncher current build launcher
2625
* @param workspace Current build workspace
2726
* @param launcher Current build launcher
2827
* @param listener Current build listener
28+
* @param envVars Environment variables of the current build
2929
* @param matlabCommand MATLAB command to execute on shell
3030
* @return matlabLauncher returns the process launcher to run MATLAB commands
3131
*/
32-
default ProcStarter getProcessToRunMatlabCommand(ProcStarter matlabLauncher, FilePath workspace,
33-
Launcher launcher, TaskListener listener, String matlabCommand, String uniqueName)
32+
default ProcStarter getProcessToRunMatlabCommand(FilePath workspace,
33+
Launcher launcher, TaskListener listener, EnvVars envVars, String matlabCommand, String uniqueName)
3434
throws IOException, InterruptedException {
3535
// Get node specific tmp directory to copy matlab runner script
3636
String tmpDir = getNodeSpecificTmpFolderPath(workspace);
3737
FilePath targetWorkspace = new FilePath(launcher.getChannel(), tmpDir);
38+
ProcStarter matlabLauncher;
3839
if (launcher.isUnix()) {
3940
final String runnerScriptName = uniqueName + "/run_matlab_command.sh";
41+
matlabLauncher = launcher.launch().envs(envVars);
4042
matlabLauncher.cmds(tmpDir + "/" + runnerScriptName, matlabCommand).stdout(listener);
4143

4244
// Copy runner .sh for linux platform in workspace.
4345
copyFileInWorkspace(MatlabBuilderConstants.SHELL_RUNNER_SCRIPT, runnerScriptName,
4446
targetWorkspace);
4547
} else {
4648
final String runnerScriptName = uniqueName + "\\run_matlab_command.bat";
47-
matlabLauncher.cmds("cmd.exe","/C",tmpDir + "\\" + runnerScriptName, "\"" + matlabCommand + "\"")
49+
launcher = launcher.decorateByPrefix("cmd.exe", "/C");
50+
matlabLauncher = launcher.launch().envs(envVars);
51+
matlabLauncher.cmds(tmpDir + "\\" + runnerScriptName, "\"" + matlabCommand + "\"")
4852
.stdout(listener);
4953
// Copy runner.bat for Windows platform in workspace.
5054
copyFileInWorkspace(MatlabBuilderConstants.BAT_RUNNER_SCRIPT, runnerScriptName,

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
*
77
*/
88

9-
import java.io.File;
109
import java.io.IOException;
11-
import java.nio.charset.StandardCharsets;
1210
import javax.annotation.Nonnull;
13-
import org.apache.commons.io.FilenameUtils;
1411
import org.jenkinsci.Symbol;
1512
import org.kohsuke.stapler.DataBoundConstructor;
1613
import org.kohsuke.stapler.DataBoundSetter;
@@ -120,17 +117,18 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
120117
"command_" + getUniqueNameForRunnerFile().replaceAll("-", "_");
121118
final FilePath uniqeTmpFolderPath =
122119
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
123-
120+
124121
// Create MATLAB script
125-
createMatlabScriptByName(uniqeTmpFolderPath,uniqueCommandFile,workspace,listener);
122+
createMatlabScriptByName(uniqeTmpFolderPath, uniqueCommandFile, workspace, listener);
123+
ProcStarter matlabLauncher;
126124

127125
try {
128-
// Start the launcher from temp folder
129-
ProcStarter matlabLauncher = launcher.launch().pwd(uniqeTmpFolderPath).envs(envVars);
126+
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
127+
uniqueCommandFile, uniqueTmpFldrName);
128+
launcher.launch().pwd(uniqeTmpFolderPath).envs(envVars);
130129
listener.getLogger()
131130
.println("#################### Starting command output ####################");
132-
return getProcessToRunMatlabCommand(matlabLauncher, workspace, launcher, listener,
133-
uniqueCommandFile, uniqueTmpFldrName).join();
131+
return matlabLauncher.pwd(uniqeTmpFolderPath).join();
134132

135133
} catch (Exception e) {
136134
listener.getLogger().println(e.getMessage());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
238238
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
239239
ProcStarter matlabLauncher;
240240
try {
241-
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars);
241+
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
242+
constructCommandForTest(getInputArguments()), uniqueTmpFldrName);
242243

243244
// Copy MATLAB scratch file into the workspace.
244245
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
245246
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
246247
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
247248

248-
return getProcessToRunMatlabCommand(matlabLauncher, workspace, launcher, listener,
249-
constructCommandForTest(getInputArguments()), uniqueTmpFldrName).join();
249+
return matlabLauncher.pwd(workspace).join();
250250
} catch (Exception e) {
251251
listener.getLogger().println(e.getMessage());
252252
return 1;

0 commit comments

Comments
 (0)