commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1004851 - in /commons/proper/exec/trunk/src: changes/ main/java/org/apache/commons/exec/environment/ main/java/org/apache/commons/exec/launcher/ test/scripts/
Date Tue, 05 Oct 2010 23:01:34 GMT
Author: sebb
Date: Tue Oct  5 23:01:33 2010
New Revision: 1004851

URL: http://svn.apache.org/viewvc?rev=1004851&view=rev
Log:
Fix up OpenVMS implementation to use symbols rather than logicals.
Seems more in keeping with other OSes, and environment updates work better.

Modified:
    commons/proper/exec/trunk/src/changes/changes.xml
    commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java
    commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
    commons/proper/exec/trunk/src/test/scripts/environment.dcl
    commons/proper/exec/trunk/src/test/scripts/test.dcl

Modified: commons/proper/exec/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/changes/changes.xml?rev=1004851&r1=1004850&r2=1004851&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/changes/changes.xml (original)
+++ commons/proper/exec/trunk/src/changes/changes.xml Tue Oct  5 23:01:33 2010
@@ -24,6 +24,9 @@
     </properties>
     <body>
         <release version="1.1-SNAPSHOT" date="as in SVN" description="Maintenance Release">
+            <action dev="sebb" type="fix" date="2010-10-05" >
+                OpenVMS now uses symbols instead of logicals for environment variables.
+            </action>
             <action dev="sgoeschl" type="add" date="2010-09-21" >
                 Adding 'Argument' class and quote the arguments after expansion.        
       
             </action>

Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java?rev=1004851&r1=1004850&r2=1004851&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java
(original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java
Tue Oct  5 23:01:33 2010
@@ -20,7 +20,6 @@ package org.apache.commons.exec.environm
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.commons.exec.CommandLine;
@@ -34,17 +33,13 @@ public class OpenVmsProcessingEnvironmen
     /**
      * Find the list of environment variables for this process.
      *
-     * @return a amp containing the environment variables
+     * @return a map containing the environment variables
      * @throws IOException the operation failed
      */    
     protected Map createProcEnvironment() throws IOException {
         if (procEnvironment == null) {
-            procEnvironment = new HashMap();
-
             BufferedReader in = runProcEnvCommand();
-
-            procEnvironment = addVMSLogicals(procEnvironment, in);
-            return procEnvironment;
+            procEnvironment = addVMSenvironmentVariables(new HashMap(), in);
         }
 
         return procEnvironment;
@@ -58,61 +53,34 @@ public class OpenVmsProcessingEnvironmen
      */    
     protected CommandLine getProcEnvCommand() {
         CommandLine commandLine = new CommandLine("show");
-        commandLine.addArgument("logical");
+        commandLine.addArgument("symbol/global"); // the parser assumes symbols are global
+        commandLine.addArgument("*");
         return commandLine;
     }
 
     /**
      * 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 (,).
+     * symbols from <code>in</code> and adds them to <code>environment</code>.
+     * <code>in</code> is expected to be the output of "SHOW SYMBOL/GLOBAL *".
      *
      * @param environment the current environment
      * @param in the reader from the process to determine VMS env variables
      * @return the updated environment
      * @throws IOException operation failed
      */
-    private Map addVMSLogicals(final Map environment,
+    private Map addVMSenvironmentVariables(final Map environment,
             final BufferedReader in) throws IOException {
         String line;
-        HashMap logicals = new HashMap();
-        String logName = null, logValue = null, newLogName;
         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);
-                }
+            final String SEP = "=="; // global symbol separator
+            int sepidx = line.indexOf(SEP);
+            if (sepidx > 0){
+                String name = line.substring(0, sepidx).trim();
+                String value = line.substring(sepidx+SEP.length()).trim();
+                value = value.substring(1,value.length()-1); // drop enclosing quotes
+                environment.put(name,value);
             }
         }
-        // Since we "look ahead" before adding, there's one last env var.
-        if (logName != null) {
-            logicals.put(logName, logValue);
-        }
-
-        for (Iterator i = logicals.entrySet().iterator(); i.hasNext();) {
-            String logical = (String) ((Map.Entry) i.next()).getKey();
-            environment.put(logical, logicals.get(logical));
-        }
         return environment;
     }
 }

Modified: commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java?rev=1004851&r1=1004850&r2=1004851&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
(original)
+++ commons/proper/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
Tue Oct  5 23:01:33 2010
@@ -83,16 +83,30 @@ public class VmsCommandLauncher extends 
         try {
             out = new PrintWriter(new FileWriter(script.getAbsolutePath(),true));
 
-            // add the environment as logicals to the DCL script
+            // add the environment as global symbols for the DCL script
             if (env != null) {
                 Set entries = env.entrySet();
 
                 for (Iterator iter = entries.iterator(); iter.hasNext();) {
                     Entry entry = (Entry) iter.next();
-                    out.print("$ DEFINE/NOLOG ");
+                    out.print("$ ");
                     out.print(entry.getKey());
-                    out.print(" \"");
-                    out.print(entry.getValue());
+                    out.print(" == "); // define as global symbol
+                    out.println('\"');
+                    String value = (String) entry.getValue();
+                    // Any embedded " values need to be doubled
+                    if (value.indexOf('\"') > 0){
+                        StringBuffer sb = new StringBuffer();
+                        for (int i = 0; i < value.length(); i++) {
+                            char c = value.charAt(i);
+                            if (c == '\"') {
+                                sb.append('\"');
+                            }
+                            sb.append(c);
+                        }
+                        value=sb.toString();
+                    }
+                    out.print(value);
                     out.println('\"');
                 }
             }

Modified: commons/proper/exec/trunk/src/test/scripts/environment.dcl
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/environment.dcl?rev=1004851&r1=1004850&r2=1004851&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/environment.dcl (original)
+++ commons/proper/exec/trunk/src/test/scripts/environment.dcl Tue Oct  5 23:01:33 2010
@@ -19,4 +19,4 @@ $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 $!
 $! print the "environment" variables
 $!
-$ show logical
\ No newline at end of file
+$ show symbol *
\ No newline at end of file

Modified: commons/proper/exec/trunk/src/test/scripts/test.dcl
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/test.dcl?rev=1004851&r1=1004850&r2=1004851&view=diff
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/test.dcl (original)
+++ commons/proper/exec/trunk/src/test/scripts/test.dcl Tue Oct  5 23:01:33 2010
@@ -20,7 +20,6 @@ $! 
 $! print the given environment variable and command line parameter
 $! since this is verified by the regression test
 $!
-$ ENV_VAR=f$trnlnm("TEST_ENV_VAR")
-$ write sys$output "FOO.''ENV_VAR'.''P1'"
+$ write sys$output "FOO.''TEST_ENV_VAR'.''P1'"
 $!
 $ exit 1 ! normal exit
\ No newline at end of file



Mime
View raw message