ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <jakarta-...@ehatchersolutions.com>
Subject Re: System.getProperties() returns an empty list when unit test runwithin Ant
Date Fri, 16 Aug 2002 15:10:25 GMT
I recommend using fork="true" for <junit>.  Will that solve this problem?

Jerome Lacoste wrote:
> Hi Anties,
> 
> I've got this strange problem: one of my UnitTest fails when I run it 
> within Ant, while it doens't fail when I run it directly from the same VM.
> I've had trouble like that before and they are usualy environment 
> related but this one is very strange:
> Here's the code of my Unit Test:
> 
> public void testSystemGetProperties() {
>    // Skip debug code to printout System.getProperties()
>    ...
>    if (System.getProperties().size() == 0)
>    {
>      fail("WARNING something is wrong in your environment. 
> System.getProperties().size() == 0");
>    }
>  }
> 
> As you can see, System.getProperties().size() == 0 fails when I run this 
> test within ant. According to the API this should never happen.
> Even more strange is that if I try to access any single System property 
> within the same code, I will obtain it without problem!
> I.e. System.getProperty("user.dir") works OK but System.getProperties() 
> still returns an empty list!!
> 
> The following batch file demonstrate the problem for me:
> 
>  > type runtest.bat
> %JAVA_HOME%\bin\java -cp 
> classes\test;classes;lib\junit3.7\junit.jar;lib\log4j\log4j-1.2.4.jar 
> no.bbc.basis.util.PropertyFileReaderTest
> ant test.case -Dtestcase=no.bbc.basis.util.PropertyFileReaderTest
> 
> The first call works while the second doesn't
> 
> My Ant test.case target is realy simple:
>    <target name="test.case" if="testcase" depends="compile.tests"
>      description="Runs the specified JUnit test case">
>        <junit printsummary="withOutAndErr" haltonfailure="yes">
>        <classpath>
>            <path refid="tests.classpath" />
>        </classpath>
>        <formatter type="plain" usefile="false" />
>              <test name="${testcase}" />
>        </junit>
>    </target>
> 
> where the classpath is set using a fileset filter of all jar file in my 
> lib directories + my classes dir
> 
> 
> It seems to be an environment problem, but I can't figure it out.
> I first though it to be a JDK problem, but given the fact that my test 
> works when I invoke it from the command line but not within Ant, I am 
> confused.
> I've searched throught the Ant mailing list, the releases notes for Ant 
> 1.5, Sun's bug database and Google without luck.
> 
> I am currently downloading a newer version of Ant (1.5) and of the JDK 
> (1.4.1beta) to rerun my tests, but on my modem line, it's going to take 
> some time.
> In the meantime I submit my problem to you in case one of you spots a 
> problem.
> 
> Some more information about my environment:
> 
> I am developing on WinNT 4.0.
> 
> Here's my environment:
> ANT_HOME=D:\dev\jakarta-ant-1.4.1
> CLASSPATH=D:\j2sdk1.4.0_01\lib\tools.jar
> JAVA_HOME=D:\j2sdk1.4.0_01
> Path=D:\dev\jakarta-ant-1.4.1\bin;C:\WINNT\SYSTEM32;C:\WINNT;C:\WINNT\SYSTEM32\WBEM;C:\DMI\WIN32\BIN;D:\PROGRA~1\ULTRAE~1
> 
> D:\>ant -version
> Ant version 1.4.1 compiled on October 11 2001
> 
>  >%JAVA_HOME%\bin\java -version
> java version "1.4.0_01"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
> Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
> 
> Attached are:
> - SysProp_fromJDK: output of Properties printed out by my test code when 
> code executed from the command line:
> - SysProp_fromAnt:   Same properties printed out by my test code when 
> code is executed within Ant
> 
> Notice how System.getProperties() displays 0 elements but all its 
> properties are effectively found!
> 
> 
> 
> Here's the diff of the two output files:
> 
> Comparing: 
> D:\Projects\Basis\ProofOfConcept\bugs\System_getProperties_in_Ant\SysProp_fromAnt.txt
> To: 
> D:\Projects\Basis\ProofOfConcept\bugs\System_getProperties_in_Ant\SysProp_fromJDK.txt
> ====
> ====
> 2     <! Displaying 0 element(s) in properties [System.getProperties()]:
>       !> Displaying 50 element(s) in properties [System.getProperties()]:
> 32     <! p->user.timezone=Europe/Berlin
>         !> p->user.timezone=
> 36     <! 
> p->java.class.path=D:\j2sdk1.4.0_01\lib\tools.jar;D:\dev\jakarta-ant-1.4.1\lib\optional.jar;D:\dev\jakarta-ant-1.4.1\lib\junit.jar;D:\dev\jakarta-ant-1.4.1\lib\jaxp.jar;D:\dev\jakarta-ant-1.4.1\lib\crimson.jar;D:\dev\jakarta-ant-1.4.1\lib\ant.jar;D:\j2sdk1.4.0_01\lib\tools.jar
>     !> 
> p->java.class.path=classes\test;classes;lib\junit3.7\junit.jar;lib\log4j\log4j-1.2.4.jar
> 
> [Don't ask me why the "user.timezone" is not properly propagated.]
> 
> Only noticeable difference is the java.class.path, but isn't that normal?
> 
> Cheers,
> 
> Jerome
> 
> 
> ------------------------------------------------------------------------
> 
> testSystemGetProperties
> Displaying 50 element(s) in properties [System.getProperties()]:
> p->java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition
> p->sun.boot.library.path=D:\j2sdk1.4.0_01\jre\bin
> p->java.vm.version=1.4.0_01-b03
> p->java.vm.vendor=Sun Microsystems Inc.
> p->java.vendor.url=http://java.sun.com/
> p->path.separator=;
> p->java.vm.name=Java HotSpot(TM) Client VM
> p->file.encoding.pkg=sun.io
> p->user.country=US
> p->sun.os.patch.level=Service Pack 6
> p->java.vm.specification.name=Java Virtual Machine Specification
> p->user.dir=D:\Projects\Basis\ProofOfConcept
> p->java.runtime.version=1.4.0_01-b03
> p->java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
> p->java.endorsed.dirs=D:\j2sdk1.4.0_01\jre\lib\endorsed
> p->os.arch=x86
> p->java.io.tmpdir=C:\TEMP\
> p->line.separator=
> 
> p->java.vm.specification.vendor=Sun Microsystems Inc.
> p->user.variant=
> p->os.name=Windows NT
> p->sun.java2d.fontpath=
> p->java.library.path=D:\j2sdk1.4.0_01\bin;.;C:\WINNT\System32;C:\WINNT;D:\dev\jakarta-ant-1.4.1\bin;C:\WINNT\SYSTEM32;C:\WINNT;C:\WINNT\SYSTEM32\WBEM;C:\DMI\WIN32\BIN;D:\PROGRA~1\ULTRAE~1
> p->java.specification.name=Java Platform API Specification
> p->java.class.version=48.0
> p->java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory
> p->os.version=4.0
> p->user.home=C:\WINNT\Profiles\Jerome
> p->user.timezone=
> p->java.awt.printerjob=sun.awt.windows.WPrinterJob
> p->file.encoding=Cp1252
> p->java.specification.version=1.4
> p->java.class.path=classes\test;classes;lib\junit3.7\junit.jar;lib\log4j\log4j-1.2.4.jar
> p->user.name=Jerome
> p->java.vm.specification.version=1.0
> p->java.home=D:\j2sdk1.4.0_01\jre
> p->sun.arch.data.model=32
> p->user.language=en
> p->java.specification.vendor=Sun Microsystems Inc.
> p->awt.toolkit=sun.awt.windows.WToolkit
> p->java.vm.info=mixed mode
> p->java.version=1.4.0_01
> p->java.ext.dirs=D:\j2sdk1.4.0_01\jre\lib\ext
> p->sun.boot.class.path=D:\j2sdk1.4.0_01\jre\lib\rt.jar;D:\j2sdk1.4.0_01\jre\lib\i18n.jar;D:\j2sdk1.4.0_01\jre\lib\sunrsasign.jar;D:\j2sdk1.4.0_01\jre\lib\jsse.jar;D:\j2sdk1.4.0_01\jre\lib\jce.jar;D:\j2sdk1.4.0_01\jre\lib\charsets.jar;D:\j2sdk1.4.0_01\jre\classes
> p->java.vendor=Sun Microsystems Inc.
> p->file.separator=\
> p->java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
> p->sun.io.unicode.encoding=UnicodeLittle
> p->sun.cpu.endian=little
> p->sun.cpu.isalist=
> 
> 
> ------------------------------------------------------------------------
> 
> testSystemGetProperties
> Displaying 0 element(s) in properties [System.getProperties()]:
> p->java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition
> p->sun.boot.library.path=D:\j2sdk1.4.0_01\jre\bin
> p->java.vm.version=1.4.0_01-b03
> p->java.vm.vendor=Sun Microsystems Inc.
> p->java.vendor.url=http://java.sun.com/
> p->path.separator=;
> p->java.vm.name=Java HotSpot(TM) Client VM
> p->file.encoding.pkg=sun.io
> p->user.country=US
> p->sun.os.patch.level=Service Pack 6
> p->java.vm.specification.name=Java Virtual Machine Specification
> p->user.dir=D:\Projects\Basis\ProofOfConcept
> p->java.runtime.version=1.4.0_01-b03
> p->java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
> p->java.endorsed.dirs=D:\j2sdk1.4.0_01\jre\lib\endorsed
> p->os.arch=x86
> p->java.io.tmpdir=C:\TEMP\
> p->line.separator=
> 
> p->java.vm.specification.vendor=Sun Microsystems Inc.
> p->user.variant=
> p->os.name=Windows NT
> p->sun.java2d.fontpath=
> p->java.library.path=D:\j2sdk1.4.0_01\bin;.;C:\WINNT\System32;C:\WINNT;D:\dev\jakarta-ant-1.4.1\bin;C:\WINNT\SYSTEM32;C:\WINNT;C:\WINNT\SYSTEM32\WBEM;C:\DMI\WIN32\BIN;D:\PROGRA~1\ULTRAE~1
> p->java.specification.name=Java Platform API Specification
> p->java.class.version=48.0
> p->java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory
> p->os.version=4.0
> p->user.home=C:\WINNT\Profiles\Jerome
> p->user.timezone=Europe/Berlin
> p->java.awt.printerjob=sun.awt.windows.WPrinterJob
> p->file.encoding=Cp1252
> p->java.specification.version=1.4
> p->java.class.path=D:\j2sdk1.4.0_01\lib\tools.jar;D:\dev\jakarta-ant-1.4.1\lib\optional.jar;D:\dev\jakarta-ant-1.4.1\lib\junit.jar;D:\dev\jakarta-ant-1.4.1\lib\jaxp.jar;D:\dev\jakarta-ant-1.4.1\lib\crimson.jar;D:\dev\jakarta-ant-1.4.1\lib\ant.jar;D:\j2sdk1.4.0_01\lib\tools.jar
> p->user.name=Jerome
> p->java.vm.specification.version=1.0
> p->java.home=D:\j2sdk1.4.0_01\jre
> p->sun.arch.data.model=32
> p->user.language=en
> p->java.specification.vendor=Sun Microsystems Inc.
> p->awt.toolkit=sun.awt.windows.WToolkit
> p->java.vm.info=mixed mode
> p->java.version=1.4.0_01
> p->java.ext.dirs=D:\j2sdk1.4.0_01\jre\lib\ext
> p->sun.boot.class.path=D:\j2sdk1.4.0_01\jre\lib\rt.jar;D:\j2sdk1.4.0_01\jre\lib\i18n.jar;D:\j2sdk1.4.0_01\jre\lib\sunrsasign.jar;D:\j2sdk1.4.0_01\jre\lib\jsse.jar;D:\j2sdk1.4.0_01\jre\lib\jce.jar;D:\j2sdk1.4.0_01\jre\lib\charsets.jar;D:\j2sdk1.4.0_01\jre\classes
> p->java.vendor=Sun Microsystems Inc.
> p->file.separator=\
> p->java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
> p->sun.io.unicode.encoding=UnicodeLittle
> p->sun.cpu.endian=little
> p->sun.cpu.isalist=
> 
> 
> ------------------------------------------------------------------------
> 
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>



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


Mime
View raw message