bodewig     2003/07/25 07:06:36

  Modified:    docs/manual/CoreTasks property.html
               src/main/org/apache/tools/ant/taskdefs Execute.java
  Log:
  Add support for OpenVMS logicals as "environment variables".
  
  Submitted by: Knut Wannheden <knut dot wannheden at paranor dot ch>
  
  Revision  Changes    Path
  1.16      +10 -0     ant/docs/manual/CoreTasks/property.html
  
  Index: property.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/property.html,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- property.html     18 Jun 2003 08:10:21 -0000      1.15
  +++ property.html     25 Jul 2003 14:06:35 -0000      1.16
  @@ -38,6 +38,16 @@
   This also holds for properties loaded from a property file.</p>
   <p>A list of predefined properties can be found <a
   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>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  
  
  
  1.60      +60 -1     ant/src/main/org/apache/tools/ant/taskdefs/Execute.java
  
  Index: Execute.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Execute.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- Execute.java      25 Jul 2003 12:14:42 -0000      1.59
  +++ Execute.java      25 Jul 2003 14:06:36 -0000      1.60
  @@ -63,6 +63,8 @@
   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 @@
               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) {
  @@ -585,6 +592,58 @@
               throw new BuildException("Could not launch " + cmdline[0] + ": "
                   + exc, task.getLocation());
           }
  +    }
  +
  +    /**
  +     * 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;
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to