pmd: correct documentation for pmd's ant task to select the language
and adding more unit tests.
This commit is contained in:
parent
2e85f1f935
commit
3901ad7ddb
@ -99,7 +99,7 @@
|
||||
|
||||
<p><code>auxclasspath</code> nested element - extra classpath used for Type Resolution rules.</p>
|
||||
|
||||
<p><code>language</code> nested element - specify which language (Java, Ecmascript, XML,...) and the associated version (1.5, 1.6,...)</p>
|
||||
<p><code>sourceLanguage</code> nested element - specify which language (Java, Ecmascript, XML,...) and the associated version (1.5, 1.6,...)</p>
|
||||
|
||||
<p><code>ruleset</code> nested element - another way to specify rulesets. Here's an example:</p>
|
||||
<source>
|
||||
@ -107,7 +107,7 @@
|
||||
<target name="pmd">
|
||||
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask"/>
|
||||
<pmd shortFilenames="true">
|
||||
<language name="java" versio="1.6"/>
|
||||
<sourceLanguage name="java" version="1.6"/>
|
||||
<ruleset>rulesets/java/design.xml</ruleset>
|
||||
<ruleset>java-basic</ruleset>
|
||||
<formatter type="html" toFile="pmd_report.html" linkPrefix="http://pmd.sourceforge.net/xref/"/>
|
||||
@ -122,6 +122,30 @@
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="Language selection">
|
||||
<p>The language to be used for parsing is selected via the <code>sourceLanguage</code> nested element.
|
||||
Possible values are:</p>
|
||||
|
||||
<source>
|
||||
<![CDATA[
|
||||
<sourceLanguage name="cpp" version=""/>
|
||||
<sourceLanguage name="fortran" version=""/>
|
||||
<sourceLanguage name="ecmascript" version="3"/>
|
||||
<sourceLanguage name="java" version="1.3"/>
|
||||
<sourceLanguage name="java" version="1.4"/>
|
||||
<sourceLanguage name="java" version="1.5"/>
|
||||
<sourceLanguage name="java" version="1.6"/>
|
||||
<sourceLanguage name="java" version="1.7"/>
|
||||
<sourceLanguage name="jsp" version=""/>
|
||||
<sourceLanguage name="php" version=""/>
|
||||
<sourceLanguage name="ruby" version=""/>
|
||||
<sourceLanguage name="xsl" version=""/>
|
||||
<sourceLanguage name="xml" version=""/>
|
||||
]]>
|
||||
</source>
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="Postprocessing the report file with XSLT">
|
||||
<p>Several folks (most recently, Wouter Zelle) have written XSLT scripts
|
||||
which you can use to transform the XML report into nifty HTML. To do this,
|
||||
|
@ -6,6 +6,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
import net.sourceforge.pmd.ant.SourceLanguage;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -16,20 +17,41 @@ import org.junit.runners.Parameterized.Parameters;
|
||||
@RunWith(Parameterized.class)
|
||||
public class LanguageVersionTest {
|
||||
|
||||
private String language;
|
||||
private String version;
|
||||
private String terseName;
|
||||
private LanguageVersion expected;
|
||||
|
||||
public LanguageVersionTest(String terseName, LanguageVersion expected) {
|
||||
this.terseName = terseName;
|
||||
public LanguageVersionTest(String language, String version, LanguageVersion expected) {
|
||||
this.language = language;
|
||||
this.version = version;
|
||||
this.terseName = language;
|
||||
if (version != null && !version.isEmpty()) {
|
||||
this.terseName += " " + version;
|
||||
}
|
||||
this.expected = expected;
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection data() {
|
||||
return Arrays.asList(new Object[][] { { "java 1.3", LanguageVersion.JAVA_13 },
|
||||
{ "java 1.4", LanguageVersion.JAVA_14 }, { "java 1.5", LanguageVersion.JAVA_15 },
|
||||
{ "java 1.6", LanguageVersion.JAVA_16 }, { "java 1.7", LanguageVersion.JAVA_17 },
|
||||
{ "jsp", LanguageVersion.JSP }, });
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ "java", "1.3", LanguageVersion.JAVA_13 },
|
||||
{ "java", "1.4", LanguageVersion.JAVA_14 },
|
||||
{ "java", "1.5", LanguageVersion.JAVA_15 },
|
||||
{ "java", "1.6", LanguageVersion.JAVA_16 },
|
||||
{ "java", "1.7", LanguageVersion.JAVA_17 },
|
||||
{ "jsp", "", LanguageVersion.JSP },
|
||||
{ "xml", "", LanguageVersion.XML },
|
||||
{ "xsl", "", LanguageVersion.XSL },
|
||||
{ "ecmascript", "3", LanguageVersion.ECMASCRIPT },
|
||||
{ "cpp", "", LanguageVersion.CPP },
|
||||
{ "fortran", "", LanguageVersion.FORTRAN },
|
||||
{ "php", "", LanguageVersion.PHP },
|
||||
{ "ruby", "", LanguageVersion.RUBY },
|
||||
|
||||
// this one won't be found: case sensitive!
|
||||
{ "JAVA", "1.7", null },
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -37,6 +59,18 @@ public class LanguageVersionTest {
|
||||
assertEquals(expected, LanguageVersion.findByTerseName(terseName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindVersionsForLanguageTerseName() {
|
||||
SourceLanguage sourceLanguage = new SourceLanguage();
|
||||
sourceLanguage.setName(language);
|
||||
sourceLanguage.setVersion(version);
|
||||
|
||||
LanguageVersion languageVersion = LanguageVersion.findVersionsForLanguageTerseName(sourceLanguage.getName(),
|
||||
sourceLanguage.getVersion());
|
||||
|
||||
assertEquals(expected, languageVersion);
|
||||
}
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
return new JUnit4TestAdapter(LanguageVersionTest.class);
|
||||
}
|
||||
|
@ -111,6 +111,12 @@ public class PMDTaskTest extends BuildFileTest {
|
||||
assertOutputContaining("Use ===/!== to compare with true/false or Numbers");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXML() {
|
||||
executeTarget("testXML");
|
||||
assertOutputContaining("Potentialy mistyped CDATA section with extra [ at beginning or ] at the end.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClasspath() {
|
||||
executeTarget("testClasspath");
|
||||
|
7
pmd/src/test/resources/ant/xml/mistypedcdata.xml
Normal file
7
pmd/src/test/resources/ant/xml/mistypedcdata.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<root>
|
||||
<child>
|
||||
<![CDATA[[
|
||||
some text data
|
||||
]]>
|
||||
</child>
|
||||
</root>
|
@ -128,6 +128,16 @@
|
||||
</pmd>
|
||||
</target>
|
||||
|
||||
<target name="testXML">
|
||||
<pmd rulesetfiles="${pmd.home}/src/main/resources/rulesets/xml/basic.xml">
|
||||
<sourceLanguage name="xml" version=""/>
|
||||
<formatter type="text" toConsole="true"/>
|
||||
<fileset dir="${pmd.home}/src/test/resources/ant/xml/">
|
||||
<include name="*.xml"/>
|
||||
</fileset>
|
||||
</pmd>
|
||||
</target>
|
||||
|
||||
<target name="testClasspath">
|
||||
<pmd>
|
||||
<ruleset>classpathtest/ruleset.xml</ruleset>
|
||||
|
Loading…
x
Reference in New Issue
Block a user