运维开发网

Ant配置文件

运维开发网 https://www.qedev.com 2020-03-30 07:14 出处:网络 作者:运维开发网整理
<?xml version="1.0" encoding="UTF-8"?> <project name="OnlineExamSystem" default="deploy" basedir="."> <property environment="env"></property> <property name="src.dir" location="src" > </prope
<?xml version="1.0" encoding="UTF-8"?>
<project name="OnlineExamSystem" default="deploy" basedir=".">
    <property environment="env"></property>
    <property name="src.dir" location="src"  > </property>
    <property name="test.src.dir" location="test"></property>
    <property name="conf.dir" location="conf"></property>
    <property name="web.dir" location="WebContent"></property>
    <property name="lib.dir" location="${web.dir}/WEB-INF/lib"></property>
	
    <property name="build.dir" location="Build"></property>
    <property name="build.classes" location="${build.dir}/classes"></property>
    <property name="build.test.dir" location="${build.dir}/test"></property>
    <property name="build.test.classes" location="${build.test.dir}/classes"></property>
    <property name="build.test.report" location="${build.test.dir}/report"></property>
    <property name="build.doc.dir" location="${build.dir}/doc"></property>
    <property name="build.war.dir" location="${build.dir}/war"></property>
    <property name="test.lib.dir" location="lib"></property>
 
    <property name="cobertura.dir" location="${build.dir}/cobertura/"/>
    <property name="cobertura.html.dir" location="${cobertura.dir}/html"/>
    <property name="cobertura.class.dir" location="${cobertura.dir}/class"/>
 
    <path id="compile-classpath">
        <fileset dir="${lib.dir}" includes="*.jar"> </fileset>
        <fileset dir="${test.lib.dir}" includes="*.jar"></fileset>
        <fileset dir="${env.ANT_HOME}/lib" includes="*.jar"> </fileset>
        <fileset dir="${env.ANT_HOME}/lib" includes="*.jar"/>
    </path>
 
    <path id="compile-test-classpath">
        <path refid="compile-classpath"> </path>
        <pathelement location="${build.classes}"/>
    </path>
 
    <path id="run-test-classpath">
        <path refid="compile-test-classpath"/>
        <pathelement location="${build.test.classes}"/>
    </path>
    
 
    <taskdef classpathref="compile-test-classpath" resource="tasks.properties"/>
    <target name="clean">
        <delete dir="${Build.dir}"/>
    </target>
 
    <target name="init" depends="clean">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.classes}"/>
        <mkdir dir="${build.test.dir}"/>
        <mkdir dir="${build.test.classes}"/>
        <mkdir dir="${build.test.report}"/>
        <mkdir dir="${build.doc.dir}"/>
        <mkdir dir="${build.war.dir}"/>
        <mkdir dir="${build.war.dir}/WEB-INF"/>
        <mkdir dir="${build.war.dir}/WEB-INF/classes"/>
        <mkdir dir="${cobertura.dir}"/>
        <mkdir dir="${cobertura.html.dir}"/>
        <mkdir dir="${cobertura.class.dir}"/>
    </target>
 
    <target name="compile" depends="init">
        <javac destdir="${build.classes}" srcdir="${src.dir}" classpathref="compile-classpath" 
                          includeantruntime="true" failonerror="true" debug="true">
        </javac>
        <copy todir="${build.classes}">
            <fileset dir="${src.dir}" includes="**/*.*" excludes="**/*.java">
            </fileset>
        </copy>
        <copy todir="${build.classes}">
            <fileset dir="${conf.dir}">
            </fileset>
        </copy>
    </target>
 
    <target name="compile-test" depends="compile">
        <javac destdir="${build.test.classes}" srcdir="${test.src.dir}" includeantruntime="true"
              failonerror="true"  classpathref="compile-test-classpath">
        </javac>
    </target>
 

    <target name="run-test" depends="compile-test">
        <delete file="cobertura.ser"/>
        <cobertura-instrument todir="${cobertura.class.dir}">
            <fileset dir="${build.classes}">
                <include name="**/*.class"/>
            </fileset>
        </cobertura-instrument>
        <junit fork="true" haltonfailure="false" failureproperty="junit.fail">
            <classpath location="${cobertura.class.dir}"/>
            <classpath location="${build.classes}"/>
            <classpath location="${build.test.classes}"/>
            <classpath refid="compile-classpath"/>
            <formatter type="xml"/>
               <test name="${testcase}" todir="${reports.xml.dir}" if="testcase"/>
            <batchtest todir="${build.test.report}" unless="testcase">
                <fileset dir="${test.src.dir}" includes="**/*Test.java" >
                </fileset>
            </batchtest>
        </junit>
        <junitreport>
            <fileset dir="${build.test.report}" includes="TEST-*.xml">
            </fileset>
            <report format="frames" todir="${build.test.report}/html"/>
        </junitreport>
        <cobertura-report srcdir="${src.dir}" destdir="${cobertura.dir}" format="html"/>
        <delete file="cobertura.ser"/>
        <fail if="${junit.fail}" message="单元测试失败,具体情况请查询${build.test.report}"/>
    </target>
 
    <target name="doc" depends="run-test">
        <javadoc sourcepath="${src.dir}" use="true" packagenames="com.*" 
                   charset="UTF-8" encoding="UTF-8" docencoding="UTF-8"
                   destdir="${build.doc.dir}">
            <classpath refid="compile-classpath">
            </classpath>
        </javadoc>
    </target>
 
    <target name="unWar" depends="doc">
        <copy todir="${build.war.dir}">
            <fileset dir="${web.dir}">
            </fileset>
        </copy>
        <copy todir="${build.war.dir}/WEB-INF/classes">
            <fileset dir="${build.classes}">
            </fileset>
        </copy>
    </target>
 
    <target name="war" depends="unWar">
        <war destfile="${build.dir}/${ant.project.name}.war" webxml="${build.war.dir}/WEB-INF/web.xml">
            <fileset dir="${build.war.dir}" />
        </war>
    </target>
    <target name="deploy" depends="war">
        <exec executable="${env.ANT_HOME}/bin/shutdown.bat"/>
        <delete file="${env.ANT_HOME}/webapps/${ant.project.name}.war">
        </delete>

        <copy todir="${env.ANT_HOME}/webapps" file="${build.dir}/${ant.project.name}.war"/>
        <exec executable="${env.ANT_HOME}/bin/startup.bat"/>
    </target>
	
</project>
0

精彩评论

暂无评论...
验证码 换一张
取 消