建设更强的Build系统 Recent Build Improvement: obfuscated log4j.properties + ANT logging

自动更新log4j.properties里面的类名 Auto-update of class names in log4j.properties after obfuscation

期待已久的功能。实现起来不难 - 不外乎从混淆的log里面分析出原始及重新命名的类名,更新log4j.properties即可。

因是在build-obf.xml内实现的,故大部分build文件无需更改就可以享受此功能。注: 所有目标目录下的任何名为log4j.properties的文件将都会被更新。

使用Task将ANT输出log到文件里 ANT logging to file – Task <logtofile>

以前我们为了解决ANT logging to file, 可以使用如下的命令在影响ANT console输出的情况下log到文件:

ant -logger ant.DefaultLoggerWithFileOutput -DANT_LOG_OUTPUT_FILE=C:/a/b.txt

这样实现了基本功能,但非常不方便,尤其在IDE里面我们喜欢一键运行而不是输如上的命令。现在新的方法是使用Task将log写到文件里:

<project name="test" default="default" basedir=".">
    <taskdef classname="ant.LogToFileTask" classpath="classes" name="logtofile"></taskdef>
    <target name="default">
       <logtofile logfile="C:/test.txt"/>
        <echo>Hello</echo>
        <antcall target="greeting"></antcall>
    </target>
    <target name="greeting">
        <echo>Springfield</echo>
        <ftp password="" server="" userid=""></ftp>
    </target>
</project>

在运行如上的build script时,执行<logtofile>之前的log将仅显示在console上,之后一直到结束产生的log将被保存在指定的文件里。

<logtofile>可以被执行多次, 这意味着你可以将输出log到多个文件里。此task可以自动侦测是否两次执行到同一log文件 - 这样会破坏写入的内容 - 在此情况下后面的<logtofile>请求将被忽略。

使用攻略

建议在最顶级的target里面一开始就运行<logtofile>

建议使用内含timestamp的log文件名

log文件样本

+---------------- test build by Homer/FlandersComputer on 2010/06/22 17:01:39 000 ----------------
|
|   BUILD FILE: build\build-test.xml
|     BASE DIR: build
|     ENCODING: UTF-8
|     USER DIR: build
|  ANT VERSION: Apache Ant version 1.7.0 compiled on December 13 2006
|     ANT HOME: plugins\org.apache.ant_1.7.0.v200803061910
| JAVA VERSION: 1.6.0_16-b01
|    JAVA HOME: jre
|
+--------------------------------------------------------------------------------------------------

(Current running target: default)
     [echo] Hello

greeting:
     [echo] Springfield

BUILD FAILED
build-test.xml:6: The following error occurred while executing this line:
build-test.xml:10: Could not create type ftp due to java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClientConfig

Total time: 0 seconds