You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ja...@rzf.fin-nrw.de on 2004/10/22 08:05:00 UTC
AW: Way for buildfile to verify that Ant version is 1.5.2 or grea
ter ?
A non usual way is checking for the existing of special classes.
So you 'only' have to check which classes were added in a release and
you could check for them.
Alternativly I can send two scriptdef´s I wrote in that area.
"checkAnt" parses the ${ant.version} string and stores additional
information
(compile date - useful if you work with cvs-versions).
"needAnt" executes a <fail> if the actual version is lower than a required
one.
Jan
<project name="common-define-checkAnt">
<scriptdef name="checkAnt" language="javascript">
<![CDATA[
importClass(java.text.SimpleDateFormat);
importClass(java.util.Locale);
// String evaluation of 'ant.version' string
// e.g: 'Apache Ant version 1.6beta3 compiled on December 5
2003'
string = project.getProperty("ant.version");
version = string.substring(string.indexOf("Ant version")+12,
string.indexOf("compiled on")-1);
compiled = string.substring(string.indexOf("compiled on")+12);
// Get the compiled date: 'December 5 2003'
dateParser = new SimpleDateFormat("MMM d yyyy", Locale.US);
compiledDate = dateParser.parse(compiled);
compiledYear = (new
SimpleDateFormat("yyyy")).format(compiledDate);
compiledMonth = (new SimpleDateFormat("M")
).format(compiledDate);
compiledDay = (new SimpleDateFormat("d")
).format(compiledDate);
project.setNewProperty("ant.version.number", version);
project.setNewProperty("ant.version.compiled", compiled);
project.setNewProperty("ant.version.compiled.year",
compiledYear);
project.setNewProperty("ant.version.compiled.month",
compiledMonth);
project.setNewProperty("ant.version.compiled.day", compiledDay);
]]>
</scriptdef>
</project>
<project name="common-define-needAnt">
<scriptdef name="needAnt" language="javascript">
<attribute name="version"/>
<![CDATA[
needed = attributes.get("version");
string = project.getProperty("ant.version");
actual = string.substring(string.indexOf("Ant version")+12,
string.indexOf("compiled on")-1);
neededInt = getInt(needed);
actualInt = getInt(actual);
verbose("Needed: " + needed + " --> " + neededInt);
verbose("Actual: " + actual + " --> " + actualInt);
check = false;
if (actualInt >= neededInt) check = true;
if (!check) {
java.lang.System.out.println(" -- abbruch --");
fail = project.createTask("fail");
fail.setMessage("Needed Ant-Version (" + needed + ") not
available. Was: " + actual);
fail.perform();
}
// convert the version string to int value for easier comparison
function getInt(string) {
if (string.equals("1.1")) return 11;
if (string.equals("1.2")) return 12;
if (string.equals("1.3")) return 13;
if (string.equals("1.4")) return 14;
if (string.equals("1.4.1")) return 14.1;
if (string.equals("1.5")) return 15;
if (string.equals("1.5.1")) return 15.1;
if (string.equals("1.5.2")) return 15.2;
if (string.equals("1.5.3")) return 15.3;
if (string.equals("1.5.4")) return 15.4;
if (string.equals("1.5alpha")) return 15.880;
if (string.equals("1.6beta1")) return 15.991;
if (string.equals("1.6beta2")) return 15.992;
if (string.equals("1.6beta3")) return 15.993;
if (string.equals("1.6")) return 16;
if (string.equals("1.6.0") ) return 16;
if (string.equals("1.6.1") ) return 16.1;
if (string.equals("1.6.2") ) return 16.2;
if (string.equals("1.6.3") ) return 16.3;
if (string.equals("1.7alpha")) return 16.880;
if (string.equals("1.7beta")) return 16.990;
if (string.equals("1.7")) return 17;
if (string.equals("1.7.0")) return 17;
if (string.equals("1.7.1")) return 17.1;
if (string.equals("1.7.2")) return 17.2;
return 0;
}
// log-message
function verbose(msg) {
project.log("[needAnt] " + msg, project.MSG_VERBOSE);
}
]]>
</scriptdef>
</project>
> -----Ursprüngliche Nachricht-----
> Von: Rich Wagner [mailto:rich.wagner@savaJe.com]
> Gesendet am: Donnerstag, 21. Oktober 2004 21:08
> An: user@ant.apache.org
> Cc: rich.wagner@savaJe.com
> Betreff: Way for buildfile to verify that Ant version is 1.5.2 or
> greater ?
> Note that comparing "ant.version" to "1.5.2" for equality is NOT
> sufficient, since - for instance - a build should NOT fail if the ant
> version is 1.6.1.
>
> Is there an easier way to get what I want than (say) writing my own
> custom task to parse "ant.version" and compare the major, minor, etc.
> version numbers ?
Re: Way for buildfile to verify that Ant version is 1.5.2 or grea
ter ?
Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 22 Oct 2004, Jan Materne <Ja...@rzf.fin-nrw.de> wrote:
> A non usual way is checking for the existing of special classes. So
> you 'only' have to check which classes were added in a release and
> you could check for them.
It might help to have a concrete example ;-)
<available property="Ant-1.5.2-or-later"
classname="org.apache.tools.ant.types.ResourceFactory"/>
<fail message="You must use Ant 1.5.2 or later"
unless="Ant-1.5.2-or-later"/>
Stefan
--
http://stefanbodewig.blogger.de/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org