/*
 * Copyright (C) 2004-2005 exedio GmbH (www.exedio.com)
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package com.exedio.cope.instrument;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileList;
import org.apache.tools.ant.types.FileSet;

public final class AntTask extends Task
{
	private final ArrayList fileSetsOrLists = new ArrayList();
	private boolean verbose = true;

	public void addFileset(final FileSet fileSet)
	{
		fileSetsOrLists.add(fileSet);
	}

	public void addFilelist(final FileList fileList)
	{
		fileSetsOrLists.add(fileList);
	}
	
	public void setVerbose(final boolean verbose)
	{
		this.verbose = verbose;
	}

   public void execute() throws BuildException
	{
		try
		{
			final ArrayList sourcefiles = new ArrayList();
			
			for(final Iterator i = fileSetsOrLists.iterator(); i.hasNext(); )
			{
				final Object fileSetOrList = i.next();
				final File dir;
				final String[] fileNames;
				
				if(fileSetOrList instanceof FileSet)
				{
					final FileSet fileSet = (FileSet)fileSetOrList;
					final DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject());
					dir = fileSet.getDir(getProject());
					fileNames = directoryScanner.getIncludedFiles();
				}
				else
				{
					final FileList fileList = (FileList)fileSetOrList;
					dir = fileList.getDir(getProject());
					fileNames = fileList.getFiles(getProject());
				}
				for(int j = 0; j<fileNames.length; j++)
					sourcefiles.add(new File(dir, fileNames[j]));
			}

			(new Main()).run(sourcefiles, verbose);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new BuildException(e);
		}
	}

}

@@ -1000,16 +1000,53 @@
 canner;%0A
+import org.apache.tools.ant.Project;%0A
 import o
@@ -1071,16 +1071,16 @@
 t.Task;%0A
-
 import o
@@ -1612,16 +1612,57 @@
 try%0A%09%09%7B%0A
+%09%09%09final Project project = getProject();%0A
 %09%09%09final
@@ -2054,28 +2054,23 @@
 Scanner(
-getP
+p
 roject
-()
 );%0A%09%09%09%09%09
@@ -2086,36 +2086,31 @@
 eSet.getDir(
-getP
+p
 roject
-()
 );%0A%09%09%09%09%09file
@@ -2258,28 +2258,23 @@
 .getDir(
-getP
+p
 roject
-()
 );%0A%09%09%09%09%09
@@ -2303,28 +2303,23 @@
 etFiles(
-getP
+p
 roject
-()
 );%0A%09%09%09%09%7D

make a local project variable