Thanks for this solution :)
I am considering where I should put the version (in a Java file, a 
property file or in the build.xml)

The pros and the cons:
1) in build.xml:
I don't like it because :
- two files are modified and need to be committed when the version is 
changed (build.xml and java).
- requires to run Ant to put the correct version in the program. I am 
working under Eclipse, so Ant is only used when I need to make a 
distribution.

2) in a property file:
Seems better.
Need to modify the program and the build file at first, but after only 
one property file.

2) in the Java file:
That was my first idea.
Need to modify only the build file at first, and after only the java 
file.


After your first mail, I had a look at <filterchain> and found an other 
way to do it.
It doesn't require bcel, because I can directly parse the java source 
code.
Not very elegant, but works:
  <loadfile srcfile="constants.java"
            property="version">
    <filterchain>
      <linecontainsregexp>
        <regexp pattern='public final static String version = ".*";'/>
      </linecontainsregexp>
      <tokenfilter>
        <replaceregex pattern='public final static String version 
= "(.*)";'
                      replace='\1'/>
      </tokenfilter>
    </filterchain>
  </loadfile>


Well,
thanks a lot for the ideas

Have to decide what way to go with ;)

Nicolas

De: RADEMAKERS Tanguy <[EMAIL PROTECTED]>

> Sorted - i didn't have the bcel.jar in my lib folder. Added it and it
> works fine. 
> 
> Sooooooooooo - Nicolas, *if* you have bcel.jar installed, you can use
> the example below to get your version string out of your file!
> 
> (but you shouldn't ;)
> 
> /t 
> 
> >-----Original Message-----
> >From: RADEMAKERS Tanguy 
> >Sent: Tuesday, September 20, 2005 8:26 PM
> >To: 'Ant Users List'
> >Subject: RE: Extracting application version from Java file
> >
> >Hello List,
> >
> >I was going to reply to Nicolas that, whilst i agree with the 
> >other two replies (you should pass the version in somehow and 
> >not read it from the java source file), you *can* achieve what 
> >he is trying to do using the <loadproperties> task with a 
> >nested <classconstants> filterchain. But i can't seem to get 
> >it to work. I've posted my example below, can anybody see what 
> >i'm doing wrong?
> >
> >------mytest.java----
> >public class mytest
> >{
> >   public static final String VERSION = "XX.YY.ZZ";
> >
> >   public static void main(String[] args)
> >   {
> >      System.out.println("Hello, World!");
> >   }
> >}
> >
> >------build.xml----
> ><project name="test" default="main" basedir=".">
> >
> >    <target name="main">
> >
> >        <javac srcdir="." 
> >               destdir="." 
> >               includes="mytest.java"/>
> >     
> >        <loadproperties srcfile="mytest.class">
> >            <filterchain>
> >                <classconstants/>
> >            </filterchain>
> >        </loadproperties>
> >
> >        <echo>${VERSION}</echo>
> >
> >    </target>
> >
> ></project>
> >
> >i get a "Unable to load file: java.io.IOException" message. 
> >I've tried putting a static properties file and loading that - 
> >no probs. I've tried copying the class to a properties file by 
> >using the classconstants filterchain... didn't work (same error). 
> >
> >/t
> 
> -------------------------------------------------------------------
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to