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 +43
-20
lines changed
main/java/com/mathworks/ci
test/java/com/mathworks/ci Expand file tree Collapse file tree 3 files changed +43
-20
lines changed Original file line number Diff line number Diff line change 1+ package com .mathworks .ci ;
2+
3+ /**
4+ * Copyright 2019-2020 The MathWorks, Inc.
5+ *
6+ * This is Utility class which provides commonly used methods for form validations across builders
7+ *
8+ */
9+ import java .util .List ;
10+ import java .util .function .Function ;
11+ import com .mathworks .ci .UseMatlabVersionBuildWrapper .UseMatlabVersionDescriptor ;
12+ import hudson .util .FormValidation ;
13+ import hudson .util .FormValidation .Kind ;
14+ import jenkins .model .Jenkins ;
15+
16+ public class FormValidationUtil {
17+
18+ public static FormValidation getFirstErrorOrWarning (
19+ List <Function <String , FormValidation >> validations ) {
20+ if (validations == null || validations .isEmpty ())
21+ return FormValidation .ok ();
22+ try {
23+ String matlabRoot = Jenkins .getInstance ()
24+ .getDescriptorByType (UseMatlabVersionDescriptor .class ).getMatlabRootFolder ();
25+ for (Function <String , FormValidation > val : validations ) {
26+ FormValidation validationResult = val .apply (matlabRoot );
27+ if (validationResult .kind .compareTo (Kind .ERROR ) == 0
28+ || validationResult .kind .compareTo (Kind .WARNING ) == 0 ) {
29+ return validationResult ;
30+ }
31+ }
32+ } catch (Exception e ) {
33+ return FormValidation .warning (Message .getValue ("Builder.invalid.matlab.root.warning" ));
34+ }
35+ return FormValidation .ok ();
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -225,19 +225,12 @@ public void verifyCommandSupportsEnvVar() throws Exception {
225225 * Test to verify if appropriate MATALB runner file is copied in workspace.
226226 */
227227 @ Test
228- public void verifyMATLABrunnerFileGeneratedForAutomaticOption () throws Exception {
228+ public void verifyMATLABrunnerFileGenerated () throws Exception {
229229 this .buildWrapper .setMatlabRootFolder (getMatlabroot ("R2018b" ));
230230 project .getBuildWrappersList ().add (this .buildWrapper );
231231 scriptBuilder .setMatlabCommand ("pwd" );
232232 project .getBuildersList ().add (scriptBuilder );
233- project .scheduleBuild2 (0 ).get ();
234- String runnerFile ;
235- if (!System .getProperty ("os.name" ).startsWith ("Win" )) {
236- runnerFile = "run_matlab_command.sh" ;
237- }else {
238- runnerFile = "run_matlab_command.bat" ;
239- }
240- File matlabRunner = new File (System .getProperty ("java.io.tmpdir" ) + File .separator + runnerFile );
241- Assert .assertTrue (matlabRunner .exists ());
233+ FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
234+ jenkins .assertLogContains ("MATLAB_ROOT" , build );
242235 }
243236}
Original file line number Diff line number Diff line change @@ -249,17 +249,10 @@ public void verifyMATLABscratchFileGeneratedForAutomaticOption() throws Exceptio
249249 public void verifyMATLABrunnerFileGeneratedForAutomaticOption () throws Exception {
250250 this .buildWrapper .setMatlabRootFolder (getMatlabroot ("R2018b" ));
251251 project .getBuildWrappersList ().add (this .buildWrapper );
252-
252+ setAllTestArtifacts ( false , testBuilder );
253253 project .getBuildersList ().add (testBuilder );
254- project .scheduleBuild2 (0 ).get ();
255- String runnerFile ;
256- if (!System .getProperty ("os.name" ).startsWith ("Win" )) {
257- runnerFile = "run_matlab_command.sh" ;
258- }else {
259- runnerFile = "run_matlab_command.bat" ;
260- }
261- File matlabRunner = new File (System .getProperty ("java.io.tmpdir" ) + File .separator + runnerFile );
262- Assert .assertTrue (matlabRunner .exists ());
254+ FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
255+ jenkins .assertLogContains ("MATLAB_ROOT" , build );
263256 }
264257
265258 /*
You can’t perform that action at this time.
0 commit comments