/** * 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; }