comparison src/org/ssdt_ohio/tools/ant/ReplaceTargetTask.java @ 6:c989b9aa8820

USASR-644: Add ant task to replace existing ant targets
author smith@nwoca.org
date Wed, 12 Oct 2011 12:59:32 -0400
parents src/org/ssdt_ohio/tools/ant/AddDependencyTask.java@de1522a9d4bc
children 418ba4cfc553
comparison
equal deleted inserted replaced
5:de1522a9d4bc 6:c989b9aa8820
1 package org.ssdt_ohio.tools.ant;
2
3 import org.apache.tools.ant.BuildException;
4 import org.apache.tools.ant.Project;
5 import org.apache.tools.ant.Target;
6 import org.apache.tools.ant.Task;
7
8 /** @author smith */
9 public class ReplaceTargetTask extends Task {
10
11 private String target;
12 private String with;
13
14 @Override
15 public void execute() throws BuildException {
16 if (target == null) {
17 throw new BuildException("'target' attribute is required");
18 }
19 if (with == null) {
20 throw new BuildException("'with' attribute is required");
21 }
22
23 Target t = (Target) getProject().getTargets().get(target);
24 if (t == null) {
25 log(target + " to be replaced does not exist", Project.MSG_VERBOSE);
26 } else {
27 Target withTarget = (Target) getProject().getTargets().get(with);
28 if (withTarget == null) {
29 log(with + " replacement target does not exist", Project.MSG_ERR);
30 } else {
31 Target newTarget = new Target(withTarget);
32 newTarget.setName(target);
33 getProject().addOrReplaceTarget(newTarget);
34
35 log(target + " target replaced by " + with, Project.MSG_INFO);
36 }
37 }
38 }
39
40 public void setTarget(String target) {
41 this.target = target;
42 }
43
44 public void setWith(String with) {
45 this.with = with;
46 }
47 }