2020import org .kohsuke .stapler .DataBoundSetter ;
2121import org .kohsuke .stapler .QueryParameter ;
2222import org .kohsuke .stapler .StaplerRequest ;
23+ import com .mathworks .ci .UseMatlabVersionBuildWrapper .UseMatlabVersionDescriptor ;
2324import hudson .EnvVars ;
2425import hudson .Extension ;
2526import hudson .FilePath ;
3233import hudson .tasks .BuildStepDescriptor ;
3334import hudson .tasks .Builder ;
3435import hudson .util .FormValidation ;
36+ import jenkins .model .Jenkins ;
3537import jenkins .tasks .SimpleBuildStep ;
3638import net .sf .json .JSONObject ;
3739
@@ -163,7 +165,7 @@ public FormValidation doCheckCoberturaChkBx(@QueryParameter boolean coberturaChk
163165 if (coberturaChkBx ) {
164166 listOfCheckMethods .add (chkCoberturaSupport );
165167 }
166- return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods ,FormValidationUtil . getMatlabRoot ());
168+ return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods ,getMatlabRoot ());
167169 }
168170
169171 Function <String , FormValidation > chkCoberturaSupport = (String matlabRoot ) -> {
@@ -191,7 +193,7 @@ public FormValidation doCheckModelCoverageChkBx(@QueryParameter boolean modelCov
191193 if (modelCoverageChkBx ) {
192194 listOfCheckMethods .add (chkModelCoverageSupport );
193195 }
194- return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods ,FormValidationUtil . getMatlabRoot ());
196+ return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods ,getMatlabRoot ());
195197 }
196198
197199 Function <String , FormValidation > chkModelCoverageSupport = (String matlabRoot ) -> {
@@ -219,7 +221,7 @@ public FormValidation doCheckStmResultsChkBx(@QueryParameter boolean stmResultsC
219221 if (stmResultsChkBx ) {
220222 listOfCheckMethods .add (chkSTMResultsSupport );
221223 }
222- return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods ,FormValidationUtil . getMatlabRoot ());
224+ return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods ,getMatlabRoot ());
223225 }
224226
225227 Function <String , FormValidation > chkSTMResultsSupport = (String matlabRoot ) -> {
@@ -238,6 +240,17 @@ public FormValidation doCheckStmResultsChkBx(@QueryParameter boolean stmResultsC
238240 }
239241 return FormValidation .ok ();
240242 };
243+
244+ //Method to get the MatlabRoot value from Build wrapper class.
245+ public static String getMatlabRoot () {
246+ try {
247+ return Jenkins .getInstance ().getDescriptorByType (UseMatlabVersionDescriptor .class )
248+ .getMatlabRootFolder ();
249+ } catch (Exception e ) {
250+ // For any exception during getMatlabRootFolder() operation, return matlabRoot as NULL.
251+ return null ;
252+ }
253+ }
241254 }
242255
243256 @ Override
0 commit comments