Wednesday, February 16, 2011

m2e-extensions or m2e-code-quality as Project Configurators for Checkstyle, PMD and FindBugs

m2eclipse offers the projectConfigurator extension point to support integration between Maven and Eclipse plugins. But not many Eclipse plugins make use of it yet. Neither the PMD Eclipse plugin nor the Checkstyle Eclipse plugin integrate as project configurator with m2eclipse. That’s why third party plugins like m2e-extensions and m2e-code-quality were developed. This is the second post of a three part article. In the first post, I pointed out how seamless integration of Maven and Eclipse significantly contributes to code quality.[1] Here, I will describe what m2e-extensions and m2e-code-quality offer and why they were not my choice. Finally, in post three, I will share my current best practice for the project configuration - taking account of the requirements in enterprise software development.[2]

m2e-extensions and m2e-code-quality to close the gap?
Unwillingly to wait for Checkstyle, PMD and FindBugs to integrate their Eclipse plugins with m2eclipse, Mohan KR from Basis Technology Corp. developed m2e-extensions.[3],[4] Figure 1 shows how this plugin integrates into Maven and Eclipse.

m2e-extensions
Figure 1: m2e-extensions as Project Configurator (Click to enlarge)

Let's take PMD as example. To leverage the PMD configuration in pom.xml for Eclipse, m2e-extensions acts as project configurator:
  1. On checking out or editing pom.xml, m2eclipse initiates the configuration of the java project. It calls every project configurator that had been registered before.
  2. The project configurator of m2e-extensions reads the configuration of the Maven PMD plugin from pom.xml.
  3. The project configurator adds the PMD project facet and the PMD builder to the java project and creates the file .pmd.
Unfortunately, there were only two releases of m2e-extensions in early 2010 and a patch in December. Meanwhile, Benson Margulies picked up the source base and released enhancements under the new name m2e-code-quality.[5],[6]

Too many pitfalls for me
m2e-extensions as of version 0.10.0.201003211855 and m2e-code-quality as of version 0.12.0.201101251749 had the following drawbacks:
  • In the medium term, each project configurator should migrate to its dedicated plugin. For example, the PMD project configurator natively belongs in the PMD Eclipse plugin. As long as each project configurator is not adopted by its dedicated plugin, there is a risk of future incompatibility or abandonment. This could happen with each new version of m2eclipse or of the other Eclipse plugins.
  • On each saving of an edited pom.xml, the configuration files of Checkstyle and PMD are recreated. This might slow down Eclipse. And any manual configuration, that the user has added meanwhile, will be overwritten.
  • If the Checkstyle configuration is a classpath resource, eclipse is configured to directly point to the JAR in the Maven repository. This works for stable configurations. But when the JAR changes in the repository, the class loading fails in java.util.zip.InflaterInputStream.[7] Surprisingly, classpath resources for PMD work without this problem.
  • checkstyle.header.file is not defined as property for the Checkstyle Eclipse plugin. As a consequence of this, the header file location from pom.xml is not used for the Checkstyle Eclipse plugin. As workaround, we have to use an absolute path as location for our header file in checks.xml. Alternatively, we could specify an inline header in checks.xml via the header property.
  • Excludes for PMD do not work, at least with m2e-code-quality.[8]
  • FindBugs is not supported at the moment.
Altogether, I was not pleased with the feature completeness of these plugins. Read in post three how AntRun and XMLTask provide an universal approach for Maven to configure Eclipse projects.[2]

References
  1. ^ Ackermann, M. Solutions for Enterprise IT. "Use Maven to Configure Checkstyle, PMD and FindBugs Consistently in Eclipse" [cited 2011 Feb 16]
  2. ^ Ackermann, M. Solutions for Enterprise IT. "Configure Eclipse Projects from Maven with AntRun and XMLTask" [cited 2011 Mar 6]
  3. ^ KR, M. Nabble Maven Forum. "m2e-extensions up" [cited 2011 Feb 6]
  4. ^ Google, Inc. Google Code. "m2e-extensions" [cited 2011 Feb 6]
  5. ^ Margulies, B. m2e-users Mailing List. "Anyone want checkstyle and PMD?" [cited 2011 Feb 6]
  6. ^ GitHub, Inc. GitHub. "m2e-code-quality" [cited 2011 Feb 6]
  7. ^ Oracle Corporation. Bug Database. "URLClassLoader fails to reload resources from dynamically changed jar-files" [cited 2011 Feb 6] 
  8. ^ GitHub, Inc. m2e-code-quality Issues. "excludes does not work for PMD" [cited 2011 Feb 6] 

    No comments:

    Post a Comment