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

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

问题描述

我正在尝试从 Ant 内部调用 FindBugs.为了控制 FindBugs 可用的内存量,我选择不使用 ant-task.我现在遇到的问题是我想在命令行上将一些 jars 传递给 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

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

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 路径引用是一个逗号分隔 jar 列表,而不是像 FindBugs 想要的那样以空格分隔.如何以空格分隔的列表形式获取 jar 列表?

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天全站免登陆