从Ant调用FindBugs:将空格分隔的文件列表传递给Java [英] Invoking FindBugs from Ant: passing a space-separated list of files to java

查看:93
本文介绍了从Ant调用FindBugs:将空格分隔的文件列表传递给Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Ant内部调用FindBugs.为了控制FindBugs可用的内存量,我选择不使用ant-task.我现在遇到的问题是,我想在命令行上将许多jar传递给FindBugs:

I'm trying to invoke FindBugs from inside Ant. In order to control the amount of memory available to FindBugs, I've chosen not to use the ant-task. The problem I have now is that I want to pass a number of jars on the command-line to FindBugs:

java -jar .../findbugs.jar foo.jar bar.jar fie.jar

但是,由于这些jar实际上是Eclipse插件,所以我不知道这些jar的确切名称,因此我需要一种使用通配符来获取列表的方法.这是我想出的:

However, since these jars actually are Eclipse plugins, I don't know the exact name of the jars so I need a way to use a wildcard to obtain the list. This is what I've come up with:

<target name="findbugs">
    <property name="findbugs.home" location="${user.home}/eclipse/findbugs" />
    <path id="findbugs.input">
        <fileset dir="${testDirectory}/eclipse/plugins">
            <include name="my.plugins.*.jar" />
        </fileset>
    </path>
    <path id="findbugs.auxinput">
        <fileset dir="${testDirectory}/eclipse/plugins">
            <include name="*.jar" />
            <include name="**/*.jar" />
        </fileset>
    </path>
    <java jar="${findbugs.home}/lib/findbugs.jar" fork="true">
        <jvmarg value="-Xmx1048m" />
        <arg value="-textui" />
        <arg value="-output" />
        <arg value="findbugs.xml" />
        <arg value="-xml" />
        <arg value="-exclude" />
        <arg value="${basedir}/findbugsExclude.xml" />
        <arg value="-auxclasspath" />
        <arg pathref="findbugs.auxinput"/>
        <arg pathref="findbugs.input" />
    </java>
</target>

但是,findbugs.input pathref是jar的逗号分隔列表,而不是FindBugs想要的空格分隔.如何将罐子列表作为空格分隔的列表?

However, the findbugs.input pathref is a comma-separated list of jars, and not space-separated as FindBugs wants it. How do I get the list of jars as a space-separated list?

(使用FindBugs ant-task这样做可能更容易.从文档中我真的看不出来.)

(Is this perhaps easier to do with the FindBugs ant-task. I can't really tell from the documentation.)

推荐答案

使用 pathconvert ,就像这样:

<pathconvert pathsep="," property="findbugs.input.csv" refid="findbugs.input"/>

在实现您提供的目标中,我将引用从<arg pathref="findbugs.input" />更改为 到<arg value="${findbugs.input.csv}" />

Implementing in the target that you provided, I changed the reference from <arg pathref="findbugs.input" /> to <arg value="${findbugs.input.csv}" />

<target name="findbugs">
    <property name="findbugs.home" location="${user.home}/eclipse/findbugs" />
    <path id="findbugs.input">
        <fileset dir="${testDirectory}/eclipse/plugins">
            <include name="my.plugins.*.jar" />
        </fileset>
    </path>
    <pathconvert pathsep="," property="findbugs.input.csv"
                 refid="findbugs.input"/>

    <path id="findbugs.auxinput">
        <fileset dir="${testDirectory}/eclipse/plugins">
            <include name="*.jar" />
            <include name="**/*.jar" />
        </fileset>
    </path>

    <echo message="${findbugs.input.csv}" />

    <java jar="${findbugs.home}/lib/findbugs.jar" fork="true">
        <jvmarg value="-Xmx1048m" />
        <arg value="-textui" />
        <arg value="-output" />
        <arg value="findbugs.xml" />
        <arg value="-xml" />
        <arg value="-exclude" />
        <arg value="${basedir}/findbugsExclude.xml" />
        <arg value="-auxclasspath" />
        <arg pathref="findbugs.auxinput"/>
        <arg value="${findbugs.input.csv}" />
    </java>
</target>

这篇关于从Ant调用FindBugs:将空格分隔的文件列表传递给Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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