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

Commit 7715ffc

Browse files
authored
Merge pull request #251 from mathworks/2.10.1-SNAPSHOT-Qualification
Merging 2.10.1 snapshot qualification
2 parents 8faff92 + e74875c commit 7715ffc

36 files changed

+595
-317
lines changed

pom.xml

Lines changed: 238 additions & 217 deletions
Large diffs are not rendered by default.

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

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.mathworks.ci;
22
/**
3-
* Copyright 2019-2020 The MathWorks, Inc.
3+
* Copyright 2019-2023 The MathWorks, Inc.
44
*
55
* Build Interface has two default methods. MATLAB builders can override the default behavior.
66
*
77
*/
88

99
import java.io.IOException;
1010
import java.io.InputStream;
11+
import java.io.ByteArrayOutputStream;
1112
import org.apache.commons.lang.RandomStringUtils;
1213
import hudson.EnvVars;
1314
import hudson.FilePath;
1415
import hudson.Launcher;
1516
import hudson.Launcher.ProcStarter;
17+
import hudson.util.ArgumentListBuilder;
1618
import hudson.model.TaskListener;
1719

1820
public interface MatlabBuild {
@@ -29,28 +31,53 @@ public interface MatlabBuild {
2931
* @return matlabLauncher returns the process launcher to run MATLAB commands
3032
*/
3133
default ProcStarter getProcessToRunMatlabCommand(FilePath workspace,
32-
Launcher launcher, TaskListener listener, EnvVars envVars, String matlabCommand, String uniqueName)
34+
Launcher launcher, TaskListener listener, EnvVars envVars, String matlabCommand, String startupOpts, String uniqueName)
3335
throws IOException, InterruptedException {
3436
// Get node specific temp .matlab directory to copy matlab runner script
35-
FilePath targetWorkspace = new FilePath(launcher.getChannel(),
36-
workspace.getRemote() + "/" + MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME);
37+
FilePath targetWorkspace;
3738
ProcStarter matlabLauncher;
39+
ArgumentListBuilder args = new ArgumentListBuilder();
3840
if (launcher.isUnix()) {
39-
final String runnerScriptName = uniqueName + "/run_matlab_command.sh";
40-
matlabLauncher = launcher.launch().envs(envVars);
41-
matlabLauncher.cmds(MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME + "/" + runnerScriptName, matlabCommand).stdout(listener);
41+
targetWorkspace = new FilePath(launcher.getChannel(),
42+
workspace.getRemote() + "/" + MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME);
4243

43-
// Copy runner .sh for linux platform in workspace.
44-
copyFileInWorkspace(MatlabBuilderConstants.SHELL_RUNNER_SCRIPT, runnerScriptName,
45-
targetWorkspace);
44+
// Determine whether we're on Mac on Linux
45+
ByteArrayOutputStream kernelStream = new ByteArrayOutputStream();
46+
launcher.launch()
47+
.cmds("uname")
48+
.masks(true)
49+
.stdout(kernelStream)
50+
.join();
51+
52+
String binaryName;
53+
String runnerName = uniqueName + "/run-matlab-command";
54+
if (kernelStream.toString("UTF-8").contains("Linux")) {
55+
binaryName = "glnxa64/run-matlab-command";
56+
} else {
57+
binaryName = "maci64/run-matlab-command";
58+
}
59+
60+
args.add(MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME + "/" + runnerName);
61+
args.add(matlabCommand);
62+
args.add(startupOpts.split(" "));
63+
64+
matlabLauncher = launcher.launch().envs(envVars).cmds(args).stdout(listener);
65+
66+
// Copy runner for linux platform in workspace.
67+
copyFileInWorkspace(binaryName, runnerName, targetWorkspace);
4668
} else {
47-
final String runnerScriptName = uniqueName + "\\run_matlab_command.bat";
48-
launcher = launcher.decorateByPrefix("cmd.exe", "/C");
49-
matlabLauncher = launcher.launch().envs(envVars);
50-
matlabLauncher.cmds(MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME + "\\" + runnerScriptName, "\"" + matlabCommand + "\"")
51-
.stdout(listener);
52-
// Copy runner.bat for Windows platform in workspace.
53-
copyFileInWorkspace(MatlabBuilderConstants.BAT_RUNNER_SCRIPT, runnerScriptName,
69+
targetWorkspace = new FilePath(launcher.getChannel(),
70+
workspace.getRemote() + "\\" + MatlabBuilderConstants.TEMP_MATLAB_FOLDER_NAME);
71+
72+
final String runnerName = uniqueName + "\\run-matlab-command.exe";
73+
74+
args.add(targetWorkspace.toString() + "\\" + runnerName, "\"" + matlabCommand + "\"");
75+
args.add(startupOpts.split(" "));
76+
77+
matlabLauncher = launcher.launch().envs(envVars).cmds(args).stdout(listener);
78+
79+
// Copy runner for Windows platform in workspace.
80+
copyFileInWorkspace("win64/run-matlab-command.exe", runnerName,
5481
targetWorkspace);
5582
}
5683
return matlabLauncher;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2022 The MathWorks, Inc.
4+
* Copyright 2022-2023 The MathWorks, Inc.
55
*
66
*/
77

@@ -20,10 +20,12 @@ public class MatlabBuildStepExecution extends SynchronousNonBlockingStepExecutio
2020
private static final long serialVersionUID = 4771831219402275744L;
2121

2222
private String tasks;
23+
private String startupOptions;
2324

24-
public MatlabBuildStepExecution(StepContext context, String tasks) {
25+
public MatlabBuildStepExecution(StepContext context, String tasks, String startupOptions) {
2526
super(context);
2627
this.tasks = tasks;
28+
this.startupOptions = startupOptions;
2729
}
2830

2931
private String getTasks() {
@@ -71,7 +73,7 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
7173

7274
try {
7375
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
74-
"cd('"+ uniqueTmpFolderPath.getRemote().replaceAll("'", "''") +"'); "+ uniqueBuildFile, uniqueTmpFldrName);
76+
"cd('"+ uniqueTmpFolderPath.getRemote().replaceAll("'", "''") +"'); "+ uniqueBuildFile, startupOptions, uniqueTmpFldrName);
7577
listener.getLogger()
7678
.println("#################### Starting command output ####################");
7779
return matlabLauncher.pwd(workspace).join();
@@ -84,11 +86,11 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
8486
}
8587
}
8688

87-
private void createMatlabScriptByName(FilePath uniqeTmpFolderPath, String uniqueScriptName, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
89+
private void createMatlabScriptByName(FilePath uniqueTmpFolderPath, String uniqueScriptName, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
8890

8991
// Create a new command runner script in the temp folder.
9092
final FilePath matlabBuildFile =
91-
new FilePath(uniqeTmpFolderPath, uniqueScriptName + ".m");
93+
new FilePath(uniqueTmpFolderPath, uniqueScriptName + ".m");
9294
final String tasks = getContext().get(EnvVars.class).expand(getTasks());
9395
String cmd = "buildtool";
9496

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ public class MatlabBuilderConstants {
2323
static final String STM_RESULTS = "'SimulinkTestResults'";
2424
static final String COBERTURA_CODE_COVERAGE = "'CoberturaCodeCoverage'";
2525
static final String COBERTURA_MODEL_COVERAGE = "'CoberturaModelCoverage'";
26-
27-
28-
// Matlab Runner files
29-
static final String BAT_RUNNER_SCRIPT = "run_matlab_command.bat";
30-
static final String SHELL_RUNNER_SCRIPT = "run_matlab_command.sh";
3126

3227
//Matlab Script generator package
3328
static final String MATLAB_SCRIPT_GENERATOR = "matlab-script-generator.zip";

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.mathworks.ci;
22

3+
/**
4+
* Copyright 2023 The MathWorks, Inc.
5+
*
6+
*/
7+
38
import java.io.IOException;
49
import org.jenkinsci.plugins.workflow.steps.StepContext;
510
import org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution;
@@ -15,11 +20,12 @@ public class MatlabCommandStepExecution extends SynchronousNonBlockingStepExecut
1520
private static final long serialVersionUID = 1957239693658914450L;
1621

1722
private String command;
23+
private String startupOptions;
1824

19-
20-
public MatlabCommandStepExecution(StepContext context, String command) {
25+
public MatlabCommandStepExecution(StepContext context, String command, String startupOptions) {
2126
super(context);
2227
this.command = command;
28+
this.startupOptions = startupOptions;
2329
}
2430

2531
private String getCommand() {
@@ -55,6 +61,7 @@ public void stop(Throwable cause) throws Exception {
5561

5662
private int execMatlabCommand(FilePath workspace, Launcher launcher,
5763
TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
64+
5865
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
5966
final String uniqueCommandFile =
6067
"command_" + getUniqueNameForRunnerFile().replaceAll("-", "_");
@@ -67,7 +74,7 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
6774

6875
try {
6976
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
70-
"cd('"+ uniqueTmpFolderPath.getRemote().replaceAll("'", "''") +"'); "+ uniqueCommandFile, uniqueTmpFldrName);
77+
"cd('"+ uniqueTmpFolderPath.getRemote().replaceAll("'", "''") +"'); "+ uniqueCommandFile, startupOptions, uniqueTmpFldrName);
7178
listener.getLogger()
7279
.println("#################### Starting command output ####################");
7380
return matlabLauncher.pwd(workspace).join();
@@ -80,11 +87,11 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
8087
}
8188
}
8289

83-
private void createMatlabScriptByName(FilePath uniqeTmpFolderPath, String uniqueScriptName, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
90+
private void createMatlabScriptByName(FilePath uniqueTmpFolderPath, String uniqueScriptName, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
8491

8592
// Create a new command runner script in the temp folder.
8693
final FilePath matlabCommandFile =
87-
new FilePath(uniqeTmpFolderPath, uniqueScriptName + ".m");
94+
new FilePath(uniqueTmpFolderPath, uniqueScriptName + ".m");
8895
final String cmd = getContext().get(EnvVars.class).expand(getCommand());
8996
final String matlabCommandFileContent =
9097
"cd '" + workspace.getRemote().replaceAll("'", "''") + "';\n" + cmd;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2020 The MathWorks, Inc.
4+
* Copyright 2020-2023 The MathWorks, Inc.
55
*
66
*/
77

@@ -20,11 +20,12 @@ public class MatlabRunTestsStepExecution extends SynchronousNonBlockingStepExecu
2020
private static final long serialVersionUID = 6704588180717665100L;
2121

2222
private String commandArgs;
23+
private String startupOptions;
2324

24-
25-
public MatlabRunTestsStepExecution(StepContext context, String commandArgs) {
25+
public MatlabRunTestsStepExecution(StepContext context, String commandArgs, String startupOptions) {
2626
super(context);
2727
this.commandArgs = commandArgs;
28+
this.startupOptions = startupOptions;
2829
}
2930

3031
private String getCommandArgs() {
@@ -73,7 +74,7 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
7374
cmdPrefix + matlabScriptName + ",delete('.matlab/"
7475
+ genScriptLocation.getBaseName() + "/" + matlabScriptName
7576
+ ".m'),runnerScript,rmdir(tmpDir,'s')",
76-
uniqueMatlabResourceFldr);
77+
startupOptions, uniqueMatlabResourceFldr);
7778

7879
// prepare temp folder by coping genscript package and writing runner script.
7980
prepareTmpFldr(genScriptLocation,

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2022 The MathWorks, Inc.
4+
* Copyright 2022-2023 The MathWorks, Inc.
55
*
66
*/
77

@@ -22,12 +22,14 @@
2222
import hudson.model.Computer;
2323
import hudson.tasks.BuildStepDescriptor;
2424
import hudson.tasks.Builder;
25+
import hudson.Util;
2526
import jenkins.tasks.SimpleBuildStep;
2627
import net.sf.json.JSONObject;
2728

2829
public class RunMatlabBuildBuilder extends Builder implements SimpleBuildStep, MatlabBuild {
2930
private int buildResult;
3031
private String tasks;
32+
private StartupOptions startupOptions;
3133

3234
@DataBoundConstructor
3335
public RunMatlabBuildBuilder() {}
@@ -38,9 +40,18 @@ public void setTasks(String tasks) {
3840
this.tasks = tasks;
3941
}
4042

43+
@DataBoundSetter
44+
public void setStartupOptions(StartupOptions startupOptions) {
45+
this.startupOptions = startupOptions;
46+
}
47+
4148
public String getTasks() {
4249
return this.tasks;
4350
}
51+
52+
public StartupOptions getStartupOptions() {
53+
return this.startupOptions;
54+
}
4455

4556
@Extension
4657
public static class RunMatlabBuildDescriptor extends BuildStepDescriptor<Builder> {
@@ -102,16 +113,16 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
102113
final String uniqueTmpFldrName = getUniqueNameForRunnerFile();
103114
final String uniqueBuildFile =
104115
"build_" + getUniqueNameForRunnerFile().replaceAll("-", "_");
105-
final FilePath uniqeTmpFolderPath =
116+
final FilePath uniqueTmpFolderPath =
106117
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
107118

108119
// Create MATLAB script
109-
createMatlabScriptByName(uniqeTmpFolderPath, uniqueBuildFile, workspace, listener, envVars);
120+
createMatlabScriptByName(uniqueTmpFolderPath, uniqueBuildFile, workspace, listener, envVars);
110121
ProcStarter matlabLauncher;
111-
122+
String options = getStartupOptions() == null ? "" : getStartupOptions().getOptions();
112123
try {
113124
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
114-
"cd('"+ uniqeTmpFolderPath.getRemote().replaceAll("'", "''") +"');"+ uniqueBuildFile, uniqueTmpFldrName);
125+
"cd('"+ uniqueTmpFolderPath.getRemote().replaceAll("'", "''") +"');"+ uniqueBuildFile, options, uniqueTmpFldrName);
115126

116127
listener.getLogger()
117128
.println("#################### Starting command output ####################");
@@ -122,17 +133,17 @@ private int execMatlabCommand(FilePath workspace, Launcher launcher,
122133
return 1;
123134
} finally {
124135
// Cleanup the tmp directory
125-
if (uniqeTmpFolderPath.exists()) {
126-
uniqeTmpFolderPath.deleteRecursive();
136+
if (uniqueTmpFolderPath.exists()) {
137+
uniqueTmpFolderPath.deleteRecursive();
127138
}
128139
}
129140
}
130141

131-
private void createMatlabScriptByName(FilePath uniqeTmpFolderPath, String uniqueScriptName, FilePath workspace, TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
142+
private void createMatlabScriptByName(FilePath uniqueTmpFolderPath, String uniqueScriptName, FilePath workspace, TaskListener listener, EnvVars envVars) throws IOException, InterruptedException {
132143

133144
// Create a new command runner script in the temp folder.
134145
final FilePath matlabCommandFile =
135-
new FilePath(uniqeTmpFolderPath, uniqueScriptName + ".m");
146+
new FilePath(uniqueTmpFolderPath, uniqueScriptName + ".m");
136147
final String tasks = envVars.expand(getTasks());
137148
String cmd = "buildtool";
138149

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2022 The MathWorks, Inc.
4+
* Copyright 2022-2023 The MathWorks, Inc.
55
*
66
*/
77

@@ -24,6 +24,7 @@
2424
public class RunMatlabBuildStep extends Step {
2525

2626
private String tasks;
27+
private String startupOptions;
2728

2829
@DataBoundConstructor
2930
public RunMatlabBuildStep() {
@@ -34,14 +35,23 @@ public String getTasks() {
3435
return Util.fixNull(tasks);
3536
}
3637

38+
public String getStartupOptions() {
39+
return Util.fixNull(startupOptions);
40+
}
41+
3742
@DataBoundSetter
3843
public void setTasks(String tasks) {
3944
this.tasks = tasks;
4045
}
4146

47+
@DataBoundSetter
48+
public void setStartupOptions(String startupOptions) {
49+
this.startupOptions = startupOptions;
50+
}
51+
4252
@Override
4353
public StepExecution start(StepContext context) throws Exception {
44-
return new MatlabBuildStepExecution(context, getTasks());
54+
return new MatlabBuildStepExecution(context, getTasks(), getStartupOptions());
4555
}
4656

4757
@Extension

0 commit comments

Comments
 (0)