ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: AW: ant access of java constants
Date Tue, 25 Jan 2005 03:43:29 GMT
Could you post your Diagnostic.java code?

I think your best bet to solving the <classcontants> issue is to dig 
under the hood of its code and see what makes it tick and experiment.  
Or, certainly simpler, write a custom Ant task that gets the 
information from Diagnostic and sets and Ant property.  It'd only be a 
few lines of code to do this - extend from Task, implement a public 
void execute() method, get the value you want, and call 
project.setNewProperty(...).

	Erik

On Jan 24, 2005, at 9:09 PM, michael sorens wrote:

> Yes, my constants are "public static final". The problem, I found, is 
> that the definition of VERSION is a method evaluation, not a 
> compile-time constant, as you had tried. So that answers that 
> question.
>
> The remaining issue is back on the file that I really want to use, 
> Diagnostic.class. Changing nothing except the class name & path to 
> point to this file causes an IOException, so it looks like a bug to 
> me. Who does one inform of such things?
>
> BTW, Erik thanks for your <prefixlines> tip regarding constants!
>
>
> On Mon, 24 Jan 2005 12:14:56 -0500, Erik Hatcher 
> <erik@ehatchersolutions.com> wrote:
>
>> On Jan 24, 2005, at 11:05 AM, michael sorens wrote:
>>> (1) Well I tried adding bcel.jar to my ant/lib directory but it made
>>> no difference.
>>> What did make a difference was my choice of .class file to load.
>>> Instead of my Diagnostic.class
>>> I tried a simpler Version.class and then I received no error, even
>>> *without* bcel.jar. So this seems like a data-dependent bug...
>>
>> Did you make your VERSION be "public static final"?  I just tried it
>> (had to download and install BCEL into ANT_HOME/lib myself) with this
>> class:
>>
>> public class Test {
>>    public static final String VERSION = "version";
>> }
>>
>> I also tried it with an int:
>>
>>    public static final int VERSION = 123;
>>
>> with this build file snippet:
>>
>>     <loadproperties srcfile="build/Test.class">
>>         <filterchain>
>>           <classconstants/>
>>         </filterchain>
>>      </loadproperties>
>>      <echo>${VERSION}</echo>
>>
>>> (2) As I could successfully execute with my Version.class, how do I
>>> then *access* the properties?
>>> I have a constant named VERSION. I tried <echo> with "${VERSION}" and
>>> with "${com.cleancode.data.Version.VERSION}" but neither had a value.
>>> What are the rules for the name of a property from a class file?
>>
>> the property name is the constant name, no package prefix is added.
>> Though a slick trick is to use a <prefixlines prefix="constants."/>
>> after <classconstants>.
>>
>> My guess is your property is not public static final.
>>
>> 	Erik
>>
>>
>> ---------------------------------------------------------------------
>> 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