pmd (build): moved the files to the standard directories

* src/main/java | resources
* enabled tests
* removed lib/pmd-build-0.4.jar - the plan is to have this dependency in maven central

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7557 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Andreas Dangel
2011-12-11 13:41:31 +00:00
parent 90b9a04858
commit a29cc7ae89
28 changed files with 194 additions and 139 deletions

View File

Binary file not shown.

View File

@@ -33,22 +33,6 @@ only if you modify the java code.
</developer>
</developers>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>xslt/**/*.xsl</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@@ -79,6 +63,12 @@ only if you modify the java code.
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>

View File

@@ -1,48 +0,0 @@
import net.sourceforge.pmd.ant.PmdBuildTask;
import org.apache.tools.ant.BuildException;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* @author rpelisse
*
*/
public class AntTaskTest {
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void antTask() {
PmdBuildTask task = new PmdBuildTask();
task.setRulesDirectory("rulesets");
task.setTarget("target-test");
try {
task.execute();
} catch (BuildException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,75 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
import java.io.File;
import java.io.IOException;
import javax.xml.transform.TransformerException;
import net.sourceforge.pmd.build.PmdBuildException;
import net.sourceforge.pmd.build.RuleSetToDocs;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
/**
* @author Romain PELISSE, belaran@gmail.com
*
*/
public class PmdBuildTest {
private static String TEST_DIR = "target-test/";
private static File testDir;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
testDir = new File(TEST_DIR);
if (! testDir.exists() && ! testDir.mkdir() )
{
throw new PmdBuildException("Can't create " + TEST_DIR);
}
else if ( ! testDir.isDirectory() )
{
throw new PmdBuildException("testdir " + TEST_DIR + " exist !");
}
}
@Test
public void convertRulesetsTest() throws IOException {
RuleSetToDocs builder = new RuleSetToDocs();
builder.setRulesDirectory("rulesets");
builder.setTargetDirectory(TEST_DIR);
try {
builder.convertRulesets();
} catch (PmdBuildException e) {
e.printStackTrace();
}
}
@Test
public void generateIndexRules() throws IOException, TransformerException {
RuleSetToDocs builder = new RuleSetToDocs();
builder.setRulesDirectory("rulesets");
builder.setTargetDirectory(TEST_DIR);
try {
builder.generateRulesIndex();
} catch (PmdBuildException e) {
e.printStackTrace();
}
}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDown() throws Exception {
RuleSetToDocs.deleteFile(testDir);
}
}

View File

@@ -19,6 +19,7 @@ public class PmdBuildTask extends Task {
private String rulesDirectory;
private String target;
private String siteXml;
private String siteXmlTarget;
public String getSiteXml() {
return siteXml;
@@ -26,6 +27,14 @@ public class PmdBuildTask extends Task {
public void setSiteXml(String siteXml) {
this.siteXml = siteXml;
}
public String getSiteXmlTarget() {
return siteXmlTarget;
}
public void setSiteXmlTarget(String siteXmlTarget) {
this.siteXmlTarget = siteXmlTarget;
}
private String rulesetToDocs;
private String mergeRuleset;
private String rulesIndex;
@@ -61,6 +70,7 @@ public class PmdBuildTask extends Task {
PmdBuildTools tool = validate(new RuleSetToDocs());
tool.setTargetDirectory(this.target);
tool.setSiteXml(siteXml);
tool.setSiteXmlTarget(this.siteXmlTarget);
tool.setRulesDirectory(this.rulesDirectory);
try {

View File

@@ -0,0 +1,49 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd;
import java.io.File;
import net.sourceforge.pmd.build.PmdBuildException;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
/**
* Base test class which sets up the environment for the tests.
* @author Andreas Dangel
*
*/
public abstract class TestBase {
protected static String TEST_DIR = "target/test-environment/";
protected static File testDir = null;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
testDir = new File(TEST_DIR);
if (! testDir.exists() && ! testDir.mkdir() )
{
throw new PmdBuildException("Can't create " + TEST_DIR);
}
else if ( ! testDir.isDirectory() )
{
throw new PmdBuildException("testdir " + TEST_DIR + " exist !");
}
FileUtils.copyDirectory(new File("src/test/resources/sample-pmd"), testDir);
}
@After
public void tearDown() throws Exception {
if (testDir != null) {
FileUtils.deleteDirectory(testDir);
}
testDir = null;
}
}

View File

@@ -0,0 +1,26 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.ant;
import net.sourceforge.pmd.TestBase;
import org.junit.Test;
/**
* @author rpelisse
*
*/
public class PmdBuildTaskTest extends TestBase {
@Test
public void antTask() throws Exception {
PmdBuildTask task = new PmdBuildTask();
task.setRulesDirectory(TEST_DIR + "rulesets");
task.setTarget(TEST_DIR + "target");
task.setSiteXml(TEST_DIR + "site/site.pre.xml");
task.setSiteXmlTarget(TEST_DIR + "site/site.xml");
task.execute();
}
}

View File

@@ -0,0 +1,24 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.build;
import net.sourceforge.pmd.TestBase;
import org.junit.Test;
/**
* @author Romain PELISSE, belaran@gmail.com
*
*/
public class RuleSetToDocsTest extends TestBase {
@Test
public void convertRulesetsTest() throws Exception {
RuleSetToDocs builder = new RuleSetToDocs();
builder.setRulesDirectory(TEST_DIR + "rulesets");
builder.setTargetDirectory(TEST_DIR + "target");
builder.convertRulesets();
}
}

View File

@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<ruleset name="Basic"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
The Basic ruleset contains a collection of good practices which should be followed.
</description>
<rule name="JumbledIncrementer"
language="java"
since="1.0"
message="Avoid modifying an outer loop incrementer in an inner loop for update expression"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/rules/java/basic.html#JumbledIncrementer">
<description>
Avoid jumbled loop incrementers - its usually a mistake, and is confusing even if intentional.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//ForStatement
[
ForUpdate/StatementExpressionList/StatementExpression/PostfixExpression/PrimaryExpression/PrimaryPrefix/Name/@Image
=
ancestor::ForStatement/ForInit//VariableDeclaratorId/@Image
]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
public class JumbledIncrementerRule1 {
public void foo() {
for (int i = 0; i < 10; i++) { // only references 'i'
for (int k = 0; k < 20; i++) { // references both 'i' and 'k'
System.out.println("Hello");
}
}
}
}
]]>
</example>
</rule>
</ruleset>

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="PMD">
<bannerLeft>
<name>SourceForge</name>
<src>images/sflogo.png</src>
<href>http://sourceforge.net/</href>
</bannerLeft>
<bannerRight>
<name>pmd-logo</name>
<src>images/pmd_logo_small.jpg</src>
<href>http://pmd.sourceforge.net/</href>
</bannerRight>
<body>
<breadcrumbs>
<item href="http://www.sourceforge.net/" name="SourceForge"/>
<item href="http://pmd.sourceforge.net/" name="PMD"/>
</breadcrumbs>
<links>
<item href="http://sourceforge.net/projects/pmd" name="SourceForge.net Project Page"/>
<item href="http://sourceforge.net" name="Hosted by SourceForge"/>
</links>
<menu name="Overview">
<item href="/index.html" name="Download PMD 5.0"/>
</menu>
<menu name="Rule Sets"/>
</body>
</project>