Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 99192 invoked from network); 18 Sep 2007 08:24:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Sep 2007 08:24:57 -0000 Received: (qmail 17259 invoked by uid 500); 18 Sep 2007 08:24:45 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 17220 invoked by uid 500); 18 Sep 2007 08:24:45 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 17209 invoked by uid 99); 18 Sep 2007 08:24:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Sep 2007 01:24:45 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [193.109.238.66] (HELO dnsinet.rzf-nrw.de) (193.109.238.66) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Sep 2007 08:26:37 +0000 Received: from z011100.bk.fin.local (z011100.bk.fin.local [172.18.101.140]) by dnsinet.rzf-nrw.de (8.14.0/8.14.0) with ESMTP id l8I8OJTs002228 for ; Tue, 18 Sep 2007 10:24:21 +0200 Received: from z011034.bk.fin.local ([130.11.7.34]) by z011100.bk.fin.local with Microsoft SMTPSVC(6.0.3790.0); Tue, 18 Sep 2007 10:24:20 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: AW: Query definition of target? Date: Tue, 18 Sep 2007 10:24:20 +0200 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Query definition of target? Thread-Index: Acf5ppFKR0EASxMRRrq6EYlN7LP5CQAGFNCgAAOHl8A= From: To: X-OriginalArrivalTime: 18 Sep 2007 08:24:20.0770 (UTC) FILETIME=[4FEA1020:01C7F9CD] X-Virus-Checked: Checked by ClamAV on apache.org Here the condition and a buildfile compiling and testing the two conditions. Test testAAndMainIsOverwritten is failing and therefore the algorithm not fully right ...=20 import org.apache.tools.ant.BuildException; import org.apache.tools.ant.ProjectComponent; import org.apache.tools.ant.taskdefs.condition.Condition; import java.util.List; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; // inherited getProject(), getLocation() + log() public class IsTargetOverwrittenCondition extends ProjectComponent implements Condition { // target to check String target; public void setTarget(String t) { target =3D t; } =20 // specific buildfile which should be overwritten? String file; public void setFile(String f) { file =3D f; } public boolean eval() throws BuildException { if (target =3D=3D null) { throw new BuildException("Must specify 'target' to test.", getLocation()); } if (!projectHasTarget(target)) { // The target is not present, therefore it is also not overwritten. return false; } else { // imported targets are in BOTH namespace: + . List importedTargets =3D findTargetsByName(target); if (importedTargets.isEmpty()) { // only in the main buildfile, means 'not overwritten' return false; } else { if (file =3D=3D null) { return checkTargetIdentity(target, importedTargets); } else { if (filterListByPrefix(importedTargets, file).isEmpty()) { return false; } else { return true; } } } } } =20 private boolean projectHasTarget(String name) { return getProject().getTargets().containsKey(target); } private List findTargetsByName(String name) { ArrayList rv =3D new ArrayList(); for (Enumeration en =3D getProject().getTargets().keys(); en.hasMoreElements(); ) { String tName =3D (String)en.nextElement(); if (tName.endsWith("." + name)) { rv.add(tName); } } return rv; } =20 private List filterListByPrefix(List list, String prefix) { ArrayList rv =3D new ArrayList(); for (Iterator it=3Dlist.iterator(); it.hasNext();) { String name =3D (String)it.next(); if (name.startsWith(prefix)) { rv.add(name); } } return rv; } =20 private boolean checkTargetIdentity(String target, List otherTargetNames) { Object original =3D getProject().getTargets().get(target); for (Iterator it=3DotherTargetNames.iterator(); it.hasNext();) { Object next =3D it.next(); if (original.equals(next)) return true; } return false; } } =20 =20 =20 =20 Jan >A quick implementation of would be: > > > > > >import org.apache.tools.ant.BuildException; >import org.apache.tools.ant.Project; >import org.apache.tools.ant.taskdefs.condition.Condition; > >public class HasTargetCondition implements Condition { > > // dynamically set by Ant runtime > Project project; > public void setProject(Project p) { > project =3D p; > } > public Project getProject() { > return project; > } > =20 > // target to check > String target; > public void setTarget(String t) { > target =3D t; > } > =20 > //implements Condition > public boolean eval() throws BuildException { > if (target =3D=3D null) { > throw new BuildException("Must specify 'target' to test."); > } > return getProject().getTargets().containsKey(target); > } >} > > > > classpath=3D"."/> > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org