Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11240

Re: One Ant buildfile calling its subdir buildfile, how to change the base dir?

From www <xsli2@yahoo.com>
Newsgroups comp.lang.java.programmer
Subject Re: One Ant buildfile calling its subdir buildfile, how to change the base dir?
Date 2012-01-11 12:00 -0800
Organization http://groups.google.com
Message-ID <4f3ee79e-e431-4224-a08f-973b8223aaa6@cf6g2000vbb.googlegroups.com> (permalink)
References <de9cbc9c-7297-43f0-847f-83b7c650c953@p4g2000vbt.googlegroups.com>

Show all headers | View raw


After some investigation, I would like to re-phrase my question. Here
are my files:

main/build.xml containing a target invoking a target in sub directory

	<target name="test-sub">
		<echo message="main base dir=${basedir}" />

                <!--showing two tried methods below, neither one
works, all with the same error message -->
                <!-- using ant task does not work -->
		<ant dir="./sub" inheritall="false" target="MyTest"/>

                <!-- using subant does not work either-->
		<subant target="MyTest" genericantfile="sub/build.xml">
			<dirset dir="." includes="sub" />
		</subant>
	</target>


main/sub/build.xml --> containing a target "MyTest" running a JUnit
test -- calling A.B.C.MyTest class

        <echo message="sub base dir=${basedir}" />
	<target name="MyTest">
	    <junit>
	      <classpath refid="project.classpath" />
	      <formatter type="brief" usefile="false" />
	      <test name="A.B.C.MyTest" />
	    </junit>
	</target>
Inside MyTest.java, I added this print out:
        final String currentDir = new File(".").getAbsolutePath();
        System.out.println("currentDir=" + currentDir);

Running the target MyTest at main/sub is *fine*, with these printout:

     [echo] sub base dir=/xxx/xx/main/sub

MyTest:
    [junit] currentDir=/xxx/xx/main/sub/. <------The printout in
MyTest shows that it is run at main/sub, so inside MyTest, a relative
path is correct

Running the target test-sub at main is *bad*, with these printout:
test-sub:
     [echo] main base dir=/xxx/xx/main
     [echo] sub base dir=/xxx/xx/main/sub/. <--- the echo from sub/
build.xml shows that the base dir is already main/sub, not main/,
however, MyTest is still run at main/, not main/sub

MyTest:
    [junit] currentDir=/xxx/xx/main/.  <------The printout in MyTest
shows that it is still be run at main/, not main/sub, so inside
MyTest, a relative path becomes invalid

Thank you very much.

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

One Ant buildfile calling its subdir buildfile, how to change the base dir? www <xsli2@yahoo.com> - 2012-01-11 09:11 -0800
  Re: One Ant buildfile calling its subdir buildfile, how to change the base dir? www <xsli2@yahoo.com> - 2012-01-11 12:00 -0800

csiph-web