@@ -84,11 +84,26 @@ private void run() {
84
84
logger .fine (() -> "Running code coverage reporter for " + pathList + "..." );
85
85
try {
86
86
final UtplsqlDao dal = new UtplsqlDao (conn );
87
- final String content = dal .htmlCodeCoverage (pathList , toStringList (schemas ),
87
+ final String html = dal .htmlCodeCoverage (pathList , toStringList (schemas ),
88
88
toStringList (includeObjects ), toStringList (excludeObjects ));
89
+ openInBrowser (html );
90
+ } finally {
91
+ try {
92
+ DatabaseTools .closeConnection (conn );
93
+ } catch (GenericDatabaseAccessException e ) {
94
+ // ignore
95
+ }
96
+ if (frame != null ) {
97
+ frame .exit ();
98
+ }
99
+ }
100
+ }
101
+
102
+ public static void openInBrowser (String html ) {
103
+ try {
89
104
final File file = File .createTempFile ("utplsql_" , ".html" );
90
105
logger .fine (() -> "Writing result to " + file + "..." );
91
- FileTools .writeFile (file .toPath (), Arrays .asList (content .split (System .lineSeparator ())), StandardCharsets .UTF_8 );
106
+ FileTools .writeFile (file .toPath (), Arrays .asList (html .split (System .lineSeparator ())), StandardCharsets .UTF_8 );
92
107
final URL url = file .toURI ().toURL ();
93
108
logger .fine (() -> "Opening " + url .toExternalForm () + " in browser..." );
94
109
final Desktop desktop = Desktop .isDesktopSupported () ? Desktop .getDesktop () : null ;
@@ -97,21 +112,12 @@ private void run() {
97
112
logger .fine (() -> url .toExternalForm () + " opened in browser." );
98
113
} else {
99
114
logger .severe (
100
- () -> "Could not launch " + file + "in browser. No default browser defined on this system." );
115
+ () -> "Could not launch " + file + " in browser. No default browser defined on this system." );
101
116
}
102
117
} catch (Exception e ) {
103
- final String msg = "Error while running code coverage for " + pathList + " ." ;
118
+ final String msg = "Error while opening code coverage HTML report in browser ." ;
104
119
logger .severe (() -> msg );
105
120
throw new GenericRuntimeException (msg , e );
106
- } finally {
107
- try {
108
- DatabaseTools .closeConnection (conn );
109
- } catch (GenericDatabaseAccessException e ) {
110
- // ignore
111
- }
112
- if (frame != null ) {
113
- frame .exit ();
114
- }
115
121
}
116
122
}
117
123
0 commit comments