Skip to content
Permalink
Browse files

Fix several issues discovered by FindBugs

  • Loading branch information...
oleg-nenashev committed Jul 25, 2015
1 parent b0c8653 commit 489e3ae33bbef585834c4954946dfc595e176f82
@@ -41,6 +41,7 @@

import javax.servlet.ServletException;
import java.io.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -65,13 +66,16 @@ public HtmlPublisher(List<HtmlPublisherTarget> reportTargets) {
}

private static void writeFile(ArrayList<String> lines, File path) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
for (int i = 0; i < lines.size(); i++) {
bw.write(lines.get(i));
bw.newLine();
}
bw.close();
return;
//TODO: consider using UTF-8
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), Charset.defaultCharset()));
try {
for (int i = 0; i < lines.size(); i++) {
bw.write(lines.get(i));
bw.newLine();
}
} finally {
bw.close();
}
}

public ArrayList<String> readFile(String filePath) throws java.io.FileNotFoundException,
@@ -81,7 +85,8 @@ private static void writeFile(ArrayList<String> lines, File path) throws IOExcep
try {
final InputStream is = this.getClass().getResourceAsStream(filePath);
try {
final Reader r = new InputStreamReader(is);
// We expect that files have been generated with the default system's charset
final Reader r = new InputStreamReader(is, Charset.defaultCharset());
try {
final BufferedReader br = new BufferedReader(r);
try {
@@ -176,7 +181,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
reports.add(report);
String tabNo = "tab" + (j + 1);
// Make the report name the filename without the extension.
int end = report.lastIndexOf(".");
int end = report.lastIndexOf('.');
String reportName;
if (end > 0) {
reportName = report.substring(0, end);
@@ -62,7 +62,7 @@
/**
* The name of the file which will be used as the wrapper index.
*/
private final String wrapperName = "htmlpublisher-wrapper.html";
private static final String WRAPPER_NAME = "htmlpublisher-wrapper.html";

@DataBoundConstructor
public HtmlPublisherTarget(String reportName, String reportDir, String reportFiles, boolean keepAll, boolean alwaysLinkToLastBuild, boolean allowMissing) {
@@ -105,7 +105,7 @@ public String getSanitizedName() {
}

public String getWrapperName() {
return this.wrapperName;
return WRAPPER_NAME;
}

public FilePath getArchiveTarget(AbstractBuild build) {
@@ -154,7 +154,7 @@ public boolean shouldLinkToLastBuild() {
*/
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
DirectoryBrowserSupport dbs = new DirectoryBrowserSupport(this, new FilePath(this.dir()), this.getTitle(), "graph.gif", false);
dbs.setIndexFileName(HtmlPublisherTarget.this.wrapperName); // Hudson >= 1.312
dbs.setIndexFileName(HtmlPublisherTarget.WRAPPER_NAME); // Hudson >= 1.312
dbs.generateResponse(req, rsp, this);
}

0 comments on commit 489e3ae

Please sign in to comment.
You can’t perform that action at this time.