@@ -281,47 +281,60 @@ public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace,
281281 }
282282
283283 private synchronized int execMatlabCommand (FilePath workspace , Launcher launcher ,
284- TaskListener listener , EnvVars envVars )
285- throws IOException , InterruptedException {
286-
284+ TaskListener listener , EnvVars envVars ) throws IOException , InterruptedException {
287285 ProcStarter matlabLauncher ;
288286 try {
289287 // Get matlabroot set in wrapper class.
290- String matlabRoot = envVars .get ("matlabroot" );
291- CommandConstructUtil cmdUtils = new CommandConstructUtil (launcher , matlabRoot );
288+ String matlabRoot = envVars .get ("matlabroot" );
292289 matlabLauncher = launcher .launch ().pwd (workspace ).envs (envVars );
293290 FilePath targetWorkspace = new FilePath (launcher .getChannel (), workspace .getRemote ());
294- if (launcher .isUnix ()) {
295- matlabLauncher = launcher .launch ().pwd (workspace ).envs (envVars ).cmds ("/bin/bash" ,"-c" ,"./run_matlab_command.sh " +cmdUtils .constructCommandForTest (getInputArguments ())).stdout (listener );
296- //Copy runner .sh for linux platform in workspace.
297- cmdUtils .copyMatlabScratchFileInWorkspace (MatlabBuilderConstants .SHELL_RUNNER_SCRIPT , "Builder.matlab.runner.script.target.file.linux.name" , targetWorkspace );
298- }else {
299- launcher = launcher .decorateByPrefix ("cmd.exe" ,"/C" );
300- matlabLauncher = launcher .launch ().pwd (workspace ).envs (envVars ).cmds ("run_matlab_command.bat" ,"\" " +cmdUtils .constructCommandForTest (getInputArguments ())+"\" " ).stdout (listener );
301- //Copy runner.bat for Windows platform in workspace.
302- cmdUtils .copyMatlabScratchFileInWorkspace (MatlabBuilderConstants .BAT_RUNNER_SCRIPT , "Builder.matlab.runner.script.target.file.windows.name" , targetWorkspace );
291+ if (launcher .isUnix ()) {
292+ matlabLauncher =
293+ launcher .launch ().pwd (workspace ).envs (envVars )
294+ .cmds ("./run_matlab_command.sh" ,
295+ constructCommandForTest (getInputArguments ()))
296+ .stdout (listener );
297+ // Copy runner .sh for linux platform in workspace.
298+ cpoyFileInWorkspace (MatlabBuilderConstants .SHELL_RUNNER_SCRIPT ,
299+ "Builder.matlab.runner.script.target.file.linux.name" , targetWorkspace );
300+ } else {
301+ launcher = launcher .decorateByPrefix ("cmd.exe" , "/C" );
302+ matlabLauncher = launcher .launch ().pwd (workspace ).envs (envVars )
303+ .cmds ("run_matlab_command.bat" ,
304+ "\" " + constructCommandForTest (getInputArguments ()) + "\" " )
305+ .stdout (listener );
306+ // Copy runner.bat for Windows platform in workspace.
307+ cpoyFileInWorkspace (MatlabBuilderConstants .BAT_RUNNER_SCRIPT ,
308+ "Builder.matlab.runner.script.target.file.windows.name" , targetWorkspace );
303309 }
304-
310+
305311 // Copy MATLAB scratch file into the workspace.
306- cmdUtils .copyMatlabScratchFileInWorkspace (MatlabBuilderConstants .MATLAB_RUNNER_RESOURCE , MatlabBuilderConstants .MATLAB_RUNNER_TARGET_FILE , targetWorkspace );
312+ cpoyFileInWorkspace (MatlabBuilderConstants .MATLAB_RUNNER_RESOURCE ,
313+ MatlabBuilderConstants .MATLAB_RUNNER_TARGET_FILE , targetWorkspace );
307314 } catch (Exception e ) {
308315 listener .getLogger ().println (e .getMessage ());
309316 return 1 ;
310317 }
311318 return matlabLauncher .join ();
312319 }
313320
314- /* private void copyMatlabScratchFileInWorkspace(String matlabRunnerResourcePath,
315- String matlabRunnerTarget, FilePath targetWorkspace)
316- throws IOException, InterruptedException {
321+ public String constructCommandForTest (String inputArguments ) {
322+ String runCommand ;
323+ String matlabFunctionName = FilenameUtils .removeExtension (
324+ Message .getValue (MatlabBuilderConstants .MATLAB_RUNNER_TARGET_FILE ));
325+ runCommand = "exit(" + matlabFunctionName + "(" + inputArguments + "))" ;
326+ return runCommand ;
327+ }
328+
329+ private void cpoyFileInWorkspace (String matlabRunnerResourcePath , String matlabRunnerTarget ,
330+ FilePath targetWorkspace ) throws IOException , InterruptedException {
317331 final ClassLoader classLoader = getClass ().getClassLoader ();
318- FilePath targetFile =
319- new FilePath(targetWorkspace, Message.getValue(matlabRunnerTarget));
332+ FilePath targetFile = new FilePath (targetWorkspace , Message .getValue (matlabRunnerTarget ));
320333 InputStream in = classLoader .getResourceAsStream (matlabRunnerResourcePath );
321334 targetFile .copyFrom (in );
322- //set executable permission to the file.
323- targetFile.chmod(0777 );
324- }*/
335+ // set executable permission to the file.
336+ targetFile .chmod (0755 );
337+ }
325338
326339 // Concatenate the input arguments
327340 private String getInputArguments () {
@@ -330,11 +343,10 @@ private String getInputArguments() {
330343 String junitResults = MatlabBuilderConstants .JUNIT_RESULTS + "," + this .getJunitChkBx ();
331344 String stmResults = MatlabBuilderConstants .STM_RESULTS + "," + this .getStmResultsChkBx ();
332345 String coberturaCodeCoverage = MatlabBuilderConstants .COBERTURA_CODE_COVERAGE + "," + this .getCoberturaChkBx ();
333- String coberturaModelCoverage = MatlabBuilderConstants .COBERTURA_MODEL_COVERAGE + "," + this .getModelCoverageChkBx ();
334-
346+ String coberturaModelCoverage = MatlabBuilderConstants .COBERTURA_MODEL_COVERAGE + "," + this .getModelCoverageChkBx ();
335347 String inputArgsToMatlabFcn = pdfReport + "," + tapResults + "," + junitResults + ","
336348 + stmResults + "," + coberturaCodeCoverage + "," + coberturaModelCoverage ;
337-
349+
338350 return inputArgsToMatlabFcn ;
339351 }
340352}
0 commit comments