ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jerome Lacoste <lacostej...@altern.org>
Subject System.getProperties() returns an empty list when unit test runwithin Ant
Date Fri, 16 Aug 2002 14:23:45 GMT
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


Mime
View raw message