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

Commit 1e4ac95

Browse files
committed
Changes updated to work with bash & remove unwanted util class.
1 parent ff3f51e commit 1e4ac95

File tree

5 files changed

+71
-136
lines changed

5 files changed

+71
-136
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,21 @@ public FormValidation getFirstErrorOrWarning(
142142
public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher launcher,
143143
TaskListener listener, EnvVars initialEnvironment)
144144
throws IOException, InterruptedException {
145-
CommandConstructUtil utils = new CommandConstructUtil(launcher, getLocalMatlab());
146145
// Set Environment variable
147146

148147
setEnv(initialEnvironment);
149-
String nodeSpecificFileSep = utils.getNodeSpecificFileSeperator();
148+
String nodeSpecificFileSep = getNodeSpecificFileSeperator(launcher);
150149
// Add "matlabroot" without bin as env variable which will be available across the build.
151150
context.env("matlabroot", getLocalMatlab());
152151
// Add matlab bin to path to invoke MATLAB directly on command line.
153152
context.env("PATH+matlabroot", getLocalMatlab() + nodeSpecificFileSep + "bin");
154153
}
154+
155+
private String getNodeSpecificFileSeperator(Launcher launcher) {
156+
if (launcher.isUnix()) {
157+
return "/";
158+
} else {
159+
return "\\";
160+
}
161+
}
155162
}

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

Lines changed: 0 additions & 102 deletions
This file was deleted.

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import java.io.IOException;
10+
import java.io.InputStream;
1011
import javax.annotation.Nonnull;
1112
import org.jenkinsci.Symbol;
1213
import org.kohsuke.stapler.DataBoundConstructor;
@@ -115,23 +116,33 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
115116
try {
116117
// Get mMatlabroot set in wrapper.
117118
String matlabRoot = envVars.get("matlabroot");
118-
CommandConstructUtil cmdUtils = new CommandConstructUtil(launcher, matlabRoot);
119119
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars);
120120
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
121121
if(launcher.isUnix()) {
122-
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars).cmds("/bin/bash","-c","./run_matlab_command.sh "+cmdUtils.constructCommandForRunCommand(getCommand())).stdout(listener);
122+
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars).cmds("./run_matlab_command.sh",getCommand()).stdout(listener);
123123
//Copy runner .sh for linux platform in workspace.
124-
cmdUtils.copyMatlabScratchFileInWorkspace(MatlabBuilderConstants.SHELL_RUNNER_SCRIPT, "Builder.matlab.runner.script.target.file.linux.name", targetWorkspace);
124+
copyFileInWorkspace(MatlabBuilderConstants.SHELL_RUNNER_SCRIPT, "Builder.matlab.runner.script.target.file.linux.name", targetWorkspace);
125125
}else {
126126
launcher = launcher.decorateByPrefix("cmd.exe","/C");
127-
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars).cmds("run_matlab_command.bat","\""+cmdUtils.constructCommandForRunCommand(getCommand())+"\"").stdout(listener);
127+
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars).cmds("run_matlab_command.bat","\""+getCommand()+"\"").stdout(listener);
128128
//Copy runner.bat for Windows platform in workspace.
129-
cmdUtils.copyMatlabScratchFileInWorkspace(MatlabBuilderConstants.BAT_RUNNER_SCRIPT, "Builder.matlab.runner.script.target.file.windows.name", targetWorkspace);
129+
copyFileInWorkspace(MatlabBuilderConstants.BAT_RUNNER_SCRIPT, "Builder.matlab.runner.script.target.file.windows.name", targetWorkspace);
130130
}
131131
} catch (Exception e) {
132132
listener.getLogger().println(e.getMessage());
133133
return 1;
134134
}
135135
return matlabLauncher.join();
136136
}
137+
138+
public void copyFileInWorkspace(String matlabRunnerResourcePath, String matlabRunnerTarget,
139+
FilePath targetWorkspace) throws IOException, InterruptedException {
140+
final ClassLoader classLoader = getClass().getClassLoader();
141+
FilePath targetFile = new FilePath(targetWorkspace, Message.getValue(matlabRunnerTarget));
142+
InputStream in = classLoader.getResourceAsStream(matlabRunnerResourcePath);
143+
targetFile.copyFrom(in);
144+
// set executable permission
145+
targetFile.chmod(0755);
146+
}
147+
137148
}

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

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -281,47 +281,60 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace,
281281
}
282282

