33import com .beust .jcommander .Parameter ;
44import com .beust .jcommander .Parameters ;
55import io .github .utplsql .api .OutputBuffer ;
6- import io .github .utplsql .api .OutputBufferLines ;
76import io .github .utplsql .api .TestRunner ;
87import io .github .utplsql .api .types .BaseReporter ;
98import io .github .utplsql .api .types .DocumentationReporter ;
10- import io .github .utplsql .api .utPLSQL ;
119
1210import java .sql .Connection ;
1311import java .sql .SQLException ;
@@ -24,15 +22,23 @@ public class RunCommand {
2422
2523 @ Parameter (
2624 required = true , converter = ConnectionStringConverter .class ,
25+ arity = 1 ,
2726 description = "user/pass@[[host][:port]/]db" )
2827 private List <ConnectionInfo > connectionInfoList ;
2928
3029 @ Parameter (
3130 names = {"-p" , "--path" },
3231 description = "run suites/tests by path, format: \n " +
33- "schema or schema:[suite ...][.test] or schema[.suite ...][.test]" )
32+ "-p schema or schema:[suite ...][.test] or schema[.suite ...][.test]" )
3433 private List <String > testPaths ;
3534
35+ @ Parameter (
36+ names = {"-f" , "--format" },
37+ variableArity = true ,
38+ description = "output reporter format: \n " +
39+ "-f reporter_name [output_file] [console_output]" )
40+ private List <String > reporterParams ;
41+
3642 public ConnectionInfo getConnectionInfo () {
3743 return connectionInfoList .get (0 );
3844 }
@@ -44,78 +50,49 @@ public String getTestPaths() {
4450 return (testPaths == null ) ? null : String .join ("," , testPaths );
4551 }
4652
53+ public List <String > getReporterParams () {
54+ return reporterParams ;
55+ }
56+
4757 public void run () throws Exception {
48- ConnectionInfo ci = getConnectionInfo ();
58+ final ConnectionInfo ci = getConnectionInfo ();
4959 System .out .println ("Running Tests For: " + ci .toString ());
5060
51- utPLSQL .init (ci .getConnectionUrl (), ci .getUser (), ci .getPassword ());
52-
5361 String tempTestPaths = getTestPaths ();
5462 if (tempTestPaths == null ) tempTestPaths = ci .getUser ();
5563
56- final BaseReporter reporter = createDocumentationReporter ();
64+ final BaseReporter reporter = new DocumentationReporter ();
5765 final String testPaths = tempTestPaths ;
5866
67+ try (Connection conn = ci .getConnection ()) {
68+ reporter .init (conn );
69+ } catch (SQLException e ) {
70+ // TODO
71+ e .printStackTrace ();
72+ }
73+
5974 ExecutorService executorService = Executors .newFixedThreadPool (2 );
6075
6176 executorService .submit (() -> {
62- Connection conn = null ;
63- try {
64- conn = utPLSQL .getConnection ();
77+ try (Connection conn = ci .getConnection ()){
6578 new TestRunner ().run (conn , testPaths , reporter );
66-
67- OutputBufferLines outputLines = new OutputBuffer (reporter .getReporterId ())
68- .fetchAll (conn );
69-
70- if (outputLines .getLines ().size () > 0 )
71- System .out .println (outputLines .toString ());
7279 } catch (SQLException e ) {
7380 // TODO
7481 e .printStackTrace ();
75- } finally {
76- if (conn != null )
77- try { conn .close (); } catch (SQLException ignored ) {}
7882 }
7983 });
8084
81- // executorService.submit(() -> {
82- // Connection conn = null;
83- // try {
84- // conn = utPLSQL.getConnection();
85- // OutputBufferLines outputLines;
86- // do {
87- // outputLines = new OutputBuffer(reporter.getReporterId())
88- // .fetchAvailable(conn);
89- //
90- // Thread.sleep(500);
91- //
92- // if (outputLines.getLines().size() > 0)
93- // System.out.println(outputLines.toString());
94- // } while (!outputLines.isFinished());
95- // } catch (SQLException | InterruptedException e) {
96- // // TODO
97- // e.printStackTrace();
98- // } finally {
99- // if (conn != null)
100- // try { conn.close(); } catch (SQLException ignored) {}
101- // }
102- // });
85+ executorService .submit (() -> {
86+ try (Connection conn = ci .getConnection ()){
87+ new OutputBuffer (reporter ).printAvailable (conn , System .out );
88+ } catch (SQLException e ) {
89+ // TODO
90+ e .printStackTrace ();
91+ }
92+ });
10393
10494 executorService .shutdown ();
10595 executorService .awaitTermination (60 , TimeUnit .MINUTES );
10696 }
10797
108- private BaseReporter createDocumentationReporter () throws SQLException {
109- Connection conn = null ;
110- try {
111- conn = utPLSQL .getConnection ();
112- BaseReporter reporter = new DocumentationReporter ();
113- reporter .setReporterId (utPLSQL .newSysGuid (conn ));
114- return reporter ;
115- } finally {
116- if (conn != null )
117- try { conn .close (); } catch (SQLException ignored ) {}
118- }
119- }
120-
12198}
0 commit comments