Permalink
Browse files

Setting for character encoding of source files.

Adds a feature that set the character encoding of source files.
Currently, character encodings of source files and the platform
have to be matched.

This change adds two ways to set the character encoding of
source files.
1) "report.source.encoding" property as EMMA report
   generation property.
2) "sourceencoding" attribute of html element for Ant.
If the character encoding of source files is not set,
the default encoding of the platform ("file.encoding"
property) is set. If "file.encoding" property is also
not defined, UTF-8 is set.

Currently, the character encoding of source files and
the platform have to be matched. Because the current HTML report
generator uses "file.encoding" property of JRE while reading
source files.

Change-Id: I43cc5d093cdcc9dc157e62146b9609f282d54e07
  • Loading branch information...
mikanbako committed Mar 11, 2013
1 parent 4d37e21 commit f475102f4916b57b7eb471bba09817af02d5ed8f
@@ -169,6 +169,11 @@ protected final String getType ()
super (task, settings);
}
public void setSourceEncoding (final String encoding)
{
m_settings.setProperty (m_prefix.concat (SOURCE_ENCODING), encoding);
}
static final String TYPE = "html";
@@ -26,6 +26,9 @@
String OUT_DIR = "out.dir";
String OUT_FILE = "out.file";
// parameter:
String SOURCE_ENCODING = "source.encoding";
// parameter:
String UNITS_TYPE = "units";
// values:
@@ -73,6 +73,18 @@ public File getOutFile ()
{
return m_outFile;
}
public void setSourceEncoding (final String sourceEncoding)
{
if ($assert.ENABLED) $assert.ASSERT (sourceEncoding != null, "null input: sourceEncoding");
m_sourceEncoding = sourceEncoding;
}
public String getSourceEncoding ()
{
return m_sourceEncoding;
}
public void setUnitsType (final int unitsType)
{
@@ -164,6 +176,7 @@ void validate () throws IllegalArgumentException
{
$assert.ASSERT (m_outEncoding != null, "m_outEncoding not set");
$assert.ASSERT (m_outDir != null || m_outFile != null, "either m_outDir or m_outFile must be set");
$assert.ASSERT (m_sourceEncoding != null, "m_sourceEncoding not set");
$assert.ASSERT (m_columnOrder != null, "m_columnOrder not set");
$assert.ASSERT (m_sortOrder != null, "m_sortOrder not set");
$assert.ASSERT (m_metrics != null, "m_metrics not set");
@@ -175,6 +188,8 @@ void validate () throws IllegalArgumentException
private File m_outDir;
private File m_outFile;
private String m_sourceEncoding;
private int m_unitsType;
private int m_viewType;
@@ -270,6 +285,11 @@ else if (outDirName != null)
result.setOutDir (new File (outDirName));
}
}
{
// Set encoding from properties or platform default encoding.
result.setSourceEncoding (getReportProperty (properties, type, IReportProperties.SOURCE_ENCODING, false, System.getProperty ("file.encoding", "UTF-8")));
}
{
final String unitsType = getReportProperty (properties, type, IReportProperties.UNITS_TYPE, true, IReportProperties.DEFAULT_UNITS_TYPE);
@@ -11,9 +11,10 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
@@ -1142,7 +1143,7 @@ private void embedSrcFile (final SrcFileItem item, final HTMLDocument page,
BufferedReader in = null;
try
{
in = new BufferedReader (new FileReader (srcFile), IO_BUF_SIZE);
in = new BufferedReader (new InputStreamReader (new FileInputStream (srcFile), m_settings.getSourceEncoding ()), IO_BUF_SIZE);
final boolean markupCoverage = m_hasLineNumberInfo;
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit f475102

Please sign in to comment.