Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@apache.org Received: (qmail 88846 invoked from network); 17 Sep 2002 14:10:21 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 17 Sep 2002 14:10:21 -0000 Received: (qmail 27245 invoked by uid 97); 17 Sep 2002 14:10:47 -0000 Delivered-To: qmlist-jakarta-archive-ant-user@jakarta.apache.org Received: (qmail 27206 invoked by uid 97); 17 Sep 2002 14:10:47 -0000 Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 27184 invoked by uid 98); 17 Sep 2002 14:10:46 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <28336AC23B25D411BEA300105AC7F5441199A659@ICEXCH2> From: "Shackelford, John-Mason" To: 'Ant Users List' Subject: RE: Overload?! Date: Tue, 17 Sep 2002 09:10:05 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C25E53.EBBE02B0" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------_=_NextPart_000_01C25E53.EBBE02B0 Content-Type: text/plain Christian, You are on the right track. The only reason you have a problem is that you include the target twice in build1.xml and build2.xml. I use a similar approach to manage build files for a project with multiple versions. Use one entity (your include.xml) for targets common across versions and another set of entities for the targets that are version specific. Then write a build-1.xml and build-2.xml, build-3.xml, etc.for each version doing two entity includes in each: one for common targets, and another for version specific targets. You can then launch ant using the -buildfile option or write your own ant runner to make the switch for you on the basis of a property file. (I have enclosed an example.) John-Mason Shackelford Software Developer NCS Pearson - Measurement Services 2510 North Dodge St. Iowa City, IA 52245 319-354-9200x6214 shacjo@ncs.com -----Original Message----- From: Christian Holmqvist, IT, Posten [mailto:christian.holmqvist@posten.se] Sent: Tuesday, September 17, 2002 4:53 AM To: 'Ant Users List' Subject: Overload?! Hi My situation is that I have made a include.xml file with a number of targets that is correct for 95% of our projects. The problem is the last 5%. So my question is: Is there any way to overload a target with Ant? This is how I would like it to work: ---- include.xml -------- ---- build.xml ---- ]> &include; ----- build1.xml ----- ]> &include; ------- build2.xml -------------- ]> &include; -------------------------------------- When this is done today ant tells med that compile is duplicated (or something like that). Is there a way around this?? Thanks for your time! Cheers Christian -- To unsubscribe, e-mail: For additional commands, e-mail: **************************************************************************** This email may contain confidential material. If you were not an intended recipient, Please notify the sender and delete all copies. We may monitor email to and from our network. **************************************************************************** ------_=_NextPart_000_01C25E53.EBBE02B0 Content-Type: application/octet-stream; name="AntRunner.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="AntRunner.java" package org.shackelford.ant; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Properties; import org.apache.tools.ant.Main; /** * Executes Ant launching a version specific build.xml *=20 *

using the -buildfile option overrides the special functionality = of this * class. If the required property file and key are not located = somewhere on * the classpath, the AntRunner will use the default build.xml = file.

* *

Note that this class needs to be rewritten to support JDK = 1.x.

* *

Thanks to Dominique = Devienne * for suggesting this approach.

* * @author John-Mason P. = Shackelford * @version $Revision: 1.0 $, $Date: Jul 24 2002 12:07:44 $ */ public class AntRunner { public static String PROPERTY_FILE =3D "local.build.properties"; public static String PROPERTY_FILE_ALTERNATE =3D = "build.properties"; public static String PROPERTY_KEY =3D "application.build.version"; public static void main(String[] args) { Date time =3D new Date(); = System.out.println("----------------------------------------------------= ---"); System.out.println("AntRunner " + time); = System.out.println("----------------------------------------------------= ---\n"); // // debugging -- iterate through args // System.out.println("INPUT:"); // for (int i =3D 0; i < args.length; i++) { // System.out.println((i + 1) + ". " + args[i]); // } // if (args.length =3D=3D 0) { // System.out.println("No args"); // } // List myArgs =3D new ArrayList(); boolean isBuildfileSpecified =3D false; int buildfileAtElement =3D 0; // process the command line arguments to include our special = version // swapping and strip the old AntRunner if it should appear for (int i =3D 0; i < args.length; i++) { if (!args[i].equals("org.apache.tools.ant.Main")) { myArgs.add(args[i]); } if (args[i].equalsIgnoreCase("-buildfile")) { isBuildfileSpecified =3D true; buildfileAtElement =3D i + 1; } } // get the build version from a property file String version =3D getBuildVersion(PROPERTY_FILE, = PROPERTY_KEY); if (version =3D=3D null || version.length() < 1) version =3D getBuildVersion(PROPERTY_FILE_ALTERNATE, = PROPERTY_KEY); // add our own buildfile specification based on our version String buildfile =3D null; if (!isBuildfileSpecified) { if (version =3D=3D null || version.length() < 1) { System.out.println("Using default buildfile: = build.xml."); } else { buildfile =3D "build-" + version + ".xml"; System.out.println( "Using buildfile for version " + version + ": " + = buildfile + "."); myArgs.add("-buildfile"); myArgs.add(buildfile); } } else { System.out.println("Using the specified buildfile: " + = args[buildfileAtElement] + "."); } // launch ant String[] newArgs =3D (String[]) myArgs.toArray(new String[0]); // // debugging -- iterate through args // for (int i =3D 0; i < newArgs.length; i++) { // System.out.println((i + 1) + ". " + newArgs[i]); // } // if (newArgs.length =3D=3D 0) { // System.out.println("No args"); // } Main.main(newArgs); } /** * load up the build version from the specified key in the named=20 * property file located somewhere on the classpath * @param file the file name of the property file to load=20 * (Do not include path information!) * @param key the property key to use for the version */ private static String getBuildVersion(String file, String key) { // get the property file=20 System.out.println("Searching the classpath for " + file + = "."); ClassLoader classLoader =3D ClassLoader.getSystemClassLoader(); InputStream stream =3D classLoader.getResourceAsStream(file); Properties props =3D null; if (stream !=3D null) { props =3D new Properties(); try { props.load(stream); } catch (IOException ioe) {} } // if the property file is found and a build version is=20 // specified, use it to launch the correct build.xml // otherwise run ant as usual String version =3D null; if (props =3D=3D null) { System.out.println("The " + file + " file was not found."); } else { version =3D props.getProperty(key); if (version =3D=3D null || version.length() < 1) { System.out.println("The " + key + " key was not = found."); } else { System.out.println("Running Ant for application version = " + version + "."); } } return version; } } ------_=_NextPart_000_01C25E53.EBBE02B0 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: ------_=_NextPart_000_01C25E53.EBBE02B0--