git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271000 13f79535-47bb-0310-9956-ffa450edef68master
@@ -135,6 +135,9 @@ Other changes: | |||||
* A "package" mapper type has been added to allow package directory | * A "package" mapper type has been added to allow package directory | ||||
names replaced with the dotted form. | names replaced with the dotted form. | ||||
* you can now specify environment variables in the <java> task | |||||
if the fork attribute has been set to true. | |||||
Changes from Ant 1.4 to Ant 1.4.1 | Changes from Ant 1.4 to Ant 1.4.1 | ||||
=========================================== | =========================================== | ||||
@@ -94,6 +94,13 @@ JVM. | |||||
<td valign="top">Name of a file to write the output to.</td> | <td valign="top">Name of a file to write the output to.</td> | ||||
<td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">newenvironment</td> | |||||
<td valign="top">Do not propagate old environment when new | |||||
environment variables are specified. Default is "false" | |||||
(ignored if fork is disabled).</td> | |||||
<td align="center" valign="top">No</td> | |||||
</tr> | |||||
</table> | </table> | ||||
<h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
<h4>arg and jvmarg</h4> | <h4>arg and jvmarg</h4> | ||||
@@ -111,6 +118,14 @@ variables</a>.</p> | |||||
<p><code>Java</code>'s <i>classpath</i> attribute is a <a | <p><code>Java</code>'s <i>classpath</i> attribute is a <a | ||||
href="../using.html#path">PATH like structure</a> and can also be set via a nested | href="../using.html#path">PATH like structure</a> and can also be set via a nested | ||||
<i>classpath</i> element.</p> | <i>classpath</i> element.</p> | ||||
<h4>env</h4> | |||||
<p>It is possible to specify environment variables to pass to the | |||||
forked VM via nested <i>env</i> elements. See the description in the | |||||
section about <a href="exec.html#env">exec</a></p> | |||||
<p>Please note that the environment of the current Ant process is | |||||
<b>not</b> passed to the forked VM if you specify variables using | |||||
<i>env</i>.</p> | |||||
<p>Settings will be ignored if fork is disabled.</p> | |||||
<h3>Examples</h3> | <h3>Examples</h3> | ||||
<pre> | <pre> | ||||
<java classname="test.Main" > | <java classname="test.Main" > | ||||
@@ -150,7 +165,7 @@ and with a maximum memory of 128MB. Any non zero return code breaks the build. | |||||
JVM, as it takes different parameters for other JVMs, | JVM, as it takes different parameters for other JVMs, | ||||
That JVM can be started from <exec> if required. | That JVM can be started from <exec> if required. | ||||
<hr> | <hr> | ||||
<p align="center">Copyright © 2001 Apache Software Foundation. All rights | |||||
<p align="center">Copyright © 2001-2002 Apache Software Foundation. All rights | |||||
Reserved.</p> | Reserved.</p> | ||||
</body> | </body> | ||||
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * The Apache Software License, Version 1.1 | ||||
* | * | ||||
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights | |||||
* Copyright (c) 2000-2002 The Apache Software Foundation. All rights | |||||
* reserved. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -81,7 +81,9 @@ import java.util.Vector; | |||||
public class Java extends Task { | public class Java extends Task { | ||||
private CommandlineJava cmdl = new CommandlineJava(); | private CommandlineJava cmdl = new CommandlineJava(); | ||||
private Environment env = new Environment(); | |||||
private boolean fork = false; | private boolean fork = false; | ||||
private boolean newEnvironment = false; | |||||
private File dir = null; | private File dir = null; | ||||
private File out; | private File out; | ||||
private PrintStream outStream = null; | private PrintStream outStream = null; | ||||
@@ -128,6 +130,11 @@ public class Java extends Task { | |||||
log("Working directory ignored when same JVM is used.", Project.MSG_WARN); | log("Working directory ignored when same JVM is used.", Project.MSG_WARN); | ||||
} | } | ||||
if (newEnvironment || null != env.getVariables()) { | |||||
log("Changes to environment variables are ignored when same JVM is used.", | |||||
Project.MSG_WARN); | |||||
} | |||||
log("Running in same VM " + cmdl.getJavaCommand().toString(), | log("Running in same VM " + cmdl.getJavaCommand().toString(), | ||||
Project.MSG_VERBOSE); | Project.MSG_VERBOSE); | ||||
try { | try { | ||||
@@ -268,6 +275,28 @@ public class Java extends Task { | |||||
cmdl.setVmversion(value); | cmdl.setVmversion(value); | ||||
} | } | ||||
/** | |||||
* Add a nested env element - an environment variable. | |||||
* | |||||
* <p>Will be ignored if we are not forking a new VM. | |||||
* | |||||
* @since 1.32, Ant 1.5 | |||||
*/ | |||||
public void addEnv(Environment.Variable var) { | |||||
env.addVariable(var); | |||||
} | |||||
/** | |||||
* Use a completely new environment | |||||
* | |||||
* <p>Will be ignored if we are not forking a new VM. | |||||
* | |||||
* @since 1.32, Ant 1.5 | |||||
*/ | |||||
public void setNewenvironment(boolean newenv) { | |||||
newEnvironment = newenv; | |||||
} | |||||
protected void handleOutput(String line) { | protected void handleOutput(String line) { | ||||
if (outStream != null) { | if (outStream != null) { | ||||
outStream.println(line); | outStream.println(line); | ||||
@@ -340,6 +369,16 @@ public class Java extends Task { | |||||
exe.setWorkingDirectory(dir); | exe.setWorkingDirectory(dir); | ||||
String[] environment = env.getVariables(); | |||||
if (environment != null) { | |||||
for (int i=0; i<environment.length; i++) { | |||||
log("Setting environment variable: "+environment[i], | |||||
Project.MSG_VERBOSE); | |||||
} | |||||
} | |||||
exe.setNewenvironment(newEnvironment); | |||||
exe.setEnvironment(environment); | |||||
exe.setCommandline(command); | exe.setCommandline(command); | ||||
try { | try { | ||||
return exe.execute(); | return exe.execute(); | ||||