ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 23552] New: - Clearer documentation on best practices with JUnit and optional.jar are needed
Date Wed, 01 Oct 2003 19:21:46 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23552>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23552

Clearer documentation on best practices with JUnit and optional.jar are needed

           Summary: Clearer documentation on best practices with JUnit and
                    optional.jar are needed
           Product: Ant
           Version: 1.5.4
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Documentation
        AssignedTo: dev@ant.apache.org
        ReportedBy: scott@alodar.com


Fighting with junit.jar and optional.jar was a great pain when I had to do it recently.  It
would have 
helped me to have a clearer document than what now exists on how to set up your ant 
installation and build.xml using junit.jar and optional.jar if you do not want to include
those jars in 
ant/lib.

Putting jars in ant/lib begins to fail as you need more specialty jars.  For example, several
of my 
recent projects have been bitten badly by having out of date versions of xalan in ant/lib,
used with 
the style task.  Further, your ant install gets arcane as more and more specialty jars get
added.  
xdoclet, for example, requires a whole raft of jars in ant/lib, and is very likely to get
out of date 
with other apache-based projects.

Our group thus moved to refactor our ANT installation to be a pure, from the factory, install.
 We 
are also directed to include xalan.jar, junit.jar, and the like, from a known-safe per project
install.  
(Actually, we have a lib dir with a zillion versions of libraries in it, and individual projects
include 
the version they need.)

Making this work with junit and optional not in ant/lib has been a real pain.  I finally figured
out 
what to do, but it took a lot more effort than I really wanted to spend on what seems to be
a very 
common task.

What I would like is a document that spells out very clearly the best practices for integrating
junit 
tasks and style tasks when junit.jar and xalan.jar are not in ant/lib.  In my mind, the best
way to 
do this is with a simple build.xml that builds a java file, builds a Test java file, runs
the junit test, 
and boxes up the resulting jar.  I have attached such a build file, but I am not sure it contains
what 
would be thought of as best practices.  I submit it in hopes that a better build.xml and 
explanatory document might appear for 1.6.

If it seems appropriate, feel free to add explanatory text as needed, to simplify, or to otherwise

make it easier for someone else to do what took me so long.

<project default="package" basedir=".">
  <property name="test.dir" location="./test/"/>
  <property name="src.dir" location="./src/"/>
  <property name="src.test" location="${test.dir}/src/"/>
  <property name="lib.dir" location="./lib"/>
  <property name="optional.jar" location="${ant.home}/optional/optional.jar"/>
  <property name="junit.jar" location="${lib.dir}/junit.jar"/>

  <path id="junit.classpath">
    <pathelement location="${optional.jar}"/>
    <pathelement location="${junit.jar}"/>
  </path>

  <taskdef name= "junit" classname= "org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"

classpathref="junit.classpath"/> 
  <taskdef name= "junitperf" classname= "org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"

classpathref="junit.classpath"/> 
  <taskdef name= "junit" classname= "org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"

classpathref="junit.classpath"/> 
  <property name="build.dir" location="./build"/>
  <property name="build.dest" location="./build/classes"/>
  <property name="build.test" location="./build/test"/>
  <property name="dist.root" location="./dist"/>
  <property name="build.debug" value="yes"/>
  <property name="build.deprecation" value="yes"/>
  <property name="build.optimize" value="yes"/>
  <property name="jar.name.base" value="bonusfinder"/>
  <property name="jar.name" location="${build.dir}/${jar.name.base}.jar"/>
  <property name="jar.main-class" value="BonusFinder"/>

  <path id="compile.classpath">
  </path>

  <path id="test.classpath">
    <path refid="compile.classpath"/>
    <pathelement location="${junit.jar}"/>
    <pathelement location="${jar.name}"/>
    <pathelement location="${build.test}"/>
  </path>

  <target name="init">
    <tstamp/>
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dest}"/>
    <mkdir dir="${build.test}"/>
  </target>

  <!-- 
============================================================
======= -->
  <!-- Compiles the source directory                                       -->
  <!-- 
============================================================
======= -->
  <target name="compile" depends="init">
    <javac srcdir="${src.dir}"
           destdir="${build.dest}"
           debug="${build.debug}"
           deprecation="${build.deprecation}"
           optimize="${build.optimize}">
      <classpath refid="compile.classpath"/>
    </javac>
  </target>

  <!-- 
============================================================
======= -->
  <!-- Compiles the test directory                                       -->
  <!-- 
============================================================
======= -->
  <target name="compile-test" depends="package">
    <javac srcdir="${src.test}"
           destdir="${build.test}"
           debug="${build.debug}"
           deprecation="${build.deprecation}"
           optimize="${build.optimize}">
           <classpath refid="test.classpath"/>
    </javac>
    <copy todir="${build.test}">
      <fileset dir="${src.test}" excludes="**/*.java"/>
    </copy>
  </target>

  <!-- 
============================================================
======= -->
  <!-- Runs the tests                                           -->
  <!-- 
============================================================
======= -->
  <target name="test" depends="compile-test">
    <junit haltonfailure="true" printsummary="true" includeantruntime="false">
      <classpath refid="test.classpath"/>
      <formatter type="brief" usefile="false"/>
      <test name="SimpleTest" />
    </junit>
  </target>

  <!-- 
============================================================
======= -->
  <!-- Creates the jar                                           -->
  <!-- 
============================================================
======= -->
  <target name="package" depends="compile">
    <jar jarfile="jar.name" basedir="${build.dest}">
      <manifest>
        <attribute name="Main-Class" value="${jar.main-class}"/>
      </manifest>
    </jar>
  </target>

  <!-- 
============================================================
======= -->
  <!-- Clean targets                                                       -->
  <!-- 
============================================================
======= -->
  <target name="clean" depends="init">
    <delete dir="${build.dir}"/>
  </target>

</project>

<!-- End of file -->

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message