annotate 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
rev   line source
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
1 package org.ssdt_ohio.tools.ant;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
2
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
3 import org.apache.tools.ant.BuildException;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
4 import org.apache.tools.ant.Project;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
5 import org.apache.tools.ant.Target;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
6 import org.apache.tools.ant.Task;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
7
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
8 /** @author smith */
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
9 public class ReplaceTargetTask extends Task {
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
10
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
11 private String target;
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
12 private String with;
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
13
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
14 @Override
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
15 public void execute() throws BuildException {
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
16 if (target == null) {
1
82fc5e17cc59 clean up task messages
smith@nwoca.org
parents: 0
diff changeset
17 throw new BuildException("'target' attribute is required");
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
18 }
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
19 if (with == null) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
20 throw new BuildException("'with' attribute is required");
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
21 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
22
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
23 Target t = (Target) getProject().getTargets().get(target);
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
24 if (t == null) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
25 log(target + " to be replaced does not exist", Project.MSG_VERBOSE);
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
26 } else {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
27 Target withTarget = (Target) getProject().getTargets().get(with);
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
28 if (withTarget == null) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
29 log(with + " replacement target does not exist", Project.MSG_ERR);
5
de1522a9d4bc Ignore missing target in adddependency
smith@nwoca.org
parents: 1
diff changeset
30 } else {
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
31 Target newTarget = new Target(withTarget);
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
32 newTarget.setName(target);
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
33 getProject().addOrReplaceTarget(newTarget);
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
34
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
35 log(target + " target replaced by " + with, Project.MSG_INFO);
5
de1522a9d4bc Ignore missing target in adddependency
smith@nwoca.org
parents: 1
diff changeset
36 }
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
37 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
38 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
39
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
40 public void setTarget(String target) {
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
41 this.target = target;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
42 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
43
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
44 public void setWith(String with) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
45 this.with = with;
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
46 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
47 }