You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Paul Arzul <pa...@exinet.co.za> on 2000/09/29 12:05:28 UTC

javac task filtering

hi *,

(ant 1.1)

the javac task has a filtering attribute, which does
not work as i expected.

in the example below, @version@ is not replaced before or
after compliation, while Test.java is complied fine.

Test.java
---8<---
// @version@

public class Test {
  public static void main(String[] args) {
  }
}
--->8---

Text.xml
---8<---
<?xml version="1.0"?>

<project name="Filter Test" default="Test" basedir=".">
  <target name="Test">
    <tstamp />
    <filter token="version" value="${TODAY}" />    
    <javac srcdir="." destdir="." />
  </target>
</project>
--->8---

i've resorted to:
---8<---
    <filter token="version" value="${TODAY}" />    

    <copyfile filtering="on" src="Test.java" dest="Test2.java" />
    <rename src="Test2.java" dest="Test.java" />
--->8---

am i being stupid?

aside: is there version numbering support in ant 
1.2? something that could read a file, and auto increment a
build number?

this list is wonderful,
thanks,

- p


Re: javac task filtering

Posted by Nico Seessle <ni...@seessle.de>.
----- Original Message -----
From: "Paul Arzul" <pa...@exinet.co.za>
To: <an...@jakarta.apache.org>
Sent: Friday, September 29, 2000 12:05 PM
Subject: javac task filtering


> aside: is there version numbering support in ant
> 1.2? something that could read a file, and auto increment a
> build number?
>

No direct support, but you can do something like this as follows:

- Read current value from property-file
- Increment value (or do anything else to them)
- write them back to the property-file
- use them

This example requires the script-task (and therefor BSF (bean scripting
framework) from IBM - last time I looked at there page it seemed to ba
available only by CVS...) and rhino (the Javascript-Engine) from
http://www.mozilla.org

<?xml version="1.0"?>
<project name="myProject" default="default" basedir=".">

    <target name="default">
       <property file="myProject.properties"/>

       <script language="javascript"> <![CDATA[
           var buildNumber = parseInt(myProject.getProperty('buildNumber'));
// get current value
           if (isNaN(buildNumber)) buildNumber = 0;  // if not a number (no
value) initialize to zero
           buildNumber = buildNumber + 1; // Increment by one
           myProject.setProperty('buildNumber', buildNumber); // and put
back
       ]]></script>

       <echo file="myProject.properties">## Automatically generated.
##
## Do not modify!
##
buildNumber=${buildNumber}
       </echo>

       <echo>
          This is Build ${buildNumber}
       </echo>
    </target>

</project>

Nico




Re: javac task filtering

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "PA" == Paul Arzul <pa...@exinet.co.za> writes:

 PA> the javac task has a filtering attribute, which does not work as
 PA> i expected.

Yes, it's a little bit misleading. Filtering only happens when support
files are copied - it doesn't have any effect on the Java sources that
get compiled.

Ant 1.2's <javac> won't copy support files and consequently doesn't
have the filtering attribute anymore.

Stefan