99 */
1010
1111import 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 .*;
1713import javax .annotation .Nonnull ;
1814import org .kohsuke .stapler .DataBoundConstructor ;
1915import 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
0 commit comments