forked from phoedos/pmd
Added J2EE ruleset and initial rule UseProperClassLoader; thanks to Olaf Heimburger for the rule!
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4385 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
New rules:
|
||||
Basic-JSP ruleset: DuplicateJspImport
|
||||
Design ruleset: PreserveStackTrace
|
||||
J2EE ruleset: UseProperClassLoader
|
||||
Implemented RFE 1462019 - Add JSPs to Ant Task
|
||||
Implemented RFE 1462020 - Add JSPs to Designer
|
||||
Fixed bug 1461426 InsufficientStringBufferDeclaration does not consider paths
|
||||
|
@ -0,0 +1,34 @@
|
||||
package test.net.sourceforge.pmd.rules.j2ee;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
import test.net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
|
||||
public class UseProperClassLoaderTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() throws RuleSetNotFoundException {
|
||||
rule = findRule("j2ee", "UseProperClassLoader");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[]{
|
||||
new TestDescriptor(TEST1, "failure case", 1, rule),
|
||||
new TestDescriptor(TEST2, "correct way", 0, rule),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void bar() { ClassLoader cl = SomeClass.class.getClassLoader(); }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST2 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void bar() { ClassLoader cl = Thread.currentThread().getContextClassLoader(); }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
}
|
31
pmd/rulesets/j2ee.xml
Normal file
31
pmd/rulesets/j2ee.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="J2EE Rules"
|
||||
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
|
||||
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
|
||||
|
||||
<rule name="UseProperClassLoader"
|
||||
message="In J2EE, getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead."
|
||||
class="net.sourceforge.pmd.rules.XPathRule">
|
||||
<description>
|
||||
In J2EE getClassLoader() might not work as expected. Use Thread.currentThread().getContextClassLoader() instead.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//PrimarySuffix[@Image='getClassLoader']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties> <priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
SomeClass.class.getClassLoader();
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
@ -8,6 +8,7 @@ This ruleset contains links to rules that are new in PMD v3.7
|
||||
|
||||
<rule ref="rulesets/basic-jsp.xml/DuplicateJspImports"/>
|
||||
<rule ref="rulesets/design.xml/PreserveStackTrace"/>
|
||||
<rule ref="rulesets/j2ee.xml/UseProperClassLoader"/>
|
||||
</ruleset>
|
||||
|
||||
|
||||
|
@ -52,6 +52,7 @@ public class SimpleRuleSetNameMapper {
|
||||
nameMap.put("design", "rulesets/design.xml");
|
||||
nameMap.put("finalizers", "rulesets/finalizers.xml");
|
||||
nameMap.put("imports", "rulesets/imports.xml");
|
||||
nameMap.put("j2ee", "rulesets/j2ee.xml");
|
||||
nameMap.put("junit", "rulesets/junit.xml");
|
||||
nameMap.put("javabeans", "rulesets/javabeans.xml");
|
||||
nameMap.put("logging-java", "rulesets/logging-java.xml");
|
||||
|
@ -48,6 +48,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li><a href="http://www.orablogs.com/olaf/">Olaf Heimburger</a> - wrote the UseProperClassLoader rule, code changes to get JDeveloper plugin working under JDev 10.1.3 EA, reported a possible NPE in ReportTree</li>
|
||||
<li>Mohammad Farooq - Reported new JavaNCSS URL</li>
|
||||
<li>Jeff Jensen - Reported missing XML schema references in documentation, wrote new XML schema, reported missing schema refs in example rulesets, suggested posting XML schema on PMD site, discussion of 'comments in catch block' feature, suggested description attribute in property element</li>
|
||||
<li>Christopher Stach - bug report for VariableNamingConventions, bug report for CallSuperInConstructor, many bug reports for rules that didn't handle JDK 1.5 constructs</li>
|
||||
@ -103,7 +104,6 @@
|
||||
<li>Eduard Naum - fixed JDK 1.3 runtime problems in Eclipse plugin</li>
|
||||
<li>Jacques Lebourgeois - fix for UTF8 characters in Eclipse plugin</li>
|
||||
<li>dvholten - suggestions for improving OverrideBothEqualsAndHashcode, formatting suggestions for HTML report, test cases for ConstructorCallsOverridableMethod, reported several NullAssignment bugs</li>
|
||||
<li><a href="http://www.orablogs.com/olaf/">Olaf Heimburger</a> - code changes to get JDeveloper plugin working under JDev 10.1.3 EA, reported a possible NPE in ReportTree</li>
|
||||
<li><a href="http://www.orablogs.com/duffblog/">Brian Duff</a> - helped get Oracle JDeveloper plugin working</li>
|
||||
<li>Sivakumar Mambakkam - bug report 1314086 for missing name in SimpleRuleSetNameMapper</li>
|
||||
<li>Rodrigo Ruiz - bug report 1312723 for FieldDeclaration nodes inside interfaces, bug report 1312754 for pmd.bat option handling, bug report 1312720 (and code fix!) for DefaultPackage, bug report 1309235 for TooManyFields</li>
|
||||
|
Reference in New Issue
Block a user