ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Checking the version of Ant
Date Mon, 15 Jul 2002 15:21:09 GMT
Ant's not using a validating parser, has there's no fixed DTD since Ant is
open ended/extensible. You can extract the DTD of Ant for a given set of
tasks though, using <antstructure>.

One easy solution would be to substitute the normal Ant main class
(org.apache.tools.ant.Main) by your own Main class, which loads the
org/apache/tools/ant/version.txt resource properties file (it does exist for
Ant 1.4.1 and 1.5, and maybe earlier too), and check the VERSION and DATE
Java properties.

If the version of Ant you're about to use is OK with you, then pass on all
the args to your main to the Main of Ant:

public class AntVersionChecker {

  private AntVersionChecker() {}

  public static void main(String[] args) {
    String versionPropFile = "org/apache/tools/ant/version.txt";
    // Use ClassLoader.getSystemResources(versionPropFile) to find out
    // if we can find more than one such resource, which would indicate
    // 2 different version of Ant is on the classpath... Not good!
    Properties props = Properties.load(
      ClassLoader.getSystemResourceAsStream(versionPropFile));
    String version = props.getProperty("VERSION");
    String date = props.getProperty("DATE");
    if (...) {
      System.out.println("Wrong version of Ant... Abort!");
      System.exit(-1);
    }
    org.apache.tools.ant.Main.main(args);
  }
}

Code below not tested. This doe require you to change the script to start
Ant, but you seem to be doing that anyway... --DD

-----Original Message-----
From: Andrew.Beacock@nokia.com [mailto:Andrew.Beacock@nokia.com] 
Sent: Monday, July 15, 2002 9:08 AM
To: ant-user@jakarta.apache.org
Subject: Checking the version of Ant

All,

I am currently looking at how I can check the version of Ant used to 
build out software, so that if an 'unsupported' or old version of Ant 
is used, the developer gets a failure message.

I current grab the version string information from Ant (ant -version) 
and store that in a properties file.

Then I have my Ant script read in the properties file, and compare the 
version string with ${ant.version}.

This works great, and I can fail the build if the strings don't match, 
but I have found a couple of issues when testing this check with Ant1.5 
and Ant1.4.1.

I use the <mail> task in Ant1.5 which allows the nested <fileset> 
element, but Ant1.4.1 doesn't support this.

So rather than getting my nice clear failure message, I get:

    Mon 07/15/2002 10:04 C:\beacock\apps\UNIT_T~1>ant
    Buildfile: build.xml

    BUILD FAILED

    C:\beacock\apps\UNIT_T~1\build.xml:361: The <mail> task doesn't 
    support the nested "fileset" element.

    Total time: 1 second

Now, I know that this is due to Ant parsing the buildfile with a 
validating XML parser, so would there be anyway that we can 'mark' the 
build.xml with a version string or identifier of some description, so 
that the parser can check the required version against itself as it 
validates?

Just a thought...

Andy.

--
Andrew Beacock
Principal Software Engineer
Nokia
NMP/MSW/SSP/MMS

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message