/hg/gfx-test: 2012-02-21 Pavel Tisnovsky <ptisnovs at redhat.com>
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Tue Feb 21 05:47:40 PST 2012
changeset b320e45d2759 in /hg/gfx-test
details: http://icedtea.classpath.org/hg/gfx-test?cmd=changeset;node=b320e45d2759
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Tue Feb 21 14:49:56 2012 +0100
2012-02-21 Pavel Tisnovsky <ptisnovs at redhat.com>
*
src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java:
* src/org/gfxtest/ImageDiffer/ResultWriters/ResultWriter.java:
* src/org/gfxtest/harness/Configuration.java:
* src/org/gfxtest/harness/ExternalCommands.java:
* src/org/gfxtest/harness/FileSystemTools.java:
* src/org/gfxtest/harness/SourceViewer.java:
* src/org/gfxtest/reporter/Reporter.java:
* src/org/gfxtest/testsuites/ScaledPolylines.java: More changes
which fix some issues found by FindBugs.
diffstat:
ChangeLog | 12 ++
src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java | 53 ++++++++-
src/org/gfxtest/ImageDiffer/ResultWriters/ResultWriter.java | 10 +-
src/org/gfxtest/harness/Configuration.java | 38 ++++++-
src/org/gfxtest/harness/ExternalCommands.java | 9 +-
src/org/gfxtest/harness/FileSystemTools.java | 24 ++++-
src/org/gfxtest/harness/SourceViewer.java | 30 ++++-
src/org/gfxtest/reporter/Reporter.java | 13 ++-
src/org/gfxtest/testsuites/ScaledPolylines.java | 2 +-
9 files changed, 165 insertions(+), 26 deletions(-)
diffs (404 lines):
diff -r ea826a03b3bd -r b320e45d2759 ChangeLog
--- a/ChangeLog Mon Feb 20 16:28:10 2012 +0100
+++ b/ChangeLog Tue Feb 21 14:49:56 2012 +0100
@@ -1,3 +1,15 @@
+2012-02-21 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java:
+ * src/org/gfxtest/ImageDiffer/ResultWriters/ResultWriter.java:
+ * src/org/gfxtest/harness/Configuration.java:
+ * src/org/gfxtest/harness/ExternalCommands.java:
+ * src/org/gfxtest/harness/FileSystemTools.java:
+ * src/org/gfxtest/harness/SourceViewer.java:
+ * src/org/gfxtest/reporter/Reporter.java:
+ * src/org/gfxtest/testsuites/ScaledPolylines.java:
+ More changes which fix some issues found by FindBugs.
+
2012-02-20 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/gfxtest/ImageDiffer/Main.java:
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java
--- a/src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/ImageDiffer/ResultWriters/HtmlStructureWriter.java Tue Feb 21 14:49:56 2012 +0100
@@ -44,17 +44,22 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
+
import org.gfxtest.ImageDiffer.ComparisonResult;
import org.gfxtest.ImageDiffer.Configuration;
-
import org.gfxtest.framework.Log;
/**
@@ -64,6 +69,11 @@
*/
public class HtmlStructureWriter
{
+ /**
+ * Default encoding used for all input/output operations.
+ */
+ private static final String DEFAULT_ENCODING = "UTF-8";
+
private static final String TEMPLATE_DIR = "templates";
static Log log = new Log(HtmlStructureWriter.class.getName(), true);
@@ -99,23 +109,52 @@
BufferedReader template = null;
try
{
- writer = new BufferedWriter(new FileWriter(new File(newDir, "result.html")));
- template = new BufferedReader(new FileReader(new File(TEMPLATE_DIR, templateName)));
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(newDir, "result.html")), DEFAULT_ENCODING));
+ template = new BufferedReader(new InputStreamReader(new FileInputStream(new File(TEMPLATE_DIR, templateName)), DEFAULT_ENCODING));
String line;
while ((line = template.readLine()) != null)
{
writer.write(replacePlaceholders(cr, newDir, line));
}
}
+ catch (UnsupportedEncodingException e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
finally
{
if (template != null)
{
- template.close();
+ try
+ {
+ template.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
}
if (writer != null)
{
- writer.close();
+ try
+ {
+ writer.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
}
}
}
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/ImageDiffer/ResultWriters/ResultWriter.java
--- a/src/org/gfxtest/ImageDiffer/ResultWriters/ResultWriter.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/ImageDiffer/ResultWriters/ResultWriter.java Tue Feb 21 14:49:56 2012 +0100
@@ -43,14 +43,20 @@
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import org.gfxtest.ImageDiffer.ComparisonResult;
import org.gfxtest.ImageDiffer.Configuration;
public abstract class ResultWriter
{
+ /**
+ * Default encoding used for all input/output operations.
+ */
+ private static final String DEFAULT_ENCODING = "UTF-8";
+
protected BufferedWriter writer = null;
public ResultWriter(File outputDirectory, String fileName) throws IOException
@@ -66,7 +72,7 @@
private BufferedWriter createFile(File outputDirectory, String fileName) throws IOException
{
- return outputDirectory == null ? null : new BufferedWriter(new FileWriter(new File(outputDirectory, fileName)));
+ return outputDirectory == null ? null : new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outputDirectory, fileName)), DEFAULT_ENCODING));
}
public void close() throws IOException
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/harness/Configuration.java
--- a/src/org/gfxtest/harness/Configuration.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/harness/Configuration.java Tue Feb 21 14:49:56 2012 +0100
@@ -99,9 +99,11 @@
// Read properties file.
Properties properties = new Properties();
+ FileInputStream fileInputStream = null;
try
{
- properties.load(new FileInputStream(PROPERTIES_FILE_NAME));
+ fileInputStream = new FileInputStream(PROPERTIES_FILE_NAME);
+ properties.load(fileInputStream);
}
catch (FileNotFoundException e)
{
@@ -115,6 +117,21 @@
this.printErrorMessage(e);
this.setDefaultValues();
}
+ finally
+ {
+ if (fileInputStream != null)
+ {
+ try
+ {
+ fileInputStream.close();
+ }
+ catch (IOException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
this.setReferenceJava(properties.getProperty("jre.reference"));
this.setTestedJava(properties.getProperty("jre.tested"));
this.setVerboseCompile("true".equals(properties.getProperty("compile.verbose")));
@@ -147,16 +164,31 @@
properties.setProperty("mainWindow.height", "" + this.getMainWindowHeight());
properties.setProperty("paths.samplesDirectory", this.getSamplesDirectory());
properties.setProperty("paths.outputDirectory", this.getOutputDirectory());
-
+ FileOutputStream fileOutputStream = null;
try
{
- properties.store(new FileOutputStream(PROPERTIES_FILE_NAME), null);
+ fileOutputStream = new FileOutputStream(PROPERTIES_FILE_NAME);
+ properties.store(fileOutputStream, null);
}
catch (IOException e)
{
result = false;
e.printStackTrace();
}
+ finally
+ {
+ if (fileOutputStream != null)
+ {
+ try
+ {
+ fileOutputStream.close();
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
return result;
}
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/harness/ExternalCommands.java
--- a/src/org/gfxtest/harness/ExternalCommands.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/harness/ExternalCommands.java Tue Feb 21 14:49:56 2012 +0100
@@ -57,6 +57,11 @@
public class ExternalCommands
{
/**
+ * Default encoding used for all input/output operations.
+ */
+ private static final String DEFAULT_ENCODING = "UTF-8";
+
+ /**
* Run options used to start each test suite.
*/
private static final String RUN_OPTIONS =
@@ -93,7 +98,7 @@
*/
private static String fetchStandardOutput(Process process) throws IOException
{
- BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream(), DEFAULT_ENCODING));
return copyFromBufferedReaderToString(stdInput);
}
@@ -107,7 +112,7 @@
*/
private static String fetchErrorOutput(Process process) throws IOException
{
- BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+ BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream(), DEFAULT_ENCODING));
return copyFromBufferedReaderToString(stdError);
}
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/harness/FileSystemTools.java
--- a/src/org/gfxtest/harness/FileSystemTools.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/harness/FileSystemTools.java Tue Feb 21 14:49:56 2012 +0100
@@ -49,6 +49,12 @@
*/
public class FileSystemTools
{
+ /**
+ * Create directory.
+ *
+ * @param directoryName
+ * directory which should be created
+ */
public static void createDirectory(String directoryName)
{
File directory = new File(directoryName);
@@ -60,16 +66,30 @@
}
if (!directory.exists())
{
- directory.mkdir();
+ if (directory.mkdir())
+ {
+ System.out.println("Warning: cannot create directory " + directory.getAbsolutePath());
+ }
}
}
+ /**
+ * Try to delete all files in given directory.
+ *
+ * @param directoryName
+ * directory which content should be deleted
+ */
public static void eraseDirectory(String directoryName)
{
File directory = new File(directoryName);
for (String fileName : directory.list())
{
- new File(directory, fileName).delete();
+ File fileToDelete = new File(directory, fileName);
+ // try to delete work file
+ if (!fileToDelete.delete())
+ {
+ System.out.println("Warning: cannot delete file " + fileToDelete.getAbsolutePath());
+ }
}
}
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/harness/SourceViewer.java
--- a/src/org/gfxtest/harness/SourceViewer.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/harness/SourceViewer.java Tue Feb 21 14:49:56 2012 +0100
@@ -47,8 +47,9 @@
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStreamReader;
@@ -60,6 +61,11 @@
public class SourceViewer
{
+ /**
+ * Default encoding used for all input/output operations.
+ */
+ private static final String DEFAULT_ENCODING = "UTF-8";
+
protected JFrame frame = new JFrame(Configuration.getWindowTitle());
private JTextArea textArea = new JTextArea();
private JButton buttonClose = new JButton("Close");
@@ -86,14 +92,24 @@
{
throw new IOException("File " + fin.getCanonicalPath() + " not found");
}
- BufferedReader reader = new BufferedReader(new FileReader(fin));
- String line;
- while ((line=reader.readLine())!=null)
+ BufferedReader reader = null;
+ try
{
- this.textArea.append(line);
- this.textArea.append("\n");
+ reader = new BufferedReader(new InputStreamReader(new FileInputStream(fin), DEFAULT_ENCODING));
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ this.textArea.append(line);
+ this.textArea.append("\n");
+ }
}
- reader.close();
+ finally
+ {
+ if (reader != null)
+ {
+ reader.close();
+ }
+ }
}
private void constructFrame() {
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/reporter/Reporter.java
--- a/src/org/gfxtest/reporter/Reporter.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/reporter/Reporter.java Tue Feb 21 14:49:56 2012 +0100
@@ -60,6 +60,11 @@
@SuppressWarnings("nls")
public class Reporter
{
+ /**
+ * Default encoding used for all input/output operations.
+ */
+ private static final String DEFAULT_ENCODING = "UTF-8";
+
private Log log = null;
private ReporterConfiguration configuration = null;
@@ -114,8 +119,12 @@
{
this.configuration = new ReporterConfiguration(args, this.log);
Map<String, TestResult> testResults = readAllTestResults();
- input = new BufferedReader(new FileReader(new File(TEMPLATE_DIR, INPUT_FILE_NAME)));
- output = new BufferedWriter(new FileWriter(new File(this.configuration.getOutputPath(), OUTPUT_FILE_NAME)));
+
+ Reader reader = new InputStreamReader(new FileInputStream(new File(TEMPLATE_DIR, INPUT_FILE_NAME)), DEFAULT_ENCODING);
+ Writer writer = new OutputStreamWriter(new FileOutputStream(new File(this.configuration.getOutputPath(), OUTPUT_FILE_NAME)), DEFAULT_ENCODING);
+
+ input = new BufferedReader(reader);
+ output = new BufferedWriter(writer);
writeHtmlHeader(input, output);
writeHeaderForCommonTests(output);
for (String entity : ENTITIES)
diff -r ea826a03b3bd -r b320e45d2759 src/org/gfxtest/testsuites/ScaledPolylines.java
--- a/src/org/gfxtest/testsuites/ScaledPolylines.java Mon Feb 20 16:28:10 2012 +0100
+++ b/src/org/gfxtest/testsuites/ScaledPolylines.java Tue Feb 21 14:49:56 2012 +0100
@@ -70,7 +70,7 @@
int x1 = (int) (OFFSET / scale);
int y1 = (int) ((image.getHeight() - OFFSET) / scale);
- int x2 = (int) ((image.getWidth() / 2) / scale);
+ int x2 = (int) ((image.getWidth() / 2.0) / scale);
int y2 = (int) (OFFSET / scale);
int x3 = (int) ((image.getWidth() - OFFSET) / scale);
int y3 = y1;
More information about the distro-pkg-dev
mailing list