| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib.antserver.commands; |
| 17 |
|
| 18 |
import java.io.InputStream; |
| 19 |
import java.util.Enumeration; |
| 20 |
import java.util.Vector; |
| 21 |
|
| 22 |
import org.apache.tools.ant.Project; |
| 23 |
import org.apache.tools.ant.taskdefs.Ant; |
| 24 |
import org.apache.tools.ant.taskdefs.CallTarget; |
| 25 |
import org.apache.tools.ant.taskdefs.Property; |
| 26 |
|
| 27 |
import net.sf.antcontrib.antserver.Command; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class RunTargetCommand |
| 41 |
extends AbstractCommand |
| 42 |
implements Command |
| 43 |
{ |
| 44 |
private String target; |
| 45 |
private Vector properties; |
| 46 |
private Vector references; |
| 47 |
private boolean inheritall = false; |
| 48 |
private boolean interitrefs = false; |
| 49 |
|
| 50 |
public RunTargetCommand() |
| 51 |
{ |
| 52 |
super(); |
| 53 |
this.properties = new Vector(); |
| 54 |
this.references = new Vector(); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
public String getTarget() |
| 59 |
{ |
| 60 |
return target; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
public void setTarget(String target) |
| 65 |
{ |
| 66 |
this.target = target; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
public Vector getProperties() |
| 71 |
{ |
| 72 |
return properties; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
public void setProperties(Vector properties) |
| 77 |
{ |
| 78 |
this.properties = properties; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public Vector getReferences() |
| 84 |
{ |
| 85 |
return references; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
public void setReferences(Vector references) |
| 90 |
{ |
| 91 |
this.references = references; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
public boolean isInheritall() |
| 96 |
{ |
| 97 |
return inheritall; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
public void setInheritall(boolean inheritall) |
| 102 |
{ |
| 103 |
this.inheritall = inheritall; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
public boolean isInteritrefs() |
| 108 |
{ |
| 109 |
return interitrefs; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
public void setInteritrefs(boolean interitrefs) |
| 114 |
{ |
| 115 |
this.interitrefs = interitrefs; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
public void addConfiguredProperty(PropertyContainer property) |
| 120 |
{ |
| 121 |
properties.addElement(property); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
public void addConfiguredReference(ReferenceContainer reference) |
| 126 |
{ |
| 127 |
references.addElement(reference); |
| 128 |
} |
| 129 |
|
| 130 |
public void validate(Project project) |
| 131 |
{ |
| 132 |
} |
| 133 |
|
| 134 |
public boolean execute(Project project, |
| 135 |
long contentLength, |
| 136 |
InputStream content) |
| 137 |
throws Throwable |
| 138 |
{ |
| 139 |
CallTarget callTarget = (CallTarget)project.createTask("antcall"); |
| 140 |
callTarget.setInheritAll(inheritall); |
| 141 |
callTarget.setInheritRefs(interitrefs); |
| 142 |
|
| 143 |
String toExecute = target; |
| 144 |
if (toExecute == null) |
| 145 |
toExecute = project.getDefaultTarget(); |
| 146 |
callTarget.setTarget(toExecute); |
| 147 |
|
| 148 |
Enumeration e = properties.elements(); |
| 149 |
PropertyContainer pc = null; |
| 150 |
Property p = null; |
| 151 |
while (e.hasMoreElements()) |
| 152 |
{ |
| 153 |
pc = (PropertyContainer)e.nextElement(); |
| 154 |
p = callTarget.createParam(); |
| 155 |
p.setName(pc.getName()); |
| 156 |
p.setValue(pc.getValue()); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
e = references.elements(); |
| 161 |
ReferenceContainer rc = null; |
| 162 |
Ant.Reference ref = null; |
| 163 |
while (e.hasMoreElements()) |
| 164 |
{ |
| 165 |
rc = (ReferenceContainer)e.nextElement(); |
| 166 |
ref = new Ant.Reference(); |
| 167 |
ref.setRefId(rc.getRefId()); |
| 168 |
ref.setToRefid(rc.getToRefId()); |
| 169 |
callTarget.addReference(ref); |
| 170 |
} |
| 171 |
|
| 172 |
callTarget.execute(); |
| 173 |
|
| 174 |
return false; |
| 175 |
} |
| 176 |
} |