Checkstyle - How to exclude any file, but the ones ending with 'Impl.java', with a regex?

醉酒当歌 提交于 2019-12-13 21:27:19

问题


I have been thinking some time about this problem.

I have a huge Maven multi module project and using build-tools I share a custom set of rules for all modules (no problem around here).

The problem comes when I want to apply one rule to just one set of files in just one of the modules. By using checkstyle suppressions file I can easyly exclude all files that I don't want the rule to apply, but it has its limitations. Lets put this into an example:

Files:

a/b/c/d/FileImpl.java
a/b/c/d/File.java
a/b/c/d/e/FileImpl.java
a/b/c/FileImpl.java
...

What regex would you write that assures you that all files (including future files that may be introduced) get excluded but just the ones that end with Impl.java under package a.b.c.d? in terms of regex, it has to be a regex that matches anything but the file ending I want.

It would be easyer if I could just set an "includes" referring only to the set of files to apply the rule to, but as far as I know that's not possible. It has to be using suppressions, so that it suppresses all files but the ones I want.

I have tried using capturing groups, lookahead and lookbehind but had no success at all.

Any ideas?


回答1:


What regex would you write that assures you that all files (including future files that may be introduced) get excluded but just the ones that end with Impl.java under package a.b.c.d?

Try this regex:

a/b/c/d/.+Impl\.java$

Demo

http://fiddle.re/rpqgg




回答2:


Found the right solution to the not so clear question, hope it helps anyone interested.

http://fiddle.re/9wvfg

Regex Goal --> match any chain but the ones that match the internal regex.

Regex --> ^((?!d/\w+Impl\.java).)*$

Using negative lookahead and the template: ^((?!regexp).)*$

Thanks for the support!!



来源:https://stackoverflow.com/questions/21851615/checkstyle-how-to-exclude-any-file-but-the-ones-ending-with-impl-java-with

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