2525import java .util .List ;
2626import java .util .logging .Logger ;
2727
28+ import org .utplsql .sqldev .dal .RealtimeReporterDao ;
2829import org .utplsql .sqldev .dal .UtplsqlDao ;
2930import org .utplsql .sqldev .exception .GenericDatabaseAccessException ;
3031import org .utplsql .sqldev .exception .GenericRuntimeException ;
3132import org .utplsql .sqldev .model .DatabaseTools ;
3233import org .utplsql .sqldev .model .FileTools ;
34+ import org .utplsql .sqldev .model .preference .PreferenceModel ;
35+ import org .utplsql .sqldev .runner .UtplsqlRunner ;
3336import org .utplsql .sqldev .ui .coverage .CodeCoverageReporterDialog ;
3437
38+ import oracle .ide .config .Preferences ;
39+
3540public class CodeCoverageReporter {
3641 private static final Logger logger = Logger .getLogger (CodeCoverageReporter .class .getName ());
3742
43+ private String connectionName ;
3844 private Connection conn ;
3945 private List <String > pathList ;
4046 private List <String > includeObjectList ;
@@ -50,6 +56,7 @@ public CodeCoverageReporter(final List<String> pathList, final List<String> incl
5056 setConnection (connectionName );
5157 }
5258
59+ // constructor for testing purposes only
5360 public CodeCoverageReporter (final List <String > pathList , final List <String > includeObjectList ,
5461 final Connection conn ) {
5562 this .pathList = pathList ;
@@ -64,7 +71,8 @@ private void setConnection(final String connectionName) {
6471 throw new NullPointerException ();
6572 } else {
6673 // must be closed manually
67- conn = DatabaseTools .cloneConnection (connectionName );
74+ this .connectionName = connectionName ;
75+ this .conn = DatabaseTools .getConnection (connectionName );
6876 }
6977 }
7078
@@ -83,19 +91,43 @@ private ArrayList<String> toStringList(final String s) {
8391 private void run () {
8492 logger .fine (() -> "Running code coverage reporter for " + pathList + "..." );
8593 try {
86- final UtplsqlDao dal = new UtplsqlDao (conn );
87- final String html = dal .htmlCodeCoverage (pathList , toStringList (schemas ),
94+ final RealtimeReporterDao dao = new RealtimeReporterDao (conn );
95+ final PreferenceModel preferences = PreferenceModel .getInstance (Preferences .getPreferences ());
96+ if (preferences .isUseRealtimeReporter () && dao .isSupported ()) {
97+ runCodeCoverageWithRealtimeReporter ();
98+ } else {
99+ runCodeCoverageStandalone ();
100+ }
101+ } finally {
102+ if (frame != null ) {
103+ frame .exit ();
104+ }
105+ }
106+ }
107+
108+ private void runCodeCoverageWithRealtimeReporter () {
109+ final UtplsqlRunner runner = new UtplsqlRunner (pathList , toStringList (schemas ), toStringList (includeObjects ),
110+ toStringList (excludeObjects ), connectionName );
111+ runner .runTestAsync ();
112+ }
113+
114+ private void runCodeCoverageStandalone () {
115+ Connection coverageConn = null ;
116+ try {
117+ coverageConn = conn != null ? conn : DatabaseTools .cloneConnection (connectionName );
118+ final UtplsqlDao dao = new UtplsqlDao (coverageConn );
119+ final String html = dao .htmlCodeCoverage (pathList , toStringList (schemas ),
88120 toStringList (includeObjects ), toStringList (excludeObjects ));
89121 openInBrowser (html );
90122 } finally {
91123 try {
92- DatabaseTools .closeConnection (conn );
124+ if (coverageConn != null && conn == null ) {
125+ // close only if connection has been cloned
126+ DatabaseTools .closeConnection (coverageConn );
127+ }
93128 } catch (GenericDatabaseAccessException e ) {
94129 // ignore
95130 }
96- if (frame != null ) {
97- frame .exit ();
98- }
99131 }
100132 }
101133
0 commit comments