CruiseControl 实践(2)
CruiseControl 实践(二)
<?xml version="1.0" encoding="gb2312"?> <project name="FWMS_CHRIST" basedir="." default="core"> <!-- 设置初始化参数 --> <property file="db.properties"></property> <taskdef name="wlserver" classname="weblogic.ant.taskdefs.management.WLServer" classpath="${domain.lib}/weblogic.jar" /> <taskdef name="FindBugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpath="${findbugs.home}/lib/findbugs-ant.jar"/> <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpath="${pmd.home}/lib/pmd-4.2.5.jar"/> <taskdef name="convertXmlToText" classname="edu.umd.cs.findbugs.anttask.ConvertXmlToTextTask" classpath="${findbugs.home}/lib/findbugs-ant.jar"/> <!-- 设置classpath --> <path id="libpath"> <fileset dir="${java160.home}"> <include name="lib/tools.jar" /> <include name="jre/lib/rt.jar" /> </fileset> <fileset dir="${bea.lib}"> <include name="ojdbc6.jar" /> <include name="*weblogic.jar" /> <include name="*webservices.jar" /> </fileset> <fileset dir="${junit_src}"> <include name="junit-4.8.1.jar" /> </fileset> <fileset dir="${ear.dir}/APP-INF/lib"> <include name="*.jar" /> <include name="*.zip" /> </fileset> </path> <path id="checkstyle-lib"> <fileset dir="${checkstyle.dir}"> <include name="checkstyle-5.3.jar" /> <include name="checkstyle-5.3-all.jar" /> </fileset> </path> <!--清除--> <target name="init"> <delete dir="${ear.dir}/APP-INF/classes" /> <delete dir="${reports}" /> <delete dir="${checkresults}" /> <delete dir="${build.src}" /> <delete dir="${jar.dest}" /> <delete dir="${war.dest}" /> <delete dir="${buildwar.dest}" /> <delete dir="${build.lib}" /> <delete dir="${build.classes}" /> <antcall target="stop"></antcall> </target> <!-- 获取源文件 --> <target name="CheckOutFromStarTeam"> <mkdir dir="${build.dir}" /> <stcheckout URL="${ST.url}" username="${ST.user}" password="${ST.password}" projectname="FWMS_CHRIST" rootlocalfolder="${build.dir}" rootstarteamfolder="code/webApp" deleteuncontrolled="true" forced="true" recursive="true" /> </target> <!-- 编译 --> <target name="compilecode"> <mkdir dir="${ear.dir}/APP-INF/classes" /> <javac srcdir="${src.dir}" destdir="${ear.dir}/APP-INF/classes" verbose="false" debug="true" failonerror="false" encoding="GBK" source="1.6" target="1.6"> <classpath refid="libpath" /> <compilerarg line="-Xlint:deprecation -Xlint:unchecked" /> <include name="**/*.java" /> </javac> </target> <!--CheckStyle--> <target name="checkstyle"> <delete dir="${checkresults}" /> <mkdir dir="${checkresults}" /> <taskdef resource="checkstyletask.properties" classpath="${checkstyle-lib}"> </taskdef> <checkstyle config="D:/eclipse/个人设置/comtop-checkstyle-1.1(200903).xml" failureProperty="checkstyle.failure" failOnViolation="false"> <formatter type="xml" toFile="${checkresults}/checkstyle_report.xml" /> <fileset dir="${src.dir}"> <include name="**/*.java" /> </fileset> </checkstyle> <xslt in="${checkresults}/checkstyle_report.xml" out="${checkresults}/simple_checkstyle_report.html" style="${checkstyle.dir}/contrib/checkstyle-simple.xsl" /> <xslt in="${checkresults}/checkstyle_report.xml" out="${checkresults}/author_checkstyle_report.html" style="${checkstyle.dir}/contrib/checkstyle-author.xsl" /> <xslt in="${checkresults}/checkstyle_report.xml" out="${checkresults}/noframes_checkstyle_report.html" style="${checkstyle.dir}/contrib/checkstyle-noframes.xsl" /> <xslt in="${checkresults}/checkstyle_report.xml" out="${checkresults}/noframes_sorted_checkstyle_report.html" style="${checkstyle.dir}/contrib/checkstyle-noframes-sorted.xsl" /> </target> <!--pmd--> <target name="pmd"> <delete dir="pmd-results/xml" /> <delete dir="pmd-results/html" /> <mkdir dir="pmd-results/html" /> <mkdir dir="pmd-results/xml" /> <pmd shortFilenames="true"> <ruleset>D:/eclipse/个人设置/comtop-PMD-rules-1.1.xml</ruleset> <formatter type="xml" toFile="./pmd-results/xml/FWMS_CHRIST-pmd.xml" toConsole="false" linePrefix=".line" /> <fileset dir="${src.dir}"> <include name="**/*.java" /> </fileset> </pmd> <xslt in="./pmd-results/xml/FWMS_CHRIST-pmd.xml" out="./pmd-results/html/perclass_pmd_report.html" style="${pmd.home}/etc/xslt/pmd-report-per-class.xslt" /> <xslt in="./pmd-results/xml/FWMS_CHRIST-pmd.xml" out="./pmd-results/html/wz_pmd_report.html" style="${pmd.home}/etc/xslt/wz-pmd-report.xslt" /> </target> <!--复制配置文件--> <target name="copyfile"> <copy todir="${ear.dir}/APP-INF/classes" overwrite="true" includeEmptyDirs="false"> <fileset dir="${src.dir}/resources"> <exclude name="**/*.java" /> </fileset> </copy> <copy todir="${ear.dir}/APP-INF/classes" overwrite="true" includeEmptyDirs="false"> <fileset dir="${src.dir}/bussiness"> <exclude name="**/*.java" /> </fileset> </copy> <copy todir="${ear.dir}/APP-INF/classes" overwrite="true" includeEmptyDirs="false"> <fileset dir="${src.dir}/test"> <exclude name="**/*.java" /> </fileset> </copy> </target> <!-- 编译属性文件 --> <target name="buildproperties"> <native2ascii encoding="GBK" src="${src.dir}" dest="${ear.dir}/APP-INF/classes" includes="*.properties" ext="_zh_CN.properties" /> </target> <!-- 删除jar缓存文件 --> <target name="deletetmp"> <delete dir="${domain.dir}/servers/AdminServer/tmp" /> </target> <!-- 预编译JSP --> <target name="precompilejsp"> <delete dir="${jsp.dir}" /> <java classname="weblogic.jspc" fork="true" jvm="${java160.home}/bin/java"> <jvmarg line="-Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0 -Xms512m -Xmx1024m" /> <classpath refid="libpath" /> <arg line="-encoding GBK -verboseJspc -linenumbers -noImplicitTlds -webapp ${ear.dir}/web -d ${jsp.dir}" /> </java> </target> <!--关闭weblogic --> <target name="shutdownweblogic"> <wlserver classpath="${domain.lib}/weblogic.jar" forceshutdown="true" dir="${domain.dir}" host="127.0.0.1" port="7777" action="shutdown" servername="AdminServer" weblogichome="${bea.home}" username="weblogic" password="weblogic" /> </target> <!--启动weblogic--> <target name="startWebLogic" description="starts a WebLogic"> <wlserver productionmodeenabled="true" noexit="true" verbose="true" maxmemory="512M" generateconfig="false" classpath="${domain.lib}/weblogic.jar" dir="${domain.dir}" host="127.0.0.1" port="7777" action="start" servername="AdminServer" weblogichome="${bea.home}" username="weblogic" password="weblogic" > <jvmarg line="-Xms512m -Xmx768m" /> <jvmarg value="-XX:MaxPermSize=512m"/> </wlserver> </target> <!--junit测试--> <target name="junitTest"> <mkdir dir="${reports}" /> <mkdir dir="${reports}/xml" /> <junit haltonfailure="no" printsummary="on" jvm="${fvt.java.home}/bin/java"> <classpath refid="libpath" /> <formatter type="brief" usefile="false" /> <formatter type="xml" /> <batchtest> <fileset dir="${test.dir}"> <patternset> <include name="**/*Test.java" /> </patternset> </fileset> </batchtest> <classpath> <pathelement location="${ear.dir}/APP-INF/classes" /> </classpath> </junit> <move todir="${reports}/xml"> <fileset dir="."> <include name="TEST-*.xml" /> </fileset> </move> </target> <!--Findbugs检查--> <target name="convert" > <delete dir="findbugs-results/xml"/> <delete dir="findbugs-results/html"/> <mkdir dir="findbugs-results/html"/> <mkdir dir="findbugs-results/xml"/> <FindBugs home="${findbugs.home}" output="xml:withMessages" outputFile="findbugs-results/xml/FWMS_CHRIST-fb.xml" jvmargs="-Xmx1024m"> <class location="${ear.dir}/APP-INF/classes" /> <sourcePath path="${src.dir}" /> </FindBugs> <convertXmlToText home="${findbugs.home}" input="findbugs-results/xml/FWMS_CHRIST-fb.xml" output="findbugs-results/html/findbugs.html" format="html:fancy.xsl" > </convertXmlToText> </target> <target name="test"> <mkdir dir="${reports}/html" /> <!--调用junitreport来产生TESTS-TestSuites.xml及web报告--> <junitreport todir="${reports}"> <report todir="${reports}/html" /> </junitreport> <!--避免反馈两份JUNIT测试报告到EMAIL 把总报告[TESTS-TestSuites.xml]剪切到根目录下--> <move todir="."> <fileset dir="${reports}"> <include name="TESTS-*.xml" /> </fileset> </move> </target> <!--构建--> <target name="buildTask" depends="stop"> <!--初始化--> <antcall target="init"> </antcall> <!--获取源代码--> <antcall target="CheckOutFromStarTeam"> </antcall> <!--checkstyle检查--> <antcall target="checkstyle"> </antcall> <!--pmd--> <antcall target="pmd"> </antcall> <!--编译源码--> <antcall target="compilecode"> </antcall> <!--Findbugs检查--> <antcall target="convert"> </antcall> <!--拷贝配置文件--> <antcall target="copyfile"> </antcall> <!--编译属性文件--> <antcall target="buildproperties"> </antcall> <!--JUNIT测试--> <antcall target="junitTest"> </antcall> <!--拷贝测试报告--> <antcall target="test"> </antcall> </target> <!--自动化部署--> <target name="deployTask"> <!-- 删除jar缓存文件 --> <antcall target="deletetmp"> </antcall> <!--预编译JSP--> <antcall target="precompilejsp"> </antcall> <!--启动weblogic <antcall target="startWebLogic"> </antcall> --> </target> <!--持续集成--> <target name="core" depends="buildTask,deployTask" /> <!--启动weblogic--> <target name="start" depends="startWebLogic"/> <!--关闭weblogic--> <target name="stop" depends="shutdownweblogic"/> </project>