Ant setter执行取决于属性位置

时间:2014-10-23 21:10:35

标签: java ant

这让我很难过。

我编写了一个ant任务,它通过属性(logLevel =“INFO”)设置日志记录级别。 setter像这样实现

public void setLogLevel(String logLevel) {
    System.out.println("Log level passed to ant task: " + logLevel);
    this.level = Level.toLevel(logLevel);
    System.out.println("Log level set to " + level.toString());
}

当我测试任务时,此setter从未执行过,即使该属性拼写正确且已设置。经过大量的拔毛后,我决定尝试一些不重要的东西;我将logLevel属性移到我的其他属性之前(它紧挨着)。猜猜是什么 - 这个改变导致了setter的执行。

我多次来回更改了属性以确保它有所不同,确实如此。如果属性是遇到的第一个属性之一,则执行setter并设置属性。如果它是最后遇到的一个,则setter不会执行。

我在Ant 1.7.1和1.9.0中都看到过这种行为。谁能告诉我为什么这种奇怪的行为正在发生以及我可能做错了什么?我的任务有15个属性,当第11个属性或更低属性时,不设置logLevel属性。

Per Martin Clayton这里是build.xml文件中的xml片段。 logLevel属性在此处设置,但如果我将其向下移动几行则不会设置。

        <testReport report="${report}/report.xml" 
        logLevel="${logLevel}"
        highestSeverityCountProperty="highestCount"
        highSeverityCountProperty="highCount" 
        mediumSeverityCountProperty="mediumCount"
        lowSeverityCountProperty="lowCount" 
        lowestSeverityCountProperty="lowestCount"
        totalViolationsCountProperty="totalCount"
        failOnHighestSeverityCount="${lvl1ViolationsFailValue}" 
        failOnHighSeverityCount="${lvl2ViolationsFailValue}"
        failOnMeidumSeverityCount="${lvl3ViolationsFailValue}" 
        failOnLowSeverityCount="${lvl4ViolationsFailValue}"
        failOnLowestSeverityCount="${lvl5ViolationsFailValue}" 
        failOnTotalViolationsCount="${totalViolationsFailValue}"
        failureReason="failMessage"/>

1 个答案:

答案 0 :(得分:0)

我遇到的问题是并非所有属性都已设置。在命令行或eclipse的ant构建中不会发生此问题。它发生在使用IBM Rational Team Concert Jazz Build Engine的ant构建期间。

我不知道问题是什么,但我找到了使用没有setter的动态ant任务的解决方法。有关简单说明,请参阅here。这对我有用。