lexy

          支持開源,尊重他人的勞動!

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            17 隨筆 :: 0 文章 :: 9 評論 :: 0 Trackbacks

          <?xml version="1.0" encoding="GB2312" ?>

          <!-- 一個項目,可包含很多任務組(target) -->
          <project default="gen-report-coverage" basedir=".">

              <!--設置Java類被注入字節碼后存放的路徑-->
              <property name="bin.instrument.dir" value="${basedir}/out/instrbin"/>
              <!--設置覆蓋率元數據和報告的路徑-->
              <property name="coverage.dir" value="${basedir}/out/coverage"/>
              <!--設置junit報告的路徑 -->
              <property name="junitReport.dir" value="${basedir}/out/junitReport"/>
              <!--設置主題代碼源路徑-->
              <property name="src.main.dir" value="${basedir}/../src/mcc">
              </property>
              <!--設置測試代碼源路徑-->
              <property name="src.test.dir" value="${basedir}/java">
              </property>
              <!--設置主題代碼bin路徑-->
              <property name="bin.main.dir" value="${basedir}/out/srcbin">
              </property>
              <!--設置測試代碼bin路徑-->
              <property name="bin.test.dir" value="${basedir}/out/testbin">
              </property>

              <property name="lib.dir" value="${basedir}/lib">
              </property>

              <path id="compile.path">
                  <pathelement location="${bin.main.dir}"/>
                  <pathelement location="${basedir}\..\lib\ganymed.jar"/>
                  <pathelement location="${basedir}\..\lib\junit-3.8.1.jar"/>
                  <pathelement location="${basedir}\..\lib\svnClientAdapter1.3.jar"/>
                  <pathelement location="${basedir}\..\lib\svnjavahl.jar"/>
                  <pathelement location="${basedir}\..\lib\svnkit.jar"/>
              </path>

              <!--指示 emma.jar 和emma_ant.jar 的路徑-->
              <path id="emma.lib">
                  <pathelement location="${lib.dir}/emma.jar"/>
                  <pathelement location="${lib.dir}/emma_ant.jar"/>
              </path>

              <path id="compile.classes">
                  <pathelement path="${bin.main.dir}"/>
              </path>

              <!--允許emma-->
              <property name="emma.enabled" value="true"/>

              <taskdef resource="emma_ant.properties" classpathref="emma.lib"/>

              <!-- 項目中的一個任務組,可包含很多任務(task:javac,java...) -->
              <target name="init">
                  <delete dir="${bin.main.dir}"/>
                  <delete dir="${bin.test.dir}"/>
                  <delete dir="${bin.instrument.dir}"/>
                  <delete dir="${coverage.dir}"/>
                  <delete dir="${junitReport.dir}"/>
                  <mkdir dir="${bin.main.dir}"/>
                  <mkdir dir="${bin.test.dir}"/>
                  <mkdir dir="${bin.instrument.dir}"/>
                  <mkdir dir="${coverage.dir}"/>
                  <mkdir dir="${junitReport.dir}"/>
              </target>

              <!--編譯源代碼-->
              <target name="compile-src.main" depends="init">
                  <javac destdir="${bin.main.dir}" debug="on">
                      <src path="${src.main.dir}"></src>
                      <classpath refid="compile.path"></classpath>
                  </javac>
                  <copy todir="${bin.main.dir}">
                      <fileset dir="${src.main.dir}">
                          <exclude name="**/*.java"/>
                      </fileset>
                  </copy>
              </target>

              <!--編譯測試代碼-->
              <target name="compile-src.test" depends="compile-src.main">
                  <javac destdir="${bin.test.dir}" debug="on">
                      <src path="${src.test.dir}"/>
                      <classpath refid="compile.path"></classpath>
                  </javac>
                  <copy todir="${bin.test.dir}">
                      <fileset dir="${src.test.dir}">
                          <exclude name="**/*.java"/>
                      </fileset>
                  </copy>
              </target>

              <!--對編譯在路徑bin.main.dir中的Java類注入字節碼,
              并且把注入字節碼的新Java類存放到路徑bin.instrument.dir-->
              <!--覆蓋率的元數據存放在路徑coverage.dir中-->

              <target name="instrument" depends="compile-src.test">
                  <emma enabled="${emma.enabled}" verbosity="info">
                      <instr instrpathref="compile.classes"
                             destdir="${bin.instrument.dir}"
                             metadatafile="${coverage.dir}/metadata.emma"
                             merge="true">
                      </instr>
                  </emma>
                  <!--<copy todir="${bin.instrument.dir}">-->
                  <!--<fileset dir="${bin.main.dir}">-->
                  <!--<exclude name="**/*.java"/>-->
                  <!--</fileset>-->
                  <!--</copy>-->
              </target>

              <!--執行測試用例同時生成junit測試報告和emma代碼覆蓋率報告-->
              <target name="test" depends="instrument">
                  <junit fork="true" forkmode="once"
                         printsummary="withOutAndErr"
                         errorproperty="test.error"
                         showoutput="on">
                      <!--指明代碼覆蓋率的元數據的存放位置-->
                      <jvmarg
                              value="-Demma.coverage.out.file=${coverage.dir}/metadata.emma"/>
                      <jvmarg value="-Demma.coverage.out.merge=true"/>

                      <classpath location="${bin.instrument.dir}"/>
                      <classpath location="${bin.test.dir}"/>
                      <classpath refid="emma.lib"/>
                      <classpath refid="compile.path"/>

                      <formatter type="xml"/>
                      <!--執行所有以TestSuite結尾的junit測試用例-->
                      <batchtest todir="${junitReport.dir}" haltonfailure="no">
                          <fileset dir="${bin.test.dir}">
                              <include name="**/*TestSuite.class"/>
                          </fileset>
                      </batchtest>
                  </junit>
              </target>

              <target name="gen-report-junit" depends="test">
                  <!--生成junit測試報告-->
                  <junitreport todir="${junitReport.dir}">
                      <fileset dir="${junitReport.dir}">
                          <include name="*"/>
                      </fileset>
                      <report format="frames" todir="${junitReport.dir}"/>
                  </junitreport>
              </target>

              <!--生成代碼覆蓋率報告-->
              <target name="gen-report-coverage" depends="test">
                  <!--如果屬性emma.enabled的值是true,就生成代碼覆蓋率報告 -->
                  <emma enabled="${emma.enabled}">
                      <report sourcepath="${src.main.dir}"
                              sort="+line,+block,+name,+method,+class"
                              metrics="method:100,block:90,line:90,class:100">
                          <fileset dir="${coverage.dir}">
                              <include name="metadata.emma"/>
                          </fileset>
                          <html outfile="${coverage.dir}/coverage.html"
                                depth="method"/>
                      </report>
                  </emma>
              </target>
          </project>

          posted on 2007-10-25 17:18 lexy 閱讀(498) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 高台县| 修武县| 略阳县| 城步| 扎兰屯市| 信宜市| 喜德县| 昭通市| 屏山县| 昂仁县| 隆回县| 博罗县| 东明县| 西青区| 绥芬河市| 高密市| 洛浦县| 安化县| 淳安县| 育儿| 甘洛县| 望都县| 上杭县| 河东区| 克什克腾旗| 育儿| 宁德市| 南漳县| 银川市| 稷山县| 辉南县| 中牟县| 清新县| 东乌珠穆沁旗| 思南县| 城口县| 大新县| 福海县| 壤塘县| 泰宁县| 阿拉善盟|