25
25
import java .util .List ;
26
26
import java .util .logging .Logger ;
27
27
28
+ import org .utplsql .sqldev .dal .RealtimeReporterDao ;
28
29
import org .utplsql .sqldev .dal .UtplsqlDao ;
29
30
import org .utplsql .sqldev .exception .GenericDatabaseAccessException ;
30
31
import org .utplsql .sqldev .exception .GenericRuntimeException ;
31
32
import org .utplsql .sqldev .model .DatabaseTools ;
32
33
import org .utplsql .sqldev .model .FileTools ;
34
+ import org .utplsql .sqldev .model .preference .PreferenceModel ;
35
+ import org .utplsql .sqldev .runner .UtplsqlRunner ;
33
36
import org .utplsql .sqldev .ui .coverage .CodeCoverageReporterDialog ;
34
37
38
+ import oracle .ide .config .Preferences ;
39
+
35
40
public class CodeCoverageReporter {
36
41
private static final Logger logger = Logger .getLogger (CodeCoverageReporter .class .getName ());
37
42
43
+ private String connectionName ;
38
44
private Connection conn ;
39
45
private List <String > pathList ;
40
46
private List <String > includeObjectList ;
@@ -50,6 +56,7 @@ public CodeCoverageReporter(final List<String> pathList, final List<String> incl
50
56
setConnection (connectionName );
51
57
}
52
58
59
+ // constructor for testing purposes only
53
60
public CodeCoverageReporter (final List <String > pathList , final List <String > includeObjectList ,
54
61
final Connection conn ) {
55
62
this .pathList = pathList ;
@@ -64,7 +71,8 @@ private void setConnection(final String connectionName) {
64
71
throw new NullPointerException ();
65
72
} else {
66
73
// must be closed manually
67
- conn = DatabaseTools .cloneConnection (connectionName );
74
+ this .connectionName = connectionName ;
75
+ this .conn = DatabaseTools .getConnection (connectionName );
68
76
}
69
77
}
70
78
@@ -83,19 +91,43 @@ private ArrayList<String> toStringList(final String s) {
83
91
private void run () {
84
92
logger .fine (() -> "Running code coverage reporter for " + pathList + "..." );
85
93
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 ),
88
120
toStringList (includeObjects ), toStringList (excludeObjects ));
89
121
openInBrowser (html );
90
122
} finally {
91
123
try {
92
- DatabaseTools .closeConnection (conn );
124
+ if (coverageConn != null && conn == null ) {
125
+ // close only if connection has been cloned
126
+ DatabaseTools .closeConnection (coverageConn );
127
+ }
93
128
} catch (GenericDatabaseAccessException e ) {
94
129
// ignore
95
130
}
96
- if (frame != null ) {
97
- frame .exit ();
98
- }
99
131
}
100
132
}
101
133
0 commit comments