ant daily build 学习三(pakege、junit、findbugs)

上篇文章中阐述了compile

这篇文章中将继续阐述,主要阐述pakege、junit、findbugs,后续章节继续阐述其他功能实现细节。

 

写道
<target name="pakege" description="打包调用这必须传jar.name参数和classes参数">
<if>
      <and>
                <available file="MANIFEST.MF" filepath="${project.path}/${classes}/META-INF"/>
      </and>
<then>
                <jar destfile="${deploy_module.dir}/${jar.name}" manifest="${project.path}/${classes}/META-INF/MANIFEST.MF">
                         <fileset dir="${project.path}/${classes}">
                                  <exclude name="**/*Test.class"/>
                         </fileset>
                </jar>
</then>
<else>
                <jar destfile="${deploy_module.dir}/${jar.name}">
                           <fileset dir="${project.path}/${classes}">
                                     <exclude name="**/*Test.class"/>
                           </fileset>
                </jar>
</else>
</if>
</target>

 说明: java程序打包中存在一个特别文件MANIFEST.MF,此文件的作用请查阅其他资料说明,由于是用于非手工的日编译系统所以这个文件靠脚本动态的设置需要定义特殊的设置文件。脚本读取文件来进行动态的构建。另一种方式直接定义好MANIFEST.MF文件,这样在打包的时候存在此类文件jar任务中自动填写此文件的功能将失效,也就说说此文件将采用用户自定义的MANIFEST.MF而非系统默认产生的。

 

接下来说明JUnit的实现细节

写道
<target name="junit" description="junit 单元测试">
<if>
      <or>
             <not>
                      <isset property="switch-junit"/>
             </not>
             <and>
                       <isset property="switch-junit"/>
                       <equals arg1="${switch-junit}" arg2="true"/>
             </and>
     </or><!--开关选项设置和利用--->
<then>
             <junit printsummary="yes" haltοnerrοr="no" haltonfailure="no" fork="no">
                    <formatter type="xml"/>
                             <batchtest todir="${report.dir}/junit">
                                        <fileset dir="${project.path}/${classes}">
                                                     <include name="**/*Test.class"/>
                                        </fileset>
                             </batchtest>
                             <classpath>
                                        <path refid="classpath"/><!---下面pathelement必须加入除非你生成的class路径在java的classpath中,负责必须通过此方式加入到junit的classpath中-->
                                        <pathelement location="${project.path}/${classes}"/>
                             </classpath>
             </junit>
</then>
<else>
             <echo message="用户忽略了junit测试"/>
</else>
</if>
</target>

 

此target中涉及到了第一篇文章中阐述的的功能开关,通过功能开关来启动是否运行此target。这里面需要注意的是在命令中放入的-D参数设置的property 必须不会在脚本中事先定义,否则进入脚本中会被忽略掉,也就是-D设置的无效。

关于ant脚本中property的设置于注意选项请参见官方的doc文档。

 

接下来阐述的是findbugs

写道
<path id="findbugs.lib">
            <fileset dir="${findbugs.home}/lib">
                   <include name="findbugs.jar"/>
            </fileset>
</path>

<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
                 <classpath refid="findbugs.lib"/>
</taskdef>

<target name="findbugs">
<if>
       <or>
              <not>
                       <isset property="switch-findbugs"/>
             </not>
             <and>
                      <isset property="switch-findbugs"/>
                      <equals arg1="${switch-findbugs}" arg2="true"/>
             </and>
     </or>
<then>
              <findbugs home="${findbugs.home}" output="xml" outputFile="${report.dir}/findbugs/${name}_findbugsparts.xml" jvmargs="-Xmx1024M">
                        <sourcePath path="${project.path}/${src}" />
                        <class location="${project.path}/${classes}" />
             </findbugs>
</then>
</if>
</target>

 

     此target不再累述,参见findbugs官方doc,里面有详细的说明和example

 

    注意findbugs-1.3.9中是存在bug的主要是关于日志合并的bug在官方的bug提交日志列表中也有说明,并且关闭了。不知道以后的版本会不会修复此bug,关于此bug的说明会在后续的文章中阐述到,并且提供修复好的类库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值