11
11
import java .io .IOException ;
12
12
import java .util .*;
13
13
import javax .annotation .Nonnull ;
14
- import org .apache .commons .collections .map .HashedMap ;
15
- import org .apache .commons .io .FilenameUtils ;
16
- import org .jenkinsci .Symbol ;
17
14
import org .kohsuke .stapler .DataBoundConstructor ;
18
15
import org .kohsuke .stapler .DataBoundSetter ;
19
16
import org .kohsuke .stapler .StaplerRequest ;
@@ -239,13 +236,15 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
239
236
final String uniqueTmpFldrName = getUniqueNameForRunnerFile ();
240
237
ProcStarter matlabLauncher ;
241
238
try {
239
+ FilePath genScriptLocation =
240
+ getFilePathForUniqueFolder (launcher , uniqueTmpFldrName , workspace );
241
+
242
242
matlabLauncher = getProcessToRunMatlabCommand (workspace , launcher , listener , envVars ,
243
- constructCommandForTest (getInputArguments () ), uniqueTmpFldrName );
243
+ constructCommandForTest (genScriptLocation ), uniqueTmpFldrName );
244
244
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 ())));
249
248
250
249
return matlabLauncher .pwd (workspace ).join ();
251
250
} catch (Exception e ) {
@@ -260,11 +259,11 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
260
259
}
261
260
}
262
261
}
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 ;
268
267
return runCommand ;
269
268
}
270
269
@@ -278,12 +277,14 @@ private String getInputArguments() {
278
277
new ArrayList <Artifact >(Arrays .asList (getPdfReportArtifact (), getTapArtifact (),
279
278
getJunitArtifact (), getStmResultsArtifact (), getCoberturaArtifact (),
280
279
getModelCoverageArtifact ()));
280
+
281
+ inputArgsList .add ("'Test'" );
281
282
282
283
for (Artifact artifact : artifactList ) {
283
284
artifact .addFilePathArgTo (args );
284
285
}
285
286
286
- args .forEach ((key , val ) -> inputArgsList .add ("'" + key + "'" + "," + "'" + val + "'" ));
287
+ args .forEach ((key , val ) -> inputArgsList .add ("'" + key + "'" + "," + "'" + val . replaceAll ( "'" , "''" ) + "'" ));
287
288
288
289
return String .join ("," , inputArgsList );
289
290
}
@@ -301,7 +302,7 @@ private String getInputArguments() {
301
302
*/
302
303
public static class PdfArtifact extends AbstractArtifactImpl {
303
304
304
- private static final String PDF_REPORT_PATH = "PDFReportPath " ;
305
+ private static final String PDF_TEST_REPORT = "PDFTestReport " ;
305
306
306
307
@ DataBoundConstructor
307
308
public PdfArtifact (String pdfReportFilePath ) {
@@ -310,13 +311,13 @@ public PdfArtifact(String pdfReportFilePath) {
310
311
311
312
@ Override
312
313
public void addFilePathArgTo (Map <String , String > inputArgs ) {
313
- inputArgs .put (PDF_REPORT_PATH , getFilePath ());
314
+ inputArgs .put (PDF_TEST_REPORT , getFilePath ());
314
315
}
315
316
}
316
317
317
318
public static class TapArtifact extends AbstractArtifactImpl {
318
319
319
- private static final String TAP_RESULTS_PATH = "TAPResultsPath " ;
320
+ private static final String TAP_TEST_RESULTS = "TAPTestResults " ;
320
321
321
322
@ DataBoundConstructor
322
323
public TapArtifact (String tapReportFilePath ) {
@@ -325,13 +326,13 @@ public TapArtifact(String tapReportFilePath) {
325
326
326
327
@ Override
327
328
public void addFilePathArgTo (Map <String , String > inputArgs ) {
328
- inputArgs .put (TAP_RESULTS_PATH , getFilePath ());
329
+ inputArgs .put (TAP_TEST_RESULTS , getFilePath ());
329
330
}
330
331
}
331
332
332
333
public static class JunitArtifact extends AbstractArtifactImpl {
333
334
334
- private static final String JUNIT_RESULTS_PATH = "JUnitResultsPath " ;
335
+ private static final String JUNIT_TEST_RESULTS = "JUnitTestResults " ;
335
336
336
337
@ DataBoundConstructor
337
338
public JunitArtifact (String junitReportFilePath ) {
@@ -340,13 +341,13 @@ public JunitArtifact(String junitReportFilePath) {
340
341
341
342
@ Override
342
343
public void addFilePathArgTo (Map <String , String > inputArgs ) {
343
- inputArgs .put (JUNIT_RESULTS_PATH , getFilePath ());
344
+ inputArgs .put (JUNIT_TEST_RESULTS , getFilePath ());
344
345
}
345
346
}
346
347
347
348
public static class CoberturaArtifact extends AbstractArtifactImpl {
348
349
349
- private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath " ;
350
+ private static final String COBERTURA_CODE_COVERAGE = "CoberturaCodeCoverage " ;
350
351
351
352
@ DataBoundConstructor
352
353
public CoberturaArtifact (String coberturaReportFilePath ) {
@@ -355,13 +356,13 @@ public CoberturaArtifact(String coberturaReportFilePath) {
355
356
356
357
@ Override
357
358
public void addFilePathArgTo (Map <String , String > inputArgs ) {
358
- inputArgs .put (COBERTURA_CODE_COVERAGE_PATH , getFilePath ());
359
+ inputArgs .put (COBERTURA_CODE_COVERAGE , getFilePath ());
359
360
}
360
361
}
361
362
362
363
public static class StmResultsArtifact extends AbstractArtifactImpl {
363
364
364
- private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath " ;
365
+ private static final String STM_RESULTS = "SimulinkTestResults " ;
365
366
366
367
@ DataBoundConstructor
367
368
public StmResultsArtifact (String stmResultsFilePath ) {
@@ -370,13 +371,13 @@ public StmResultsArtifact(String stmResultsFilePath) {
370
371
371
372
@ Override
372
373
public void addFilePathArgTo (Map <String , String > inputArgs ) {
373
- inputArgs .put (STM_RESULTS_PATH , getFilePath ());
374
+ inputArgs .put (STM_RESULTS , getFilePath ());
374
375
}
375
376
}
376
377
377
378
public static class ModelCovArtifact extends AbstractArtifactImpl {
378
379
379
- private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath " ;
380
+ private static final String COBERTURA_MODEL_COVERAGE = "CoberturaModelCoverage " ;
380
381
381
382
@ DataBoundConstructor
382
383
public ModelCovArtifact (String modelCoverageFilePath ) {
@@ -385,7 +386,7 @@ public ModelCovArtifact(String modelCoverageFilePath) {
385
386
386
387
@ Override
387
388
public void addFilePathArgTo (Map <String , String > inputArgs ) {
388
- inputArgs .put (COBERTURA_MODEL_COVERAGE_PATH , getFilePath ());
389
+ inputArgs .put (COBERTURA_MODEL_COVERAGE , getFilePath ());
389
390
}
390
391
}
391
392
0 commit comments