Mercurial > public > ssdtant
view src/org/ssdt_ohio/tools/ant/ReplaceTargetTask.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 | c989b9aa8820 |
children |
line wrap: on
line source
package org.ssdt_ohio.tools.ant; import java.util.Enumeration; 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 ReplaceTargetTask extends Task { private String target; private String with; @Override public void execute() throws BuildException { if (target == null) { throw new BuildException("'target' attribute is required"); } if (with == null) { throw new BuildException("'with' attribute is required"); } Target t = (Target) getProject().getTargets().get(target); if (t == null) { log(target + " to be replaced does not exist", Project.MSG_VERBOSE); } else { Target withTarget = (Target) getProject().getTargets().get(with); if (withTarget == null) { log(with + " replacement target does not exist", Project.MSG_ERR); } else { Target newTarget = new Target(withTarget); for (Enumeration en = t.getDependencies(); en.hasMoreElements();) { String dep = (String) en.nextElement(); if (!newTarget.dependsOn(dep)) { newTarget.addDependency(dep); } } newTarget.setName(target); getProject().addOrReplaceTarget(newTarget); log(target + " target replaced by " + with, Project.MSG_INFO); } } } public void setTarget(String target) { this.target = target; } public void setWith(String with) { this.with = with; } }