001/*
002 * The Apache Software License, Version 1.1
003 *
004 * Copyright (C) 2000-2002 The Apache Software Foundation.  All rights
005 * reserved.
006 * Copyright (C) 2003 jcoverage ltd.
007 * Copyright (C) 2005 Mark Doliner
008 * Copyright (C) 2005 Joakim Erdfelt
009 * Copyright (C) 2005 Grzegorz Lukasik
010 *
011 * Redistribution and use in source and binary forms, with or without
012 * modification, are permitted provided that the following conditions
013 * are met:
014 *
015 * 1. Redistributions of source code must retain the above copyright
016 *    notice, this list of conditions and the following disclaimer.
017 *
018 * 2. Redistributions in binary form must reproduce the above copyright
019 *    notice, this list of conditions and the following disclaimer in
020 *    the documentation and/or other materials provided with the
021 *    distribution.
022 *
023 * 3. The end-user documentation included with the redistribution, if
024 *    any, must include the following acknowlegement:
025 *       "This product includes software developed by the
026 *        Apache Software Foundation (http://www.apache.org/)."
027 *    Alternately, this acknowlegement may appear in the software itself,
028 *    if and wherever such third-party acknowlegements normally appear.
029 *
030 * 4. The names "Ant" and "Apache Software
031 *    Foundation" must not be used to endorse or promote products derived
032 *    from this software without prior written permission. For written
033 *    permission, please contact apache@apache.org.
034 *
035 * 5. Products derived from this software may not be called "Apache"
036 *    nor may "Apache" appear in their names without prior written
037 *    permission of the Apache Group.
038 *
039 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
040 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
041 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
042 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
043 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
044 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
045 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
046 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
047 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
048 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
049 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
050 * SUCH DAMAGE.
051 * ====================================================================
052 *
053 * This software consists of voluntary contributions made by many
054 * individuals on behalf of the Apache Software Foundation.  For more
055 * information on the Apache Software Foundation, please see
056 * <http://www.apache.org/>.
057 */
058
059package net.sourceforge.cobertura.ant;
060
061import java.io.IOException;
062
063import net.sourceforge.cobertura.util.CommandLineBuilder;
064
065import org.apache.tools.ant.BuildException;
066import org.apache.tools.ant.Project;
067
068public class MergeTask extends CommonMatchingTask
069{
070
071        private String dataFile = null;
072
073        public MergeTask()
074        {
075                super("net.sourceforge.cobertura.merge.Main");
076        }
077
078        public void execute() throws BuildException {
079                CommandLineBuilder builder = null;
080                try {
081                        builder = new CommandLineBuilder();
082                        if (dataFile != null)
083                                builder.addArg("--datafile", dataFile);
084
085                        createArgumentsForFilesets(builder);
086
087                        builder.saveArgs();
088                } catch (IOException ioe) {
089                        getProject().log("Error creating commands file.", Project.MSG_ERR);
090                        throw new BuildException("Unable to create the commands file.", ioe);
091                }
092
093                // Execute GPL licensed code in separate virtual machine
094                getJava().createArg().setValue("--commandsfile");
095                getJava().createArg().setValue(builder.getCommandLineFile());
096                AntUtil.transferCoberturaDataFileProperty(getJava());
097                if (getJava().executeJava() != 0) {
098                        throw new BuildException(
099                                        "Error running reports. See messages above.");
100                }
101
102                builder.dispose();
103        }
104
105        public void setDataFile(String dataFile)
106        {
107                this.dataFile = dataFile;
108        }
109
110}