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

Commit 575ba75

Browse files
authored
Merge pull request #140 from mathworks/hot_fixes_issue_132
Hot fixes issue 132
2 parents 4cb26c9 + ac1f9b2 commit 575ba75

File tree

2 files changed

+38
-36
lines changed

2 files changed

+38
-36
lines changed

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

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
*/
1010

1111
import java.io.IOException;
12-
import java.util.ArrayList;
13-
import java.util.Arrays;
14-
import java.util.HashMap;
15-
import java.util.List;
16-
import java.util.Map;
12+
import java.util.*;
1713
import javax.annotation.Nonnull;
1814
import org.kohsuke.stapler.DataBoundConstructor;
1915
import org.kohsuke.stapler.DataBoundSetter;
@@ -137,7 +133,12 @@ public Artifact getPdfReportArtifact() {
137133

138134
public String getPdfReportFilePath() {
139135
return this.getPdfReportArtifact().getFilePath();
140-
}
136+
}
137+
138+
private Artifact getArtifactObject(boolean isChecked, Artifact returnVal) {
139+
// If previously checked assign valid artifact object else NullArtifact.
140+
return (isChecked) ? returnVal : new NullArtifact();
141+
}
141142

142143
private void setEnv(EnvVars env) {
143144
this.env = env;
@@ -149,35 +150,35 @@ private EnvVars getEnv() {
149150

150151
// To retain Backward compatibility
151152
protected Object readResolve() {
152-
// Assign default values to new elements.
153-
this.pdfReportArtifact = new NullArtifact();
154-
this.tapArtifact = new NullArtifact();
155-
this.junitArtifact = new NullArtifact();
156-
this.coberturaArtifact = new NullArtifact();
157-
this.stmResultsArtifact = new NullArtifact();
158-
this.modelCoverageArtifact = new NullArtifact();
159-
160-
// Assign appropriate artifact type if it was selected earlier.
161-
if (pdfReportChkBx) {
162-
this.pdfReportArtifact = new PdfArtifact("matlabTestArtifacts/testreport.pdf");
163-
}
164-
if (tapChkBx) {
165-
this.tapArtifact = new TapArtifact("matlabTestArtifacts/taptestresults.tap");
166-
}
167-
if (junitChkBx) {
168-
this.junitArtifact = new JunitArtifact("matlabTestArtifacts/junittestresults.xml");
169-
}
170-
if (coberturaChkBx) {
171-
this.coberturaArtifact = new CoberturaArtifact("matlabTestArtifacts/cobertura.xml");
172-
}
173-
if (stmResultsChkBx) {
174-
this.stmResultsArtifact =
175-
new StmResultsArtifact("matlabTestArtifacts/simulinktestresults.mldatx");
176-
}
177-
if (modelCoverageChkBx) {
178-
this.modelCoverageArtifact =
179-
new ModelCovArtifact("matlabTestArtifacts/coberturamodelcoverage.xml");
180-
}
153+
154+
/*
155+
* Assign appropriate artifact objects if it was selected in release 2.0.0 or earlier.
156+
* If using a later plugin release, check if artifact objects were previously serialized.
157+
* */
158+
this.pdfReportArtifact = Optional.ofNullable(this.pdfReportArtifact).orElseGet(() ->
159+
this.getArtifactObject(pdfReportChkBx, new PdfArtifact("matlabTestArtifacts/testreport.pdf"))
160+
);
161+
162+
this.tapArtifact = Optional.ofNullable(this.tapArtifact).orElseGet(() ->
163+
this.getArtifactObject(tapChkBx, new TapArtifact("matlabTestArtifacts/taptestresults.tap"))
164+
);
165+
166+
this.junitArtifact = Optional.ofNullable(this.junitArtifact).orElseGet(() ->
167+
this.getArtifactObject(junitChkBx, new JunitArtifact("matlabTestArtifacts/junittestresults.xml"))
168+
);
169+
170+
this.coberturaArtifact = Optional.ofNullable(this.coberturaArtifact).orElseGet(() ->
171+
this.getArtifactObject(coberturaChkBx, new CoberturaArtifact("matlabTestArtifacts/cobertura.xml"))
172+
);
173+
174+
this.stmResultsArtifact = Optional.ofNullable(this.stmResultsArtifact).orElseGet(() ->
175+
this.getArtifactObject(stmResultsChkBx, new StmResultsArtifact("matlabTestArtifacts/simulinktestresults.mldatx"))
176+
);
177+
178+
this.modelCoverageArtifact = Optional.ofNullable(this.modelCoverageArtifact).orElseGet(() ->
179+
this.getArtifactObject(modelCoverageChkBx, new ModelCovArtifact("matlabTestArtifacts/coberturamodelcoverage.xml"))
180+
);
181+
181182
return this;
182183
}
183184

src/test/java/com/mathworks/ci/RunMatlabCommandBuilderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void verifyBuildFailureWhenMatlabCommandFails() throws Exception {
187187
*/
188188

189189
@Test
190-
public void verifyBuildFailureWhenMatlabCommandPasses() throws Exception {
190+
public void verifyBuildPassesWhenMatlabCommandPasses() throws Exception {
191191
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
192192
project.getBuildWrappersList().add(this.buildWrapper);
193193
RunMatlabCommandBuilderTester tester =
@@ -196,6 +196,7 @@ public void verifyBuildFailureWhenMatlabCommandPasses() throws Exception {
196196
project.getBuildersList().add(tester);
197197
FreeStyleBuild build = project.scheduleBuild2(0).get();
198198
jenkins.assertBuildStatus(Result.SUCCESS, build);
199+
199200
}
200201

201202
/*

0 commit comments

Comments
 (0)