Skip to content

Commit f112f21

Browse files
authored
Merge pull request mathworks#324 from mathworks/dev_main
Dev main
2 parents 3b4387c + ae30902 commit f112f21

22 files changed

+306
-197
lines changed

pom.xml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,49 @@
124124
<goal>wget</goal>
125125
</goals>
126126
<configuration>
127-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v1/glnxa64/run-matlab-command</url>
127+
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command</url>
128128
<unpack>false</unpack>
129129
<outputDirectory>${basedir}/src/main/resources/glnxa64</outputDirectory>
130130
<skipCache>true</skipCache>
131131
<overwrite>true</overwrite>
132132
</configuration>
133133
</execution>
134134
<execution>
135-
<id>get-matlab-runner-mac</id>
135+
<id>get-matlab-runner-maci</id>
136136
<phase>validate</phase>
137137
<goals>
138138
<goal>wget</goal>
139139
</goals>
140140
<configuration>
141-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v1/maci64/run-matlab-command</url>
141+
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maci64/run-matlab-command</url>
142142
<unpack>false</unpack>
143143
<outputDirectory>${basedir}/src/main/resources/maci64</outputDirectory>
144144
<skipCache>true</skipCache>
145145
<overwrite>true</overwrite>
146146
</configuration>
147147
</execution>
148+
<execution>
149+
<id>get-matlab-runner-maca</id>
150+
<phase>validate</phase>
151+
<goals>
152+
<goal>wget</goal>
153+
</goals>
154+
<configuration>
155+
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maca64/run-matlab-command</url>
156+
<unpack>false</unpack>
157+
<outputDirectory>${basedir}/src/main/resources/maca64</outputDirectory>
158+
<skipCache>true</skipCache>
159+
<overwrite>true</overwrite>
160+
</configuration>
161+
</execution>
148162
<execution>
149163
<id>get-matlab-runner-windows</id>
150164
<phase>validate</phase>
151165
<goals>
152166
<goal>wget</goal>
153167
</goals>
154168
<configuration>
155-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v1/win64/run-matlab-command.exe</url>
169+
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/win64/run-matlab-command.exe</url>
156170
<unpack>false</unpack>
157171
<outputDirectory>${basedir}/src/main/resources/win64</outputDirectory>
158172
<skipCache>true</skipCache>

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
public class BuildArtifactAction implements Action {
2323
private Run<?, ?> build;
24-
private FilePath workspace;
2524
private int totalCount;
2625
private int skipCount;
2726
private int failCount;
27+
private String actionID;
2828
private static final String ROOT_ELEMENT = "taskDetails";
29-
private static final String BUILD_ARTIFACT_FILE = "buildArtifact.json";
29+
private static final String BUILD_ARTIFACT_FILE = "buildArtifact";
3030

31-
public BuildArtifactAction(Run<?, ?> build, FilePath workspace) {
31+
public BuildArtifactAction(Run<?, ?> build, String actionID) {
3232
this.build = build;
33-
this.workspace = workspace;
33+
this.actionID = actionID;
3434

3535
// Setting the counts of task when Action is created.
3636
try{
@@ -42,6 +42,10 @@ public BuildArtifactAction(Run<?, ?> build, FilePath workspace) {
4242
}
4343
}
4444

45+
public String getActionID(){
46+
return (this.actionID == null) ? "" : this.actionID;
47+
}
48+
4549
@CheckForNull
4650
@Override
4751
public String getIconFileName() {
@@ -57,12 +61,19 @@ public String getDisplayName() {
5761
@CheckForNull
5862
@Override
5963
public String getUrlName() {
60-
return "buildresults";
64+
return (this.actionID == null) ? "buildresults" : "buildresults" + this.actionID ;
6165
}
6266

6367
public List<BuildArtifactData> getBuildArtifact() throws ParseException, InterruptedException, IOException {
6468
List<BuildArtifactData> artifactData = new ArrayList<BuildArtifactData>();
65-
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" + BUILD_ARTIFACT_FILE));
69+
FilePath fl;
70+
if(this.actionID == null){
71+
fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" +
72+
BUILD_ARTIFACT_FILE + ".json"));
73+
} else {
74+
fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" +
75+
BUILD_ARTIFACT_FILE + this.actionID + ".json"));
76+
}
6677
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) {
6778
Object obj = new JSONParser().parse(reader);
6879
JSONObject jo = (JSONObject) obj;
@@ -130,13 +141,17 @@ public void setOwner(Run owner) {
130141
this.build = owner;
131142
}
132143

133-
public FilePath getWorkspace() {
134-
return this.workspace;
135-
}
136144

137145
private void setCounts() throws InterruptedException, ParseException {
138146
List<BuildArtifactData> artifactData = new ArrayList<BuildArtifactData>();
139-
FilePath fl = new FilePath(new File(build.getRootDir(), BUILD_ARTIFACT_FILE));
147+
FilePath fl;
148+
if(this.actionID == null){
149+
fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" +
150+
BUILD_ARTIFACT_FILE + ".json"));
151+
} else {
152+
fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + "/" +
153+
BUILD_ARTIFACT_FILE + this.actionID + ".json"));
154+
}
140155
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(fl.toURI())), "UTF-8")) {
141156
Object obj = new JSONParser().parse(reader);
142157
JSONObject jo = (JSONObject) obj;

src/main/java/com/mathworks/ci/actions/RunMatlabBuildAction.java

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
import hudson.FilePath;
1212
import hudson.model.Run;
13-
import hudson.console.LineTransformationOutputStream;
1413

1514
import com.mathworks.ci.BuildArtifactAction;
1615
import com.mathworks.ci.BuildConsoleAnnotator;
1716
import com.mathworks.ci.MatlabExecutionException;
1817
import com.mathworks.ci.parameters.BuildActionParameters;
1918
import com.mathworks.ci.utilities.MatlabCommandRunner;
19+
import org.apache.commons.lang.RandomStringUtils;
2020

2121
public class RunMatlabBuildAction {
2222
private BuildActionParameters params;
@@ -29,9 +29,15 @@ public class RunMatlabBuildAction {
2929
"+ciplugins/+jenkins/BuildReportPlugin.m";
3030
private static String TASK_RUN_PROGRESS_PLUGIN =
3131
"+ciplugins/+jenkins/TaskRunProgressPlugin.m";
32+
private String actionID;
33+
34+
public String getActionID(){
35+
return this.actionID;
36+
}
3237

3338
public RunMatlabBuildAction(MatlabCommandRunner runner, BuildConsoleAnnotator annotator, BuildActionParameters params) {
3439
this.runner = runner;
40+
this.actionID = RandomStringUtils.randomAlphanumeric(8);
3541
this.annotator = annotator;
3642
this.params = params;
3743
}
@@ -49,11 +55,16 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
4955
runner.copyFileToTempFolder(DEFAULT_PLUGIN, DEFAULT_PLUGIN);
5056
runner.copyFileToTempFolder(BUILD_REPORT_PLUGIN, BUILD_REPORT_PLUGIN);
5157
runner.copyFileToTempFolder(TASK_RUN_PROGRESS_PLUGIN, TASK_RUN_PROGRESS_PLUGIN);
58+
5259

5360
// Set environment variable
5461
runner.addEnvironmentVariable(
5562
"MW_MATLAB_BUILDTOOL_DEFAULT_PLUGINS_FCN_OVERRIDE",
5663
"ciplugins.jenkins.getDefaultPlugins");
64+
runner.addEnvironmentVariable("MW_BUILD_PLUGIN_ACTION_ID",this.getActionID());
65+
runner.addEnvironmentVariable(
66+
"MW_MATLAB_TEMP_FOLDER",
67+
runner.getTempFolder().toString());
5768

5869
// Redirect output to the build annotator
5970
runner.redirectStdOut(annotator);
@@ -81,21 +92,33 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
8192
throw(e);
8293
} finally {
8394
annotator.forceEol();
84-
}
8595

86-
// Handle build result
87-
Run<?,?> build = this.params.getBuild();
88-
FilePath jsonFile = new FilePath(params.getWorkspace(), ".matlab" + File.separator + "buildArtifact.json");
89-
if (jsonFile.exists()) {
90-
FilePath rootLocation = new FilePath(
91-
new File(
92-
build.getRootDir()
93-
.getAbsolutePath()
94-
+ File.separator
95-
+ "buildArtifact.json"));
96-
jsonFile.copyTo(rootLocation);
97-
jsonFile.delete();
98-
build.addAction(new BuildArtifactAction(build, this.params.getWorkspace()));
96+
try {
97+
// Handle build result
98+
Run<?,?> build = this.params.getBuild();
99+
FilePath jsonFile = new FilePath(runner.getTempFolder(), "buildArtifact.json");
100+
if (jsonFile.exists()) {
101+
FilePath rootLocation = new FilePath(
102+
new File(
103+
build.getRootDir().getAbsolutePath(),
104+
"buildArtifact" + this.getActionID() + ".json")
105+
);
106+
jsonFile.copyTo(rootLocation);
107+
jsonFile.delete();
108+
build.addAction(new BuildArtifactAction(build, this.getActionID()));
109+
}
110+
} catch (Exception e) {
111+
// Don't want to override more important error
112+
// thrown in catch block
113+
System.err.println(e.toString());
114+
} finally {
115+
try {
116+
this.runner.removeTempFolder();
117+
} catch (Exception e) {
118+
System.err.println(e.toString());
119+
}
120+
}
99121
}
122+
100123
}
101-
}
124+
}

