From e26de080622ea9eb9d15c16cbf69741077256be6 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Tue, 27 Jan 2009 23:52:27 +0000 Subject: [PATCH] new ruleset for Android platform git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6803 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/rules/android/AndroidRulesTest.java | 20 +++ .../pmd/rules/android/xml/CallSuperFirst.xml | 32 ++++ .../pmd/rules/android/xml/CallSuperLast.xml | 32 ++++ .../pmd/rules/android/xml/ProtectLogD.xml | 38 ++++ .../pmd/rules/android/xml/ProtectLogV.xml | 38 ++++ pmd/rulesets/android.xml | 166 ++++++++++++++++++ pmd/rulesets/internal/all-java.xml | 1 + pmd/rulesets/rulesets.properties | 4 +- .../pmd/SimpleRuleSetNameMapper.java | 1 + pmd/src/site/site.xml | 1 + pmd/xdocs/navigation.xml | 1 + 11 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/android/AndroidRulesTest.java create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperLast.xml create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogD.xml create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogV.xml create mode 100644 pmd/rulesets/android.xml diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/android/AndroidRulesTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/android/AndroidRulesTest.java new file mode 100644 index 0000000000..c08a4d189c --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/android/AndroidRulesTest.java @@ -0,0 +1,20 @@ +package test.net.sourceforge.pmd.rules.android; + +import org.junit.Before; + +import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; + +public class AndroidRulesTest extends SimpleAggregatorTst { + + @Before + public void setUp() { + addRule("android", "CallSuperFirst"); + addRule("android", "CallSuperLast"); + addRule("android", "ProtectLogD"); + addRule("android", "ProtectLogV"); + } + + public static junit.framework.Test suite() { + return new junit.framework.JUnit4TestAdapter(AndroidRulesTest.class); + } +} diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml new file mode 100644 index 0000000000..9ae1745d31 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperFirst.xml @@ -0,0 +1,32 @@ + + + + + 0 + + + + + 1 + + + \ No newline at end of file diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperLast.xml b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperLast.xml new file mode 100644 index 0000000000..da62fa9b34 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/CallSuperLast.xml @@ -0,0 +1,32 @@ + + + + + 0 + + + + + 1 + + + \ No newline at end of file diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogD.xml b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogD.xml new file mode 100644 index 0000000000..b67578ec2e --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogD.xml @@ -0,0 +1,38 @@ + + + + + 0 + + + + + 1 + + + \ No newline at end of file diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogV.xml b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogV.xml new file mode 100644 index 0000000000..beab9103a7 --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/android/xml/ProtectLogV.xml @@ -0,0 +1,38 @@ + + + + + 0 + + + + + 1 + + + \ No newline at end of file diff --git a/pmd/rulesets/android.xml b/pmd/rulesets/android.xml new file mode 100644 index 0000000000..c6c86b96be --- /dev/null +++ b/pmd/rulesets/android.xml @@ -0,0 +1,166 @@ + + + + +These rules deal with the Android SDK, mostly related to best practices. +To get better results, make sure that the auxclasspath is defined for type resolution to work. + + + + Super must be called at the start of the method + 3 + + + + + + + + + + + + Super must be called at the end of the method + 3 + + + + + + + + + + + + + + Log.d must be protected by checking Config.LOGD + 3 + + + + + + + + + + + + + + Log.v must be protected by checking Config.LOGV + 3 + + + + + + + + + + + + + + diff --git a/pmd/rulesets/internal/all-java.xml b/pmd/rulesets/internal/all-java.xml index 24d5ae4db1..ce0c310d4a 100644 --- a/pmd/rulesets/internal/all-java.xml +++ b/pmd/rulesets/internal/all-java.xml @@ -7,6 +7,7 @@ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> Every Java Rule in PMD + diff --git a/pmd/rulesets/rulesets.properties b/pmd/rulesets/rulesets.properties index 3ae2310503..853713e8e9 100644 --- a/pmd/rulesets/rulesets.properties +++ b/pmd/rulesets/rulesets.properties @@ -1,2 +1,2 @@ -rulesets.filenames=rulesets/basic.xml,rulesets/braces.xml,rulesets/clone.xml,rulesets/codesize.xml,rulesets/controversial.xml,rulesets/coupling.xml,rulesets/design.xml,rulesets/finalizers.xml,rulesets/imports.xml,rulesets/j2ee.xml,rulesets/javabeans.xml,rulesets/junit.xml,rulesets/logging-jakarta-commons.xml,rulesets/logging-java.xml,rulesets/migrating.xml,rulesets/naming.xml,rulesets/optimizations.xml,rulesets/strictexception.xml,rulesets/strings.xml,rulesets/sunsecure.xml,rulesets/unusedcode.xml -rulesets.testnames=rulesets/basic.xml,rulesets/braces.xml,rulesets/clone.xml,rulesets/codesize.xml,rulesets/controversial.xml,rulesets/coupling.xml,rulesets/design.xml,rulesets/finalizers.xml,rulesets/imports.xml,rulesets/j2ee.xml,rulesets/javabeans.xml,rulesets/junit.xml,rulesets/logging-jakarta-commons.xml,rulesets/logging-java.xml,rulesets/migrating.xml,rulesets/naming.xml,rulesets/optimizations.xml,rulesets/strictexception.xml,rulesets/strings.xml,rulesets/sunsecure.xml,rulesets/unusedcode.xml +rulesets.filenames=rulesets/android.xml,rulesets/basic.xml,rulesets/braces.xml,rulesets/clone.xml,rulesets/codesize.xml,rulesets/controversial.xml,rulesets/coupling.xml,rulesets/design.xml,rulesets/finalizers.xml,rulesets/imports.xml,rulesets/j2ee.xml,rulesets/javabeans.xml,rulesets/junit.xml,rulesets/logging-jakarta-commons.xml,rulesets/logging-java.xml,rulesets/migrating.xml,rulesets/naming.xml,rulesets/optimizations.xml,rulesets/strictexception.xml,rulesets/strings.xml,rulesets/sunsecure.xml,rulesets/unusedcode.xml +rulesets.testnames=rulesets/android.xml,rulesets/basic.xml,rulesets/braces.xml,rulesets/clone.xml,rulesets/codesize.xml,rulesets/controversial.xml,rulesets/coupling.xml,rulesets/design.xml,rulesets/finalizers.xml,rulesets/imports.xml,rulesets/j2ee.xml,rulesets/javabeans.xml,rulesets/junit.xml,rulesets/logging-jakarta-commons.xml,rulesets/logging-java.xml,rulesets/migrating.xml,rulesets/naming.xml,rulesets/optimizations.xml,rulesets/strictexception.xml,rulesets/strings.xml,rulesets/sunsecure.xml,rulesets/unusedcode.xml diff --git a/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java b/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java index 6e90cca107..2ce23c7f97 100644 --- a/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java +++ b/pmd/src/net/sourceforge/pmd/SimpleRuleSetNameMapper.java @@ -41,6 +41,7 @@ public class SimpleRuleSetNameMapper { } private void populateNameMap() { + nameMap.put("android", "rulesets/android.xml"); nameMap.put("basic", "rulesets/basic.xml"); nameMap.put("jsp", "rulesets/basic-jsp.xml"); nameMap.put("jsf", "rulesets/basic-jsf.xml"); diff --git a/pmd/src/site/site.xml b/pmd/src/site/site.xml index 1c0a4c9e4c..6560285ea3 100644 --- a/pmd/src/site/site.xml +++ b/pmd/src/site/site.xml @@ -50,6 +50,7 @@ + diff --git a/pmd/xdocs/navigation.xml b/pmd/xdocs/navigation.xml index b5f6fe4db0..2b229f11d6 100644 --- a/pmd/xdocs/navigation.xml +++ b/pmd/xdocs/navigation.xml @@ -48,6 +48,7 @@ +