Browse Source

Add support for OpenVMS logicals as "environment variables".

Submitted by:	Knut Wannheden <knut dot wannheden at paranor dot ch>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274952 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
96404f8700
2 changed files with 69 additions and 0 deletions
  1. +10
    -0
      docs/manual/CoreTasks/property.html
  2. +59
    -0
      src/main/org/apache/tools/ant/taskdefs/Execute.java

+ 10
- 0
docs/manual/CoreTasks/property.html View File

@@ -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.</p> This also holds for properties loaded from a property file.</p>
<p>A list of predefined properties can be found <a <p>A list of predefined properties can be found <a
href="../using.html#built-in-props">here</a>.</p> href="../using.html#built-in-props">here</a>.</p>

<h4>OpenVMS Users</h4>
<p>With the <code>environment</code> 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).
</p>

<h3>Parameters</h3> <h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0"> <table border="1" cellpadding="2" cellspacing="0">
<tr> <tr>


+ 59
- 0
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -63,6 +63,8 @@ import java.io.PrintWriter;
import java.io.StringReader; import java.io.StringReader;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
@@ -192,6 +194,11 @@ public class Execute {
BufferedReader in = BufferedReader in =
new BufferedReader(new StringReader(toString(out))); new BufferedReader(new StringReader(toString(out)));


if (Os.isFamily("openvms")) {
procEnvironment = addVMSLogicals(procEnvironment, in);
return procEnvironment;
}

String var = null; String var = null;
String line, lineSep = System.getProperty("line.separator"); String line, lineSep = System.getProperty("line.separator");
while ((line = in.readLine()) != null) { 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 <code>in</code> and adds them to
* <code>environment</code>. <code>in</code> 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 command launcher for a particular JVM/OS platform. This class is
* a general purpose command launcher which can only launch commands in * a general purpose command launcher which can only launch commands in


Loading…
Cancel
Save