--- "O'Hara, Patrick" <[EMAIL PROTECTED]> wrote: > I have gotten the latest and greatest Version of ant from the site > (1.3). I am noticing that some things have to change in my build.xml. > I am wondering if ant has a requires type command like perl. This works > by saying something like "requires 1.3;". In ant it might look > something like <requires version="1.3">. The result would be that ant > would not run on the build.xml unless it's version was 1.3 or greater. I'd been looking for a little functionality I could use to write my first task for (someone beat me to <cat> -- except they named it something a lot longer), so... Here's <requires> :) I'm a Java neophyte, so if it's not as slick as it could be, please be kind :) It's also probably obsolescing even as we speak, since I think I remember something in the Ant2 discussions about changing the way the version stuff was done, but oh well, at least it'll be usable for a little while. Enjoy, Diane ===== ([EMAIL PROTECTED]) __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
/* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.*; import java.io.*; import java.util.*; /** * Requires * * Verify that a specified required version of Ant is being used, or * issue an error and exit. * * @author [EMAIL PROTECTED] */ public class Requires extends Task { private String version; private static final String FAIL_MSG = "Requires version "; /** * Sets the version number. * * @param version Sets the value for the version to verify. */ public void setVersion(String version) { this.version = version; } // The method executing the task public void execute() throws BuildException { if (version == null) { throw new BuildException("version attribute must be set."); } try { if (! version.equals(getVersion())) { throw new BuildException(FAIL_MSG + version); } else { log("Version: " + version, Project.MSG_INFO); } } catch (NullPointerException npe) { throw new BuildException("Could not load version information! Please verify your Ant installation."); } } // Retrieve the version of Ant being run. public String getVersion() { Properties props = new Properties(); try { InputStream is = Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt"); props.load(is); is.close(); } catch (IOException ioe) { System.err.println("I/O error trying to load version information."); } return new String (props.getProperty("VERSION")); } }
