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

Commit 254f0e8

Browse files
committed
update as per review comments
1 parent 49cbe24 commit 254f0e8

File tree

19 files changed

+517
-146
lines changed

19 files changed

+517
-146
lines changed

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

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

33
/*
4-
* Copyright 2019-2024 The MathWorks, Inc.
4+
* Copyright 2019-2025 The MathWorks, Inc.
55
*/
66

77
public class MatlabBuilderConstants {
@@ -45,12 +45,6 @@ public class MatlabBuilderConstants {
4545
public static final String TEST_RESULTS_VIEW_ARTIFACT = "matlabTestResults";
4646
public static final String BUILD_ARTIFACT = "buildArtifact";
4747

48-
// MATLAB Test Result Statuses
49-
public static final String PASSED = "Passed";
50-
public static final String FAILED = "Failed";
51-
public static final String INCOMPLETE = "Incomplete";
52-
public static final String NOT_RUN = "NotRun";
53-
5448
public static final String NEW_LINE = System.getProperty("line.separator");
5549

5650
// MATLAB Runner Script

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

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

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2025, The MathWorks Inc.
55
*
66
* Class to store MATLAB test case information
77
*
@@ -12,38 +12,22 @@
1212

1313
import org.apache.commons.lang.RandomStringUtils;
1414

15+
import com.mathworks.ci.TestResultsViewAction.TestStatus;
16+
1517
public class MatlabTestCase {
1618
private String name;
1719
private List<MatlabTestDiagnostics> diagnostics;
18-
private boolean passed;
19-
private boolean failed;
20-
private boolean incomplete;
21-
private String status;
20+
private TestStatus status;
2221
private Double duration;
2322
private String id;
2423

25-
public MatlabTestCase() {
26-
this.name = "";
24+
public MatlabTestCase(String name) {
25+
this.name = name;
2726
this.diagnostics = new ArrayList<MatlabTestDiagnostics>();
28-
this.passed = false;
29-
this.failed = false;
30-
this.incomplete = false;
31-
this.status = MatlabBuilderConstants.NOT_RUN;
27+
this.status = TestStatus.NOT_RUN;
3228
this.duration = 0.0;
3329
this.id = RandomStringUtils.randomAlphanumeric(8);
3430
}
35-
36-
public void updateStatus() {
37-
if (this.failed){
38-
this.status = MatlabBuilderConstants.FAILED;
39-
}
40-
else if (this.incomplete) {
41-
this.status = MatlabBuilderConstants.INCOMPLETE;
42-
}
43-
else if(this.passed) {
44-
this.status = MatlabBuilderConstants.PASSED;
45-
}
46-
}
4731

4832
public String getName() {
4933
return this.name;
@@ -61,35 +45,11 @@ public void setDiagnostics(List<MatlabTestDiagnostics> diagnostics) {
6145
this.diagnostics = diagnostics;
6246
}
6347

64-
public boolean getPassed() {
65-
return this.passed;
66-
}
67-
68-
public void setPassed(boolean passed) {
69-
this.passed = passed;
70-
}
71-
72-
public boolean getFailed() {
73-
return this.failed;
74-
}
75-
76-
public void setFailed(boolean failed) {
77-
this.failed = failed;
78-
}
79-
80-
public boolean getIncomplete() {
81-
return this.incomplete;
82-
}
83-
84-
public void setIncomplete(boolean incomplete) {
85-
this.incomplete = incomplete;
86-
}
87-
88-
public String getStatus() {
48+
public TestStatus getStatus() {
8949
return this.status;
9050
}
9151

92-
public void setStatus(String status) {
52+
public void setStatus(TestStatus status) {
9353
this.status = status;
9454
}
9555

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

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

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2025, The MathWorks Inc.
55
*
66
* Class to store MATLAB test diagnostics information
77
*

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

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

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2025, The MathWorks Inc.
55
*
66
* Class to store MATLAB test file information
77
*
@@ -12,19 +12,21 @@
1212

1313
import org.apache.commons.lang.RandomStringUtils;
1414

15+
import com.mathworks.ci.TestResultsViewAction.TestStatus;
16+
1517
public class MatlabTestFile {
1618
private String path;
1719
private String name;
1820
private Double duration;
19-
private String status;
21+
private TestStatus status;
2022
private List<MatlabTestCase> matlabTestCases;
2123
private String id;
2224

23-
public MatlabTestFile() {
25+
public MatlabTestFile(String name) {
26+
this.name = name;
2427
this.path = "";
25-
this.name = "";
2628
this.duration = 0.0;
27-
this.status = MatlabBuilderConstants.NOT_RUN;
29+
this.status = TestStatus.NOT_RUN;
2830
this.matlabTestCases = new ArrayList<MatlabTestCase>();
2931
this.id = RandomStringUtils.randomAlphanumeric(8);
3032
}
@@ -34,21 +36,27 @@ public void incrementDuration(Double matlabTestCaseDuration) {
3436
}
3537

3638
public void updateStatus(MatlabTestCase matlabTestCase) {
37-
if (!this.status.equals(MatlabBuilderConstants.FAILED)) {
38-
if (matlabTestCase.getFailed()){
39-
this.status = MatlabBuilderConstants.FAILED;
39+
if (!this.status.equals(TestStatus.FAILED)) {
40+
if (matlabTestCase.getStatus().equals(TestStatus.FAILED)){
41+
this.status = TestStatus.FAILED;
4042
}
41-
else if (!this.status.equals(MatlabBuilderConstants.INCOMPLETE)){
42-
if (matlabTestCase.getIncomplete()){
43-
this.status = MatlabBuilderConstants.INCOMPLETE;
43+
else if (!this.status.equals(TestStatus.INCOMPLETE)){
44+
if (matlabTestCase.getStatus().equals(TestStatus.INCOMPLETE)){
45+
this.status = TestStatus.INCOMPLETE;
4446
}
45-
else if (matlabTestCase.getPassed()){
46-
this.status = MatlabBuilderConstants.PASSED;
47+
else if (matlabTestCase.getStatus().equals(TestStatus.PASSED)){
48+
this.status = TestStatus.PASSED;
4749
}
4850
}
4951
}
5052
}
5153

54+
public void addTestCase(MatlabTestCase matlabTestCase){
55+
this.incrementDuration(matlabTestCase.getDuration());
56+
this.updateStatus(matlabTestCase);
57+
this.getMatlabTestCases().add(matlabTestCase);
58+
}
59+
5260
public String getPath() {
5361
return this.path;
5462
}
@@ -73,11 +81,11 @@ public void setDuration(Double duration) {
7381
this.duration = duration;
7482
}
7583

76-
public String getStatus() {
84+
public TestStatus getStatus() {
7785
return this.status;
7886
}
7987

80-
public void setStatus(String status) {
88+
public void setStatus(TestStatus status) {
8189
this.status = status;
8290
}
8391

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

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

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2025, The MathWorks Inc.
55
*
66
*/
77

@@ -40,6 +40,13 @@ public class TestResultsViewAction implements RunAction2 {
4040
private int incompleteCount;
4141
private int notRunCount;
4242

43+
public enum TestStatus {
44+
PASSED,
45+
FAILED,
46+
INCOMPLETE,
47+
NOT_RUN
48+
}
49+
4350
public TestResultsViewAction(Run<?, ?> build, FilePath workspace, String actionID) throws InterruptedException, IOException {
4451
this.build = build;
4552
this.workspace = workspace;
@@ -63,7 +70,7 @@ public TestResultsViewAction(Run<?, ?> build, FilePath workspace, String actionI
6370

6471
public List<List<MatlabTestFile>> getTestResults() throws ParseException, InterruptedException, IOException {
6572
List<List<MatlabTestFile>> testResults = new ArrayList<>();
66-
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath() + File.separator + MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json"));
73+
FilePath fl = new FilePath(new File(build.getRootDir().getAbsolutePath(), MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT + this.actionID + ".json"));
6774
try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(Paths.get(fl.toURI())), StandardCharsets.UTF_8)) {
6875
this.totalCount = 0;
6976
this.passedCount = 0;
@@ -96,8 +103,7 @@ else if(jsonTestSessionResults instanceof JSONObject) {
96103

97104
testResults.add(testSessionResults);
98105
}
99-
}
100-
catch (Exception e) {
106+
} catch (Exception e) {
101107
throw new IOException(e.getLocalizedMessage());
102108
}
103109

@@ -116,8 +122,7 @@ private void getTestSessionResults(List<MatlabTestFile> testSessionResults, JSON
116122
// Check if test's file was known or not
117123
MatlabTestFile matlabTestFile = map.get(baseFolder + File.separator + matlabTestFileName);
118124
if(matlabTestFile == null) {
119-
matlabTestFile = new MatlabTestFile();
120-
matlabTestFile.setName(matlabTestFileName);
125+
matlabTestFile = new MatlabTestFile(matlabTestFileName);
121126

122127
map.put(baseFolder + File.separator + matlabTestFileName, matlabTestFile);
123128
testSessionResults.add(matlabTestFile);
@@ -130,17 +135,22 @@ private void getTestSessionResults(List<MatlabTestFile> testSessionResults, JSON
130135

131136
matlabTestFile.setPath(this.workspace.getName() + File.separator + relPath.toString());
132137

133-
MatlabTestCase matlabTestCase = new MatlabTestCase();
134-
matlabTestCase.setName(matlabTestCaseName);
135-
matlabTestCase.setPassed((boolean) matlabTestCaseResult.get("Passed"));
136-
matlabTestCase.setFailed((boolean) matlabTestCaseResult.get("Failed"));
137-
matlabTestCase.setIncomplete((boolean) matlabTestCaseResult.get("Incomplete"));
138+
MatlabTestCase matlabTestCase = new MatlabTestCase(matlabTestCaseName);
138139
if (matlabTestCaseResult.get("Duration") instanceof Long) {
139140
matlabTestCase.setDuration(((Long) matlabTestCaseResult.get("Duration")).doubleValue());
140141
} else if (matlabTestCaseResult.get("Duration") instanceof Double) {
141142
matlabTestCase.setDuration(((Double) matlabTestCaseResult.get("Duration")));
142143
}
143-
matlabTestCase.updateStatus();
144+
145+
if ((boolean) matlabTestCaseResult.get("Failed")){
146+
matlabTestCase.setStatus(TestStatus.FAILED);
147+
}
148+
else if ((boolean) matlabTestCaseResult.get("Incomplete")) {
149+
matlabTestCase.setStatus(TestStatus.INCOMPLETE);
150+
}
151+
else if((boolean) matlabTestCaseResult.get("Passed")) {
152+
matlabTestCase.setStatus(TestStatus.PASSED);
153+
}
144154

145155
Object diagnostics = ((JSONObject)matlabTestCaseResult.get("Details")).get("DiagnosticRecord");
146156
if(diagnostics instanceof JSONObject) {
@@ -161,24 +171,22 @@ else if(diagnostics instanceof JSONArray && ((JSONArray)diagnostics).size() > 0)
161171
}
162172
}
163173

164-
matlabTestFile.incrementDuration(matlabTestCase.getDuration());
165-
matlabTestFile.updateStatus(matlabTestCase);
166-
matlabTestFile.getMatlabTestCases().add(matlabTestCase);
174+
matlabTestFile.addTestCase(matlabTestCase);
167175
updateCount(matlabTestCase);
168176
}
169177

170178
private void updateCount(MatlabTestCase matlabTestCase) {
171179
this.totalCount += 1;
172-
if (matlabTestCase.getStatus().equals(MatlabBuilderConstants.NOT_RUN)) {
180+
if (matlabTestCase.getStatus().equals(TestStatus.NOT_RUN)) {
173181
this.notRunCount += 1;
174182
}
175-
else if (matlabTestCase.getPassed()) {
183+
else if (matlabTestCase.getStatus().equals(TestStatus.PASSED)) {
176184
this.passedCount += 1;
177185
}
178-
else if (matlabTestCase.getFailed()) {
186+
else if (matlabTestCase.getStatus().equals(TestStatus.FAILED)) {
179187
this.failedCount += 1;
180188
}
181-
else if (matlabTestCase.getIncomplete()) {
189+
else if (matlabTestCase.getStatus().equals(TestStatus.INCOMPLETE)) {
182190
this.incompleteCount += 1;
183191
}
184192
}

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

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

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2024-25, The MathWorks Inc.
55
*/
66

77
import com.mathworks.ci.BuildArtifactAction;
@@ -94,6 +94,15 @@ private void moveJsonArtifactToBuildRoot(MatlabActionParameters params, String a
9494
file.copyTo(rootLocation);
9595
file.delete();
9696

97+
switch (artifactBaseName) {
98+
case MatlabBuilderConstants.BUILD_ARTIFACT:
99+
build.addAction(new BuildArtifactAction(build, this.getActionID()));
100+
break;
101+
case MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT:
102+
build.addAction(new TestResultsViewAction(build, workspace, this.getActionID()));
103+
break;
104+
}
105+
97106
if(artifactBaseName.equals(MatlabBuilderConstants.BUILD_ARTIFACT)) {
98107
build.addAction(new BuildArtifactAction(build, this.getActionID()));
99108
} else if(artifactBaseName.equals(MatlabBuilderConstants.TEST_RESULTS_VIEW_ARTIFACT)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci.actions;
22

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2024-25, The MathWorks Inc.
55
*/
66

77
import java.io.IOException;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci.actions;
22

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2024-25, The MathWorks Inc.
55
*/
66

77
import java.io.IOException;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci.actions;
22

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2024-25, The MathWorks Inc.
55
*/
66

77
import java.io.IOException;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci.utilities;
22

33
/**
4-
* Copyright 2024, The MathWorks Inc.
4+
* Copyright 2024-25, The MathWorks Inc.
55
*/
66

77
import java.io.IOException;

0 commit comments

Comments
 (0)