home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (build.xml)

This example Groovy source code file (build.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

datatypes, datatypes, html, html, todo, todo

The Groovy build.xml source code

<?xml version="1.0"?>
<project name="tck" default="default">

  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
  <!--                   compile settings                -->
  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
  <property name="build.debug" value="on"/>
  
  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
  <!--                   directories                     -->
  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
  <property name="src.dir" value="src"/>
  <property name="build.dir" value="build"/>
  <property name="build.classes.dir" value="${build.dir}/classes"/>
  <property name="dist.dir" value="dist"/>

  <!-- javadoc properties -->
  <property name="javadoc.dir" value="doc"/>
  <property name="javadoc.packages" value="org.codehaus.groovy.*"/>

  <!-- junit properties -->
  <property name="junit.style.dir" value="styles"/>
  <property name="testcase.src.dir" value="test"/>
  <property name="generated.test.src.dir" value="gentest"/>
  
  <property name="test.classes.dir" value="${build.dir}/test/classes"/>

  <!-- TODO: here you specify where the classes to test reside -->
  <property name="items.under.test.dir" value="../../target/install/lib"/>
  
  <property name="test.reports.dir" value="reports"/>
  
  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
  <!--                  targets                          -->
  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
  <target name="default" 
          depends="clean,test-compile" 
          description="default: run the groovy test suite"
  />
  
  <target name="all" 
          depends="test,dist" 
          description="build and test everything"
  />

  <target name="clean" description="remove all built files">
    <delete dir="${javadoc.dir}" />
    <delete dir="${build.dir}" />
    <delete dir="${dist.dir}" />
    <delete dir="${generated.test.src.dir}" />
  </target>

  <target name="dist" 
          depends="compile" 
          description="create distributables (jars etc)">
    <mkdir dir="${dist.dir}" />
    <jar jarfile="${dist.dir}/tck.jar" 
         manifest="${src.dir}/manifest.txt">
      <fileset dir="${build.classes.dir}"/>
    </jar>
  </target>

  <target name="docs" depends="init" description="generate documentation">
    <mkdir dir="${javadoc.dir}" />
    <javadoc sourcepath="${src.dir}" 
             destdir="${javadoc.dir}" 
             packagenames="${javadoc.packages}"
             use="true"
             windowtitle="tck"
             private="true"/>
  </target>

  <target name="run" depends="compile" description="compile and run">
    <java classname="org.codehaus.groovy.tck.GenerateTestCases" 
          fork="yes" 
          classpathref="project.classpath"/>
  </target>

  <target name="plain-test"
          depends="test-compile" 
          description="run all test cases">
    <junit haltonfailure="true" fork="no">
      <classpath refid="project.classpath"/>
      <formatter type="plain" usefile="false"/>
      <formatter type="xml" usefile="true"/>
      <batchtest todir="${test.reports.dir}">
        <fileset dir="${test.classes.dir}">
          <include name="**/*Test.class" />
        </fileset>
      </batchtest>
    </junit>
  </target>
        
  <target name="test" 
          depends="test-compile" 
          description="HTML output of test cases">
    <mkdir dir="${test.reports.dir}"/>
    <junit haltonfailure="false" fork="no">
      <classpath refid="project.classpath"/>
      <formatter type="xml" usefile="true"/>

      <batchtest todir="${test.reports.dir}">
        <fileset dir="${test.classes.dir}">
            <include name="**/*Test.class" /> 
        </fileset>
      </batchtest>

    </junit>

    <junitreport todir="${test.reports.dir}">
      <fileset dir="${test.reports.dir}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" styledir="${junit.style.dir}" todir="${test.reports.dir}"/>
    </junitreport>
    <echo>
+-------------------------+
| open reports/index.html |
+-------------------------+
</echo>
  </target>



  <target name="compile" depends="init" description="compile java and groovy sources">
    <mkdir dir="${build.classes.dir}" />

    <groovyc destdir="${build.classes.dir}"
             srcdir="${src.dir}"
             listfiles="true">
        <classpath refid="project.classpath"/>
    </groovyc>

    <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           classpathref="project.classpath"
           debug="${build.debug}"
           deprecation="on"/>
  </target>

    <target name="generate" depends="dist" description="generate test cases">
      <mkdir dir="${generated.test.src.dir}" />
      <taskdef name="gentests" classname="org.codehaus.groovy.tck.GenerateTestCases" classpathref="project.classpath"/>

      <gentests destdir="${generated.test.src.dir}"
                srcdir="${testcase.src.dir}"
                listfiles="true"/>
    </target>

  <target name="test-compile" depends="generate" description="compile tests">
    <mkdir dir="${test.classes.dir}" />
    <javac srcdir="${generated.test.src.dir}"
           destdir="${test.classes.dir}" 
           classpathref="project.classpath" 
           debug="${build.debug}" 
           deprecation="on">
    </javac>
  </target>

  <target name="independent-test-compile" depends="generate" description="compile tests">
    <mkdir dir="${test.classes.dir}" />
    <javac srcdir="${generated.test.src.dir}"
           destdir="${test.classes.dir}" 
           classpathref="project.classpath" 
           debug="${build.debug}" 
           deprecation="on">
    </javac>
  </target>

  <target name="init" depends="init.sub.build,init.independent.build">
    <tstamp/>
  </target>

  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->
  <!--                     Datatypes                     -->
  <!-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -->

  <!-- this target is performed we are within a maven build -->
  <target name="init.sub.build" if="maven.compile.source">

    <path id="project.classpath">
      <pathelement location="${test.classes.dir}"/>
      <path refid="passed.classpath"/>
      <pathelement location="${build.classes.dir}"/>
    </path>
  
  </target>

  <!-- this target is performed when ant is called from command line -->
  <target name="init.independent.build" unless="maven.compile.source">

    <path id="project.classpath">
      <pathelement location="${test.classes.dir}"/>
      <pathelement location="${build.classes.dir}"/>
      <fileset dir="${items.under.test.dir}">
        <include name="**/*.jar" />
      </fileset>
    </path>

  </target>
       
</project>

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy build.xml source code file:

new blog posts

 

Copyright 1998-2013 Alvin Alexander, alvinalexander.com
All Rights Reserved.