Invoking FindBugs from Ant: passing a space-separated list of files to java

不羁的心 提交于 2019-12-07 18:14:25

问题


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

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>

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?

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


回答1:


Use pathconvert, like this:

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

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>



回答2:


Use <pathconvert> to convert the path into the proper format, storing it into a property then use <arg value...> instead of <arg pathref...>




回答3:


You can control the memory from the ant task:

    <findbugs   jvmargs="-Xms512m -Xmx512m" ...>
      ...
   </findbugs>


来源:https://stackoverflow.com/questions/1356418/invoking-findbugs-from-ant-passing-a-space-separated-list-of-files-to-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!