Disable all checkstyle checks for a specific java package

不羁岁月 提交于 2019-12-22 01:57:38

问题


I have two packages namely

com/mydomain/abc/delegate/xyz/jaxws/managed

and com/mydomain/abc/xyz/jaxws/managed

I require checkstyle to be disabled only for the second package as these holds proxy classes that are autogenerated.

I use a suppression.xml as shown below

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
    "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "suppressions_1_1.dtd">

<suppressions>
       <!-- Suppress JavadocPackage in the test packages -->
       <suppress checks="JavadocPackage" files="[\\/]test[\\/]"/>

    <!-- Suppress all checkstyle for autogenerated jaxws.managed package -->
    <suppress checks="[a-zA-Z0-9]*" files="([^(delegate)])+([a-z]*[\\/]jaxws[\\/]managed[\\/])+"/>
</suppressions>

Please note the first suppression for disabling JavadocPackage check works fine but the second one does not. I am afraid that my regex for selecting the package might be wrong. Any help is much appreciated.

To state my requirements with an example:

The criteria for selection is that the package name should end in jaxws.managed but should not contain delegate in package name. More over delegate should come before jaxws.managed in the package name:

eg: checktyle checks in package com.mycomany.delegate.service.jaxws.managed must be enabled while that in com.mycompany.abc.service.jaxws.service must be disabled and it is to be noted that I do not know all the pakages names upfront except for this pattern.

Thanks and Regards Sibi


回答1:


Just use the suppression:

<suppress checks="." files="com[\\/]mydomain[\\/]abc[\\/]xyz[\\/]jaxws[\\/]managed[\\/]"/>

Alternatively, I would recommend only passing the files you want checked to Checkstyle. For example, if you are using ANT, use a to specify the files to process, and use to specify files to ignore.

For example:

<fileset dir="src">
  <include name="**/*.java"/>
  <exclude name="com/mycompany/abc/service/jaxws/service/*.java"/>
</fileset>



回答2:


(?! delegate \b) [\/][a-z]*[\/]jaxws[\/]managed[\/]



来源:https://stackoverflow.com/questions/4020478/disable-all-checkstyle-checks-for-a-specific-java-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!