Skip to content

Commit dc2f2b5

Browse files
committed
Change exception handling in ReportWriter
1 parent 597ad61 commit dc2f2b5

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/main/java/org/utplsql/maven/plugin/UtPlsqlMojo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.utplsql.maven.plugin.model.ReporterParameter;
2929

3030
import java.io.File;
31+
import java.io.IOException;
3132
import java.sql.Connection;
3233
import java.sql.SQLException;
3334
import java.util.ArrayList;
@@ -193,7 +194,7 @@ public void execute() throws MojoExecutionException {
193194
DBHelper.disableDBMSOutput(connection);
194195
connection.close();
195196
}
196-
} catch (SQLException e) {
197+
} catch (SQLException | IOException e) {
197198
getLog().error(e.getMessage(), e);
198199
}
199200
}

src/main/java/org/utplsql/maven/plugin/io/ReportWriter.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ public void addReporter(ReporterParameter parameter, Reporter reporter) {
6565
* Writes the reports to the output.
6666
*
6767
* @param connection The database {@link Connection}
68-
* @throws MojoExecutionException if any exception happens
68+
* @throws SQLException if database access fails
69+
* @throws IOException if files can't be written
6970
*/
70-
public void writeReports(Connection connection) throws MojoExecutionException {
71+
public void writeReports(Connection connection) throws SQLException, IOException {
7172
for (Pair<Reporter, ReporterParameter> pair : reporters) {
7273
writeReports(connection, pair.getLeft(), pair.getRight());
7374
}
7475
}
7576

76-
private void writeReports(Connection connection, Reporter reporter, ReporterParameter reporterParameter) throws MojoExecutionException {
77+
private void writeReports(Connection connection, Reporter reporter, ReporterParameter reporterParameter) throws IOException, SQLException {
7778
FileOutputStream fileOutputStream = null;
7879
try {
7980
OutputBuffer buffer = OutputBufferProvider.getCompatibleOutputBuffer(databaseVersion, reporter, connection);
@@ -103,15 +104,9 @@ private void writeReports(Connection connection, Reporter reporter, ReporterPara
103104

104105
buffer.printAvailable(connection, printStreams);
105106

106-
} catch (FileNotFoundException | SQLException e) {
107-
throw new MojoExecutionException(e.getMessage(), e);
108107
} finally {
109108
if (fileOutputStream != null) {
110-
try {
111-
fileOutputStream.close();
112-
} catch (IOException e) {
113-
log.error(format("Couldn't close the output stream %s", reporterParameter.getClass()));
114-
}
109+
fileOutputStream.close();
115110
}
116111
}
117112
}

0 commit comments

Comments
 (0)