Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@apache.org Received: (qmail 40520 invoked from network); 22 Apr 2002 19:07:13 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 22 Apr 2002 19:07:13 -0000 Received: (qmail 11956 invoked by uid 97); 22 Apr 2002 19:07:03 -0000 Delivered-To: qmlist-jakarta-archive-ant-user@jakarta.apache.org Received: (qmail 11840 invoked by uid 97); 22 Apr 2002 19:07:02 -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 11741 invoked from network); 22 Apr 2002 19:07:02 -0000 Message-ID: <006c01c1ea30$e1d58080$7c688f80@darden.virginia.edu> From: "Erik Hatcher" To: "Ant Users List" References: <3CC3E444.80107@ieg.com.br> Subject: Re: Problems creating a task Date: Mon, 22 Apr 2002 15:07:00 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N You should only have one of: addXXX or createXXX (or now addConfiguredXXX). You have two for Descriptors. What is the exact problem you're having? Erik ----- Original Message ----- From: "Leonardo Andersen Lopes" To: Sent: Monday, April 22, 2002 6:21 AM Subject: Problems creating a task > HiALL, > > I have a problem to create a task with nested elements. > i don't have ideia whats happen. > > archive attached. > > thankz a lot! > > -- > =========================== > Leonardo Andersen Lopes > Florianopolis - SC - Brasil > e-mail: notinf@ieg.com.br > leonardo@java.mailbr.com.br > =========================== > > ---------------------------------------------------------------------------- ---- > package br.com.perfiltecnologia.codegen; > > import org.apache.tools.ant.*; > import org.apache.tools.ant.types.*; > import org.apache.tools.ant.taskdefs.MatchingTask; > import java.io.*; > import java.util.*; > > public class TaskXML2Java extends MatchingTask { > protected Elemento desc, templ; > > public Elemento createDescriptors() { > if (desc == null) > desc = new Elemento(); > return desc; > } > > public void addDescriptors(Elemento de){ > desc = de; > } > > public Elemento getDescriptors(){ > return desc; > } > > public void execute() throws BuildException { > if (desc.usedMatchingTask) { > log("DEPRECATED - Use of the implicit FileSet is deprecated. Use a nested fileset element instead."); > } > > if (desc.file == null && desc.dir == null && desc.filesets.size() == 0) { > throw new BuildException("At least one of the file or dir attributes, or a fileset element, must be set."); > } > > if (desc.quiet && desc.failonerror) { > throw new BuildException("quiet and failonerror cannot both be set to true", > location); > } > > > // delete the single file > if (desc.file != null) { > if (desc.file.exists()) { > if (desc.file.isDirectory()) { > log("Directory " + desc.file.getAbsolutePath() + " cannot be removed using the file attribute. Use dir instead."); > } else { > log("Achado: " + desc.file.getAbsolutePath()); > } > } else { > log("Could not find file " + desc.file.getAbsolutePath() + " to delete.", > org.apache.tools.ant.Project.MSG_VERBOSE); > } > } > > // delete the files in the filesets > for (int i=0; i FileSet fs = (FileSet) desc.filesets.elementAt(i); > try { > DirectoryScanner ds = fs.getDirectoryScanner(project); > String[] files = ds.getIncludedFiles(); > String[] dirs = ds.getIncludedDirectories(); > showFiles(fs.getDir(project), files, dirs); > } catch (BuildException be) { > // directory doesn't exist or is not readable > if (desc.failonerror) { > throw be; > } else { > log(be.getMessage(), > desc.quiet ? org.apache.tools.ant.Project.MSG_VERBOSE : org.apache.tools.ant.Project.MSG_WARN); > } > } > } > > // delete the files from the default fileset > if (desc.usedMatchingTask && desc.dir != null) { > try { > DirectoryScanner ds = super.getDirectoryScanner(desc.dir); > String[] files = ds.getIncludedFiles(); > String[] dirs = ds.getIncludedDirectories(); > showFiles(desc.dir, files, dirs); > } catch (BuildException be) { > // directory doesn't exist or is not readable > if (desc.failonerror) { > throw be; > } else { > log(be.getMessage(), > desc.quiet ? org.apache.tools.ant.Project.MSG_VERBOSE : org.apache.tools.ant.Project.MSG_WARN); > } > } > } > } > > //************************************************************************ > // protected and private methods > //************************************************************************ > > /** > * remove an array of files in a directory, and a list of subdirectories > * which will only be deleted if 'includeEmpty' is true > * @param d directory to work from > * @param files array of files to delete; can be of zero length > * @param dirs array of directories to delete; can of zero length > */ > protected void showFiles(File d, String[] files, String[] dirs) { > if (files.length > 0) { > log("Mostrando " + files.length + " files from " + d.getAbsolutePath()); > for (int j=0; j File f = new File(d, files[j]); > log("Mostrando " + f.getAbsolutePath()); > } > } > > if (dirs.length > 0 && desc.includeEmpty) { > int dirCount = 0; > for (int j=dirs.length-1; j>=0; j--) { > File dir = new File(d, dirs[j]); > String[] dirFiles = dir.list(); > if (dirFiles == null || dirFiles.length == 0) { > log("Mostrando " + dir.getAbsolutePath(), desc.verbosity); > dirCount++; > } > } > > if (dirCount > 0) { > log("Mostrado " + dirCount + " director" + > (dirCount==1 ? "y" : "ies") + > " from " + d.getAbsolutePath()); > } > } > } > } > > class Elemento extends MatchingTask{ > protected File file = null; > protected File dir = null; > protected Vector filesets = new Vector(); > protected boolean usedMatchingTask = false; > protected boolean includeEmpty = false; // by default, remove matching empty dirs > > protected int verbosity = org.apache.tools.ant.Project.MSG_VERBOSE; > protected boolean quiet = false; > protected boolean failonerror = true; > > public Elemento(){ > } > > public void setFile(File file) { > this.file = file; > } > > public void setDir(File dir) { > this.dir = dir; > } > > public void setVerbose(boolean verbose) { > if (verbose) { > this.verbosity = org.apache.tools.ant.Project.MSG_INFO; > } else { > this.verbosity = org.apache.tools.ant.Project.MSG_VERBOSE; > } > } > > public void setQuiet(boolean quiet) { > this.quiet = quiet; > if (quiet) { > this.failonerror = false; > } > } > > public void setFailOnError(boolean failonerror) { > this.failonerror=failonerror; > } > > > public void setIncludeEmptyDirs(boolean includeEmpty) { > this.includeEmpty = includeEmpty; > } > > public void addFileSet(FileSet set) { > filesets.addElement(set); > } > > public PatternSet.NameEntry createInclude() { > usedMatchingTask = true; > return super.createInclude(); > } > > public PatternSet.NameEntry createExclude() { > usedMatchingTask = true; > return super.createExclude(); > } > > public PatternSet createPatternSet() { > usedMatchingTask = true; > return super.createPatternSet(); > } > > public void setIncludes(String includes) { > usedMatchingTask = true; > super.setIncludes(includes); > } > > public void setExcludes(String excludes) { > usedMatchingTask = true; > super.setExcludes(excludes); > } > > public void setDefaultexcludes(boolean useDefaultExcludes) { > usedMatchingTask = true; > super.setDefaultexcludes(useDefaultExcludes); > } > > public void setIncludesfile(File includesfile) { > usedMatchingTask = true; > super.setIncludesfile(includesfile); > } > > public void setExcludesfile(File excludesfile) { > usedMatchingTask = true; > super.setExcludesfile(excludesfile); > } > > } > > ---------------------------------------------------------------------------- ---- > -- > To unsubscribe, e-mail: > For additional commands, e-mail: -- To unsubscribe, e-mail: For additional commands, e-mail: