aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-02-08 11:28:38 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-02-08 11:28:38 +0100
commit940fc6143ae975b2ea0e611121bab63e0df58948 (patch)
tree731f1761fe070369a77fc6fc6b3407c3a19181ed /sonar-batch/src/main/java
parentf73dbafaa20c7e4d14d6b4ac8aa72f01ed07e25b (diff)
downloadsonarqube-940fc6143ae975b2ea0e611121bab63e0df58948.tar.gz
sonarqube-940fc6143ae975b2ea0e611121bab63e0df58948.zip
Improve quality
Diffstat (limited to 'sonar-batch/src/main/java')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java24
1 files changed, 6 insertions, 18 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java
index a850e8d4535..369ba2b5e91 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/HtmlReport.java
@@ -124,8 +124,6 @@ public class HtmlReport implements Reporter {
}
public void writeToFile(IssuesReport report, File toFile, boolean complete) {
- Writer writer = null;
- FileOutputStream fos = null;
try {
freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE);
freemarker.template.Configuration cfg = new freemarker.template.Configuration();
@@ -138,17 +136,14 @@ public class HtmlReport implements Reporter {
root.put("complete", complete);
Template template = cfg.getTemplate("issuesreport.ftl");
- fos = new FileOutputStream(toFile);
- writer = new OutputStreamWriter(fos, fs.encoding());
- template.process(root, writer);
- writer.flush();
+ try (FileOutputStream fos = new FileOutputStream(toFile); Writer writer = new OutputStreamWriter(fos, fs.encoding())) {
+ template.process(root, writer);
+ writer.flush();
+ }
} catch (Exception e) {
throw new IllegalStateException("Fail to generate HTML Issues Report to: " + toFile, e);
- } finally {
- IOUtils.closeQuietly(writer);
- IOUtils.closeQuietly(fos);
}
}
@@ -173,18 +168,11 @@ public class HtmlReport implements Reporter {
}
private void copyDependency(File target, String filename) {
- InputStream input = null;
- OutputStream output = null;
- try {
- input = getClass().getResourceAsStream("/org/sonar/batch/scan/report/issuesreport_files/" + filename);
- output = new FileOutputStream(new File(target, filename));
+ try (InputStream input = getClass().getResourceAsStream("/org/sonar/batch/scan/report/issuesreport_files/" + filename);
+ OutputStream output = new FileOutputStream(new File(target, filename))) {
IOUtils.copy(input, output);
-
} catch (IOException e) {
throw new IllegalStateException("Fail to copy file " + filename + " to " + target, e);
- } finally {
- IOUtils.closeQuietly(input);
- IOUtils.closeQuietly(output);
}
}