This repository was archived by the owner on Mar 27, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed
src/main/java/com/mathworks/ci Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 1616public class FormValidationUtil {
1717
1818 public static FormValidation getFirstErrorOrWarning (
19- List <Function <String , FormValidation >> validations ) {
19+ List <Function <String , FormValidation >> validations , String validationArg ) {
2020 if (validations == null || validations .isEmpty ())
2121 return FormValidation .ok ();
2222 try {
23- String matlabRoot = Jenkins .getInstance ()
24- .getDescriptorByType (UseMatlabVersionDescriptor .class ).getMatlabRootFolder ();
2523 for (Function <String , FormValidation > val : validations ) {
26- FormValidation validationResult = val .apply (matlabRoot );
24+ FormValidation validationResult = val .apply (validationArg );
2725 if (validationResult .kind .compareTo (Kind .ERROR ) == 0
2826 || validationResult .kind .compareTo (Kind .WARNING ) == 0 ) {
2927 return validationResult ;
@@ -34,4 +32,16 @@ public static FormValidation getFirstErrorOrWarning(
3432 }
3533 return FormValidation .ok ();
3634 }
35+
36+ //Method to get the MATLAB root from build wrapper class.
37+
38+ public static String getMatlabRoot () {
39+ try {
40+ return Jenkins .getInstance ().getDescriptorByType (UseMatlabVersionDescriptor .class )
41+ .getMatlabRootFolder ();
42+ } catch (Exception e ) {
43+ // For any exception during getMatlabRootFolder() operation, return matlabRoot as NULL.
44+ return null ;
45+ }
46+ }
3747}
Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ public FormValidation doCheckCoberturaChkBx(@QueryParameter boolean coberturaChk
163163 if (coberturaChkBx ) {
164164 listOfCheckMethods .add (chkCoberturaSupport );
165165 }
166- return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods );
166+ return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods , FormValidationUtil . getMatlabRoot () );
167167 }
168168
169169 Function <String , FormValidation > chkCoberturaSupport = (String matlabRoot ) -> {
@@ -191,7 +191,7 @@ public FormValidation doCheckModelCoverageChkBx(@QueryParameter boolean modelCov
191191 if (modelCoverageChkBx ) {
192192 listOfCheckMethods .add (chkModelCoverageSupport );
193193 }
194- return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods );
194+ return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods , FormValidationUtil . getMatlabRoot () );
195195 }
196196
197197 Function <String , FormValidation > chkModelCoverageSupport = (String matlabRoot ) -> {
@@ -219,7 +219,7 @@ public FormValidation doCheckStmResultsChkBx(@QueryParameter boolean stmResultsC
219219 if (stmResultsChkBx ) {
220220 listOfCheckMethods .add (chkSTMResultsSupport );
221221 }
222- return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods );
222+ return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods , FormValidationUtil . getMatlabRoot () );
223223 }
224224
225225 Function <String , FormValidation > chkSTMResultsSupport = (String matlabRoot ) -> {
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ public FormValidation doCheckMatlabRootFolder(@QueryParameter String matlabRootF
9393 listOfCheckMethods .add (chkMatlabEmpty );
9494 listOfCheckMethods .add (chkMatlabSupportsRunTests );
9595
96- return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods );
96+ return FormValidationUtil .getFirstErrorOrWarning (listOfCheckMethods , matlabRootFolder );
9797 }
9898
9999 Function <String , FormValidation > chkMatlabEmpty = (String matlabRootFolder ) -> {
You can’t perform that action at this time.
0 commit comments