How about considering submitting this to the ant-contrib Sourceforge project?
----- Original Message ----- From: "Damian O'Neill" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, February 26, 2002 7:56 AM Subject: optional task for etags > Apologies if I am incorrect, I am unsure if this is the correct mailing > list, or the correct procedure for submitting this mail too. > > I have implemented a task(attached) to provide basic support for etags. > > If you feel that this maybe useful, feel free to use/distribute it. > > > > Regards, > Damian ONeill > > > > -- > [EMAIL PROTECTED] > > Damian O'Neill > Software Engineer > AePONA Ltd, > Interpoint Building, > 20-24 York Street, > Belfast, > BT15 1AQ > > +44 (0) 2890 275246 > > http://www.aepona.com > ---------------------------------------------------------------------------- ---- > /* > * The Apache Software License, Version 1.1 > * > * Copyright (c) 2000-2001 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.optional; > > import org.apache.tools.ant.Task; > import org.apache.tools.ant.BuildException; > import org.apache.tools.ant.Project; > import org.apache.tools.ant.DirectoryScanner; > import org.apache.tools.ant.types.FileSet; > > import java.io.File; > import java.io.IOException; > > import java.util.Vector; > > /** > * Used to create a tag table file, in a format understood by emacs -- corresponds to the Unix etags command. > * > * <p>This task read the file(s) specified, and writes a tag table (defaults: `TAGS') in the current working directory.</p> > * > * > * @author <a href="mailto:[EMAIL PROTECTED]">Damian ONeill</a> > */ > public class ETags extends Task { > > private File file; > private Vector filesets = new Vector(); > private int noOfFiles = 0; > > private boolean failOnError = false; > > > > /** > * Sets a single source file to build a TAGS file. If the file does not exist > * the task will be ignored. > * @param file The absolute path to the file to be used to generate the TAGS file > */ > public void setFile(File file) { > this.file = file; > } > > /** > * Sets fail on error to true or false. > * If this is not set, fail on error will be false. > * @param fail flag determining whether ant should stop on error or continue > */ > public void setFailonerror(boolean fail) { > failOnError = fail; > } > > > > /** > * Adds a set of files (nested fileset attribute). > * @param set group of files > */ > public void addFileset(FileSet set) { > filesets.addElement(set); > } > > /** > * Execute the etags operation. > * @throws BuildException thrown if there is a problem running the unix etags command > */ > public void execute() throws BuildException { > if (file == null && filesets.size() == 0) { > throw > new BuildException("Specify at least one source - a file or a fileset."); > } > > if (file != null && file.exists() && file.isDirectory()) { > throw new BuildException("Use a fileset to build TAGS file from directories."); > } > > etags(); > > log("Appended " + noOfFiles + ((noOfFiles != 1)?" files to ":" file to ") + System.getProperty("user.dir") + "/TAGS"); > } > > /** > * Does the actual work. > * @throws BuildException thrown if there is a problem running the unix etags command > */ > protected void etags() throws BuildException { > if (file != null) { > if (!file.exists()) { > throw new BuildException("Could not build TAGS file from " + file + ", this file does not exist"); > } > } > > if (file != null) { > etags(file); > } > > // deal with the filesets > for (int i=0; i < filesets.size(); i++) { > FileSet fs = (FileSet) filesets.elementAt(i); > DirectoryScanner ds = fs.getDirectoryScanner(project); > File fromDir = fs.getDir(project); > > String[] srcFiles = ds.getIncludedFiles(); > String[] srcDirs = ds.getIncludedDirectories(); > > for(int j=0; j < srcFiles.length ; j++) { > etags(new File(fromDir, srcFiles[j])); > } > > for(int j=0; j < srcDirs.length ; j++) { > etags(new File(fromDir, srcDirs[j])); > } > } > } > > /** Used to append a single file to the TAGS file > * @param file The absolute path to the file to be used to generate the TAGS file > * @throws BuildException thrown if there is a problem running the unix etags command > */ > protected void etags(File file) throws BuildException { > > String cmd = "etags -a " + file.getAbsolutePath(); > > try { > > // start command running > Process proc = Runtime.getRuntime().exec(cmd); > > // wait for command to terminate > proc.waitFor(); > > // check its exit value > if (proc.exitValue() != 0) { > if (failOnError) { > throw new BuildException("etags process did not complete correctly for file " + file.getAbsolutePath()); > } else { > log("Result: " + proc.exitValue(), Project.MSG_ERR); > } > } > > > // update the no of files counter > noOfFiles++; > > > } > catch (InterruptedException ex) { > throw new BuildException("etags process was interrupted, for file " + file.getAbsolutePath()); > } > catch (IOException ex) { > throw new BuildException("etags process encountered a problem with io for file " + file.getAbsolutePath()); > } > > > } > > } > > ---------------------------------------------------------------------------- ---- > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
