Skip to content

Commit

Permalink
Updated form validation logic to get matlab root value.
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed Mar 3, 2020
1 parent 3d764b3 commit 06f1582
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
14 changes: 0 additions & 14 deletions src/main/java/com/mathworks/ci/FormValidationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}
}
}
19 changes: 16 additions & 3 deletions src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, FormValidation> chkCoberturaSupport = (String matlabRoot) -> {
Expand Down Expand Up @@ -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<String, FormValidation> chkModelCoverageSupport = (String matlabRoot) -> {
Expand Down Expand Up @@ -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<String, FormValidation> chkSTMResultsSupport = (String matlabRoot) -> {
Expand All @@ -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
Expand Down

0 comments on commit 06f1582

Please sign in to comment.