@@ -60,6 +60,7 @@ public class MatlabBuilder extends Builder implements SimpleBuildStep {
6060 private static final String MATLAB_RUNNER_RESOURCE =
6161 "com/mathworks/ci/MatlabBuilder/runMatlabTests.m" ;
6262 private static final String AUTOMATIC_OPTION = "RunTestsAutomaticallyOption" ;
63+ private String nodeSpecificfileSeparator ;
6364
6465
6566 @ DataBoundConstructor
@@ -101,6 +102,7 @@ private String getCustomMatlabCommand() {
101102 private void setEnv (EnvVars env ) {
102103 this .env = env ;
103104 }
105+
104106
105107 @ Extension
106108 public static class MatlabDescriptor extends BuildStepDescriptor <Builder > {
@@ -190,14 +192,15 @@ public FormValidation getFirstErrorOrWarning(
190192 final MatrixPatternResolver resolver = new MatrixPatternResolver (matlabRoot );
191193 if (!resolver .hasVariablePattern ()) {
192194 try {
193- rel = new MatlabReleaseInfo (matlabRoot );
195+ FilePath matlabRootPath = new FilePath (new File (matlabRoot ));
196+ rel = new MatlabReleaseInfo (matlabRootPath );
194197 if (rel .verLessThan (BASE_MATLAB_VERSION_RUNTESTS_SUPPORT )) {
195198 return FormValidation
196199 .error (Message .getValue ("Builder.matlab.test.support.error" ));
197200 }
198201 } catch (MatlabVersionNotFoundException e ) {
199202 return FormValidation
200- .error (Message .getValue ("Builder.invalid.matlab.root.error " ));
203+ .warning (Message .getValue ("Builder.invalid.matlab.root.warning " ));
201204 }
202205 }
203206 return FormValidation .ok ();
@@ -257,7 +260,8 @@ public FormValidation doCheckTaCoberturaChkBx(@QueryParameter boolean taCobertur
257260 }
258261
259262 Function <String , FormValidation > chkCoberturaSupport = (String matlabRoot ) -> {
260- rel = new MatlabReleaseInfo (matlabRoot );
263+ FilePath matlabRootPath = new FilePath (new File (matlabRoot ));
264+ rel = new MatlabReleaseInfo (matlabRootPath );
261265 final MatrixPatternResolver resolver = new MatrixPatternResolver (matlabRoot );
262266 if (!resolver .hasVariablePattern ()) {
263267 try {
@@ -266,7 +270,7 @@ public FormValidation doCheckTaCoberturaChkBx(@QueryParameter boolean taCobertur
266270 .warning (Message .getValue ("Builder.matlab.cobertura.support.warning" ));
267271 }
268272 } catch (MatlabVersionNotFoundException e ) {
269- return FormValidation .error (Message .getValue ("Builder.invalid.matlab.root.error " ));
273+ return FormValidation .warning (Message .getValue ("Builder.invalid.matlab.root.warning " ));
270274 }
271275 }
272276
@@ -393,40 +397,44 @@ public String getStringByName(String memberName) {
393397 public void perform (@ Nonnull Run <?, ?> build , @ Nonnull FilePath workspace ,
394398 @ Nonnull Launcher launcher , @ Nonnull TaskListener listener )
395399 throws InterruptedException , IOException {
396- final boolean isLinuxLauncher = launcher .isUnix ();
400+ //Set the environment variable specific to the this build
401+ setEnv (build .getEnvironment (listener ));
402+ nodeSpecificfileSeparator = getNodeSpecificFileSeperator (launcher );
397403
398404 // Invoke MATLAB command and transfer output to standard
399405 // Output Console
400406
401- buildResult = execMatlabCommand (build , workspace , launcher , listener , isLinuxLauncher );
407+ buildResult = execMatlabCommand (workspace , launcher , listener );
402408
403409 if (buildResult != 0 ) {
404410 build .setResult (Result .FAILURE );
405411 }
406412 }
407413
408- private synchronized int execMatlabCommand (Run <?, ?> build , FilePath workspace , Launcher launcher ,
409- TaskListener listener , boolean isLinuxLauncher )
414+ private synchronized int execMatlabCommand (FilePath workspace , Launcher launcher ,
415+ TaskListener listener )
410416 throws IOException , InterruptedException {
411- setEnv (build .getEnvironment (listener ));
412- final String testRunMode = this .getTestRunTypeList ().getDescriptor ().getId ();
413-
414- // Copy MATLAB scratch file into the workspace only if Automatic option is selected.
415- if (testRunMode .contains (AUTOMATIC_OPTION )) {
416- copyMatlabScratchFileInWorkspace (MATLAB_RUNNER_RESOURCE , MATLAB_RUNNER_TARGET_FILE ,
417- workspace , getClass ().getClassLoader ());
418- }
419417 ProcStarter matlabLauncher ;
420418 try {
421- MatlabReleaseInfo rel = new MatlabReleaseInfo (getLocalMatlab ());
419+ FilePath nodeSpecificMatlabRoot = new FilePath (launcher .getChannel (),getLocalMatlab ());
420+ MatlabReleaseInfo rel = new MatlabReleaseInfo (nodeSpecificMatlabRoot );
422421 matlabLauncher = launcher .launch ().pwd (workspace ).envs (this .env );
423422 if (rel .verLessThan (BASE_MATLAB_VERSION_BATCH_SUPPORT )) {
424423 ListenerLogDecorator outStream = new ListenerLogDecorator (listener );
425- matlabLauncher = matlabLauncher .cmds (constructDefaultMatlabCommand (isLinuxLauncher )).stderr (outStream );
424+ matlabLauncher = matlabLauncher .cmds (constructDefaultMatlabCommand (launcher . isUnix () )).stderr (outStream );
426425 } else {
427426 matlabLauncher = matlabLauncher .cmds (constructMatlabCommandWithBatch ()).stdout (listener );
428427 }
429- } catch (MatlabVersionNotFoundException e ) {
428+
429+ //Check the test run mode option selected by user and identify the target workspace to copy the scratch file.
430+ final String testRunMode = this .getTestRunTypeList ().getDescriptor ().getId ();
431+
432+ // Copy MATLAB scratch file into the workspace only if Automatic option is selected.
433+ if (testRunMode .contains (AUTOMATIC_OPTION )) {
434+ FilePath targetWorkspace = new FilePath (launcher .getChannel (), workspace .getRemote ());
435+ copyMatlabScratchFileInWorkspace (MATLAB_RUNNER_RESOURCE , MATLAB_RUNNER_TARGET_FILE , targetWorkspace );
436+ }
437+ } catch (Exception e ) {
430438 listener .getLogger ().println (e .getMessage ());
431439 return 1 ;
432440 }
@@ -450,7 +458,7 @@ public List<String> constructMatlabCommandWithBatch() {
450458 }
451459
452460 matlabDefaultArgs =
453- Arrays .asList (getLocalMatlab () + File . separator + "bin" + File . separator + "matlab" ,
461+ Arrays .asList (getLocalMatlab () + nodeSpecificfileSeparator + "bin" + nodeSpecificfileSeparator + "matlab" ,
454462 "-batch" , runCommand );
455463
456464 return matlabDefaultArgs ;
@@ -473,7 +481,7 @@ public List<String> constructDefaultMatlabCommand(boolean isLinuxLauncher) {
473481
474482 private String [] getPreRunnerSwitches () {
475483 String [] preRunnerSwitches =
476- {getLocalMatlab () + File . separator + "bin" + File . separator + "matlab" , "-nosplash" ,
484+ {getLocalMatlab () + nodeSpecificfileSeparator + "bin" + nodeSpecificfileSeparator + "matlab" , "-nosplash" ,
477485 "-nodesktop" , "-noAppIcon" };
478486 return preRunnerSwitches ;
479487 }
@@ -504,13 +512,22 @@ private String[] getRunnerSwitch() {
504512 }
505513
506514 private void copyMatlabScratchFileInWorkspace (String matlabRunnerResourcePath ,
507- String matlabRunnerTarget , FilePath workspace , ClassLoader classLoader )
515+ String matlabRunnerTarget , FilePath targetWorkspace )
508516 throws IOException , InterruptedException {
517+ final ClassLoader classLoader = getClass ().getClassLoader ();
518+ FilePath targetFile =
519+ new FilePath (targetWorkspace , Message .getValue (matlabRunnerTarget ));
509520 InputStream in = classLoader .getResourceAsStream (matlabRunnerResourcePath );
510- Path target =
511- new File (workspace .getRemote (), Message .getValue (matlabRunnerTarget )).toPath ();
512521
513- Files .copy (in , target , StandardCopyOption .REPLACE_EXISTING );
522+ targetFile .copyFrom (in );
523+ }
524+
525+ private String getNodeSpecificFileSeperator (Launcher launcher ) {
526+ if (launcher .isUnix ()) {
527+ return "/" ;
528+ } else {
529+ return "\\ " ;
530+ }
514531 }
515532
516533}
0 commit comments