3
3
import com .beust .jcommander .Parameter ;
4
4
import com .beust .jcommander .Parameters ;
5
5
import io .github .utplsql .api .OutputBuffer ;
6
- import io .github .utplsql .api .OutputBufferLines ;
7
6
import io .github .utplsql .api .TestRunner ;
8
7
import io .github .utplsql .api .types .BaseReporter ;
9
8
import io .github .utplsql .api .types .DocumentationReporter ;
10
- import io .github .utplsql .api .utPLSQL ;
11
9
12
10
import java .sql .Connection ;
13
11
import java .sql .SQLException ;
@@ -24,15 +22,23 @@ public class RunCommand {
24
22
25
23
@ Parameter (
26
24
required = true , converter = ConnectionStringConverter .class ,
25
+ arity = 1 ,
27
26
description = "user/pass@[[host][:port]/]db" )
28
27
private List <ConnectionInfo > connectionInfoList ;
29
28
30
29
@ Parameter (
31
30
names = {"-p" , "--path" },
32
31
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]" )
34
33
private List <String > testPaths ;
35
34
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
+
36
42
public ConnectionInfo getConnectionInfo () {
37
43
return connectionInfoList .get (0 );
38
44
}
@@ -44,78 +50,49 @@ public String getTestPaths() {
44
50
return (testPaths == null ) ? null : String .join ("," , testPaths );
45
51
}
46
52
53
+ public List <String > getReporterParams () {
54
+ return reporterParams ;
55
+ }
56
+
47
57
public void run () throws Exception {
48
- ConnectionInfo ci = getConnectionInfo ();
58
+ final ConnectionInfo ci = getConnectionInfo ();
49
59
System .out .println ("Running Tests For: " + ci .toString ());
50
60
51
- utPLSQL .init (ci .getConnectionUrl (), ci .getUser (), ci .getPassword ());
52
-
53
61
String tempTestPaths = getTestPaths ();
54
62
if (tempTestPaths == null ) tempTestPaths = ci .getUser ();
55
63
56
- final BaseReporter reporter = createDocumentationReporter ();
64
+ final BaseReporter reporter = new DocumentationReporter ();
57
65
final String testPaths = tempTestPaths ;
58
66
67
+ try (Connection conn = ci .getConnection ()) {
68
+ reporter .init (conn );
69
+ } catch (SQLException e ) {
70
+ // TODO
71
+ e .printStackTrace ();
72
+ }
73
+
59
74
ExecutorService executorService = Executors .newFixedThreadPool (2 );
60
75
61
76
executorService .submit (() -> {
62
- Connection conn = null ;
63
- try {
64
- conn = utPLSQL .getConnection ();
77
+ try (Connection conn = ci .getConnection ()){
65
78
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 ());
72
79
} catch (SQLException e ) {
73
80
// TODO
74
81
e .printStackTrace ();
75
- } finally {
76
- if (conn != null )
77
- try { conn .close (); } catch (SQLException ignored ) {}
78
82
}
79
83
});
80
84
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
+ });
103
93
104
94
executorService .shutdown ();
105
95
executorService .awaitTermination (60 , TimeUnit .MINUTES );
106
96
}
107
97
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
-
121
98
}
0 commit comments