如何定义抑制定义checkstyle,使用ant和eclipse [英] How to define suppressions-definitions for checkstyle, that work with both ant and eclipse
问题描述
我在一个项目checkstyle中使用,并且在我的checkstyle中定义了一个 SuppressionFilter -组态。我使用Apache Ant通过持续集成自动构建。
我的问题来自以下情况:我不想填充很多文件到基于项目的,因此checkstyle.xml和suppressions.xml都位于名为conf的子目录中(用于构建的配置)。现在Ant和Eclipse在寻找suppressions.xml方面的工作方式不同。
在我声明了ant任务之后,Ant使用project-basedir作为basedir来找到suppressions.xml使用checkstyle的基本配置来查找checkstyle.xml。此checkstyle.xml现在包含以下内容:
< module name =SuppressionFilter>
< property name =filevalue =conf / suppressions.xml/>
< / module>
这样,ant-build就会找到suppressions.xml,因为build的basedir是项目-directory。
现在使用 checkstyle-plugin 对于Eclipse带来了问题。它查找从checkstyle.xml具有(conf)的路径开始的suppressions.xml。对于Eclipse,声明必须如下所示:
< module name =SuppressionFilter>
< property name =filevalue =suppressions.xml/>
< / module>
编辑:即使那不起作用,Eclipse似乎总是需要一个绝对路径。 >
我想知道一种方法,Eclipse和Ant可以使用相同的checkstyle配置。有人知道这个问题的解决方案吗?绝对路径没有解决方案,因为每个开发人员和CI服务器对于项目目录都有不同的路径。
使用Checkstyle 媒体资源扩展功能。在 checkstyle.xml
中,将 SupressionFilter
声明为:
< module name =SuppressionFilter>
< property name =filevalue =$ {checkstyle.suppressions.file}default =suppressions.xml/>
< / module>
然后在Ant构建脚本中修改Checkstyle任务,以包含嵌套属性:
< checkstyle config =conf / checkstyle.xml>
< fileset dir =srcincludes =** / *。java/>
< property key =checkstyle.suppressions.filevalue =conf / suppressions.xml/>
< / checkstyle>
I use in a project checkstyle and I have defined a SuppressionFilter in my checkstyle-configuration. I use Apache ant to make automatic builds via Continuous Integration.
My problems comes from the following situation: I don't want to fill to much files into the project-basedir, so the checkstyle.xml and the suppressions.xml are both in a subdirectory named conf (for configuration for build). Now Ant and Eclipse work differently for finding the suppressions.xml.
Ant use the project-basedir as basedir for finding the suppressions.xml, after I declared an ant-task to find the checkstyle.xml with the base-configuration of checkstyle. This checkstyle.xml now contains the following:
<module name="SuppressionFilter">
<property name="file" value="conf/suppressions.xml"/>
</module>
This way the ant-build finds the suppressions.xml, because the basedir of the build is the project-directory.
Now using the checkstyle-plugin for Eclipse brings a problem. It looks for the suppressions.xml starting with the path the checkstyle.xml has (conf). For Eclipse the declaration had to look like this, to work:
<module name="SuppressionFilter">
<property name="file" value="suppressions.xml"/>
</module>
EDIT: Even that doesn't work, Eclipse seems to need always an absolute path.
I want to know a way, that both Eclipse and Ant can work with the same checkstyle-configuration. Someone knows a solution to this problem? Absolute paths are no solution, because every developer and the CI-Server have different paths for the project-directory.
Use Checkstyle's property expansion functionality. In your checkstyle.xml
declare your SupressionFilter
as:
<module name="SuppressionFilter">
<property name="file" value="${checkstyle.suppressions.file}" default="suppressions.xml"/>
</module>
Then modify your Checkstyle task in your Ant build script to include a nested property:
<checkstyle config="conf/checkstyle.xml">
<fileset dir="src" includes="**/*.java"/>
<property key="checkstyle.suppressions.file" value="conf/suppressions.xml"/>
</checkstyle>
这篇关于如何定义抑制定义checkstyle,使用ant和eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!