2727
2828import javax .swing .JFrame ;
2929
30+ import org .utplsql .sqldev .coverage .CodeCoverageReporter ;
3031import org .utplsql .sqldev .dal .RealtimeReporterDao ;
3132import org .utplsql .sqldev .dal .RealtimeReporterEventConsumer ;
3233import org .utplsql .sqldev .model .DatabaseTools ;
4849public class UtplsqlRunner implements RealtimeReporterEventConsumer {
4950 private static final Logger logger = Logger .getLogger (UtplsqlRunner .class .getName ());
5051
51- private List <String > pathList ;
52+ private final boolean withCodeCoverage ;
53+ private final List <String > pathList ;
54+ private final List <String > schemaList ;
55+ private final List <String > includeObjectList ;
56+ private final List <String > excludeObjectList ;
5257 private String connectionName ;
5358 private Connection producerConn ;
5459 private Connection consumerConn ;
55- private final String reporterId = UUID .randomUUID ().toString ().replace ("-" , "" );
60+ private final String realtimeReporterId = UUID .randomUUID ().toString ().replace ("-" , "" );
61+ private final String coverageReporterId = UUID .randomUUID ().toString ().replace ("-" , "" );
5662 private Run run ;
5763 private RunnerPanel panel ;
64+ private JFrame frame ; // for testing purposes only (outside of SQL Developer)
5865 private Thread producerThread ;
5966 private Thread consumerThread ;
6067
6168 public UtplsqlRunner (final List <String > pathList , final String connectionName ) {
69+ this .withCodeCoverage = false ;
6270 this .pathList = pathList ;
71+ this .schemaList = null ;
72+ this .includeObjectList = null ;
73+ this .excludeObjectList = null ;
74+ setConnection (connectionName );
75+ }
76+
77+ public UtplsqlRunner (final List <String > pathList , final List <String > schemaList ,
78+ final List <String > includeObjectList , final List <String > excludeObjectList , final String connectionName ) {
79+ this .withCodeCoverage = true ;
80+ this .pathList = pathList ;
81+ this .schemaList = schemaList ;
82+ this .includeObjectList = includeObjectList ;
83+ this .excludeObjectList = excludeObjectList ;
6384 setConnection (connectionName );
6485 }
6586
6687 /**
67- * this constructor is intended for tests only
88+ * this constructor is intended for tests only (without code coverage)
6889 */
6990 public UtplsqlRunner (final List <String > pathList , final Connection producerConn , final Connection consumerConn ) {
91+ this .withCodeCoverage = false ;
7092 this .pathList = pathList ;
93+ this .schemaList = null ;
94+ this .includeObjectList = null ;
95+ this .excludeObjectList = null ;
96+ this .producerConn = producerConn ;
97+ this .consumerConn = consumerConn ;
98+ }
99+
100+ /**
101+ * this constructor is intended for tests only (with code coverage)
102+ */
103+ public UtplsqlRunner (final List <String > pathList , final List <String > schemaList ,
104+ final List <String > includeObjectList , final List <String > excludeObjectList , final Connection producerConn ,
105+ final Connection consumerConn ) {
106+ this .withCodeCoverage = true ;
107+ this .pathList = pathList ;
108+ this .schemaList = schemaList ;
109+ this .includeObjectList = includeObjectList ;
110+ this .excludeObjectList = excludeObjectList ;
71111 this .producerConn = producerConn ;
72112 this .consumerConn = consumerConn ;
73113 }
@@ -86,6 +126,9 @@ public void dispose() {
86126 // running in SQL Developer
87127 DatabaseTools .closeConnection (producerConn );
88128 DatabaseTools .closeConnection (consumerConn );
129+ if (frame != null ) {
130+ frame .setVisible (false );
131+ }
89132 }
90133
91134 @ Override
@@ -116,7 +159,7 @@ private String getSysdate() {
116159 }
117160
118161 private void initRun () {
119- run = new Run (reporterId , connectionName , pathList );
162+ run = new Run (realtimeReporterId , connectionName , pathList );
120163 run .setStartTime (getSysdate ());
121164 run .getCounter ().setDisabled (0 );
122165 run .getCounter ().setSuccess (0 );
@@ -128,14 +171,14 @@ private void initRun() {
128171 run .setCurrentTestNumber (0 );
129172 run .setStatus (UtplsqlResources .getString ("RUNNER_INITIALIZING_TEXT" ));
130173 panel .setModel (run );
131- panel .update (reporterId );
174+ panel .update (realtimeReporterId );
132175 }
133176
134177 private void doProcess (final PreRunEvent event ) {
135178 run .setTotalNumberOfTests (event .getTotalNumberOfTests ());
136179 run .put (event .getItems ());
137180 run .setStatus (UtplsqlResources .getString ("RUNNER_RUNNING_TEXT" ));
138- panel .update (reporterId );
181+ panel .update (realtimeReporterId );
139182 }
140183
141184 private void doProcess (final PostRunEvent event ) {
@@ -145,7 +188,7 @@ private void doProcess(final PostRunEvent event) {
145188 run .setErrorStack (event .getErrorStack ());
146189 run .setServerOutput (event .getServerOutput ());
147190 run .setStatus (UtplsqlResources .getString ("RUNNER_FINNISHED_TEXT" ));
148- panel .update (reporterId );
191+ panel .update (realtimeReporterId );
149192 }
150193
151194 private void doProcess (final PreSuiteEvent event ) {
@@ -189,7 +232,7 @@ private void doProcess(final PostSuiteEvent event) {
189232 sb .append (event .getServerOutput ());
190233 test .setServerOutput (sb .toString ());
191234 }
192- panel .update (reporterId );
235+ panel .update (realtimeReporterId );
193236 }
194237
195238 private void doProcess (final PreTestEvent event ) {
@@ -203,7 +246,7 @@ private void doProcess(final PreTestEvent event) {
203246 run .setStatus (event .getId () + "..." );
204247 run .setCurrentTestNumber (event .getTestNumber ());
205248 run .setCurrentTest (test );
206- panel .update (reporterId );
249+ panel .update (realtimeReporterId );
207250 }
208251
209252 private void doProcess (final PostTestEvent event ) {
@@ -234,37 +277,45 @@ private void doProcess(final PostTestEvent event) {
234277 run .getCounter ().setSuccess (run .getCounter ().getSuccess () + event .getCounter ().getSuccess ());
235278 run .getCounter ().setFailure (run .getCounter ().getFailure () + event .getCounter ().getFailure ());
236279 run .getCounter ().setError (run .getCounter ().getError () + event .getCounter ().getError ());
237- panel .update (reporterId );
280+ panel .update (realtimeReporterId );
238281 }
239282
240283 private void produce () {
241284 try {
242- logger .fine (() -> "Running utPLSQL tests and producing events via reporter id " + reporterId + "..." );
285+ logger .fine (() -> "Running utPLSQL tests and producing events via reporter id " + realtimeReporterId + "..." );
243286 final RealtimeReporterDao dao = new RealtimeReporterDao (producerConn );
244- dao .produceReport (reporterId , pathList );
245- logger .fine (() -> "All events produced for reporter id " + reporterId + "." );
287+ if (withCodeCoverage ) {
288+ dao .produceReportWithCoverage (realtimeReporterId , coverageReporterId , pathList , schemaList , includeObjectList , excludeObjectList );
289+ } else {
290+ dao .produceReport (realtimeReporterId , pathList );
291+ }
292+ logger .fine (() -> "All events produced for reporter id " + realtimeReporterId + "." );
246293 } catch (Exception e ) {
247- logger .severe (() -> "Error while producing events for reporter id " + reporterId + ": "
294+ logger .severe (() -> "Error while producing events for reporter id " + realtimeReporterId + ": "
248295 + (e != null ? e .getMessage () : "???" ));
249296 }
250297 }
251298
252299 private void consume () {
253300 try {
254- logger .fine (() -> "Consuming events from reporter id " + reporterId + " in realtime..." );
301+ logger .fine (() -> "Consuming events from reporter id " + realtimeReporterId + " in realtime..." );
255302 final RealtimeReporterDao dao = new RealtimeReporterDao (consumerConn );
256- dao .consumeReport (reporterId , this );
303+ dao .consumeReport (realtimeReporterId , this );
257304 logger .fine (() -> "All events consumed." );
305+ if (withCodeCoverage ) {
306+ String html = dao .getHtmlCoverage (coverageReporterId );
307+ CodeCoverageReporter .openInBrowser (html );
308+ }
258309 } catch (Exception e ) {
259- logger .severe (() -> "Error while consuming events for reporter id " + reporterId + ": "
310+ logger .severe (() -> "Error while consuming events for reporter id " + realtimeReporterId + ": "
260311 + (e != null ? e .getMessage () : "???" ));
261312 }
262313 if (run .getTotalNumberOfTests () < 0 ) {
263314 run .setStatus (UtplsqlResources .getString ("RUNNER_NO_TESTS_FOUND_TEXT" ));
264315 run .setExecutionTime (Double .valueOf (System .currentTimeMillis () - Double .valueOf (run .getStart ())) / 1000 );
265316 run .setEndTime (getSysdate ());
266317 run .setTotalNumberOfTests (0 );
267- panel .update (reporterId );
318+ panel .update (realtimeReporterId );
268319 }
269320 if (isRunningInSqlDeveloper ()) {
270321 dispose ();
@@ -285,7 +336,7 @@ private boolean initGUI() {
285336 RunnerFactory .showDockable ();
286337 panel = dockable .getRunnerPanel ();
287338 } else {
288- final JFrame frame = new JFrame ("utPLSQL Runner Panel" );
339+ frame = new JFrame ("utPLSQL Runner Panel" );
289340 frame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
290341 panel = new RunnerPanel ();
291342 frame .add (panel .getGUI ());
0 commit comments