Mercurial > public > ssdtant
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 | 1 package org.ssdt_ohio.tools.ant; |
2 | |
7
418ba4cfc553
USASR-644: preserve dependencies in replaced target
smith@nwoca.org
parents:
6
diff
changeset
|
3 import java.util.Enumeration; |
0 | 4 import org.apache.tools.ant.BuildException; |
5 import org.apache.tools.ant.Project; | |
6 import org.apache.tools.ant.Target; | |
7 import org.apache.tools.ant.Task; | |
8 | |
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 | 11 |
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 | 14 |
15 @Override | |
16 public void execute() throws BuildException { | |
17 if (target == null) { | |
1 | 18 throw new BuildException("'target' attribute is required"); |
0 | 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 | 22 } |
23 | |
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 | 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 | 46 } |
0 | 47 } |
48 } | |
49 | |
50 public void setTarget(String target) { | |
51 this.target = target; | |
52 } | |
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 | 56 } |
57 } |