如何定义燮pressions-定义为Checkstyle的,这项工作既蚂蚁和Eclipse [英] How to define suppressions-definitions for checkstyle, that work with both ant and eclipse

查看:245
本文介绍了如何定义燮pressions-定义为Checkstyle的,这项工作既蚂蚁和Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目的Checkstyle使用,我在我的Checkstyle配置定义的燮pressionFilter 。我使用Apache Ant的,使通过持续集成自动构建。

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.

我的问题来自于以下情况:我不想填得多文件到项目BASEDIR,所以checkstyle.xml和SUP pressions.xml都在一个子目录名为配置(用于为构建配置)。现在,Ant和Eclipse的工作以不同的方式寻找SUP pressions.xml。

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.

蚂蚁利用项目作为BASEDIR BASEDIR寻找的SUP pressions.xml,当我宣布一个蚂蚁任务找到的Checkstyle的基本配置checkstyle.xml。这checkstyle.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>

这样,蚂蚁构建找到燮pressions.xml,因为构建的BASEDIR是项目目录。

This way the ant-build finds the suppressions.xml, because the basedir of the build is the project-directory.

现在使用的Checkstyle-plugin的为Eclipse带来的一个问题。它看起来的SUP pressions.xml先从checkstyle.xml具有路径(CONF)。 Eclipse的声明必须是这样的,工作:

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>

编辑:即使不工作时,Eclipse似乎总是需要一个绝对路径

Even that doesn't work, Eclipse seems to need always an absolute path.

我想知道一个办法,Eclipse和蚂蚁可以用相同的Checkstyle配置工作。有人知道解决这个问题呢?绝对路径是无解的,因为每个开发商和CI-服务器对项目目录不同的路径。

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.

推荐答案

使用的Checkstyle的财产扩张功能。在你的 checkstyle.xml 宣布你的苏pressionFilter 为:

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>

然后修改您的Checkstyle任务在Ant生成脚本包含嵌套的属性:

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>

这篇关于如何定义燮pressions-定义为Checkstyle的,这项工作既蚂蚁和Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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