Google Java格式在格式化时无法读取文件

时间:2019-05-14 04:59:45

标签: java ant google-java-format

我在编译之前添加了一个ant任务来格式化源。 但是,当提供文件路径列表时,格式化程序会出现问题,而作为Java Ant任务运行时,格式化程序会跳过(无法读取)文件。 单独或批量运行相同脚本不会产生相同的错误。

这是Java Ant任务的问题吗? 在Java任务中将fork =“ True”设置为无效。返回的结果代码仍为1。

bash脚本在我的存储库LearnJava中可用。

这些脚本是:buildant,buildantall,format和formatall。

Build.xml和build.properties在每个项目目录下。

您可以尝试单独运行脚本的项目是Facade2和Composite2。

您至少需要JDK 8才能编译全部。除了使用lambda表达式的Composite2之外,JDK 7还将对所有其他项目起作用。

先谢谢了。

ant任务设置如下:

<target name="gformat">
    <exec executable="find" dir="${basedir}"
        failonerror="true" outputproperty="sources">
        <arg line=" . -type f -name '*.java'"/>
    </exec>

    <echo message="About to format ...: ${sources}"/>

    <java classname="${gformat.main.class}">
        <arg line=" -i ${sources}"/>
        <classpath>
            <pathelement location="../${gformat.jar}"/>
            <pathelement path="${java.class.path}"/>
        </classpath>
    </java>
</target>

1 个答案:

答案 0 :(得分:0)

find任务的问题在于,它在每个文件名之间放置了一个行分隔符,而不是格式化程序在命令行上期望的空格字符。解决方案是使用grep并将行分隔符替换为空格,或者使用指定了空格分隔符的上述ant任务。