src/main/java/com/mathworks/ci/actions/RunMatlabCommandAction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
3131
this.params.getTaskListener().getLogger()
3232
.println(e.getMessage());
3333
throw(e);
34-
}
34+
} finally {
35+
try {
36+
this.runner.removeTempFolder();
37+
} catch (Exception e) {
38+
// Don't want to override more important error
39+
// thrown in catch block
40+
System.err.println(e.toString());
41+
}
42+
}
3543
}
3644
}

src/main/java/com/mathworks/ci/actions/RunMatlabTestsAction.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ public void run() throws IOException, InterruptedException, MatlabExecutionExcep
5050
.getLogger()
5151
.println(e.getMessage());
5252
throw(e);
53-
}
53+
} finally {
54+
try {
55+
this.runner.removeTempFolder();
56+
} catch (Exception e) {
57+
// Don't want to override more important error
58+
// thrown in catch block
59+
System.err.println(e.toString());
60+
}
61+
}
5462
}
5563

5664
private String singleQuotify(String in) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,25 @@ public static void addAliases() {
311311
Items.XSTREAM2.addCompatibilityAlias("com.mathworks.ci.RunMatlabTestsBuilder", RunMatlabTestsBuilder.class);
312312
Items.XSTREAM2.addCompatibilityAlias("com.mathworks.ci.SourceFolderPaths", SourceFolderPaths.class);
313313
Items.XSTREAM2.addCompatibilityAlias("com.mathworks.ci.TestFolders", TestFolders.class);
314+
315+
Items.XSTREAM2.addCompatibilityAlias(
316+
"com.mathworks.ci.RunMatlabTestsBuilder$PdfArtifact",
317+
RunMatlabTestsBuilder.PdfArtifact.class);
318+
Items.XSTREAM2.addCompatibilityAlias(
319+
"com.mathworks.ci.RunMatlabTestsBuilder$JunitArtifact",
320+
RunMatlabTestsBuilder.JunitArtifact.class);
321+
Items.XSTREAM2.addCompatibilityAlias(
322+
"com.mathworks.ci.RunMatlabTestsBuilder$TapArtifact",
323+
RunMatlabTestsBuilder.TapArtifact.class);
324+
Items.XSTREAM2.addCompatibilityAlias(
325+
"com.mathworks.ci.RunMatlabTestsBuilder$CoberturaArtifact",
326+
RunMatlabTestsBuilder.CoberturaArtifact.class);
327+
Items.XSTREAM2.addCompatibilityAlias(
328+
"com.mathworks.ci.RunMatlabTestsBuilder$StmResultsArtifact",
329+
RunMatlabTestsBuilder.StmResultsArtifact.class);
330+
Items.XSTREAM2.addCompatibilityAlias(
331+
"com.mathworks.ci.RunMatlabTestsBuilder$ModelCovArtifact",
332+
RunMatlabTestsBuilder.ModelCovArtifact.class);
314333
}
315334

