diff --git a/docs/manual/CoreTasks/property.html b/docs/manual/CoreTasks/property.html index f9634b065..016e8761f 100644 --- a/docs/manual/CoreTasks/property.html +++ b/docs/manual/CoreTasks/property.html @@ -38,6 +38,16 @@ properties. These references are resolved at the time these properties are set. This also holds for properties loaded from a property file.

A list of predefined properties can be found here.

+ +

OpenVMS Users

+

With the environment attribute this task will load all defined +logicals on an OpenVMS system. Logicals with multiple equivalence names get +mapped to a property whose value is a comma separated list of all equivalence +names. If a logical is defined in multiple tables, only the most local +definition is available (the table priority order being PROCESS, JOB, GROUP, +SYSTEM). +

+

Parameters

diff --git a/src/main/org/apache/tools/ant/taskdefs/Execute.java b/src/main/org/apache/tools/ant/taskdefs/Execute.java index 740c93558..30f14082f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Execute.java +++ b/src/main/org/apache/tools/ant/taskdefs/Execute.java @@ -63,6 +63,8 @@ import java.io.PrintWriter; import java.io.StringReader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Iterator; import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -192,6 +194,11 @@ public class Execute { BufferedReader in = new BufferedReader(new StringReader(toString(out))); + if (Os.isFamily("openvms")) { + procEnvironment = addVMSLogicals(procEnvironment, in); + return procEnvironment; + } + String var = null; String line, lineSep = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { @@ -587,6 +594,58 @@ public class Execute { } } + /** + * This method is VMS specific and used by getProcEnvironment(). + * + * Parses VMS logicals from in and adds them to + * environment. in is expected to be the + * output of "SHOW LOGICAL". The method takes care of parsing the output + * correctly as well as making sure that a logical defined in multiple + * tables only gets added from the highest order table. Logicals with + * multiple equivalence names are mapped to a variable with multiple + * values separated by a comma (,). + */ + private static Vector addVMSLogicals(Vector environment, BufferedReader in) + throws IOException { + HashMap logicals = new HashMap(); + + String logName = null, logValue = null, newLogName; + String line, lineSep = System.getProperty("line.separator"); + while ((line = in.readLine()) != null) { + // parse the VMS logicals into required format ("VAR=VAL[,VAL2]") + if (line.startsWith("\t=")) { + // further equivalence name of previous logical + if (logName != null) { + logValue += "," + line.substring(4, line.length() - 1); + } + } else if (line.startsWith(" \"")) { + // new logical? + if (logName != null) { + logicals.put(logName, logValue); + } + int eqIndex = line.indexOf('='); + newLogName = line.substring(3, eqIndex - 2); + if (logicals.containsKey(newLogName)) { + // already got this logical from a higher order table + logName = null; + } else { + logName = newLogName; + logValue = line.substring(eqIndex + 3, line.length() - 1); + } + } + } + // Since we "look ahead" before adding, there's one last env var. + if (logName != null) { + logicals.put(logName, logValue); + } + + for (Iterator i = logicals.keySet().iterator(); i.hasNext();) { + String logical = (String) i.next(); + environment.add(logical + "=" + logicals.get(logical)); + } + return environment; + } + /** * A command launcher for a particular JVM/OS platform. This class is * a general purpose command launcher which can only launch commands in