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

Commit d73abe9

Browse files
committed
Address review feedback
1 parent 8fd9383 commit d73abe9

File tree

1 file changed

+39
-46
lines changed

1 file changed

+39
-46
lines changed

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

Lines changed: 39 additions & 46 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.apache.commons.collections.map.HashedMap;
1915
import org.apache.commons.io.FilenameUtils;
@@ -140,7 +136,16 @@ public Artifact getPdfReportArtifact() {
140136

141137
public String getPdfReportFilePath() {
142138
return this.getPdfReportArtifact().getFilePath();
143-
}
139+
}
140+
141+
private Artifact getArtifactObject(boolean isChecked, Artifact returnVal) {
142+
// If previously checked assign valid artifact object else NullArtifact.
143+
if (isChecked){
144+
return returnVal;
145+
}else{
146+
return new NullArtifact();
147+
}
148+
}
144149

145150
private void setEnv(EnvVars env) {
146151
this.env = env;
@@ -152,47 +157,35 @@ private EnvVars getEnv() {
152157

153158
// To retain Backward compatibility
154159
protected Object readResolve() {
155-
// Assign default values to new elements if not already deserialized from config.
156-
if (this.pdfReportArtifact == null) {
157-
this.pdfReportArtifact = new NullArtifact();
158-
}
159-
if (this.tapArtifact == null) {
160-
this.tapArtifact = new NullArtifact();
161-
}
162-
if (this.junitArtifact == null) {
163-
this.junitArtifact = new NullArtifact();
164-
}
165-
if (this.coberturaArtifact == null) {
166-
this.coberturaArtifact = new NullArtifact();
167-
}
168-
if (this.stmResultsArtifact == null) {
169-
this.stmResultsArtifact = new NullArtifact();
170-
}
171-
if (this.modelCoverageArtifact == null) {
172-
this.modelCoverageArtifact = new NullArtifact();
173-
}
174160

175-
// Assign appropriate artifact type if it was selected in release 2.0.0 or earlier.
176-
if (pdfReportChkBx) {
177-
this.pdfReportArtifact = new PdfArtifact("matlabTestArtifacts/testreport.pdf");
178-
}
179-
if (tapChkBx) {
180-
this.tapArtifact = new TapArtifact("matlabTestArtifacts/taptestresults.tap");
181-
}
182-
if (junitChkBx) {
183-
this.junitArtifact = new JunitArtifact("matlabTestArtifacts/junittestresults.xml");
184-
}
185-
if (coberturaChkBx) {
186-
this.coberturaArtifact = new CoberturaArtifact("matlabTestArtifacts/cobertura.xml");
187-
}
188-
if (stmResultsChkBx) {
189-
this.stmResultsArtifact =
190-
new StmResultsArtifact("matlabTestArtifacts/simulinktestresults.mldatx");
191-
}
192-
if (modelCoverageChkBx) {
193-
this.modelCoverageArtifact =
194-
new ModelCovArtifact("matlabTestArtifacts/coberturamodelcoverage.xml");
195-
}
161+
/*
162+
* Assign appropriate artifact objects if it was selected in release 2.0.0 or earlier.
163+
* If using a later plugin release, check if artifact objects were previously serialized.
164+
* */
165+
this.pdfReportArtifact = Optional.ofNullable(this.pdfReportArtifact).orElseGet(() ->
166+
this.getArtifactObject(pdfReportChkBx, new PdfArtifact("matlabTestArtifacts/testreport.pdf"))
167+
);
168+
169+
this.tapArtifact = Optional.ofNullable(this.tapArtifact).orElseGet(() ->
170+
this.getArtifactObject(tapChkBx, new TapArtifact("matlabTestArtifacts/taptestresults.tap"))
171+
);
172+
173+
this.junitArtifact = Optional.ofNullable(this.junitArtifact).orElseGet(() ->
174+
this.getArtifactObject(junitChkBx, new JunitArtifact("matlabTestArtifacts/junittestresults.xml"))
175+
);
176+
177+
this.coberturaArtifact = Optional.ofNullable(this.coberturaArtifact).orElseGet(() ->
178+
this.getArtifactObject(coberturaChkBx, new CoberturaArtifact("matlabTestArtifacts/cobertura.xml"))
179+
);
180+
181+
this.stmResultsArtifact = Optional.ofNullable(this.stmResultsArtifact).orElseGet(() ->
182+
this.getArtifactObject(stmResultsChkBx, new StmResultsArtifact("matlabTestArtifacts/simulinktestresults.mldatx"))
183+
);
184+
185+
this.modelCoverageArtifact = Optional.ofNullable(this.modelCoverageArtifact).orElseGet(() ->
186+
this.getArtifactObject(modelCoverageChkBx, new ModelCovArtifact("matlabTestArtifacts/coberturamodelcoverage.xml"))
187+
);
188+
196189
return this;
197190
}
198191

0 commit comments

Comments
 (0)