ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dubois, Jeff" <jeff.dub...@thomson.com>
Subject RE: Ant not passing System values to JUnit task
Date Tue, 02 Dec 2003 18:33:22 GMT
Hi Peter,
Thanks for your response regarding the need to use the <sysproperty> element
to set a system property for the <junit> target, and you indicated that my
attachment did not come through.

My command line when invoking ant is as follows:

%JAVA_HOME%\bin\java -cp "%classpath%" -Dactive.level=dev
-Dant.home=%ANT_HOME% org.apache.tools.ant.Main -f "myBuild.xml" jarUp

This does set the system/environment of the ant script, even though I am not
passing the -Dactive.level=dev as an argument to ant (it's an argument to
java).

I verified this by eching out in the runUnitTest target with the ant script:
      <echo message="active.level is ${active.level}" />

I get as output:

runUnitTest:
     [echo] active.level is dev


However, this active.level vm/system/environment variable is not getting
passed to the system of the junit task, and it seems like it should be.

To quote the ant manual:
"Ant provides access to all system properties as if they had been defined
using a <property> task. For example, ${os.name} expands to the name of the
operating system."

And what I am wondering is, shouldn't all those system properties that the
ant script is running under, be automatically/by-default, passed to the
junit task when it is executed?  
In other words I shouldn't have to use <sysproperty> to set a property of
something that already exists.

Here is the build script (see runUnitTest target):

<?xml version="1.0"?>
<!--=======================================================================-
->
<!--
    The following jar files need to be included in the classpath that is
used to invoke ANT (they are used by
    the Junit tasks) :

        xalan.jar (xalan_2.4.0.jar)
        xercesImpl.jar (xercesImpl_2.2.0.jar)
        xml-apis.jar (xml-apis_1.2.2.jar)
        xmlParserAPIs.jar (xmlParserAPIs_2.2.0.jar)
-->

<!--=======================================================================-
->
<project name="StandardBuild" default="compile" basedir=".">

   <!-- set up properties to reference directories/files relative to the
base directory-->

   <!-- this file contains an explicit listing of relative project
dependancies, it is read in by this build file to
        construct the proper classpath -->
   <property file="lib/build.dependencies.txt"/>
   <!-- relatative location of source directory-->
   <property name="source" value="src"/>
   <!-- relatative location of resource dirctory -->
   <property name="resource" value="resource"/>
   <!-- relatative location of test directory-->
   <property name="testResource" value="test"/>
   <!-- relatative location of web directory-->
   <property name="web" value="web"/>
   <!-- relatative location of classes directory-->
   <property name="build" value="classes"/>
   <!-- relatative location of dist (distribution) directory-->
   <property name="work" value="dist"/>
   <!-- relatative location of preprepatory directory for jars-->
   <property name="jarPrep" value="${work}\jarPrep"/>
   <!-- relatative location of preprepatory directory for wars-->
   <property name="warPrep" value="${work}\warPrep"/>
   <!-- relatative location of preprepatory directory for WEB-INF-->
   <property name="web-inf" value="${warPrep}\WEB-INF"/>
   <!-- relatative location of directory for libs included in war-->
   <property name="warLib" value="${web-inf}\lib"/>
   <!-- relatative location of directory for classes included in war-->
   <property name="warClasses" value="${web-inf}\classes"/>
   <!-- prefix "env" used when referring to environment variables -->
   <property environment="env" />

   
  

 
<!--===================================================================-->
   <!--Prepares-->
   <!--  creates needed directories for build and checks for and sets
properties based on available resoureces-->
 
<!--===================================================================-->
   <target name="prepare">
      <basename property="appName" file="../."/>
      <available file="${resource}" type="dir"
property="isResourceFolderAvailable"/>
      <available file="${web}" type="dir" property="isWebFolderAvailable"/>
      <available file="${testResource}" type="dir"
property="isTestResouceFolderAvailable"/>
      <available file="${source}" type="dir"
property="isSourceFolderAvailable"/>
      <available file="${web}" type="dir" property="isWebAvailable"/>
      <mkdir dir="${build}"/>
      <mkdir dir="${work}"/>
      <tstamp>
         <format property="now" pattern="d-MMMM-yyyy HH:mm:ss"/>
      </tstamp>
   </target>

 
<!--===================================================================-->
   <!--Cleans the build and work directories-->
 
<!--===================================================================-->
   <target name="clean" depends="prepare">
      <delete includeEmptyDirs="true" quiet="true">
         <fileset dir="${build}"
                includes="**/*"
                defaultexcludes="no"/>
         <fileset dir="${work}"
                includes="**/*"
                defaultexcludes="no"/>
         <fileset dir="${work}"
                includes="**/*"
                defaultexcludes="no"/>
      </delete>
   </target>
 
<!--===================================================================-->
   <!--Copy resource files-->
 
<!--===================================================================-->
   <target name="copyResource" depends="prepare"
if="isResourceFolderAvailable">
      <copy todir="${build}" includeEmptyDirs="false" overwrite="yes">
         <fileset dir="${resource}">
            <include name="**/*"/>
         </fileset>
      </copy>
   </target>
 
<!--===================================================================-->
   <!--Compile Source-->
 
<!--===================================================================-->
   <target name="compile" depends="prepare, copyResource"
if="isSourceFolderAvailable">
      <javac srcdir="${source}" destdir="${build}" debug="on" verbose="on">
         <classpath>
            <pathelement path="${library}"/>
         </classpath>
      </javac>
   </target>
 
<!--===================================================================-->
   <!--Validate the build by running the JUnit test suite-->
 
