You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by tr...@apache.org on 2005/09/23 01:57:34 UTC

svn commit: r291042 - /jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java

Author: trygvis
Date: Thu Sep 22 16:57:31 2005
New Revision: 291042

URL: http://svn.apache.org/viewcvs?rev=291042&view=rev
Log:
Fixing 36705: "small refactor of Environment for style"
Patch by Kev Jackson.

Modified:
    jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java

Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java?rev=291042&r1=291041&r2=291042&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/Environment.java Thu Sep 22 16:57:31 2005
@@ -44,6 +44,10 @@
 public class Environment extends HashMap {
 
     private static Log LOG = LogFactory.getLog(Environment.class);
+    /**
+     * TODO move this and other final static / constants into a constants class ?
+     */
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
 
     public static Environment createEnvironment() {
         if (OS.isFamilyOpenVms()) {
@@ -141,22 +145,15 @@
      */
     public static synchronized Environment getProcEnvironment() throws IOException {
         if (procEnvironment == null) {
-            try
-            {
+            try {
                 Method getenvs = System.class.getMethod( "getenv", null );
                 Map env = (Map) getenvs.invoke( null, null );
                 procEnvironment = new Environment( env );
-            }
-            catch ( NoSuchMethodException e )
-            {
+            } catch ( NoSuchMethodException e ) {
                 // ok, just not on JDK 1.5
-            }
-            catch ( IllegalAccessException e )
-            {
+            } catch ( IllegalAccessException e ) {
                 LOG.warn( "Unexpected error obtaining environment - using JDK 1.4 method" );
-            }
-            catch ( InvocationTargetException e )
-            {
+            } catch ( InvocationTargetException e ) {
                 LOG.warn( "Unexpected error obtaining environment - using JDK 1.4 method" );
             }
         }
@@ -166,15 +163,15 @@
             BufferedReader in = runProcEnvCommand();
 
             String var = null;
-            String line, lineSep = System.getProperty("line.separator");
+            String line;
             while ((line = in.readLine()) != null) {
                 if (line.indexOf('=') == -1) {
                     // Chunk part of previous env var (UNIX env vars can
                     // contain embedded new lines).
                     if (var == null) {
-                        var = lineSep + line;
+                        var = LINE_SEPARATOR + line;
                     } else {
-                        var += lineSep + line;
+                        var += LINE_SEPARATOR + line;
                     }
                 } else {
                     // New env var...append the previous one if we have it.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org