ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jose Alberto Fernandez <JFernan...@viquity.com>
Subject RE: References do not work for me.
Date Fri, 17 Nov 2000 01:13:49 GMT
> From: John Hempe [mailto:jhempe@north.com]
> 
> Now wait a minute, do you mean "discouraged" or "not supported"?  The
> problem with initializing properties outside of targets is 
> that this makes
> initialization "a priori" with respect to executed targets.  
> It follows that
> I can't do something nifty like have one of two different 
> property files
> sucked in depending on my present OS.  
> 

You can define properties inside targets, if you want them to be defined
ONLY after the target has been executed; or you can defined at the project
level so that they get defined as the XML file is read.

> Regardless of that specific complaint, I don't see why the 
> semantics of the
> two examples should be different, and I protest:  by the time I use my
> defined path, "myprop" has been resolved, so what's the problem with
> interpolating ${myprop} when I actually use the path reference?  
> 

The problem you have is that you are defining the property in a target,
nothing
wrong with that, but you are defining your <path> at the project level
which gets evaluated as the XML is read. Hence at that time the property
does not exists yet. To achieve what you want you need to define your <path>
inside a target
that will execute after the <property> task gets executed.

The semantics is quite clear.

> It sounds like Ant is trying to eliminate the conditional setting of
> properties entirely, and is trying to have its cake and 
> restrict it too:
> either don't support property initialization in targets at 
> all, I argue, or
> support it properly with runtime interpolation of path and 
> other referenced
> elements.  As it is now, the semantics feel very "buggy" and 
> I'm going to
> have to throw out referenced paths entirely to proceed.
> 

You can define properties conditionally see several threads on how to do
that.

> --John
> 
> P.S.  Your example works but also illustrates my problem with the
> inconsistent semantics.
> 
> 
> > -----Original Message-----
> > From: glennm@ca.ibm.com [mailto:glennm@ca.ibm.com]
> > Sent: Thursday, November 16, 2000 2:49 PM
> > To: ant-dev@jakarta.apache.org
> > Subject: Re: References do not work for me.
> > 
> > 
> > 
> > 
> > Its not that references aren't working for you, its that you 
> > are using an
> > older mechanism for setting properties that is discouraged.  
> > Other people
> > are having this problem.
> > 
> > Try this:
> > 
> > <project ...>
> >   <!-- properties don't have to be in targets -->
> >   <property name="myprop" value="foo/bar" />
> > 
> >   <path id="compile.class.path">
> >     <pathelement location="${myprop}/baz" />
> >     ...
> >   </path>
> > 
> >   ...
> > </project>
> > 
> > I haven't tested it, so YMMV, but like I said in the other 
> email, this
> > should work.
> > 
> > Glenn McAllister
> > Software Developer. IBM Toronto Lab, (416) 448-3805
> > "An approximate answer to the right question is better than the
> > right answer to the wrong question." - John W. Tukey
> > 
> > 
> > Please respond to ant-dev@jakarta.apache.org
> > 
> > To:   "'ant-dev@jakarta.apache.org'" <ant-dev@jakarta.apache.org>
> > cc:
> > Subject:  References do not work for me.
> > 
> > References don't act nice like properties, there must be 
> > something about
> > them I'm not "getting".  Are they supposed to be working or 
> > is this feature
> > incomplete?
> > 
> > They don't expand right, and they simply don't work for me.  If the
> > following file is "test.xml":
> > 
> > <project name="testref" basedir=".">
> > <target name="init">
> >   <property name="myprop" value="foo/bar"/>
> >   <property name="ugly.class.path" value="this:that:the_other"/>
> > </target>
> > 
> > <path id="compile.class.path">
> >   <pathelement location="/${myprop}/baz"/>
> >   <pathelement location="/only/hardcoded/paths/work"/>
> > </path>
> > 
> > <target name="list" depends="init">
> >   <property name="transfer.compile.class.path" 
> > refid="compile.class.path"/>
> >   <echo message="CLASS PATH is ${transfer.compile.class.path}"/>
> >   <echo message="Ugly class path actually works and is:
> > ${ugly.class.path}"/>
> > </target>
> > </project>
> > 
> > My output is as follows:
> > 
> > build >ant -version
> > Ant version 1.2 compiled on October 24 2000
> > 
> > build >ant -buildfile test.xml list
> > Buildfile: test.xml
> > 
> > init:
> > 
> > list:
> > CLASS PATH is /${myprop}/baz:/only/hardcoded/paths/work
> > Ugly class path actually works and is: this:that:the_other
> > 
> > BUILD SUCCESSFUL
> > Total time: 0 seconds
> > 
> > To add insult to injury, when I use a "javac" task in verbose 
> > mode, and
> > specify classpath by reference, I seem to get a class path 
> > that has nothing
> > whatsoever to do with the one I specified.
> > I'm referencing it correctly I believe:
> > 
> > <target name="compile" depends="init">
> >   <javac srcdir="path/to/my/classes"
> >       debug="on">
> >     <classpath refid="compile.class.path"/>
> >   </javac>
> > </target>
> > 
> > If I use a version of this target with my test script listed 
> > above, invoked
> > with -verbose, I get:
> >     [javac] Compilation args: -d path/to/my/classes -classpath
> > /path/to/my/classes:/prefix/jakarta-ant/lib/ant.jar:/prefix/ja
> > karta-ant/lib/
> > 
> > jaxp.jar:/prefix/jakarta-ant/lib/parser.jar:/opt/jdk1.2.1_04/l
> > ib/tools.jar
> > -sourcepath [path] -g
> > 
> > This classpath looks a heckuvalot more like the path the Ant 
> > sh script uses
> > to invoke itself than what I referenced, which should be in 
> > the worst case
> > /${myprop}/baz:/only/hardcoded/paths/work
> > And ideally:
> > /foo/bar/baz:/only/hardcoded/paths/work
> > 
> > So my first question is, why don't properties in 
> referentially defined
> > paths
> > seem to expand correctly?
> > 
> > The second one is, why don't referenced classpaths seem to 
> > work AT ALL for
> > me???
> > 
> > --John Hempe
> > 
> > 
> > 
> > 
> > 
> > > -----Original Message-----
> > > From: Stefan Bodewig [mailto:bodewig@bost.de]
> > > Sent: Thursday, November 16, 2000 12:36 AM
> > > To: ant-user@jakarta.apache.org
> > > Subject: Re: Debugging references
> > >
> > >
> > > John Hempe <jhempe@north.com> wrote:
> > >
> > > > So if I define something like:
> > > >
> > > > <path id="compile.class.path">
> > > >   <pathelement location="${something}/classes"/>
> > > >   <pathelement location="${something.else}/classes"/>
> > > > </path>
> > > >
> > > > How can I "echo" what "compile.class.path" gets set to? 
>  How can I
> > > > see it at runtime?
> > >
> > > <snip/>
> > >
> > > > I tried <echo message="${compile.class.path}"> but that doesn't
> > > > work,
> > >
> > > Assign it to a property in between:
> > >
> > > <property name="compile.class.path" refid="compile.class.path" />
> > > <echo message="${compile.class.path}">
> > >
> > > ugly but it should work.
> > >
> > > Stefan
> > >
> > 
> > 
> > 
> 

Mime
View raw message