Posts Tagged PMD

Slides for my german presentation “Quality Assurance for ADF projects” available

I have presented today on DOAG Development 2014 in Dusseldorf. For all non DOAG members – you can find the german presentation on slideshare too.

2014-Development_Banner-Speaker-180x180

, , , , , , , , , , , , , , , , , ,

Leave a comment

Quality Assurance for ADF projects

If you speak german and you are interested in quality assurance for your ADF projects you should come and attend my presentation at DOAG Development on 06/04/2014 in Dusseldorf.

I will show you, how you can implement in the JDeveloper IDE and in Continous Integration server Jenkins:

  • static code analysis with PMD, FindBugs and Checkstyle
  • Task’s
  • Commit tests with JUnit, Mockito and Powermock for Mockito
  • Code coverage for commit tests with JaCoCo
  • Acceptance tests with JUnit and Selenium

See you!

2014-Development_Banner-Speaker-180x180

, , , , , , , , , , , , , , , , , ,

2 Comments

Have released PMD Jdeveloper Extension 5.0.5

I have finished now my work on integrating last PMD version 5.0.5 into JDeveloper.

This is available now for JDeveloper 11.1.1.6 upwards, 11.1.2.x. and 12.1.2. There is no new functionality, as the most work intensive part was the rewriting for PMD 5. There has changed a lot of api functionality.

Please give it a try, you can download it via the standard update center “Open Source and Partners Extensions” in JDveloper itself

update_center_11.1.2.5050

or directly from the PMD SourceForge.net Project Page.

, , , , ,

Leave a comment

Write ADF static code analysis rules with PMD and running these in JDeveloper

Do you know, that PMD can analyse XML files since version 5? Many of ADF files are XML configuration files – wouldn’t it be a good idea to create some static code analysis rules for ADF too?

Unfortunatly oracle configuration files in most times create references to dtd’s, which are not exist anywhere in the path. Till PMD 5.0.1 such files results in errors, as PMD tries to validate this doctype. I have switched of this validation in PMD release 5.0.2.

Following article requires configuration of PMD as described in my blog PMD Integration with JDeveloper through Ant External Tools.

You can download all requried files from here.

Let’s start from the beginning.

  1. At the moment PMD only provide XML check’s against files with the extension *.xml, there is a feature request to change this behaviour. So at the moment, we have to change the code by ourself to reach the result. Load the the 5.0.4 source code.
  2. Look for the file src\main\java\net\sourceforge\pmd\lang\Language.java and replace the line
    XML(“XML”, null, “xml”, XmlRuleChainVisitor.class, “xml”);
    with
    XML(“XML”, null, “xml”, XmlRuleChainVisitor.class, “xml”, “jws”, “jpr”, “cpx”, “xcfg”, “dcx”, “jpx”);
  3. Change to directory pmd-src-5.0.4
  4. set JAVA_HOME, e.g. to your 1.6 JDeveloper jdk
  5. run “mvn clean package”, I have succesfully used maven 2.2.1 from <JDev-Home>\jdeveloper\apache-maven-2.2.1\bin
  6. If you don’t need further extensions, you can instead running steps 2 till 5 the resulting pmd-5.0.4.jar from my side.
  7. Replace the file pmd-5.0.4.jar in pmd-bin-5.0.4\lib (see my previous blog) with the downloaded file or the file from pmd-src-5.0.4\target
  8. Now is the time to create the first adf static code analysis rule. In the adf architecture course I attend, there was a rule, that the taskflow behaviour “No controller transaction”
    should not be mixed with the other option of this selection list

    In the sourcecode this property is described through the absence of the node adfc-config/task-flow-definition/transaction, the other options create this node and additional child nodes, here e.g. for the option “Always create new transaction”
  9. In PMD you can create two kind of rules: Java and XPath. For our xml Files XPath should be the efficient option. We have to put our configuraration e.g. in file my_pmd_rules.xml in the same directory as pmd.xml in the last blog. For the above rule the XPath query in line 14 find nodes, which does not contain the transaction node
    <?xml version="1.0"?>
    <ruleset name="Oracle ADF rules" 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">
    <description>This ruleset checks Oracle ADF code for bad stuff</description>
    <!-- ADF Rules ############################################################################################### -->
    <rule name="OracleAdfTaskflowShouldNotHaveNoControllerTransaktion" since="5.0" language="xml"
    message='ADF tasklows should normally not contain transaktion behavior "No Controller Transaction"'
    >
    <priority>1</priority>
    <properties>
    <property name="xpath">
    <value><![CDATA[
    adfc-config/task-flow-definition[not(transaction)]
    ]]></value>
    </property>
    </properties>
    </rule>
    </ruleset>
    
  10. Now we have to change the configuration file pmd.xml from the last blog in the marked lines to call our new configuration and run this on files with defined Extensions
    <?xml version="1.0" encoding="windows-1252" ?>
    <project xmlns="antlib:org.apache.tools.ant" name="Project1" default="all" basedir=".">
    <path id="classpathForPMD">
    <fileset dir="pmd-bin-5.0.4\lib">
    <include name="**/**.jar"/>
    </fileset>
    </path>
    <taskdef name="pmd" classpathref="classpathForPMD" classname="net.sourceforge.pmd.ant.PMDTask"/>
    <target name="pmdAll">
    <echo message="PMD is running on directory ${dir}" level="info"/>
    <pmd rulesetfiles="my_pmd_rules.xml" failOnRuleViolation="true" minimumPriority="1">
    <fileset dir="${dir}">
    <include name="**/*.java"/>
    <include name="**/*.xml"/>
    <include name="**/*.jws"/>
    <include name="**/*.jpr"/>
    <include name="**/*.cpx"/>
    <include name="**/*.xcfg"/>
    <include name="**/*.dcx"/>
    <include name="**/*.jpx"/>
    </fileset>
    </pmd>
    </target>
    </project>
    
  11. Now call again pmd from the Fusion Order Demo Application StoreFrontModule
  12. You can see the results for xml in the message pane. Unfortunatly the direct jump to violated files does not work at the moment as pmd delivers for every xml violation -1 as line, but I have created an bug for this

