diff --git a/src/main/java/com/mathworks/ci/FormValidationUtil.java b/src/main/java/com/mathworks/ci/FormValidationUtil.java index 5fa06a78..1a29a8a4 100644 --- a/src/main/java/com/mathworks/ci/FormValidationUtil.java +++ b/src/main/java/com/mathworks/ci/FormValidationUtil.java @@ -8,10 +8,8 @@ */ import java.util.List; import java.util.function.Function; -import com.mathworks.ci.UseMatlabVersionBuildWrapper.UseMatlabVersionDescriptor; import hudson.util.FormValidation; import hudson.util.FormValidation.Kind; -import jenkins.model.Jenkins; public class FormValidationUtil { @@ -32,16 +30,4 @@ public static FormValidation getFirstErrorOrWarning( } return FormValidation.ok(); } - - //Method to get the MATLAB root from build wrapper class. - - public static String getMatlabRoot() { - try { - return Jenkins.getInstance().getDescriptorByType(UseMatlabVersionDescriptor.class) - .getMatlabRootFolder(); - } catch (Exception e) { - // For any exception during getMatlabRootFolder() operation, return matlabRoot as NULL. - return null; - } - } } diff --git a/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java b/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java index 8466c693..f9523d95 100644 --- a/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java +++ b/src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java @@ -20,6 +20,7 @@ import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; +import com.mathworks.ci.UseMatlabVersionBuildWrapper.UseMatlabVersionDescriptor; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; @@ -32,6 +33,7 @@ import hudson.tasks.BuildStepDescriptor; import hudson.tasks.Builder; import hudson.util.FormValidation; +import jenkins.model.Jenkins; import jenkins.tasks.SimpleBuildStep; import net.sf.json.JSONObject; @@ -163,7 +165,7 @@ public FormValidation doCheckCoberturaChkBx(@QueryParameter boolean coberturaChk if (coberturaChkBx) { listOfCheckMethods.add(chkCoberturaSupport); } - return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods,FormValidationUtil.getMatlabRoot()); + return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods,getMatlabRoot()); } Function chkCoberturaSupport = (String matlabRoot) -> { @@ -191,7 +193,7 @@ public FormValidation doCheckModelCoverageChkBx(@QueryParameter boolean modelCov if (modelCoverageChkBx) { listOfCheckMethods.add(chkModelCoverageSupport); } - return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods,FormValidationUtil.getMatlabRoot()); + return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods,getMatlabRoot()); } Function chkModelCoverageSupport = (String matlabRoot) -> { @@ -219,7 +221,7 @@ public FormValidation doCheckStmResultsChkBx(@QueryParameter boolean stmResultsC if (stmResultsChkBx) { listOfCheckMethods.add(chkSTMResultsSupport); } - return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods,FormValidationUtil.getMatlabRoot()); + return FormValidationUtil.getFirstErrorOrWarning(listOfCheckMethods,getMatlabRoot()); } Function chkSTMResultsSupport = (String matlabRoot) -> { @@ -238,6 +240,17 @@ public FormValidation doCheckStmResultsChkBx(@QueryParameter boolean stmResultsC } return FormValidation.ok(); }; + + //Method to get the MatlabRoot value from Build wrapper class. + public static String getMatlabRoot() { + try { + return Jenkins.getInstance().getDescriptorByType(UseMatlabVersionDescriptor.class) + .getMatlabRootFolder(); + } catch (Exception e) { + // For any exception during getMatlabRootFolder() operation, return matlabRoot as NULL. + return null; + } + } } @Override