问题描述
我希望有机会将commit / changeset中的* .java文件列表传递到pre-commit钩子,该钩子将检查这些java文件的代码样式。
I want to have an opportunity to pass the list of *.java files in commit/changeset to the pre-commit hook which will check those java files for code style.
我尝试使用,但看起来就像不可能将任意文件列表传递给它。另外,运行 mvn网站
生成的报告不应像人类可读的实体那样专门使用,因此在python脚本中使用此报告并不容易(这很简单)钩子基本上是)。
I've tried to use maven-checkstyle-plugin but it looks like it is not possible to pass to it an arbitrary list of files. Also, running mvn site
builds reports which are not supposed to be used exclusively like a human-readable entity, so it is not trivial to use this report in python scripts (which mercurial hooks basically are).
所以问题是:如何在命令行中检查* .java文件的任意列表的样式(就像我们要检查任意列表一样)
So the question is: how to check-style an arbitrary list of *.java files in command-line (just like we are checking arbitrary list of python files with pep8, or javascript files with jshint/jslint)?
通过样式检查,我的意思是不仅将报告打印到stdout,而且还以某种方式返回最终结果-是否文件已通过或未通过准则。
By style-checking I mean not only printing report to stdout but returning somehow the final result - whether files had or had not passed the guidelines.
推荐答案
如果我正确理解,您想检查项目中不是所有Java源代码,而是仅检查某些特定文件吗?
if I understand rightly, you want to check not all Java sources in the project, only some specific files?
# this checks all *.java sources
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/*.java
# this checks only sources matched by Foo*.java
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/Foo*.java
# this checks only sources matched by Foo*.java and the source Bar.java
mvn checkstyle:checkstyle -Dcheckstyle.includes=**\/Foo*.java,**\/Bar.java
在所有情况下结果都是
# for your further automatic processing
target/checkstyle-result.xml
# for humans to read
target/site/checkstyle.html
欢呼
这篇关于如何从命令行检查Java文件的样式任意列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!