77import org .utplsql .api .outputBuffer .OutputBuffer ;
88import org .utplsql .api .outputBuffer .OutputBufferProvider ;
99import org .utplsql .api .reporter .Reporter ;
10- import org .utplsql .maven .plugin .model . ReporterParameter ;
10+ import org .utplsql .maven .plugin .ReporterParameter ;
1111
1212import java .io .File ;
13+ import java .io .FileNotFoundException ;
1314import java .io .FileOutputStream ;
1415import java .io .IOException ;
1516import java .io .PrintStream ;
1617import java .sql .Connection ;
18+ import java .sql .SQLException ;
1719import java .util .ArrayList ;
1820import java .util .List ;
1921
2022import static java .lang .String .format ;
2123
22- public class ReporterWriter {
24+ /**
25+ * Writes the reports
26+ *
27+ * @author Alberto Hernández
28+ * @author Simon Martinelli
29+ */
30+ public class ReportWriter {
2331
2432 private final List <Pair <Reporter , ReporterParameter >> listReporters ;
2533
@@ -32,37 +40,35 @@ public class ReporterWriter {
3240 /**
3341 * Constructor of the reporter writer.
3442 *
35- * @param outputDirectory the reporter output directory
36- * @param databaseVersion the utPLSQL framework version
43+ * @param outputDirectory the report output directory
44+ * @param databaseVersion the utPLSQL framework {@link Version}
3745 * @param log the Maven log
3846 */
39- public ReporterWriter (String outputDirectory , Version databaseVersion , Log log ) {
47+ public ReportWriter (String outputDirectory , Version databaseVersion , Log log ) {
4048 this .listReporters = new ArrayList <>();
4149 this .outputDirectory = outputDirectory ;
4250 this .databaseVersion = databaseVersion ;
4351 this .log = log ;
4452 }
4553
4654 /**
47- * Adds a new reporter to the writter .
55+ * Adds a new reporter to the writer .
4856 *
49- * @param parameter the reporter parameter
50- * @param reporter the reporter Object
57+ * @param parameter the {@link ReporterParameter}
58+ * @param reporter the {@link Reporter}
5159 */
5260 public void addReporter (ReporterParameter parameter , Reporter reporter ) {
5361 listReporters .add (Pair .of (reporter , parameter ));
5462 }
5563
5664 /**
57- * Writes the reporters to the output.
65+ * Writes the reports to the output.
5866 *
59- * @param connection the database connection
67+ * @param connection The database {@link Connection}
6068 * @throws MojoExecutionException if any exception happens
6169 */
62- public void writeReporters (Connection connection ) throws MojoExecutionException {
63- log .debug ("Write Reporters" );
70+ public void writeReports (Connection connection ) throws MojoExecutionException {
6471 for (Pair <Reporter , ReporterParameter > pair : listReporters ) {
65- log .debug ("Write writeReports " + pair .getRight ().getName ());
6672 writeReports (connection , pair .getLeft (), pair .getRight ());
6773 }
6874 }
@@ -74,37 +80,37 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
7480 List <PrintStream > printStreams = new ArrayList <>();
7581
7682 if (reporterParameter .isFileOutput ()) {
77-
7883 File file = new File (reporterParameter .getFileOutput ());
7984 if (!file .isAbsolute ()) {
8085 file = new File (outputDirectory , reporterParameter .getFileOutput ());
8186 }
8287
8388 if (!file .getParentFile ().exists ()) {
84- log .debug ("Creating directory for reporter file " + file .getAbsolutePath ());
89+ log .debug ("Creating directory for report file " + file .getAbsolutePath ());
8590 file .getParentFile ().mkdirs ();
8691 }
8792
8893 fileOutputStream = new FileOutputStream (file );
8994 log .info (format ("Writing report %s to %s" , reporter .getTypeName (), file .getAbsolutePath ()));
9095
91- // Added to the Report
9296 printStreams .add (new PrintStream (fileOutputStream ));
9397 }
9498
9599 if (reporterParameter .isConsoleOutput ()) {
96100 log .info (format ("Writing report %s to Console" , reporter .getTypeName ()));
97101 printStreams .add (System .out );
98102 }
103+
99104 buffer .printAvailable (connection , printStreams );
100- } catch (Exception e ) {
101- throw new MojoExecutionException ("Unexpected error opening file ouput " , e );
105+
106+ } catch (FileNotFoundException | SQLException e ) {
107+ throw new MojoExecutionException ("Unexpected error opening file output " , e );
102108 } finally {
103109 if (fileOutputStream != null ) {
104110 try {
105111 fileOutputStream .close ();
106112 } catch (IOException e ) {
107- log .info (format ("Failed to closing the reporting %s" , reporterParameter .getClass ()));
113+ log .info (format ("Failed to closing the report %s" , reporterParameter .getClass ()));
108114 }
109115 }
110116 }
0 commit comments