| 1 | /* |
| 2 | * JTiger Unit Testing Framework for J2SE 1.5 |
| 3 | * Copyright (C) 2005 Tony Morris |
| 4 | * |
| 5 | * This software is licenced under the |
| 6 | * Common Public Licence version 1.0 |
| 7 | * http://www.opensource.org/licenses/cpl1.0.php |
| 8 | * |
| 9 | * You received a copy of this licence with this software. |
| 10 | */ |
| 11 | package org.jtiger.ant; |
| 12 | |
| 13 | import java.io.File; |
| 14 | import org.apache.tools.ant.BuildException; |
| 15 | import org.apache.tools.ant.Location; |
| 16 | import org.apache.tools.ant.Project; |
| 17 | import org.apache.tools.ant.Target; |
| 18 | import org.apache.tools.ant.types.Assertions; |
| 19 | import org.apache.tools.ant.types.Commandline; |
| 20 | import org.apache.tools.ant.types.Environment; |
| 21 | import org.apache.tools.ant.types.Path; |
| 22 | import org.apache.tools.ant.types.Permissions; |
| 23 | import org.apache.tools.ant.types.PropertySet; |
| 24 | import org.apache.tools.ant.types.Reference; |
| 25 | |
| 26 | /** |
| 27 | * An element used in {@link JTigerTask the Ant task} to specify the environment for the Java Virtual Machine that |
| 28 | * executes the test run. The JVM will be a forked process from the JVM that the Ant task is running in. This element is |
| 29 | * the same as <a href="%ant.url%/manual/CoreTasks/java.html" target="_blank">the core Ant <java> task</a> except |
| 30 | * that some of the elements and attributes are not present on this element. |
| 31 | * |
| 32 | * @see JTigerTask |
| 33 | * @author %javadoc.author.tag% |
| 34 | * @version %version%<br/> |
| 35 | * <i>Build Number %build.number%</i><br/> |
| 36 | * <i>Build Time %build.time% CET (GMT + 1)</i> |
| 37 | */ |
| 38 | public final class Java |
| 39 | { |
| 40 | private final org.apache.tools.ant.taskdefs.Java java; |
| 41 | |
| 42 | /** |
| 43 | * Create a <tt>Java</tt> that wraps the given Apache Ant Java task. |
| 44 | * |
| 45 | * @param java The Apache Ant Java task to wrap. |
| 46 | */ |
| 47 | public Java(final org.apache.tools.ant.taskdefs.Java java) |
| 48 | { |
| 49 | this.java = java; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Control enablement of |
| 54 | * <a href="%ant.url%/manual/CoreTypes/assertions.html" target="_blank">Java 1.4 assertions</a> with an |
| 55 | * <assertions> subelement. |
| 56 | * |
| 57 | * @param assertions The assertion set. |
| 58 | */ |
| 59 | public void addAssertions(final Assertions assertions) |
| 60 | { |
| 61 | java.addAssertions(assertions); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Adds an environment variable. |
| 66 | * |
| 67 | * @param env The new environment variable. |
| 68 | */ |
| 69 | public void addEnv(final Environment.Variable env) |
| 70 | { |
| 71 | java.addEnv(env); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Adds a system property. |
| 76 | * |
| 77 | * @param sysproperty The new system property. |
| 78 | */ |
| 79 | public void addSysproperty(final Environment.Variable sysproperty) |
| 80 | { |
| 81 | java.addSysproperty(sysproperty); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Adds a <a href="%ant.url%/manual/CoreTypes/propertyset.html" target="_blank">system property set</a>. |
| 86 | * |
| 87 | * @param syspropertyset The new system property set. |
| 88 | */ |
| 89 | public void addSyspropertyset(final PropertySet syspropertyset) |
| 90 | { |
| 91 | java.addSyspropertyset(syspropertyset); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Creates <a href="%ant.url%/manual/using.html#path" target="_blank">a boot classpath</a>. |
| 96 | * |
| 97 | * @return A new boot classpath. |
| 98 | */ |
| 99 | public Path createBootclasspath() |
| 100 | { |
| 101 | return java.createBootclasspath(); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Creates <a href="%ant.url%/manual/using.html#path" target="_blank">a classpath</a>. |
| 106 | * |
| 107 | * @return A new classpath. |
| 108 | */ |
| 109 | public Path createClasspath() |
| 110 | { |
| 111 | return java.createClasspath(); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Creates <a href="%ant.url%/manual/using.html#arg" target="_blank">a JVM argument</a>. |
| 116 | * |
| 117 | * @return A new JVM argument. |
| 118 | */ |
| 119 | public Commandline.Argument createJvmarg() |
| 120 | { |
| 121 | return java.createJvmarg(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Creates <a href="%ant.url%/manual/CoreTypes/permissions.html" target="_blank">a set of permissions</a>. |
| 126 | * |
| 127 | * @return A new set of permissions. |
| 128 | */ |
| 129 | public Permissions createPermissions() |
| 130 | { |
| 131 | return java.createPermissions(); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Sets whether output and error files should be appended to (<code>true</code>)or overwritten (<code>false</code>). |
| 136 | * |
| 137 | * @param append The value of whether output and error files should be appended to (<code>true</code>)or overwritten |
| 138 | * (<code>false</code>). |
| 139 | */ |
| 140 | public void setAppend(final boolean append) |
| 141 | { |
| 142 | java.setAppend(append); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Sets <a href="%ant.url%/manual/using.html#path" target="_blank">a classpath</a>. |
| 147 | * |
| 148 | * @param classpath A new <a href="%ant.url%/manual/using.html#path" target="_blank">classpath</a>. |
| 149 | */ |
| 150 | public void setClasspath(final Path classpath) |
| 151 | { |
| 152 | java.setClasspath(classpath); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Sets <a href="%ant.url%/manual/using.html#references" target="_blank">a classpath reference</a>. |
| 157 | * |
| 158 | * @param classpathRef A new <a href="%ant.url%/manual/using.html#references" target="_blank">classpath reference</a>. |
| 159 | */ |
| 160 | public void setClasspathRef(final Reference classpathRef) |
| 161 | { |
| 162 | java.setClasspathRef(classpathRef); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Sets the directory to invoke the VM in. |
| 167 | * |
| 168 | * @param dir The directory to invoke the VM in. |
| 169 | */ |
| 170 | public void setDir(final File dir) |
| 171 | { |
| 172 | java.setDir(dir); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Sets the file to which the standard error of the command should be redirected. |
| 177 | * |
| 178 | * @param error The file to which the standard error of the command should be redirected. |
| 179 | */ |
| 180 | public void setError(final File error) |
| 181 | { |
| 182 | java.setError(error); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Sets the name of a property in which the standard error of the command should be stored. |
| 187 | * |
| 188 | * @param errorProperty The name of a property in which the standard error of the command should be stored. |
| 189 | */ |
| 190 | public void setErrorProperty(final String errorProperty) |
| 191 | { |
| 192 | java.setErrorProperty(errorProperty); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Sets whether to stop the build process if the command exits with a returncode other than 0. |
| 197 | * |
| 198 | * @param failonerror The value of whether to stop the build process if the command exits with a returncode other |
| 199 | * than 0. |
| 200 | */ |
| 201 | public void setFailonerror(final boolean failonerror) |
| 202 | { |
| 203 | java.setFailonerror(failonerror); |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Sets the command used to invoke the Java Virtual Machine, default is '<code>java</code>'. The command is resolved |
| 208 | * by <a href="%j2se.api.spec%/java/lang/Runtime.html#exec">java.lang.Runtime.exec()</a>. |
| 209 | * |
| 210 | * @param jvm The command used to invoke the Java Virtual Machine, default is '<code>java</code>'. The command is |
| 211 | * resolved by <a href="%j2se.api.spec%/java/lang/Runtime.html#exec">java.lang.Runtime.exec()</a>. |
| 212 | */ |
| 213 | public void setJvm(final String jvm) |
| 214 | { |
| 215 | java.setJvm(jvm); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * This attribute is used when you wish to see error output in Ant's log and you are redirecting output to a |
| 220 | * file/property. The error output will not be included in the output file/property. If you redirect error with the |
| 221 | * "error" or "errorProperty" attributes, this will have no effect. |
| 222 | * |
| 223 | * @param logError This attribute is used when you wish to see error output in Ant's log and you are redirecting |
| 224 | * output to a file/property. The error output will not be included in the output file/property. If you redirect |
| 225 | * error with the "error" or "errorProperty" attributes, this will have no effect. |
| 226 | */ |
| 227 | public void setLogError(final boolean logError) |
| 228 | { |
| 229 | java.setLogError(logError); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Max amount of memory to allocate to the forked VM. |
| 234 | * |
| 235 | * @param maxmemory The maximum amount of memory to allocate to the forked VM. |
| 236 | */ |
| 237 | public void setMaxmemory(final String maxmemory) |
| 238 | { |
| 239 | java.setMaxmemory(maxmemory); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Sets whether to propagate old environment when new environment variables are specified. |
| 244 | * |
| 245 | * @param newenvironment The value of whether to propagate old environment when new environment variables are |
| 246 | * specified. |
| 247 | */ |
| 248 | public void setNewenvironment(final boolean newenvironment) |
| 249 | { |
| 250 | java.setNewenvironment(newenvironment); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Sets the name of a file to which to write the output. If the error stream is not also redirected to a file or |
| 255 | * property, it will appear in this output. |
| 256 | * |
| 257 | * @param output The name of a file to which to write the output. If the error stream is not also redirected to a |
| 258 | * file or property, it will appear in this output. |
| 259 | */ |
| 260 | public void setOutput(final File output) |
| 261 | { |
| 262 | java.setOutput(output); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Sets the name of a property in which the output of the command should be stored. Unless the error stream is |
| 267 | * redirected to a separate file or stream, this property will include the error output. |
| 268 | * |
| 269 | * @param outputproperty The name of a property in which the output of the command should be stored. Unless the |
| 270 | * error stream is redirected to a separate file or stream, this property will include the error output. |
| 271 | */ |
| 272 | public void setOutputproperty(final String outputproperty) |
| 273 | { |
| 274 | java.setOutputproperty(outputproperty); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Sets the name of a property in which the return code of the command should be stored. Only of interest if |
| 279 | * {@link #setFailonerror(boolean) <code>failonerror=false</code>}. |
| 280 | * |
| 281 | * @param resultProperty The name of a property in which the return code of the command should be stored. Only of |
| 282 | * interest if {@link #setFailonerror(boolean) <code>failonerror=false</code>}. |
| 283 | */ |
| 284 | public void setResultProperty(final String resultProperty) |
| 285 | { |
| 286 | java.setResultProperty(resultProperty); |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Sets the ability to start a process which will outlive ant. |
| 291 | * |
| 292 | * @param spawn The ability to start a process which will outlive ant. |
| 293 | */ |
| 294 | public void setSpawn(final boolean spawn) |
| 295 | { |
| 296 | java.setSpawn(spawn); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Stop the command if it doesn't finish within the specified time (given in milliseconds). |
| 301 | * |
| 302 | * @param timeout The specified time (given in milliseconds). |
| 303 | */ |
| 304 | public void setTimeout(final Long timeout) |
| 305 | { |
| 306 | java.setTimeout(timeout); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Forks the JVM using |
| 311 | * <a href="%ant.url%/manual/CoreTasks/java.html" target="_blank">the core Ant <java> task</a>. |
| 312 | * |
| 313 | * @throws BuildException IF a problem occurs during execution of the forked JVM. |
| 314 | */ |
| 315 | public void execute() throws BuildException |
| 316 | { |
| 317 | java.execute(); |
| 318 | } |
| 319 | |
| 320 | void setDescription(final String description) |
| 321 | { |
| 322 | java.setDescription(description); |
| 323 | } |
| 324 | |
| 325 | Commandline.Argument createArg() |
| 326 | { |
| 327 | return java.createArg(); |
| 328 | } |
| 329 | |
| 330 | void setClassname(final String classname) |
| 331 | { |
| 332 | java.setClassname(classname); |
| 333 | } |
| 334 | |
| 335 | void setFork(final boolean fork) |
| 336 | { |
| 337 | java.setFork(fork); |
| 338 | } |
| 339 | |
| 340 | void setLocation(final Location location) |
| 341 | { |
| 342 | java.setLocation(location); |
| 343 | } |
| 344 | |
| 345 | void setOwningTarget(final Target target) |
| 346 | { |
| 347 | java.setOwningTarget(target); |
| 348 | } |
| 349 | |
| 350 | void setTaskName(final String taskName) |
| 351 | { |
| 352 | java.setTaskName(taskName); |
| 353 | } |
| 354 | |
| 355 | void setProject(final Project project) |
| 356 | { |
| 357 | java.setProject(project); |
| 358 | } |
| 359 | |
| 360 | org.apache.tools.ant.taskdefs.Java getJava() |
| 361 | { |
| 362 | return java; |
| 363 | } |
| 364 | } |