annotate 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
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
7
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
3 import java.util.Enumeration;
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
4 import org.apache.tools.ant.BuildException;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
5 import org.apache.tools.ant.Project;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
6 import org.apache.tools.ant.Target;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
7 import org.apache.tools.ant.Task;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
8
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
9 /** @author smith */
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
10 public class ReplaceTargetTask extends Task {
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
11
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
12 private String target;
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
13 private String with;
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
14
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
15 @Override
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
16 public void execute() throws BuildException {
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
17 if (target == null) {
1
82fc5e17cc59 clean up task messages
smith@nwoca.org
parents: 0
diff changeset
18 throw new BuildException("'target' attribute is required");
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
19 }
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
20 if (with == null) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
21 throw new BuildException("'with' attribute is required");
0
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
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
24 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
25 if (t == null) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
26 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
27 } else {
7
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
28
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
29 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
30 if (withTarget == null) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
31 log(with + " replacement target does not exist", Project.MSG_ERR);
5
de1522a9d4bc Ignore missing target in adddependency
smith@nwoca.org
parents: 1
diff changeset
32 } else {
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
33 Target newTarget = new Target(withTarget);
7
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
34 for (Enumeration en = t.getDependencies(); en.hasMoreElements();) {
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
35 String dep = (String) en.nextElement();
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
36 if (!newTarget.dependsOn(dep)) {
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
37 newTarget.addDependency(dep);
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
38 }
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
39 }
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
40 newTarget.setName(target);
7
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
41
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
42 getProject().addOrReplaceTarget(newTarget);
7
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
43
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
44 log(target + " target replaced by " + with, Project.MSG_INFO);
7
418ba4cfc553 USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents: 6
diff changeset
45
5
de1522a9d4bc Ignore missing target in adddependency
smith@nwoca.org
parents: 1
diff changeset
46 }
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
47 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
48 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
49
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
50 public void setTarget(String target) {
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
51 this.target = target;
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
52 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
53
6
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
54 public void setWith(String with) {
c989b9aa8820 USASR-644: Add ant task to replace existing ant targets
smith@nwoca.org
parents: 5
diff changeset
55 this.with = with;
0
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
56 }
1918a6aed50a Initial ant tasks for SSDT develkit
smith@nwoca.org
parents:
diff changeset
57 }