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 .apache .commons .collections .map .HashedMap ;
1915import  org .apache .commons .io .FilenameUtils ;
@@ -140,7 +136,12 @@ 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+         return  (isChecked ) ? returnVal  : new  NullArtifact ();
144+     }
144145
145146    private  void  setEnv (EnvVars  env ) {
146147        this .env  = env ;
@@ -152,35 +153,35 @@ private EnvVars getEnv() {
152153
153154    // To retain Backward compatibility 
154155    protected  Object  readResolve () {
155-          // Assign default values to new elements. 
156-         this . pdfReportArtifact  =  new   NullArtifact (); 
157-         this . tapArtifact  =  new   NullArtifact (); 
158-         this . junitArtifact  =  new   NullArtifact (); 
159-         this . coberturaArtifact  =  new   NullArtifact (); 
160-         this .stmResultsArtifact  = new   NullArtifact (); 
161-         this .modelCoverageArtifact  =  new  NullArtifact (); 
162- 
163-          // Assign appropriate artifact type if it was selected earlier. 
164-         if  ( pdfReportChkBx ) { 
165-             this .pdfReportArtifact  =  new  PdfArtifact ("matlabTestArtifacts/testreport.pdf"  ); 
166-         } 
167-          if  ( tapChkBx ) { 
168-              this .tapArtifact  = new   TapArtifact ( "matlabTestArtifacts/taptestresults.tap" ); 
169-         } 
170-         if  ( junitChkBx ) { 
171-              this . junitArtifact  =  new   JunitArtifact ( "matlabTestArtifacts/junittestresults.xml" ); 
172-         } 
173-         if   (coberturaChkBx ) { 
174-              this . coberturaArtifact  =  new   CoberturaArtifact ( "matlabTestArtifacts/cobertura.xml" );
175-         } 
176-         if  ( stmResultsChkBx ) { 
177-             this .stmResultsArtifact  = 
178-                      new   StmResultsArtifact ( "matlabTestArtifacts/simulinktestresults.mldatx" );
179-         } 
180-         if  ( modelCoverageChkBx ) { 
181-             this .modelCoverageArtifact  = 
182-                      new   ModelCovArtifact ( "matlabTestArtifacts/coberturamodelcoverage.xml" );
183-         } 
156+ 
157+         /* 
158+         * Assign appropriate artifact objects if it was selected in release 2.0.0 or earlier.  
159+         * If using a later plugin release, check if artifact objects were previously serialized.  
160+         * */  
161+         this .pdfReportArtifact  = Optional . ofNullable ( this . pdfReportArtifact ). orElseGet (() -> 
162+                  this .getArtifactObject ( pdfReportChkBx ,  new  PdfArtifact ( "matlabTestArtifacts/testreport.pdf" )) 
163+         ); 
164+ 
165+         this . tapArtifact  =  Optional . ofNullable ( this . tapArtifact ). orElseGet (() -> 
166+                  this .getArtifactObject ( tapChkBx ,  new  TapArtifact ("matlabTestArtifacts/taptestresults.tap"  )) 
167+         ); 
168+ 
169+         this .junitArtifact  = Optional . ofNullable ( this . junitArtifact ). orElseGet (() -> 
170+                  this . getArtifactObject ( junitChkBx ,  new   JunitArtifact ( "matlabTestArtifacts/junittestresults.xml" )) 
171+         ); 
172+ 
173+         this . coberturaArtifact  =  Optional . ofNullable ( this . coberturaArtifact ). orElseGet (() -> 
174+                  this . getArtifactObject (coberturaChkBx ,  new   CoberturaArtifact ( "matlabTestArtifacts/cobertura.xml" )) 
175+         );
176+ 
177+         this . stmResultsArtifact  =  Optional . ofNullable ( this . stmResultsArtifact ). orElseGet (() -> 
178+                  this .getArtifactObject ( stmResultsChkBx ,  new   StmResultsArtifact ( "matlabTestArtifacts/simulinktestresults.mldatx" )) 
179+         );
180+ 
181+         this . modelCoverageArtifact  =  Optional . ofNullable ( this . modelCoverageArtifact ). orElseGet (() -> 
182+                  this .getArtifactObject ( modelCoverageChkBx ,  new   ModelCovArtifact ( "matlabTestArtifacts/coberturamodelcoverage.xml" )) 
183+         );
184+ 
184185        return  this ;
185186    }
186187
0 commit comments