That’s it.

Maybe somebody has an idea, where we can build an extension exchange for ADF rules, e.g. for creating rules for ADF Code Guidelines v1.00 or ADF Naming and Project Layout Guidelines v2.00?

Remember: you are not restricted to ADF files, e.g. we do checks to for JDeveloper application (*.jws) and project files (*.jpr) as well, as this are xml files too. The configuration you see already in step 2.

Chrysanth WebStory Published by WebStory

, , , , ,

Leave a comment

PMD Integration with JDeveloper through Ant External Tools

In the past I read following blogs from Shay Shmeltzer:

Now (after little code change in pmd) this integration is possible. I use here JDeveloper 11.2.0.4, with other versions this should be very similar. Now let’s start:

1. Create a new folder
2. Download PMD 5.0.4
3. Extract the zip file into the created folder
4. Create a file pmd.xml into the created folder
5. Enter following code into the file pmd.xml:

<?xml version="1.0" encoding="windows-1252" ?>
<project xmlns="antlib:org.apache.tools.ant" name="Project1" default="all" basedir=".">
    <path id="classpathForPMD">
        <fileset dir="pmd-bin-5.0.4\lib">
            <include name="**/**.jar"/>
        </fileset>
    </path>
    <taskdef name="pmd" classpathref="classpathForPMD" classname="net.sourceforge.pmd.ant.PMDTask"/>
    <target name="pmdAll">
        <echo message="PMD is running on directory ${dir}" level="info"/>
        <pmd rulesetfiles="rulesets/internal/dogfood.xml" failOnRuleViolation="true" minimumPriority="1">
            <fileset dir="${dir}">
                <include name="**/src/**/*.java"/>
            </fileset>
        </pmd>
    </target>
    <target name="pmd">
        <echo message="PMD is running on file ${dir}\${file}" level="info"/>
        <pmd rulesetfiles="rulesets/internal/dogfood.xml" failOnRuleViolation="true">
            <fileset dir="${dir}">
                <include name="${file}"/>
            </fileset>
        </pmd>
    </target>
</project>

6. Select Tools – Exernal Tools from the JDeveloper menu
7. Press Button New
8. Select Tool Type: Apache Ant
9. Select your created pmd.xml file in Ant Buildfile:

10. Shuttle target pmdAll to SelectedTargets

11. Add Property dir with value ${file.dir}

12. Skip the Options and Process Step to leave the defaults
13. Add the lib directory of pmd as additional classpath entry

14. Enter Caption and Icon as you want

15. Add the tool to the Navigator Context Menu and Main Toolbar and do not forget to set Log Output to Messages Log

16. Press Next and Finish.

Now you can call pmd e.g. from the fusion order demo application

You see the results of the ant process in the message pane and you can click on the link to open the file and jump to the rule violation:

In upcoming blogs I will show you how you can define your own rulesets (replacing the ones in pmd.xml) and how to use it with any kind of xml files, eg. jws, jpr, xcfg etc..

Chrysanth WebStory Published by WebStory

, , , ,

1 Comment

Have released PMD Jdeveloper Extension 4.3

Sorry for a time without new post – but I have finished now my work on integrating last PMD version 4.3 into JDeveloper.

This is available now for JDeveloper 10.1.3.x, 11.1.1.6 and 11.1.2.x. There is no new functionality, as the most work intensive part was the rewriting for 11.1.2.x. There has changed a lot of JDeveloper api functionality. Additional I tried to solve a class loader conflict in JDeveloper 11.1.1.x with the delivered libraries from PMD 4.3, but I was not succesful. Fortunatly Oracle JDeveloper product management solved this conflict in 11.1.1.6, so I can deliver at least the extension for this JDeveloper version.

Please give it a try, you can download it via the standard update center “Open Source and Partners Extensions” in JDveloper itself or directly from the PMD SourceForge.net Project Page.

, , , , ,

4 Comments

Follow

Get every new post delivered to your Inbox.

Join 52 other followers

%d bloggers like this: