Thursday, January 1. 2004Join Task for ANT
Join Task for ANT enables you to create a string consisting of file names separated by a separator you defined. I developed this ANT task in order to create the content of
archive parameter for Applet tag, which consists of a series of JAR files separated by commas, within the ANT build file. The Join tag could also serve to many other purposes.
Join Task for ANT enables you to create a string consisting of file names separated by a separator you defined. I developed this ANT task in order to create the content of 1. UsageIn your <taskdef name="join" classname="com.zdo.ant.Join" classpathref="classpath" />
<join separator="," property="joined">
<fileset dir="${src}" />
</join>
<echo message="${joined}" />
2. Installation
$ ant -projecthelp Buildfile: build.xml Main targets: bundle creates a jar bundle clean clean build directory compile compile java source files copyright display copyright message init initialize build directory test tests the task Default target: compile 3. Source CodeHere is the source code Join.java: /**
* Copyright (c) 2004
* Ali Onur Cinar <cinar(a)zdo.com>
*
* License:
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for educational purposes and without fee is hereby
* granted, provided that the above copyright notice appear in all copies
* and that both the copyright notice and this permission notice and
* warranty disclaimer appear in supporting documentation, and that the name
* of Ali Onur Cinar not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
*
* @author A. Onur Cinar <cinar(a)zdo.com>
* @version %W% %G% ZDO
* @version $Id: Join.java,v 1.1 2004/09/21 13:12:05 cinar Exp $ ZDO
* @since 1.0
*/
package com.zdo.ant;
import java.util.List;
import java.util.Vector;
import java.util.ListIterator;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.FileSet;
public class Join extends Task
{
/**
* Default Constructor.
*
*/
public Join()
{
fileSets = new Vector();
setSeparator(",");
}
/**
* Sets the separator string.
*
* @param p separator string
*/
public void setSeparator(String p)
{
separator = p;
}
/**
* Returns the separator string.
*
* @return separator string
*/
public String getSeparator()
{
return separator;
}
/**
* Sets the property name which
* will hold the result.
*
* @param p property name
*/
public void setProperty(String p)
{
property = p;
}
/**
* Returns the property name which
* will hold the result.
*
* @return property name
*/
public String getProperty()
{
return property;
}
/**
* Adds a file set.
*
* @param p file set
*/
public void addFileset(FileSet p)
{
fileSets.add(p);
}
/**
* Executes the task.
*
* @throws BuildException if property name
* is not defined.
*/
public void execute()
throws BuildException
{
if(property == null)
{
throw new BuildException(
"property attribute is required",
getLocation());
}
StringBuffer joinString = new StringBuffer();
ListIterator iterator = fileSets.listIterator();
while (iterator.hasNext()) // for each file set
{
FileSet fileSet = (FileSet)iterator.next(); // get only included
String files[] = fileSet.getDirectoryScanner( // files
getProject()).getIncludedFiles();
for (int i=0; i < files.length; i++) // for each file
{
if(joinString.length() > 0) // use separator
{
joinString.append(separator);
}
joinString.append(files[i]); // add to list
}
}
getProject().setProperty(property, // set property value
joinString.toString());
}
/** Class Data */
protected String separator;
protected List fileSets;
protected String property;
}
Trackbacks
Trackback specific URI for this entry
No Trackbacks
|