1010import org .utplsql .api .exception .DatabaseNotCompatibleException ;
1111import org .utplsql .api .exception .SomeTestsFailedException ;
1212import org .utplsql .api .exception .UtPLSQLNotInstalledException ;
13+ import org .utplsql .api .reporter .CoreReporters ;
1314import org .utplsql .api .reporter .Reporter ;
1415import org .utplsql .api .reporter .ReporterFactory ;
16+ import org .utplsql .cli .config .ReporterConfig ;
17+ import org .utplsql .cli .config .TestRunnerConfig ;
1518import org .utplsql .cli .exception .DatabaseConnectionFailed ;
1619
1720import javax .sql .DataSource ;
@@ -36,10 +39,10 @@ public class RunCommand implements ICommand {
3639
3740 @ Parameter (
3841 required = true ,
39- converter = ConnectionInfo .ConnectionStringConverter .class ,
42+ // converter = ConnectionInfo.ConnectionStringConverter.class,
4043 arity = 1 ,
4144 description = ConnectionInfo .COMMANDLINE_PARAM_DESCRIPTION )
42- private List < ConnectionInfo > connectionInfoList = new ArrayList <>() ;
45+ private String connectionInfo = "" ;
4346
4447 @ Parameter (
4548 names = {"-p" , "--path" },
@@ -100,12 +103,16 @@ public class RunCommand implements ICommand {
100103 private String excludeObjects = null ;
101104
102105
106+ private ConnectionInfo connectionInfoObj ;
103107 private CompatibilityProxy compatibilityProxy ;
104108 private ReporterFactory reporterFactory ;
105109 private ReporterManager reporterManager ;
106110
107111 public ConnectionInfo getConnectionInfo () {
108- return connectionInfoList .get (0 );
112+ if ( connectionInfoObj == null )
113+ connectionInfoObj = new ConnectionInfo (connectionInfo );
114+
115+ return connectionInfoObj ;
109116 }
110117
111118 public List <String > getTestPaths () {
@@ -326,4 +333,81 @@ private ReporterManager getReporterManager() {
326333 public List <ReporterOptions > getReporterOptionsList () {
327334 return getReporterManager ().getReporterOptionsList ();
328335 }
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+ }
329413}
0 commit comments