10
10
import org .utplsql .api .exception .DatabaseNotCompatibleException ;
11
11
import org .utplsql .api .exception .SomeTestsFailedException ;
12
12
import org .utplsql .api .exception .UtPLSQLNotInstalledException ;
13
+ import org .utplsql .api .reporter .CoreReporters ;
13
14
import org .utplsql .api .reporter .Reporter ;
14
15
import org .utplsql .api .reporter .ReporterFactory ;
16
+ import org .utplsql .cli .config .ReporterConfig ;
17
+ import org .utplsql .cli .config .TestRunnerConfig ;
15
18
import org .utplsql .cli .exception .DatabaseConnectionFailed ;
16
19
17
20
import javax .sql .DataSource ;
@@ -36,10 +39,10 @@ public class RunCommand implements ICommand {
36
39
37
40
@ Parameter (
38
41
required =true ,
39
- converter =ConnectionInfo .ConnectionStringConverter .class ,
42
+ // converter = ConnectionInfo.ConnectionStringConverter.class,
40
43
arity =1 ,
41
44
description =ConnectionInfo .COMMANDLINE_PARAM_DESCRIPTION )
42
- private List < ConnectionInfo > connectionInfoList =new ArrayList <>() ;
45
+ private String connectionInfo ="" ;
43
46
44
47
@ Parameter (
45
48
names = {"-p" ,"--path" },
@@ -100,12 +103,16 @@ public class RunCommand implements ICommand {
100
103
private String excludeObjects =null ;
101
104
102
105
106
+ private ConnectionInfo connectionInfoObj ;
103
107
private CompatibilityProxy compatibilityProxy ;
104
108
private ReporterFactory reporterFactory ;
105
109
private ReporterManager reporterManager ;
106
110
107
111
public ConnectionInfo getConnectionInfo () {
108
- return connectionInfoList .get (0 );
112
+ if (connectionInfoObj ==null )
113
+ connectionInfoObj =new ConnectionInfo (connectionInfo );
114
+
115
+ return connectionInfoObj ;
109
116
}
110
117
111
118
public List <String >getTestPaths () {
@@ -326,4 +333,81 @@ private ReporterManager getReporterManager() {
326
333
public List <ReporterOptions >getReporterOptionsList () {
327
334
return getReporterManager ().getReporterOptionsList ();
328
335
}
336
+
337
+ private List <ReporterConfig >getReporterConfigs () {
338
+ List <ReporterConfig >reporterConfigs =new ArrayList <>(5 );
339
+
340
+ String reporterName =null ;
341
+ String outputFile =null ;
342
+ Boolean forceToScreen =null ;
343
+ for (String p :reporterParams ) {
344
+ if (!p .startsWith ("-" )) {
345
+ if (reporterName !=null ) {
346
+ reporterConfigs .add (new ReporterConfig (reporterName ,outputFile ,forceToScreen ));
347
+ reporterName =null ;
348
+ outputFile =null ;
349
+ forceToScreen =null ;
350
+ }
351
+ reporterName =p ;
352
+ }
353
+ else if (p .startsWith ("-o=" ))
354
+ outputFile =p .substring (3 );
355
+ else if (p .equals ("-s" ))
356
+ forceToScreen =true ;
357
+ }
358
+
359
+ if (reporterName !=null )
360
+ reporterConfigs .add (new ReporterConfig (reporterName ,outputFile ,forceToScreen ));
361
+
362
+ return reporterConfigs ;
363
+ }
364
+
365
+ private String []getSplitList (String delimitedList ) {
366
+ if (delimitedList !=null && !delimitedList .isEmpty () )
367
+ return delimitedList .split ("," );
368
+ else
369
+ return null ;
370
+ }
371
+
372
+ public TestRunnerConfig getConfig () {
373
+ final List <Reporter >reporterList ;
374
+ List <ReporterOptions >reporterOptionsList =new ArrayList <>();
375
+ ReporterOptions reporterOptions =null ;
376
+
377
+ List <ReporterConfig >reporterConfigs =getReporterConfigs ();
378
+
379
+ // If no reporter parameters were passed, use default reporter.
380
+ if (reporterOptionsList .isEmpty ()) {
381
+ reporterOptionsList .add (new ReporterOptions (CoreReporters .UT_DOCUMENTATION_REPORTER .name ()));
382
+ }
383
+ final List <String >testPaths =getTestPaths ();
384
+
385
+ final File baseDir =new File ("" ).getAbsoluteFile ();
386
+ final FileMapperOptions []sourceMappingOptions = {null };
387
+ final FileMapperOptions []testMappingOptions = {null };
388
+
389
+ final int []returnCode = {0 };
390
+
391
+ sourceMappingOptions [0 ] =getFileMapperOptionsByParamListItem (this .sourcePathParams ,baseDir );
392
+ testMappingOptions [0 ] =getFileMapperOptionsByParamListItem (this .testPathParams ,baseDir );
393
+
394
+ String []testPathArr =new String [testPaths .size ()];
395
+ testPathArr =testPaths .toArray (testPathArr );
396
+
397
+ ReporterConfig []reporterConfigArr =new ReporterConfig [reporterConfigs .size ()];
398
+ reporterConfigArr =reporterConfigs .toArray (reporterConfigArr );
399
+
400
+ return new TestRunnerConfig (
401
+ connectionInfo ,
402
+ testPathArr ,
403
+ reporterConfigArr ,
404
+ colorConsole ,
405
+ failureExitCode ,
406
+ skipCompatibilityCheck ,
407
+ getSplitList (includeObjects ),
408
+ getSplitList (excludeObjects ),
409
+ null ,
410
+ null
411
+ );
412
+ }
329
413
}