Checkstyle-如何使用正则表达式排除以'Impl.java'结尾的文件,但不排除任何文件? [英] Checkstyle - How to exclude any file, but the ones ending with 'Impl.java', with a regex?

查看:357
本文介绍了Checkstyle-如何使用正则表达式排除以'Impl.java'结尾的文件,但不排除任何文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在考虑这个问题。

I have been thinking some time about this problem.

我有一个庞大的Maven多模块项目,并且使用构建工具为所有用户共享一套自定义规则模块(这里没有问题)。

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).

问题是当我想将一个规则仅应用于其中一个模块中的一组文件时。通过使用Checkstyle抑制文件,我可以轻松排除我不希望应用规则的所有文件,但是它有其局限性。让我们举一个例子:

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:

文件:

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

您要编写哪种正则表达式来确保所有文件(包括可能会引入的未来文件)被排除在外,而仅仅是以abcd打包的以Impl.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.

有什么想法吗?

推荐答案

找到了正确的解决方案不清楚的问题,希望对任何有兴趣的人都有帮助。

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.

正则表达式-> ^((?! d / \w + Impl\.java)。)* $

使用负前瞻和模板: ^((?! regexp)。)* $

感谢您的支持!

这篇关于Checkstyle-如何使用正则表达式排除以'Impl.java'结尾的文件,但不排除任何文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