Skip to Content

Welcome to part 2 in our series about the extensibility of NetWeaver Developer Studio (NWDS) through plug-ins.

In the Pimp Up My NWDS Part 1 I showed up a way to install and manage additional plug-ins in NWDS without modifying the standard file structure to much. This approach gives you more flexibility when doing an upgrade and also helps you maintaining the same set of plug-ins for two different NWDS installations on the same machine, e.g. for NetWeaver04 (6.40) and NetWeaver2004s (7.0).

In this part I want to show you a plug-in that will check your code using static code analysis to give hints to possible bugs and anti patterns and inefficient code. This way it will help you write better and often faster code.

PMD

PMD finds possible problems and shortcomings in your programs by analysing the Java source code. It does this by using a set of rules that you can run on your programs source code to find unused variables, unnecessary object creation, empty catch blocks, and so forth. Rules in PMD are defined in an extensible way that let’s you write your own rules specific for your organization or project.

PMD is already covered in a Analysing your Java code with PMD so I won’t go into many details but show you how to use it in NWDS. If you want to get deeper knowledge about PMD there is also a book PMD Applied written by one of its lead developers, Tom Copeland.

As most of today’s plug-ins PMD is currently developed for Eclipse 3.x but there is one brave hero still maintaining an Eclipse 2.x version named pmd-eclipse-2.3 that is only one minor version behind the official release. You can get it at PMD’s official download site. After downloading follow the instructions for installation covered in Pimp Up My NWDS Part 1.

Correctly installed PMD will give you two ways to check your code in NWDS. One way is to trigger the code checks manually against single files, folders or projects. Therefore you have to select a node or element in the Navigation view. Right click the element and the resulting context menu will show an entry PMD with several subentries. Select Check Code With PMD to start it.

The other way is to enable PMD in the project properties. Here you can also define a specific rule set for you project. This way code analysis will executed each time a file is added or saved.

image

The results of the code check will be displayed in the Tasks view or in the special PMD Violations view, which gives a more tailored display and more specific filtering options.

image

The PMD Violations view gives a more detailed view on the detected problems. It includes e.g. a severity level for each entry to help you prioritize your pending violations or filter the displayed entries. In case you don’t remember the cause of the violation you can also get more detailed information for each of the violated rules by selecting Show Rule from the context menu for an entry.

Either if you use PMD for your own project or if you introduce coding standards into an organisation it is a good practice to tailor the number of rules to the specific needs. In a project this set can be defined by a joint decision and then imported into each single NWDS.

To configure a NWDS global rule set (project specific rule sets can be defined in the project properties) open the Preferences window and go to the PMD->Rules Configuration entry. Here you can see a list of all the available PMD rules. From this list, you can go through the rules, adjust priorities, modify any of the other rule-specific properties, or remove any rules you don’t need. If necessary export your defined set and import it to any other NWDS.

image

That’s basically all you need to know about PMD in an NWDS environment. Let’s hope that the Eclipse 2.x version will be maintained another couple of month (or years?) until we get our hands dirty in a New York (a.k.a. NetWeaver 7.1) project.

Checkstyle and Findbugs

There are two other well knows tools that can help you in your development process in a similar way like PMD.

Checkstyle by Oliver Burn also analyses your code, like PMD, using the Java source. There is an Eclipse plug-in available named CheckClipse. Even though you still find a compatible 2.x version on the download page it won’t be maintained anymore and is frankly two years old now. But maybe you like it and give it try anyway or use the stand alone version.

Code analyser FindBugs by Bill Pugh takes a different approach on this topic. It examines your class or JAR files looking for potential problems by matching your bytecodes against a list of bug patterns. Checking is also done using a set of rules but because it works on the bytecode the results of course very different from what you would get with PMD or Checkstyle. Sadly the Eclipse 2.x plug-in situation is the same as with Checkstyle so if you want to try it out in NWDS you have to deal with an old version from 2004 or use the stand alone version.

Conclusion

PMD and similar tools can help you significantly reduce the time and afford involved in code reviews. All code conventions and best practices, which can be described by rules, can automatically be verified in the development process. Seamlessly integrated into your IDE they popup if necessary and get out of the way otherwise. On the other hand any automated code analysis won’t replace human code reviews, as there will always be errors that can’t be detected by machine analysis.

That’s it for part 2 of Pimp Up My NWDS. The last thing that’s missing is to point you to a nice weblog by Maksim Rashchynski The Story About How 2 Eclipse Plugins helped me to make a lot of points on SDN forum were he talks about JadEclipse and JAR Class Finder, two plug-ins which helped him getting points in the forms. Thanks Maksim!

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Deepa Prabhu
    Hi,

    I have followed the steps in part-1 of your blog, but it is not working for me..

    Can you please give me the steps with respect to PMD eclipse 2.3.1 plugin…

    Thanks

    Deepa Prabhu

    (0) 
      1. Viji Rajan
        Hi,

        I am using NWDS 7.0.16 and I wanted to use pmd eclipse 2.3.1, I followed steps in part 1 of the blog and after installation I do not see PMD option listed in windows->preferences or project->properies. Am I missing something?

        thanks
        Viji

        (0) 
        1. Oliver Kohl Post author
          Hi Viji,

          I tried the latest version (2.3.1) with my install. Make sure that you unpack the included jar files. Just using the jar files didn’t work for me. Also try simply copying the files into the plugins/features folder in your NWDS install directory.

          Let me know if you still have problems.

          Best,
            Oliver

          (0) 
  2. Sebastian Lenk
    Hi,

    great article.

    Have you also tried Findbugs? I’ve tried findbugs in NWDS 7.2 SP4. Unfortunately it doesn’t find any bug. Do have an idea?

    I worked with findbugs years ago in an open source project. I preferred it because integration in eclipse is more handy.

    Best Regards
    Sebastian

    (0) 
    1. Oliver Kohl Post author
      Hi Sebastian,

      I don’t remember if Findbugs worked for me in the time back then but it would be great if you can report in case you have success.

      Best,
        Oliver

      (0) 

Leave a Reply