66import io .github .utplsql .api .TestRunner ;
77import io .github .utplsql .api .types .BaseReporter ;
88import io .github .utplsql .api .types .CustomTypes ;
9- import io .github .utplsql .api .types .DocumentationReporter ;
109
10+ import java .io .FileNotFoundException ;
11+ import java .io .FileOutputStream ;
12+ import java .io .PrintStream ;
1113import java .sql .Connection ;
1214import java .sql .SQLException ;
1315import java .util .ArrayList ;
@@ -45,11 +47,8 @@ public ConnectionInfo getConnectionInfo() {
4547 return connectionInfoList .get (0 );
4648 }
4749
48- public String getTestPaths () {
49- // if (testPaths != null && testPaths.size() > 1)
50- // throw new RuntimeException("Multiple test paths not supported yet.");
51-
52- return (testPaths == null ) ? null : String .join ("," , testPaths );
50+ public List <String > getTestPaths () {
51+ return testPaths ;
5352 }
5453
5554 public List <ReporterOptions > getReporterOptionsList () {
@@ -73,7 +72,7 @@ public List<ReporterOptions> getReporterOptionsList() {
7372
7473 // If no reporter parameters were passed, use default reporter.
7574 if (reporterOptionsList .isEmpty ()) {
76- reporterOptionsList .add (new ReporterOptions (CustomTypes .UT_DOCUMENTATION_REPORTER . getName () ));
75+ reporterOptionsList .add (new ReporterOptions (CustomTypes .UT_DOCUMENTATION_REPORTER ));
7776 }
7877
7978 return reporterOptionsList ;
@@ -83,38 +82,62 @@ public void run() throws Exception {
8382 final ConnectionInfo ci = getConnectionInfo ();
8483 System .out .println ("Running Tests For: " + ci .toString ());
8584
86- String tempTestPaths = getTestPaths ();
87- if (tempTestPaths == null ) tempTestPaths = ci .getUser ();
85+ final List <ReporterOptions > reporterOptionsList = getReporterOptionsList ();
86+ final List <BaseReporter > reporterList = new ArrayList <>();
87+ final List <String > testPaths = getTestPaths ();
8888
89- final BaseReporter reporter = new DocumentationReporter ();
90- final String testPaths = tempTestPaths ;
89+ if (testPaths .isEmpty ()) testPaths .add (ci .getUser ());
9190
91+ // Do the reporters initialization, so we can use the id to run and gather results.
9292 try (Connection conn = ci .getConnection ()) {
93- reporter .init (conn );
93+ for (ReporterOptions ro : reporterOptionsList ) {
94+ BaseReporter reporter = CustomTypes .createReporter (ro .getReporterName ());
95+ reporter .init (conn );
96+ ro .setReporterObj (reporter );
97+ reporterList .add (reporter );
98+ }
9499 } catch (SQLException e ) {
95100 // TODO
96101 e .printStackTrace ();
97102 }
98103
99- ExecutorService executorService = Executors .newFixedThreadPool (2 );
104+ ExecutorService executorService = Executors .newFixedThreadPool (1 + reporterList . size () );
100105
101106 executorService .submit (() -> {
102107 try (Connection conn = ci .getConnection ()){
103- new TestRunner ().run (conn , testPaths , reporter );
108+ new TestRunner ().run (conn , testPaths , reporterList );
104109 } catch (SQLException e ) {
105110 // TODO
106111 e .printStackTrace ();
107112 }
108113 });
109114
110- executorService .submit (() -> {
111- try (Connection conn = ci .getConnection ()){
112- new OutputBuffer (reporter ).printAvailable (conn , System .out );
113- } catch (SQLException e ) {
114- // TODO
115- e .printStackTrace ();
116- }
117- });
115+
116+ for (ReporterOptions ro : reporterOptionsList ) {
117+ executorService .submit (() -> {
118+ List <PrintStream > printStreams = new ArrayList <>();
119+ PrintStream fileOutStream = null ;
120+
121+ try (Connection conn = ci .getConnection ()) {
122+ if (ro .outputToScreen ()) {
123+ printStreams .add (System .out );
124+ }
125+
126+ if (ro .outputToFile ()) {
127+ fileOutStream = new PrintStream (new FileOutputStream (ro .getOutputFileName ()));
128+ printStreams .add (fileOutStream );
129+ }
130+
131+ new OutputBuffer (ro .getReporterObj ()).printAvailable (conn , printStreams );
132+ } catch (SQLException | FileNotFoundException e ) {
133+ // TODO
134+ e .printStackTrace ();
135+ } finally {
136+ if (fileOutStream != null )
137+ fileOutStream .close ();
138+ }
139+ });
140+ }
118141
119142 executorService .shutdown ();
120143 executorService .awaitTermination (60 , TimeUnit .MINUTES );
0 commit comments