bodewig 02/01/29 08:20:20
Modified: . WHATSNEW
docs/manual/CoreTasks java.html
src/main/org/apache/tools/ant/taskdefs Java.java
Log:
add environment variable support in <java> for forked VMs.
Revision Changes Path
1.199 +3 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.198
retrieving revision 1.199
diff -u -r1.198 -r1.199
--- WHATSNEW 18 Jan 2002 15:26:49 -0000 1.198
+++ WHATSNEW 29 Jan 2002 16:20:20 -0000 1.199
@@ -135,6 +135,9 @@
* A "package" mapper type has been added to allow package directory
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
===========================================
1.8 +16 -1 jakarta-ant/docs/manual/CoreTasks/java.html
Index: java.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/java.html,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- java.html 10 Jan 2002 08:48:29 -0000 1.7
+++ java.html 29 Jan 2002 16:20:20 -0000 1.8
@@ -94,6 +94,13 @@
<td valign="top">Name of a file to write the output to.</td>
<td align="center" valign="top">No</td>
</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>
<h3>Parameters specified as nested elements</h3>
<h4>arg and jvmarg</h4>
@@ -111,6 +118,14 @@
<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
<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>
<pre>
<java classname="test.Main" >
@@ -150,7 +165,7 @@
JVM, as it takes different parameters for other JVMs,
That JVM can be started from <exec> if required.
<hr>
-<p align="center">Copyright © 2001 Apache Software Foundation. All
rights
+<p align="center">Copyright © 2001-2002 Apache Software Foundation. All
rights
Reserved.</p>
</body>
1.32 +40 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.java
Index: Java.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Java.java 10 Jan 2002 13:59:31 -0000 1.31
+++ Java.java 29 Jan 2002 16:20:20 -0000 1.32
@@ -1,7 +1,7 @@
/*
* 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.
*
* Redistribution and use in source and binary forms, with or without
@@ -81,7 +81,9 @@
public class Java extends Task {
private CommandlineJava cmdl = new CommandlineJava();
+ private Environment env = new Environment();
private boolean fork = false;
+ private boolean newEnvironment = false;
private File dir = null;
private File out;
private PrintStream outStream = null;
@@ -128,6 +130,11 @@
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(),
Project.MSG_VERBOSE);
try {
@@ -268,6 +275,28 @@
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) {
if (outStream != null) {
outStream.println(line);
@@ -340,6 +369,16 @@
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);
try {
return exe.execute();
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>