You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mp...@apache.org on 2006/01/09 00:59:57 UTC
svn commit: r367134 - in /maven/plugins/trunk/maven-pmd-plugin/src:
main/java/org/apache/maven/plugin/pmd/PmdReport.java site/apt/howto.apt
Author: mperham
Date: Sun Jan 8 15:59:54 2006
New Revision: 367134
URL: http://svn.apache.org/viewcvs?rev=367134&view=rev
Log:
PR: MPMD-7
Submitted by: Christian Schulte
Add support for configurable source encodings
Modified:
maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt
Modified: maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java?rev=367134&r1=367133&r2=367134&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/main/java/org/apache/maven/plugin/pmd/PmdReport.java Sun Jan 8 15:59:54 2006
@@ -17,11 +17,15 @@
*/
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.Collections;
import java.util.Iterator;
@@ -116,6 +120,12 @@
private String xrefLocation = "xref";
/**
+ * The file encoding to use when reading the java source.
+ * @parameter
+ */
+ private String sourceEncoding;
+
+ /**
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/
public String getName( Locale locale )
@@ -203,6 +213,8 @@
InputStream rulesInput = pmd.getClass().getResourceAsStream( location );
sets[idx] = ruleSetFactory.createRuleSet( rulesInput );
}
+
+ boolean hasEncoding = sourceEncoding != null;
for ( Iterator i = files.iterator(); i.hasNext(); )
{
@@ -216,8 +228,18 @@
ruleContext.setSourceCodeFilename( file.getAbsolutePath() );
for ( int idx = 0; idx < rulesets.length; idx++ )
{
- // PMD closes this Reader even though it did not open it.
- pmd.processFile( new FileReader( file ), sets[idx], ruleContext );
+ try
+ {
+ // PMD closes this Reader even though it did not open it so we have
+ // to open a new one with every call to processFile().
+ Reader reader = hasEncoding ? new InputStreamReader( new FileInputStream( file ), sourceEncoding )
+ : new FileReader( file );
+ pmd.processFile( reader, sets[idx], ruleContext );
+ }
+ catch ( UnsupportedEncodingException e1 )
+ {
+ throw new MavenReportException( "Encoding '" + sourceEncoding + "' is not supported.", e1 );
+ }
}
reportSink.endFile( file );
}
Modified: maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt?rev=367134&r1=367133&r2=367134&view=diff
==============================================================================
--- maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt (original)
+++ maven/plugins/trunk/maven-pmd-plugin/src/site/apt/howto.apt Sun Jan 8 15:59:54 2006
@@ -22,6 +22,9 @@
The PMD report will link directly to the cross-referenced source if you enable this with the linkXref parameter.
See the {{{http://mojo.codehaus.org/jxr-maven-plugin/}JXR}} plugin for more details.
+ If your source uses a non-default encoding, you can use the sourceEncoding parameter to tell Maven which
+ encoding to use when reading the java source.
+
+--------
<reporting>
<plugins>
@@ -35,6 +38,7 @@
</rulesets>
<format>xml</format>
<linkXref>true</linkXref>
+ <sourceEncoding>utf-8</sourceEncoding>
</configuration>
</plugin>
</plugins>