<!--===================================================================-->
   <target name="runUnitTest" depends="compile, copyResource" >
      <echo message="active.level is ${active.level}" />
      <junit printsummary="on" errorProperty="test.failed"
failureProperty="test.failed" filtertrace="off" showoutput="on" fork="on">
         <formatter type="xml"/>
         <classpath>
            <pathelement path="${library}"/>
            <pathelement location="resource"/>
            <pathelement location="${build}"/>
         </classpath>
         <batchtest todir="${work}">
            <fileset dir="${build}">
               <include name="**/UnitTests.class"/>
            </fileset>
         </batchtest>

       </junit>
      <junitreport toFile="${work}/junitReport.xml">
         <fileset dir="${work}">
            <include name="TEST-*.xml"/>
         </fileset>
         <report format="noframes" styledir="${commonLibraryFolder}ant"/>
      </junitreport>
      <move file="junit-noframes.html" tofile="${work}/junitReport.html"/>
      <fail message="Unit tests failed. see junitReport.html for details."
if="test.failed"/>
   </target>
 
<!--===================================================================-->
   <!--make a JAR-->
 
<!--===================================================================-->
   <target name="jarUp" depends="clean, runUnitTest">

      <mkdir dir="${jarPrep}"/>
      <delete>
         <fileset dir="${jarPrep}"/>
      </delete>
      <copy todir="${jarPrep}" overwrite="yes" includeEmptyDirs="false">
         <fileset dir="${build}"/>
      </copy>
      <copy todir="${jarPrep}/source" overwrite="yes"
includeEmptyDirs="false">
         <fileset dir="${source}"/>
      </copy>
      <manifest file="MANIFEST.MF">
         <attribute name="Library-Name" value="${appName}"/>
         <attribute name="Release-Date" value="${now}"/>
         <attribute name="Release-Label" value="${label}"/>
      </manifest>
      <jar jarfile="${work}/${appName}.jar" manifest="MANIFEST.MF"
basedir="${jarPrep}"/>
      <delete includeEmptyDirs="true">
         <fileset dir="${jarPrep}"/>
      </delete>
   </target>
 
<!--===================================================================-->
   <!--Copy web accessible files-->
 
<!--===================================================================-->
   <target name="copyWeb" depends="prepare" if="isWebFolderAvailable">
      <copy todir="${warPrep}" includeEmptyDirs="false" overwrite="yes">
         <fileset dir="${web}">
            <exclude name="**/web.xml"/>
         </fileset>
      </copy>
   </target>
 
<!--===================================================================-->
   <!--make a WAR-->
 
<!--===================================================================-->
   <target name="warUp" depends="clean, runUnitTest, copyWeb">
      <mkdir dir="${warPrep}"/>
      <copy todir="${warClasses}" overwrite="yes" includeEmptyDirs="false">
         <fileset dir="${build}"/>
      </copy>
      <copy todir="${warLib}" flatten="yes">
         <fileset dir="${commonLibraryFolder}"
includesFile="lib/build.dependencies.txt"/>
      </copy>
      <copy todir="${warLib}" flatten="yes">
         <fileset dir="${projectLibraryFolder}"
includesFile="lib/build.dependencies.txt"/>
      </copy>

      <!--remove jars provided by container-->
      <delete>
          <fileset dir="${warLib}">
            <include name="servlet.jar"/>
            <include name="servlet_1.1.jar"/>
            <include name="servlet_2.3.jar"/>
            <include name="ExportBuildDependencies.jar"/>
          </fileset>
      </delete>

      <manifest file="MANIFEST.MF">
         <attribute name="WebService-Name" value="${appName}"/>
         <attribute name="Release-Date" value="${now}"/>
         <attribute name="Release-Label" value="${label}"/>
      </manifest>
      <war jarfile="${work}/${appName}.war" manifest="MANIFEST.MF"
basedir="${warPrep}" webxml="${web}/WEB-INF/web.xml"/>
      <delete includeEmptyDirs="true">
         <fileset dir="${warPrep}"/>
      </delete>
   </target>
</project>


Thanks!  --Jeff

-----Original Message-----
From: Peter Reilly [mailto:peter.reilly@corvil.com]
Sent: Tuesday, December 02, 2003 11:25 AM
To: Ant Users List
Subject: Re: Ant not passing System values to JUnit task


Your build script did not come thu.

However
  setting -Dx=y on the ant.bat or ant shell script does *not* set a 
system property.
  It sets an ant property.

  To set the system property in the for the <junit> task, you need to
  use the nested element <sysproperty>.

<junit>
  <sysproperty key="active.level" value="${active.level}"/>
  <test name="my.test.TestCase"/>
</junit>

Peter






Dubois, Jeff wrote:

>When doing an Ant build of my project (see attached myBuild.xml script) It
>appears that ant is not passing System variables/values when executing the
>JUnit task.  I am on Windows using Ant 1.5.3.
>
>For my JUnit test cases to succeed I need a VM/System variable called
>"active.level" set to "dev"..  When executing Ant (via a batch file) I pass
>in the value of "active.level" via a "-Dactive.level=dev" argument on the
>command line.
>In my ant script I echo out the value of "active.level" and indeed it is
set
>to "dev" (see runUnitTest target in attached script).
>
>However, when I run the Unit test, this "active.level" variable is no
longer
>set.  I verified this by printing out the value of "active.level" in one of
>the Java test cases that get run.
>    The code I use is:
>           System.out.println( "active.level is: " +
>System.getProperty("active.level"));     
>The corresponding output when run through ant is:
>          [junit] active.level is: null
>By default are not all System variables supposed to be passed to the JUnit
>task? 
>
>Thanks!
>    Jeff
>
> 
> <<myBuild.xml>> 
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>


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

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


Mime
View raw message