view src/org/ssdt_ohio/tools/ant/AddDependencyTask.java @ 7:418ba4cfc553 tip

USASR-644: preserve dependencies in replaced target
author smith@nwoca.org
date Wed, 12 Oct 2011 18:12:17 -0400
parents de1522a9d4bc
children
line wrap: on
line source
package org.ssdt_ohio.tools.ant;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;

/** @author smith */
public class AddDependencyTask extends Task {

    private String target;
    private String depends;

    @Override
    public void execute() throws BuildException {
        if (target == null) {
            throw new BuildException("'target' attribute is required");
        }
        if (depends == null) {
            throw new BuildException("'depends' attribute is required");
        }

        Target t = (Target) getProject().getTargets().get(target);
        if (t != null) {

            if (t.dependsOn(depends)) {
                log(target + " already depends on " + depends, Project.MSG_VERBOSE);
            } else {
                log("Adding \"" + depends + "\" dependency to \"" + target + "\"", Project.MSG_VERBOSE);

                t.addDependency(depends);
            }
        }
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public void setDepends(String depends) {
        this.depends = depends;
    }
}