Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 06f1582

Browse files
committed
Updated form validation logic to get matlab root value.
1 parent 3d764b3 commit 06f1582

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/main/java/com/mathworks/ci/FormValidationUtil.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
*/
99
import java.util.List;
1010
import java.util.function.Function;
11-
import com.mathworks.ci.UseMatlabVersionBuildWrapper.UseMatlabVersionDescriptor;
1211
import hudson.util.FormValidation;
1312
import hudson.util.FormValidation.Kind;
14-
import jenkins.model.Jenkins;
1513

1614
public class FormValidationUtil {
1715

@@ -32,16 +30,4 @@ public static FormValidation getFirstErrorOrWarning(
3230
}
3331
return FormValidation.ok();
3432
}
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-
}
4733
}

src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.kohsuke.stapler.DataBoundSetter;
2121
import org.kohsuke.stapler.QueryParameter;
2222
import org.kohsuke.stapler.StaplerRequest;
23+
import com.mathworks.ci.UseMatlabVersionBuildWrapper.UseMatlabVersionDescriptor;
2324
import hudson.EnvVars;
2425
import hudson.Extension;
2526
import hudson.FilePath;
@@ -32,6 +33,7 @@
3233
import hudson.tasks.BuildStepDescriptor;
3334
import hudson.tasks.Builder;
3435
import hudson.util.FormValidation;
36+
import jenkins.model.Jenkins;
3537
import jenkins.tasks.SimpleBuildStep;
3638
import 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

Comments
 (0)