Generating Checkstyle Reports (with extended check

2019-02-27 21:35发布

I have some own extended checks. I have exported them as plug-in and in Eclipse, they are showing warning/error. So the extended checks are working fine.

Now I want to generate a report of the violations in HTML format.

I have checked this, and this works fine if no extended checks are included in rule.xml file. But in case of extended checks, the ant build is giving the error.

The error is:

BUILD FAILED
D:\Java_Work\JUnit_CheckStyle\buildCheckStyle.xml:12: Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate InterfaceModifier

InterfaceModifier is my extended check, and it works fine in eclipse.

In build.xml, where to provide the extendedCheck.jar so that I get the required result?

1条回答
Anthone
2楼-- · 2019-02-27 22:25

I have found out the following solution, which is working fine.

  1. extract checkstyle-x.x-all.jar
  2. copy the extended classes in the extracted directory
  3. copy the metadata,message and properties file of extended check in the same directory.
  4. if any of the file is alreasy present, then edit the file and add the content from extended checks.
  5. create a new .jar file including all these.
  6. in ant build.xml <taskdef>, set this .jar as classpath

Like, after done till 2nd step, I found checkstyle_packages.xml is already present, so I edit it and added the content from extended one in proper position.


Previous Version:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE checkstyle-packages PUBLIC
    "-//Puppy Crawl//DTD Package Names 1.0//EN"
    "http://www.puppycrawl.com/dtds/packages_1_0.dtd">

<checkstyle-packages>
  <package name="com.puppycrawl.tools.checkstyle">
    <package name="checks">
      <package name="annotation"/>
      <package name="blocks"/>
      <package name="coding"/>
      <package name="design"/>
      <package name="duplicates"/>
      <package name="header"/>
      <package name="imports"/>
      <package name="indentation"/>
      <package name="javadoc"/>
      <package name="metrics"/>
      <package name="modifier"/>
      <package name="naming"/>
      <package name="regexp"/>
      <package name="sizes"/>
      <package name="whitespace"/>
    </package>
    <package name="filters"/>
  </package>
</checkstyle-packages>

Changed Version:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE checkstyle-packages PUBLIC
    "-//Puppy Crawl//DTD Package Names 1.0//EN"
    "http://www.puppycrawl.com/dtds/packages_1_0.dtd">

<checkstyle-packages>
  <package name="com.puppycrawl.tools.checkstyle">
    <package name="checks">
      <package name="annotation"/>
      <package name="blocks"/>
      <package name="coding"/>
      <package name="design"/>
      <package name="duplicates"/>
      <package name="header"/>
      <package name="imports"/>
      <package name="indentation"/>
      <package name="javadoc"/>
      <package name="metrics"/>
      <package name="modifier"/>
      <package name="naming"/>
      <package name="regexp"/>
      <package name="sizes"/>
      <package name="whitespace"/>
    </package>
    <package name="filters"/>
  </package>

  <!-- Added this lines -->
  <package name="myCheck">
    <package name="checks"/>
  </package>
  <!--                  -->

</checkstyle-packages>

now the build file is running successfully and in the report I'm getting violation of extended checks too.

查看更多
登录 后发表回答