Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@apache.org Received: (qmail 53246 invoked from network); 7 Oct 2002 09:48:37 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 7 Oct 2002 09:48:37 -0000 Received: (qmail 18714 invoked by uid 97); 7 Oct 2002 09:49:20 -0000 Delivered-To: qmlist-jakarta-archive-ant-user@jakarta.apache.org Received: (qmail 18692 invoked by uid 97); 7 Oct 2002 09:49:19 -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 18676 invoked by uid 98); 7 Oct 2002 09:49:19 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <51A779854605D41192C000508B8BC11C148EFC@hbmpdc.stark-verlag.de> From: Software AG To: 'Ant Users List' Subject: AW: Fileset tag Date: Mon, 7 Oct 2002 11:42:29 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C26DE5.DA33A960" 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_01C26DE5.DA33A960 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, Cyriaque. Just now I created my own ant task, and it uses nested fileset = elements. It is very easy with the Netbeans IDE, since there you get a good = template to start with. Attached you find the source, this is the ant script to use it (you'll = have to modify it): =20 > -----Urspr=FCngliche Nachricht----- > Von: Cyriaque Dupoirieux [mailto:cyriaque.dupoirieux@pcotech.fr] > Gesendet: Montag, 7. Oktober 2002 11:16 > An: Liste Ant > Betreff: Fileset tag >=20 >=20 > Hello, >=20 > Do you have an example of task source that enables the use of the = > nested tag ? > =20 > Thanks, > Cyriaque, >=20 > --=20 > Cyriaque Dupoirieux > PCO Technologies > Burolines - 2 ter rue Marcel Doret > 31700 Blagnac > T=E9l : 05.34.60.44.13 - Fax : 05.34.60.44.10 >=20 >=20 ------_=_NextPart_000_01C26DE5.DA33A960 Content-Type: application/octet-stream; name="IfModified.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="IfModified.java" /*=0A= * IfModified.java=0A= *=0A= * Created on 7. Oktober 2002, 11:09=0A= * $Id$=0A= */=0A= =0A= package chaudhuri.antext;=0A= =0A= // IMPORTANT! You may need to mount ant.jar before this class will=0A= // compile. So mount the JAR modules/ext/ant-1.4.1.jar (NOT = modules/ant.jar)=0A= // from your IDE installation directory in your Filesystems before=0A= // continuing to ensure that it is in your classpath.=0A= =0A= import org.apache.tools.ant.*;=0A= import org.apache.tools.ant.types.*;=0A= =0A= /**=0A= * @author sag=0A= * @version $Revision$=0A= */=0A= public class IfModified extends Task {=0A= =0A= /** Verzeichnis/Datei, mit deren Datum verglichen wird */=0A= private java.io.File comparedto;=0A= =0A= /** Target, das eventuell ausgef=FChrt werden soll */=0A= private String runtask;=0A= =0A= /** Liste der Files, die gepr=FCft werden */=0A= private java.util.List filesets =3D new java.util.LinkedList(); // = List=0A= =0A= /** Sets the file which date is the reference=0A= * Note: f will automatically be absolute (resolved from project = basedir).=0A= *
=0A=
     * >customtask myfile=3D"foo.txt"/<=0A=
     * 