316335
// Overridden Method used to show the text under build dropdown

src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*
66
*/
77

8-
import java.io.File;
98
import java.io.IOException;
109
import java.io.InputStream;
1110
import java.io.OutputStream;
@@ -19,6 +18,7 @@
1918
import hudson.Launcher;
2019
import hudson.Launcher.ProcStarter;
2120
import hudson.model.Computer;
21+
import hudson.slaves.WorkspaceList;
2222
import hudson.util.ArgumentListBuilder;
2323

2424
import com.mathworks.ci.Utilities;
@@ -36,31 +36,19 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In
3636
this.params = params;
3737
this.additionalEnvVars = new HashMap<String,String>();
3838

39+
FilePath workspace = params.getWorkspace();
40+
3941
// Handle case where workspace doesn't exist
40-
if (!params.getWorkspace().exists()) {
41-
params.getWorkspace().mkdirs();
42+
if (!workspace.exists()) {
43+
workspace.mkdirs();
4244
}
4345

4446
// Create MATLAB folder
45-
FilePath matlabFolder = new FilePath(
46-
params.getLauncher().getChannel(), params.getWorkspace().getRemote()
47-
+ File.separator
48-
+ ".matlab");
49-
matlabFolder.mkdirs();
47+
FilePath tmpRoot = WorkspaceList.tempDir(workspace);
48+
tmpRoot.mkdirs();
5049

5150
// Create temp folder
52-
this.tempFolder = matlabFolder.createTempDir("tempDir", null);
53-
54-
// If we hit an error during shutdown while cleaning up
55-
// there's not too much that we can do.
56-
Runtime.getRuntime().addShutdownHook(
57-
new Thread(() -> {
58-
try {
59-
tempFolder.deleteRecursive();
60-
} catch(Exception e) {
61-
System.err.println(e.toString());
62-
}
63-
}));
51+
this.tempFolder = tmpRoot.createTempDir("matlab", null);
6452
}
6553

