/*
 * UnionBugs - Ant Task to Merge Findbugs Bug Reports 
 * Copyright (C) 2008 peterfranza.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 edu.umd.cs.findbugs.anttask;

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

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

/**
 * An ant task that is wraps the behavior of the UnionResults executable into an
 * ant task.
 * 
 * <taskdef name="UnionBugs2" classname="edu.umd.cs.findbugs.anttask.UnionBugs2"
 * classpath="...">
 * 
 * <UnionBugs2 to="${basedir}/findbugs.xml" > <fileset dir="plugins"> <include
 * name="*_findbugs_partial.xml" /> </fileset> </UnionBugs>
 *
 * 
 * @ant.task category="utility"
 * 
 */

public class UnionBugs2 extends AbstractFindBugsTask {

	private String to;

	private ArrayList<FileSet> fileSets = new ArrayList<FileSet>();

	public void setTo(String arg) {
		this.to = arg;
	}

	public void setFileset(FileSet arg) {
		this.fileSets.add(arg);
	}

	/**
	 * @param mainClass
	 */
	protected UnionBugs2() {
		super("edu.umd.cs.findbugs.workflow.UnionResults");
		setFailOnError(true);
	}

	@Override
	protected void checkParameters() {
		super.checkParameters();

		if (to == null)
			throw new BuildException("to attribute is required", getLocation());

		if (fileSets.size() < 1)
			throw new BuildException("fileset is required");
	}

	@Override
	protected void afterExecuteJavaProcess(int rc) {
		if (rc != 0)
			throw new BuildException("execution of " + getTaskName() + " failed");

	}

	@Override
	protected void beforeExecuteJavaProcess() {
		log("unioning bugs...");
	}

	@Override
	protected void configureFindbugsEngine() {
		addArg("-withMessages");
		addArg("-output");
		addArg(to);
		for (FileSet s : fileSets) {
			File fromDir = s.getDir(getProject());
			for(String file: s.getDirectoryScanner(getProject()).getIncludedFiles()) {
				addArg(new File(fromDir, file).toString());
			}
		}

	}

}
@@ -1640,24 +1640,134 @@
 eSet%3E();%0D%0A%0D%0A
+%09public UnionBugs2() %7B%0D%0A%09%09super(%22edu.umd.cs.findbugs.workflow.UnionResults%22);%0D%0A%09%09setFailOnError(true);%0D%0A%09%7D%0D%0A%0D%0A
 %09public void
@@ -1825,19 +1825,19 @@
 ic void 
-set
+add
 Fileset(
@@ -1889,155 +1889,8 @@
 %0D%0A%0D%0A
-%09/**%0D%0A%09 * @param mainClass%0D%0A%09 */%0D%0A%09protected UnionBugs2() %7B%0D%0A%09%09super(%22edu.umd.cs.findbugs.workflow.UnionResults%22);%0D%0A%09%09setFailOnError(true);%0D%0A%09%7D%0D%0A%0D%0A
 %09@Ov

Apply patch for UnionBugs2 to allow it to work with Ant 1.6.5 - applies patch from bug 2907327