Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / April 2005

Tip: Looking for answers? Try searching our database.

Custom ANT task having an includes tag

Thread view: 
gimme_this_gimme_that@yahoo.com - 20 Apr 2005 23:00 GMT
Hi,

I'm creating a custom ANT task that is supposed to
read a set of files (all files having a .xml suffix).

Does anyone have an example where they create an
includes tag for a custom ANT task.

As in

<mytask includes="**/*.xml"/>

Thanks
gimme_this_gimme_that@yahoo.com - 22 Apr 2005 00:59 GMT
For those who might be interested the trick is to know to use
ANTs directory scanner.

package com.*.*.ant.task;

/*
<target name="main"
depends="declare-idupdate,create-base-component.xml">
       <idupdate
           includes="**/c.xml"
           excludes="*sv*/**/c.xml"
           dir="../.."
       />
   </target>
*/

import java.io.File;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Path;

public class BuildComponentXML extends Task {

   private static String includes;   // included component.xml files
   private static String excludes;   // excluded component.xml files
    private static Path dir;

    public void setDir(org.apache.tools.ant.types.Path dir) {
        BuildComponentXML.dir = dir;
    }

   public void setIncludes(String includes) {
       BuildComponentXML.includes=includes;
   }

   public void setExcludes(String excludes) {
       BuildComponentXML.excludes=excludes;
   }

    public void execute() throws BuildException {
        System.out.println("dir is : " + BuildComponentXML.dir);
        DirectoryScanner ds = new DirectoryScanner();
        String[] a = {includes};
        ds.setIncludes(a);
        String[] b = {excludes};
        ds.setExcludes(b);
        ds.setBasedir(BuildComponentXML.dir.toString());
        ds.setCaseSensitive(true);
        ds.scan();
        System.out.println("FILES:");
        String[] files = ds.getIncludedFiles();
        for (int i = 0; i < files.length; i++) {
            System.out.println(files[i]);
        }
    }

}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.