ant daily build 学习六(BFS和DFS构建实现细节)

其实BFS和DFS的构建思路都是一致的只是在寻找取向时不一致罢了。

 

BFS构建模式中是以整个SVN中跟为构建的源头,将所有的项目checkout然后循环构建。(构建中不再需要进行依赖项checkout了,因为所有的项目都别checkout了)

DFS构建模式中是以SVN中某个项目为构建的源头,将其单独在SVN中checkout处理啊然后构建(这其中会不断的checkout依赖项目并构建依赖项目,此工作是一种迭代的方式)。

 

下面是具体的实现细节

 

写道
<target name="buid-all">
<!--<antcall target="init"/>-->
<record name="${report.dir}${file.separator}html${file.separator}builddetail.html"/>
<loadfile property="build-log-top" srcFile="${basedir}${file.separator}build-info.xsl" encoding="utf-8"/>
<echo file="${report.dir}${file.separator}html${file.separator}build-result.html" append="true">${build-log-top}</echo>
<if> 
     <or>
            <not>
                     <isset property="switch-BFS"/> 
            </not>
            <and>
                     <isset property="switch-BFS"/>
                     <equals arg1="${switch-BFS}" arg2="true"/>
            </and> 
    </or> <!--以上是判断BFS的开关是否设置--->
<then>
<!---执行BFS模式构建-->
           <property name="switch-BFS" value="true"/>
           <antcall target="checkout"><!--checkout所有资源---> 
                  <param name="project.name" value=""/> 
           </antcall>
           <trycatch property="BuildAllException"> <!--进行异常捕捉--->
                     <try>
                              <antcall target="backup"/> <!---进行类库备份-->
                              <delete file="proectlist.properties"/> <!--删除构建列表--->
                              <echo file="index" append="false">0</echo> <!--变量文件--->
<!--下面便是调用foreach对含有buid.xml文件的工程进行循环构建--->
                              <foreach list="" target="buid-sub" param="xml.path.name" delimiter=",">
                                     <fileset dir="${resource.dir}/">
                                              <include name="**/build.xml"/>
                                     </fileset>
                              </foreach>
                              <delete file="index"/> <!--删除变量文件--->
                     </try>
                     <catch>
                                 <echo message="build ocean project failure,exception:${BuildAllException}"></echo>
                     </catch> 
            </trycatch>
</then>
<else> 
<!--DFS模式构建,首先要用正则表达式在以构建列表中获取已经构建过的工程名称和序号供DFS构建时输入序号来直接对应工程名称用--->
           <propertyselector property="project.list" delimiter="*" match="key\.([^\.]*)-value\.(.*)" select="\1: \2${line.separator}" casesensitive="false"/>
                  <echo file="temp.txt" message="${project.list}"/>
                          <replace file="temp.txt">
                                      <replacefilter token="*" value=""/> 
                                      <replacefilter token="-" value="${file.separator}"/>
                          </replace>
<loadfile property="message" srcFile="temp.txt"/>
<echo message="****************已经构建过的svn资源如下************************"/>
<echo message="${message}"/>
<echo message="****************************************************************"/>
<echo message="**以上工程名仅供参考,如果构建以上中某个工程,则根据下面的提示输入序号则可以构建序号对应的工程**"/>
<echo message="**如果构建的工程不在以上列表中,则需要填写svn中的工程名称**"/>
<delete file="temp.txt"/>
<input message="输入需要build的svn工程名称" addproperty="build.name"/>
<if>
      <not>
              <equals arg1="" arg2="${build.name}"/> 
      </not>
<then>
<if> 
      <not>
              <isset property="${build.name}"/> <!--判断输入的值是否在构建列表中--->
      </not>
<then>
<input message="${build.name}工程不在以上编译列表中,请确定是否构建此svn工程(y/n)?" addproperty="user.action"/>
           <condition property="do.abort">
                    <equals arg1="n" arg2="${user.action}"/>
           </condition>
           <fail if="do.abort">Build aborted by user.</fail> 
           <property name="project.name" value="${build.name}"/>
</then>
           <else>
                      <propertycopy name="project.name" from="${build.name}"/> <!--属性复制--->
           </else>
</if> <!---checkout资源-->
<antcall target="checkout">
         <param name="project.name" value="lib"/>
</antcall>
<antcall target="checkout">
         <param name="project.name" value="${project.name}"/>
</antcall> <!--构建依赖的子工程--->
<subant target="build" failοnerrοr="false">
             <fileset dir="${resource.dir}" includes="**/build.xml"/> 
             <propertyset> <!---传递固定前缀的属性-->
                     <propertyref prefix="switch-"/>
                     <propertyref prefix="svn"/>
              </propertyset>
</subant>
</then>
<else>
<fail>工程名无效</fail>
</else>
</if>
</else>
</if>
<echo file="${report.dir}${file.separator}html${file.separator}build-result.html" append="true"></tatble></body></html></echo>
</target>

 

写道
<target name="buid-sub">
<!--记录已经编译过的工程到文件中,不区分操作系统,且兼容BFS 和 DFS 的方式构建-->
<if>
<equals arg1="${file.separator}" arg2="\"/>
<then>
<property name="regexp" value="\\"/>
<propertyregex property="prefix" input="${resource.dir}" regexp="(\\)" replace="\\\\\\\\" casesensitive="false"/>
</then>
<else>
<property name="regexp" value="/"/>
<propertycopy name="prefix" from="resource.dir"/>
</else>
</if>
<propertyregex property="project-name" input="${xml.path.name}" regexp="${prefix}${regexp}(.*)${regexp}build.xml" select="\1" casesensitive="false"/>
<if>
<equals arg1="${file.separator}" arg2="\"/>
<then>
<propertyregex property="os-project-key" input="${resource.dir}" regexp="(\\)" replace="\\\\\\\\" casesensitive="false"/>
<propertyregex property="os-project-name" input="project-name" regexp="(\\)" replace="-" casesensitive="false"/>
<if>
<and>
<not>
<isset property="os-project-key"/>
</not>
<not>
<isset property="os-project-name"/>
</not>
</and>
<then>
<propertycopy name="os-project-name" from="project-name"/>
<propertycopy name="os-project-key" from="project-name"/>
</then>
</if>
</then>
<else>
<propertyregex property="os-project-key" input="project-name" regexp="(/)" replace="-" casesensitive="false"/>
<propertycopy name="os-project-name" from="project-name"/>
<if>
<not>
<isset property="os-project-key"/>
</not>

<then>
<propertycopy name="os-project-key" from="project-name"/>
</then>
</if>
</else>
</if>
<loadfile property="index" srcFile="index"/>
<math result="result" operand1="${index}" operation="+" operand2="1" datatype="int"/>
<echo file="projectlist.properties" append="true">key.${result}-value.${os-project-key}=project${line.separator}</echo>
<echo file="projectlist.properties" append="true">${result}=${os-project-name}${line.separator}</echo>
<echo file="index" append="false">${result}</echo>
<!--开始构建子工程-->
<ant antfile="${xml.path.name}" inheritAll="false">
<propertyset>
<propertyref prefix="switch-"/>
</propertyset>
</ant>
</target>

 时间已晚,后续继续进行详细说明

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值