1111import java .io .IOException ;
1212import java .util .*;
1313import javax .annotation .Nonnull ;
14- import org .apache .commons .collections .map .HashedMap ;
15- import org .apache .commons .io .FilenameUtils ;
16- import org .jenkinsci .Symbol ;
1714import org .kohsuke .stapler .DataBoundConstructor ;
1815import org .kohsuke .stapler .DataBoundSetter ;
1916import org .kohsuke .stapler .StaplerRequest ;
@@ -239,13 +236,15 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
239236 final String uniqueTmpFldrName = getUniqueNameForRunnerFile ();
240237 ProcStarter matlabLauncher ;
241238 try {
239+ FilePath genScriptLocation =
240+ getFilePathForUniqueFolder (launcher , uniqueTmpFldrName , workspace );
241+
242242 matlabLauncher = getProcessToRunMatlabCommand (workspace , launcher , listener , envVars ,
243- constructCommandForTest (getInputArguments () ), uniqueTmpFldrName );
243+ constructCommandForTest (genScriptLocation ), uniqueTmpFldrName );
244244
245- // Copy MATLAB scratch file into the workspace.
246- FilePath targetWorkspace = new FilePath (launcher .getChannel (), workspace .getRemote ());
247- copyFileInWorkspace (MatlabBuilderConstants .MATLAB_TESTS_RUNNER_RESOURCE ,
248- MatlabBuilderConstants .MATLAB_TESTS_RUNNER_TARGET_FILE , targetWorkspace );
245+ // copy genscript package in temp folder and write a runner script.
246+ prepareTmpFldr (genScriptLocation , getRunnerScript (
247+ MatlabBuilderConstants .TEST_RUNNER_SCRIPT , envVars .expand (getInputArguments ())));
249248
250249 return matlabLauncher .pwd (workspace ).join ();
251250 } catch (Exception e ) {
@@ -260,11 +259,11 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
260259 }
261260 }
262261 }
263-
264- public String constructCommandForTest (String inputArguments ) {
265- final String matlabFunctionName =
266- FilenameUtils . removeExtension ( MatlabBuilderConstants . MATLAB_TESTS_RUNNER_TARGET_FILE );
267- final String runCommand = "exit(" + matlabFunctionName + "( " + inputArguments + "))" ;
262+
263+ public String constructCommandForTest (FilePath scriptPath ) {
264+ final String matlabScriptName = getValidMatlabFileName ( scriptPath . getBaseName ());
265+ final String runCommand = "addpath('" + scriptPath . getRemote (). replaceAll ( "'" , "''" )
266+ + "'); " + matlabScriptName ;
268267 return runCommand ;
269268 }
270269
@@ -278,12 +277,14 @@ private String getInputArguments() {
278277 new ArrayList <Artifact >(Arrays .asList (getPdfReportArtifact (), getTapArtifact (),
279278 getJunitArtifact (), getStmResultsArtifact (), getCoberturaArtifact (),
280279 getModelCoverageArtifact ()));
280+
281+ inputArgsList .add ("'Test'" );
281282
282283 for (Artifact artifact : artifactList ) {
283284 artifact .addFilePathArgTo (args );
284285 }
285286
286- args .forEach ((key , val ) -> inputArgsList .add ("'" + key + "'" + "," + "'" + val + "'" ));
287+ args .forEach ((key , val ) -> inputArgsList .add ("'" + key + "'" + "," + "'" + val . replaceAll ( "'" , "''" ) + "'" ));
287288
288289 return String .join ("," , inputArgsList );
289290 }
@@ -301,7 +302,7 @@ private String getInputArguments() {
301302 */
302303 public static class PdfArtifact extends AbstractArtifactImpl {
303304
304- private static final String PDF_REPORT_PATH = "PDFReportPath " ;
305+ private static final String PDF_TEST_REPORT = "PDFTestReport " ;
305306
306307 @ DataBoundConstructor
307308 public PdfArtifact (String pdfReportFilePath ) {
@@ -310,13 +311,13 @@ public PdfArtifact(String pdfReportFilePath) {
310311
311312 @ Override
312313 public void addFilePathArgTo (Map <String , String > inputArgs ) {
313- inputArgs .put (PDF_REPORT_PATH , getFilePath ());
314+ inputArgs .put (PDF_TEST_REPORT , getFilePath ());
314315 }
315316 }
316317
317318 public static class TapArtifact extends AbstractArtifactImpl {
318319
319- private static final String TAP_RESULTS_PATH = "TAPResultsPath " ;
320+ private static final String TAP_TEST_RESULTS = "TAPTestResults " ;
320321
321322 @ DataBoundConstructor
322323 public TapArtifact (String tapReportFilePath ) {
@@ -325,13 +326,13 @@ public TapArtifact(String tapReportFilePath) {
325326
326327 @ Override
327328 public void addFilePathArgTo (Map <String , String > inputArgs ) {
328- inputArgs .put (TAP_RESULTS_PATH , getFilePath ());
329+ inputArgs .put (TAP_TEST_RESULTS , getFilePath ());
329330 }
330331 }
331332
332333 public static class JunitArtifact extends AbstractArtifactImpl {
333334
334- private static final String JUNIT_RESULTS_PATH = "JUnitResultsPath " ;
335+ private static final String JUNIT_TEST_RESULTS = "JUnitTestResults " ;
335336
336337 @ DataBoundConstructor
337338 public JunitArtifact (String junitReportFilePath ) {
@@ -340,13 +341,13 @@ public JunitArtifact(String junitReportFilePath) {
340341
341342 @ Override
342343 public void addFilePathArgTo (Map <String , String > inputArgs ) {
343- inputArgs .put (JUNIT_RESULTS_PATH , getFilePath ());
344+ inputArgs .put (JUNIT_TEST_RESULTS , getFilePath ());
344345 }
345346 }
346347
347348 public static class CoberturaArtifact extends AbstractArtifactImpl {
348349
349- private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath " ;
350+ private static final String COBERTURA_CODE_COVERAGE = "CoberturaCodeCoverage " ;
350351
351352 @ DataBoundConstructor
352353 public CoberturaArtifact (String coberturaReportFilePath ) {
@@ -355,13 +356,13 @@ public CoberturaArtifact(String coberturaReportFilePath) {
355356
356357 @ Override
357358 public void addFilePathArgTo (Map <String , String > inputArgs ) {
358- inputArgs .put (COBERTURA_CODE_COVERAGE_PATH , getFilePath ());
359+ inputArgs .put (COBERTURA_CODE_COVERAGE , getFilePath ());
359360 }
360361 }
361362
362363 public static class StmResultsArtifact extends AbstractArtifactImpl {
363364
364- private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath " ;
365+ private static final String STM_RESULTS = "SimulinkTestResults " ;
365366
366367 @ DataBoundConstructor
367368 public StmResultsArtifact (String stmResultsFilePath ) {
@@ -370,13 +371,13 @@ public StmResultsArtifact(String stmResultsFilePath) {
370371
371372 @ Override
372373 public void addFilePathArgTo (Map <String , String > inputArgs ) {
373- inputArgs .put (STM_RESULTS_PATH , getFilePath ());
374+ inputArgs .put (STM_RESULTS , getFilePath ());
374375 }
375376 }
376377
377378 public static class ModelCovArtifact extends AbstractArtifactImpl {
378379
379- private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath " ;
380+ private static final String COBERTURA_MODEL_COVERAGE = "CoberturaModelCoverage " ;
380381
381382 @ DataBoundConstructor
382383 public ModelCovArtifact (String modelCoverageFilePath ) {
@@ -385,7 +386,7 @@ public ModelCovArtifact(String modelCoverageFilePath) {
385386
386387 @ Override
387388 public void addFilePathArgTo (Map <String , String > inputArgs ) {
388- inputArgs .put (COBERTURA_MODEL_COVERAGE_PATH , getFilePath ());
389+ inputArgs .put (COBERTURA_MODEL_COVERAGE , getFilePath ());
389390 }
390391 }
391392
0 commit comments