Posts Tagged ‘PMD’

New PMD rules for Android

Posted: April 27, 2010 in Android
Tags: ,

What is nice about this Designing for Performance post is that there is enough material there to compose a new set of PMD rules to add onto the PMD android ruleset that already comes prepackaged with PMD. Note, if you are looking for an android developer this is the type of behind the scenes stuff you want to see in the developers skill set.

New version should be posted in a few days


Why do we use PMD rules?

Posted: April 22, 2010 in Uncategorized
Tags: ,

You may wonder why we use PMD rulesets. Remember that to have one code base targeting Android 1.5, 1.6, and 2.x you have to use a minSDK of 3 and targetSDK of 4 in the manifest? So how od you get your IDE to warn you when using certain 1.6 calls when you should be using 1.5 calls?

<rule name="DoNotCodebuildStringDetectOneSix" message="Do not code detect build string as 1.6 but as 1.5" class="net.sourceforge.pmd.rules.XPathRule">
<description>do not use getApplicationInfo().targetSdkVersion use int sdkVersion = Integer.parseInt(Build.VERSION.SDK); instead</description>
<property name="xpath">
<value>//Literal[starts-with(@Image,’getApplicationInfo().targetSdkVersion ‘)]</value>

That little rule prevents you form using the android 1.6 style of detecting a build string and forces you to use the 1.5 style of detecting a build string

Reblog this post [with Zemanta]

PMD Rules for Android

Posted: April 19, 2010 in Android
Tags: ,

I posted part of the PMD rules I use for Android as a knol.

Android PMD 5

Posted: February 12, 2010 in Android
Tags: ,

PMD 5 comes with some new additions to the Android Rules and a nice new features in that you can define a rulest and stick outside the pmd.jar unlike PMD 4. Thus for an ANT target you have:

 <!-- PMD -->
			    <target name="pmd" >
                           <pmd rulesetfiles="config/androidrules.xml">
			    	                <pathelement location="${sdk-android-jar}"/>
			    	                <pathelement location="${out.classes.absolute.dir}" />
			    	                <fileset dir="libs">
			    	                    <include name="*.jar" />
			    	            <formatter type="xml" toFile="reports/pmd.xml"/>
			    	            <!-- <ruleset>rulesets/java/android.xml</ruleset> -->
			    	            <fileset dir="${source-folder}" includes="**/*.java" />
			    	    <xslt basedir="reports" destdir="reports"
			    		<param name="project" expression="${project}"/>
			    		<param name="today" expression="${today}"/>  
			    		<param name="rulesets" expression="android"/>
			    		<mapper type="glob" from="pmd.xml" to="pmd.html"/>
					   <echo>pmd report generated and transformed to html</echo>
Punctuated Sky
Image by Chris Gin via Flickr

For those who have been asking upon reading about my Android Build Tool AndCooper progress, yes I will be making a separate download available that contains specialized Checkstyle and PMD files set up for Android development. I should have those files up over the weekend.

Once the links for the downloads is up will place a link to  it at AndMob.

Reblog this post [with Zemanta]