实现从svn服务器下载代码,编译成class文件,打成war包后再上传到svn的build文件

build.xml

<?xml version="1.0" encoding="UTF-8" ?>

<project name="bianyitest" basedir=".">
        <property file="build.properties" />

        <path id="jdk">
                <fileset dir="${jdk.lib}">
                        <include name="**/*.jar" />
                </fileset>
        </path>

        <path id="tomcat.classpath">
                <fileset dir="${tomcat.lib}">
                        <include name="**/*.jar" />
                </fileset>
        </path>

        <path id="project.classpath">
                <fileset dir="${project.lib}">
                        <include name="**/*.jar" />
                </fileset>
        </path>

        <path id="svnant.lib">
                <fileset dir="${ant.lib}">
                        <include name="*.jar" />
                </fileset>
        </path>

        <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="svnant.lib" />

        <taskdef resource="org/tigris/subversion/svnant/svnantlib.xml" classpath="path.svnant" />


        <target name="init">
                <tstamp>
                        <format property="today" pattern="yyyyMMdd" offset="0" unit="day" />
                </tstamp>
                <property name="tag.curr.no" value="ITMaster_520_build_10006_${today}" />
                <echo message="tag.curr.no:${tag.curr.no}" />
        </target>

        <typedef resource="org/tigris/subversion/svnant/svnantlib.xml" /> 

        <target name="prepare" depends="init" description="Prepare the dirs for other tasks">
                <delete dir="src" />
                <delete dir="classes" />
                <delete dir="log" />
                <delete dir="project" />
                <mkdir dir="src" />
                <mkdir dir="classes" />
                <mkdir dir="log" />
                <mkdir dir="project" />
        </target>
        
        <svnSetting id="svn.setting" svnkit="true" javahl="false" username="${svn.user}" password="${svn.password}" />

        <target name="svn.co.project">
                <svn refid="svn.setting">
                        <checkout url="${svn.project.url}"
                        revision="HEAD"
                        destPath="${project.dir}" />
                </svn>
        </target>
        
        <target name="svn.co.updatedir"  depends="prepare">
                <svn refid="svn.setting">
                        <checkout url="${svn.src.url}" 
                        revision="HEAD"
                        destPath="${build.dir}" />
                </svn>
        </target>
        
        <target name="svn.checkout" depends="svn.co.updatedir,svn.co.project">
                <svn refid="svn.setting">
                        <checkout recurse="true" url="${svn.source.url}" revision="HEAD" destPath="${local.url}" force="true" />
                </svn>
                <ant target="svn.co.update" />
                <ant target="svn.co.add" />
        </target>

        <target name="svn.judge.and">
                <condition property="fileExists">
                        <and>
                                <available file="${build.dir}/idecl-sup.war"  />
                        </and>
                </condition>
        </target>

        <target name="svn.co.update" if="fileExists" depends="svn.judge.and">
                <ant target="javac.compile" />
                <ant target="ant.war" />
                <echo message="svn update" />
                <svn refid="svn.setting">
                        <update file="${build.dir}/idecl-sup.war" />
                        <commit message="Package Update" dir="${build.dir}" />
                </svn>

        </target>

        <target name="svn.judge.not">
                <condition property="fileNotExists">
                        <not>
                                <available file="${build.dir}/idecl-sup.war" />
                        </not>
                </condition>
        </target>

        <target name="svn.co.add"  if="fileNotExists" depends="svn.judge.not">
                <ant target="javac.compile" />
                <ant target="ant.war" />
                <echo message="svn add" />
                <svn refid="svn.setting">
                        <add file="${build.dir}/idecl-sup.war"  />
                        <commit message="Package Add" dir="${build.dir}" />
                </svn>
        </target>

        <target name="javac.compile" >
                <delete file="${build.dir}/idecl-sup.war" />
                <javac includejavaruntime="false" 
                includeantruntime="true" 
                excludes="${java.source}/com/ninetowns/qport/config/action/AreaCardConfigAction.java,${java.source}/com/ninetowns/qport/config/action/AreaConfigAction.java,${java.source}/com/ninetowns/qport/config/action/AreaPackConfigAction.java,${java.source}/com/ninetowns/qport/config/action/AreaSupvConfigAction.java,${java.source}/com/ninetowns/qport/config/action/CardConfigAction.java,${java.source}/com/ninetowns/qport/config/action/CommAreaCardSetAction.java,${java.source}/com/ninetowns/qport/config/action/CommAreaSetAction.java,${java.source}/com/ninetowns/qport/config/action/ConfigAuditAction.java,${java.source}/com/ninetowns/qport/customInfo/action/CustomInfoAuditAction.java,${java.source}/com/ninetowns/qport/config/action/FullCommSetAction.java,${java.source}/com/ninetowns/qport/config/action/PackAreaConfigAction.java,${java.source}/com/ninetowns/qport/config/action/PackCommSetAction.java,${java.source}/com/ninetowns/qport/config/action/PackConfigAction.java,${java.source}/com/ninetowns/qport/perBaseInfo/action/PersonAuditAction.java,${java.source}/com/ninetowns/qport/config/action/PublicConfigAuditAction.java,${java.source}/com/ninetowns/qport/config/action/SaleSSMConfigAuditAction.java,${java.source}/com/ninetowns/qport/stationClient/action/StationAuditAction.java,${java.source}/com/ninetowns/qport/config/action/SupvCommSetAction.java,${java.source}/com/ninetowns/qport/timer/Task.java,${java.source}/com/ninetowns/qport/timer/Task2.java,${java.source}/com/ninetowns/qport/timer/Task3.java,${java.source}/com/ninetowns/qport/timer/Task4.java,${java.source}/com/ninetowns/qport/timer/Task5.java,${java.source}/com/ninetowns/qport/timer/TaskNew.java,${java.source}/com/ninetowns/ssh2Frame/userDataPerm/service/impl/UserDataPermManageImpl_bak.java"
                debug="on" 
                debuglevel="source"
                srcdir="${java.source}" destdir="${build.dir}" 
                encoding="GB2312" >
                        <classpath>
                                <path refid="project.classpath" />
                                <path refid="tomcat.classpath" />
                                <path refid="jdk" />
                        </classpath>
                </javac>
        </target>

        <target name="filechange">
                <delete file="${project.dir}/WEB-INF/web.xml" />
                <copy tofile="${project.dir}/WEB-INF/web.xml" >
                        <fileset file="/root/web.xml"/>
                </copy>
        </target>

        <target name="ant.war" depends="filechange">
                <delete file="${build.dir}/idecl-sup.war" />
                <war warfile="${build.dir}/idecl-sup.war" webxml="${project.dir}/WEB-INF/web.xml">
                        <fileset dir="${project.dir}" includes="**/*.*" />
                        <lib dir="${project.lib}" />
                        <classes dir="${build.dir}" />
                </war>
        </target>

        <target name="start">
                <ant target="svn.checkout" />
        </target>

        
</project>

build..properties 

build.version=1.0.0

ant.lib=/opt/lib/ant.lib
jdk.lib=/opt/lib/jdk.lib
tomcat.lib=/opt/lib/tomcat.lib
project.dir=/opt/project
project.lib=${project.dir}/WEB-INF/lib

svn.user=test
svn.password=123456
svn.source.url=svn://192.168.2.216/bianyitest/src
svn.src.url=svn://192.168.2.216/bianyitest/complete
svn.project.url=svn://192.168.2.216/bianyitest/WebRoot
local.url=${basedir}/src

work.space=${basedir}
build.dir=${work.space}/classes
lib.dir=${work.space}/lib
java.source=${work.space}/src
java.config=${work.space}/resources


你可能感兴趣的:(ant,SVN,war)