6654
/**
@@ -69,7 +57,6 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In
6957
* @param command The command to run
7058
*/
7159
public void runMatlabCommand(String command) throws IOException, InterruptedException, MatlabExecutionException {
72-
7360
this.params.getTaskListener().getLogger()
7461
.println("\n#################### Starting command output ####################");
7562

@@ -159,6 +146,12 @@ public FilePath getTempFolder() {
159146
return tempFolder;
160147
}
161148

149+
public void removeTempFolder() throws IOException, InterruptedException {
150+
if (tempFolder.exists()) {
151+
tempFolder.deleteRecursive();
152+
}
153+
}
154+
162155
/**
163156
* Creates a file with the specified content in the temporary folder.
164157
*
@@ -193,15 +186,24 @@ protected FilePath prepareRunnerExecutable() throws IOException, InterruptedExce
193186
if (launcher.isUnix()) {
194187
// Run uname to check if we're on Linux
195188
ByteArrayOutputStream kernelStream = new ByteArrayOutputStream();
189+
190+
ArgumentListBuilder args = new ArgumentListBuilder();
191+
args.add("uname");
192+
args.add("-s");
193+
args.add("-m");
194+
196195
launcher.launch()
197-
.cmds("uname")
198-
.masks(true)
196+
.cmds(args)
197+
.masks(true, true, true)
199198
.stdout(kernelStream)
200199
.join();
201200

202201
String runnerSource;
203-
if (kernelStream.toString("UTF-8").contains("Linux")) {
202+
String kernelArch = kernelStream.toString("UTF-8");
203+
if (kernelArch.contains("Linux")) {
204204
runnerSource = "glnxa64/run-matlab-command";
205+
} else if (kernelArch.contains("arm64")) {
206+
runnerSource = "maca64/run-matlab-command";
205207
} else {
206208
runnerSource = "maci64/run-matlab-command";
207209
}

0 commit comments

Comments
 (0)