@@ -84,11 +84,26 @@ private void run() {
8484 logger .fine (() -> "Running code coverage reporter for " + pathList + "..." );
8585 try {
8686 final UtplsqlDao dal = new UtplsqlDao (conn );
87- final String content = dal .htmlCodeCoverage (pathList , toStringList (schemas ),
87+ final String html = dal .htmlCodeCoverage (pathList , toStringList (schemas ),
8888 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 {
89104 final File file = File .createTempFile ("utplsql_" , ".html" );
90105 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 );
92107 final URL url = file .toURI ().toURL ();
93108 logger .fine (() -> "Opening " + url .toExternalForm () + " in browser..." );
94109 final Desktop desktop = Desktop .isDesktopSupported () ? Desktop .getDesktop () : null ;
@@ -97,21 +112,12 @@ private void run() {
97112 logger .fine (() -> url .toExternalForm () + " opened in browser." );
98113 } else {
99114 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." );
101116 }
102117 } 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 ." ;
104119 logger .severe (() -> msg );
105120 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- }
115121 }
116122 }
117123
0 commit comments