283283
private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher,
284-
TaskListener listener, EnvVars envVars)
285-
throws IOException, InterruptedException {
286-
284+
TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
287285
ProcStarter matlabLauncher;
288286
try {
289287
// Get matlabroot set in wrapper class.
290-
String matlabRoot = envVars.get("matlabroot");
291-
CommandConstructUtil cmdUtils = new CommandConstructUtil(launcher, matlabRoot);
288+
String matlabRoot = envVars.get("matlabroot");
292289
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars);
293290
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
294-
if(launcher.isUnix()) {
295-
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars).cmds("/bin/bash","-c","./run_matlab_command.sh "+cmdUtils.constructCommandForTest(getInputArguments())).stdout(listener);
296-
//Copy runner .sh for linux platform in workspace.
297-
cmdUtils.copyMatlabScratchFileInWorkspace(MatlabBuilderConstants.SHELL_RUNNER_SCRIPT, "Builder.matlab.runner.script.target.file.linux.name", targetWorkspace);
298-
}else {
299-
launcher = launcher.decorateByPrefix("cmd.exe","/C");
300-
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars).cmds("run_matlab_command.bat","\""+cmdUtils.constructCommandForTest(getInputArguments())+"\"").stdout(listener);
301-
//Copy runner.bat for Windows platform in workspace.
302-
cmdUtils.copyMatlabScratchFileInWorkspace(MatlabBuilderConstants.BAT_RUNNER_SCRIPT, "Builder.matlab.runner.script.target.file.windows.name", targetWorkspace);
291+
if (launcher.isUnix()) {
292+
matlabLauncher =
293+
launcher.launch().pwd(workspace).envs(envVars)
294+
.cmds("./run_matlab_command.sh",
295+
constructCommandForTest(getInputArguments()))
296+
.stdout(listener);
297+
// Copy runner .sh for linux platform in workspace.
298+
cpoyFileInWorkspace(MatlabBuilderConstants.SHELL_RUNNER_SCRIPT,
299+
"Builder.matlab.runner.script.target.file.linux.name", targetWorkspace);
300+
} else {
301+
launcher = launcher.decorateByPrefix("cmd.exe", "/C");
302+
matlabLauncher = launcher.launch().pwd(workspace).envs(envVars)
303+
.cmds("run_matlab_command.bat",
304+
"\"" + constructCommandForTest(getInputArguments()) + "\"")
305+
.stdout(listener);
306+
// Copy runner.bat for Windows platform in workspace.
307+
cpoyFileInWorkspace(MatlabBuilderConstants.BAT_RUNNER_SCRIPT,
308+
"Builder.matlab.runner.script.target.file.windows.name", targetWorkspace);
303309
}
304-
310+
305311
// Copy MATLAB scratch file into the workspace.
306-
cmdUtils.copyMatlabScratchFileInWorkspace(MatlabBuilderConstants.MATLAB_RUNNER_RESOURCE, MatlabBuilderConstants.MATLAB_RUNNER_TARGET_FILE, targetWorkspace);
312+
cpoyFileInWorkspace(MatlabBuilderConstants.MATLAB_RUNNER_RESOURCE,
313+
MatlabBuilderConstants.MATLAB_RUNNER_TARGET_FILE, targetWorkspace);
307314
} catch (Exception e) {
308315
listener.getLogger().println(e.getMessage());
309316
return 1;
310317
}
311318
return matlabLauncher.join();
312319
}
313320

314-
/* private void copyMatlabScratchFileInWorkspace(String matlabRunnerResourcePath,
315-
String matlabRunnerTarget, FilePath targetWorkspace)
316-
throws IOException, InterruptedException {
321+
public String constructCommandForTest(String inputArguments) {
322+
String runCommand;
323+
String matlabFunctionName = FilenameUtils.removeExtension(
324+
Message.getValue(MatlabBuilderConstants.MATLAB_RUNNER_TARGET_FILE));
325+
runCommand = "exit(" + matlabFunctionName + "(" + inputArguments + "))";
326+
return runCommand;
327+
}
328+
329+
private void cpoyFileInWorkspace(String matlabRunnerResourcePath, String matlabRunnerTarget,
330+
FilePath targetWorkspace) throws IOException, InterruptedException {
317331
final ClassLoader classLoader = getClass().getClassLoader();
318-
FilePath targetFile =
319-
new FilePath(targetWorkspace, Message.getValue(matlabRunnerTarget));
332+
FilePath targetFile = new FilePath(targetWorkspace, Message.getValue(matlabRunnerTarget));
320333
InputStream in = classLoader.getResourceAsStream(matlabRunnerResourcePath);
321334
targetFile.copyFrom(in);
322-
//set executable permission to the file.
323-
targetFile.chmod(0777);
324-
}*/
335+
// set executable permission to the file.
336+
targetFile.chmod(0755);
337+
}
325338

326339
// Concatenate the input arguments
327340
private String getInputArguments() {
@@ -330,11 +343,10 @@ private String getInputArguments() {
330343
String junitResults = MatlabBuilderConstants.JUNIT_RESULTS + "," + this.getJunitChkBx();
331344
String stmResults = MatlabBuilderConstants.STM_RESULTS + "," + this.getStmResultsChkBx();
332345
String coberturaCodeCoverage = MatlabBuilderConstants.COBERTURA_CODE_COVERAGE + "," + this.getCoberturaChkBx();
333-
String coberturaModelCoverage = MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE + "," + this.getModelCoverageChkBx();
334-
346+
String coberturaModelCoverage = MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE + "," + this.getModelCoverageChkBx();
335347
String inputArgsToMatlabFcn = pdfReport + "," + tapResults + "," + junitResults + ","
336348
+ stmResults + "," + coberturaCodeCoverage + "," + coberturaModelCoverage;
337-
349+
338350
return inputArgsToMatlabFcn;
339351
}
340352
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div>
2+
Enter the full path to the MATLAB root folder, which is returned by the <i><b>matlabroot</b></i> function. <br><br>Example:<br><br><i><b><u>Windows:</u></b></i><br> C:\Program Files\MATLAB\R2019a <br>
3+
<i><b><u>Linux:</u></b></i><br> /usr/local/MATLAB/R2019a <br>
4+
<i><b><u>Mac:</u></b></i><br> /Applications/MATLAB_R2019a.app <br>
5+
<p>
6+
<b>Note:</b> If the job runs on a remote agent, you must specify the full path to MATLAB root folder on the remote agent.</p>
7+
</div>

0 commit comments

Comments
 (0)