Mercurial > public > ssdtant
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 | 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 */ | |
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 | 10 |
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 | 13 |
14 @Override | |
15 public void execute() throws BuildException { | |
16 if (target == null) { | |
1 | 17 throw new BuildException("'target' attribute is required"); |
0 | 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 | 21 } |
22 | |
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 | 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 | 36 } |
0 | 37 } |
38 } | |
39 | |
40 public void setTarget(String target) { | |
41 this.target = target; | |
42 } | |
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 | 46 } |
47 } |