| 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.File; |
| 19 |
import java.io.InputStream; |
| 20 |
import java.util.Enumeration; |
| 21 |
import java.util.Vector; |
| 22 |
|
| 23 |
import org.apache.tools.ant.Project; |
| 24 |
import org.apache.tools.ant.taskdefs.Ant; |
| 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 RunAntCommand |
| 41 |
extends AbstractCommand |
| 42 |
implements Command |
| 43 |
{ |
| 44 |
|
| 45 |
private String antFile; |
| 46 |
private String dir; |
| 47 |
private String target; |
| 48 |
private Vector properties; |
| 49 |
private Vector references; |
| 50 |
private boolean inheritall = false; |
| 51 |
private boolean interitrefs = false; |
| 52 |
|
| 53 |
public RunAntCommand() |
| 54 |
{ |
| 55 |
super(); |
| 56 |
this.properties = new Vector(); |
| 57 |
this.references = new Vector(); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
public String getTarget() |
| 62 |
{ |
| 63 |
return target; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
public void setTarget(String target) |
| 68 |
{ |
| 69 |
this.target = target; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
public Vector getProperties() |
| 74 |
{ |
| 75 |
return properties; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public void setProperties(Vector properties) |
| 80 |
{ |
| 81 |
this.properties = properties; |
| 82 |
} |
| 83 |
|
| 84 |
public Vector getReferences() |
| 85 |
{ |
| 86 |
return references; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
public void setReferences(Vector references) |
| 91 |
{ |
| 92 |
this.references = references; |
| 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 String getAntFile() |
| 120 |
{ |
| 121 |
return antFile; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
public void setAntFile(String antFile) |
| 126 |
{ |
| 127 |
this.antFile = antFile; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
public String getDir() |
| 132 |
{ |
| 133 |
return dir; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
public void setDir(String dir) |
| 138 |
{ |
| 139 |
this.dir = dir; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
public void addConfiguredProperty(PropertyContainer property) |
| 144 |
{ |
| 145 |
properties.addElement(property); |
| 146 |
} |
| 147 |
|
| 148 |
public void addConfiguredReference(ReferenceContainer reference) |
| 149 |
{ |
| 150 |
references.addElement(reference); |
| 151 |
} |
| 152 |
|
| 153 |
public void validate(Project project) |
| 154 |
{ |
| 155 |
} |
| 156 |
|
| 157 |
public boolean execute(Project project, |
| 158 |
long contentLength, |
| 159 |
InputStream content) |
| 160 |
throws Throwable |
| 161 |
{ |
| 162 |
Ant ant = (Ant)project.createTask("ant"); |
| 163 |
File baseDir = project.getBaseDir(); |
| 164 |
if (dir != null) |
| 165 |
baseDir = new File(dir); |
| 166 |
ant.setDir(baseDir); |
| 167 |
ant.setInheritAll(inheritall); |
| 168 |
ant.setInheritRefs(interitrefs); |
| 169 |
|
| 170 |
if (target != null) |
| 171 |
ant.setTarget(target); |
| 172 |
|
| 173 |
if (antFile != null) |
| 174 |
ant.setAntfile(antFile); |
| 175 |
|
| 176 |
Enumeration e = properties.elements(); |
| 177 |
PropertyContainer pc = null; |
| 178 |
Property p = null; |
| 179 |
while (e.hasMoreElements()) |
| 180 |
{ |
| 181 |
pc = (PropertyContainer)e.nextElement(); |
| 182 |
p = ant.createProperty(); |
| 183 |
p.setName(pc.getName()); |
| 184 |
p.setValue(pc.getValue()); |
| 185 |
} |
| 186 |
|
| 187 |
e = references.elements(); |
| 188 |
ReferenceContainer rc = null; |
| 189 |
Ant.Reference ref = null; |
| 190 |
while (e.hasMoreElements()) |
| 191 |
{ |
| 192 |
rc = (ReferenceContainer)e.nextElement(); |
| 193 |
ref = new Ant.Reference(); |
| 194 |
ref.setRefId(rc.getRefId()); |
| 195 |
ref.setToRefid(rc.getToRefId()); |
| 196 |
ant.addReference(ref); |
| 197 |
} |
| 198 |
|
| 199 |
ant.execute(); |
| 200 |
|
| 201 |
return false; |
| 202 |
} |
| 203 |
} |