=0A= */=0A= public void setComparedTo(java.io.File f) {=0A= comparedto =3D f;=0A= }=0A= =0A= /** F=FCgt ein Fileset hinzu */=0A= public void addFileset(FileSet fs) {=0A= filesets.add(fs);=0A= }=0A= =0A= /** Setzt das auszuf=FChrende Target */=0A= public void setRunTask(String runtask) {=0A= this.runtask =3D runtask;=0A= }=0A= =0A= /* For a simple option:=0A= private boolean opt;=0A= public void setOpt(boolean b) {=0A= opt =3D b;=0A= }=0A= // =0A= */=0A= =0A= /* For a simple property based on a string:=0A= private String myprop;=0A= public void setMyprop(String s) {=0A= myprop =3D s;=0A= }=0A= // =0A= */=0A= =0A= =0A= /* Custom nested elements:=0A= public static class Nestme {=0A= String val; // accessible from execute()=0A= public void setVal(String s) {=0A= val =3D s;=0A= }=0A= }=0A= private List nestmes =3D new LinkedList(); // List=0A= public Nestme createNestme() {=0A= Nestme n =3D new Nestme();=0A= nestmes.add(n);=0A= return n;=0A= }=0A= // Or:=0A= public void addNestme(Nestme n) {=0A= nestmes.add(n);=0A= }=0A= // =0A= // =0A= // =0A= */=0A= =0A= /** To add embedded filesets:=0A= * private List filesets =3D new LinkedList(); // List=0A= * public void addFileset(FileSet fs) {=0A= * filesets.add(fs);=0A= * }=0A= * // =0A= * // =0A= * // =0A= * // =0A= * // =0A= * // In execute() you can do:=0A= * Iterator it =3D filesets.iterator();=0A= * while (it.hasNext()) {=0A= * FileSet fs =3D (FileSet)it.next();=0A= * DirectoryScanner ds =3D fs.getDirectoryScanner(project);=0A= * File basedir =3D ds.getBasedir();=0A= * String[] files =3D ds.getIncludedFiles();=0A= * // process them...=0A= * }=0A= */=0A= =0A= /* For nested text:=0A= private StringBuffer text;=0A= public void addText(String t) {=0A= t =3D t.trim();=0A= if (text =3D=3D null) {=0A= text =3D new StringBuffer(t);=0A= } else {=0A= text.append(t);=0A= }=0A= }=0A= // =0A= // Some text...=0A= // =0A= */=0A= =0A= /* Some sort of path (like classpath or similar):=0A= private Path path;=0A= public void setPath(Path p) {=0A= if (path =3D=3D null) {=0A= path =3D p;=0A= } else {=0A= path.append(p);=0A= }=0A= }=0A= public Path createPath () {=0A= if (path =3D=3D null) {=0A= path =3D new Path(project);=0A= }=0A= return path.createPath();=0A= }=0A= public void setPathRef(Reference r) {=0A= createPath().setRefid(r);=0A= }=0A= // =0A= // =0A= // =0A= // =0A= // =0A= // =0A= // Etc.=0A= */=0A= =0A= /* One of a fixed set of choices:=0A= public static class FooBieBletch extends EnumeratedAttribute {=0A= public String[] getValues() {=0A= return new String[] {"foo", "bie", "bletch"};=0A= }=0A= }=0A= private String mode =3D "foo";=0A= public void setMode(FooBieBletch m) {=0A= mode =3D m.getValue();=0A= }=0A= // =0A= */=0A= =0A= public void execute() throws BuildException {=0A= log("$Id$");=0A= =0A= if(runtask=3D=3Dnull)=0A= throw new BuildException("Attribute runtask must be = set.");=0A= if(comparedto=3D=3Dnull)=0A= throw new BuildException("Attribute compareto must be = set.");=0A= if(!comparedto.exists())=0A= throw new BuildException("Reference file '"+comparedto+"' = does not exist.");=0A= =0A= long lastmodified =3D comparedto.lastModified();=0A= log("Refence file last modified "+new = java.util.Date(lastmodified), Project.MSG_VERBOSE);=0A= =0A= boolean uptodate =3D true;=0A= =0A= java.util.Iterator it =3D filesets.iterator();=0A= while (it.hasNext()) {=0A= FileSet fs =3D (FileSet)it.next();=0A= DirectoryScanner ds =3D fs.getDirectoryScanner(project);=0A= java.io.File basedir =3D ds.getBasedir();=0A= String[] files =3D ds.getIncludedFiles();=0A= // process them...=0A= int i=3D0;=0A= while((i lastmodified)=0A= uptodate =3D false;=0A= log("Comparing '"+f+"' -> uptodate=3D"+uptodate, = Project.MSG_VERBOSE);=0A= i++;=0A= }=0A= }=0A= =0A= if(!uptodate) {=0A= log(comparedto.toString()+" is not up to date, running = "+runtask);=0A= project.executeTarget(runtask);=0A= }=0A= // To log something:=0A= // log("Some message");=0A= // log("Serious message", Project.MSG_WARN);=0A= // log("Minor message", Project.MSG_VERBOSE);=0A= =0A= // To signal an error:=0A= // throw new BuildException("Problem", location);=0A= // throw new BuildException(someThrowable, location);=0A= // throw new BuildException("Problem", someThrowable, = location);=0A= =0A= // You can call other tasks too:=0A= // Zip zip =3D (Zip)project.createTask("zip");=0A= // zip.setZipfile(zipFile);=0A= // FileSet fs =3D new FileSet();=0A= // fs.setDir(baseDir);=0A= // zip.addFileset(fs);=0A= // zip.init();=0A= // zip.setLocation(location);=0A= // zip.execute();=0A= }=0A= =0A= }=0A= /*=0A= * $Log$=0A= */ ------_=_NextPart_000_01C26DE5.DA33A960 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: ------_=_NextPart_000_01C26DE5.DA33A960--