Index: /home/jingxue/workspace/ivy.svn/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
===================================================================
--- /home/jingxue/workspace/ivy.svn/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java	(revision 578532)
+++ /home/jingxue/workspace/ivy.svn/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java	(working copy)
@@ -20,6 +20,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.text.ParseException;
 import java.util.Arrays;
@@ -214,24 +216,54 @@
                 ivy.setVariable(name, value, override == null ? true : Boolean.valueOf(override)
                         .booleanValue());
             } else if ("properties".equals(qName)) {
+                String override = ivy.substitute((String) attributes.get("override"));
+                String envPrefix = ivy.substitute((String) attributes.get("environment"));
+                if (envPrefix != null) {
+                    // append a dot only if the specified prefix doesn't have one. this is
+                    // compatible with ant's behavior.
+                    if (!envPrefix.endsWith(".")) {
+                        envPrefix += ".";
+                    }
+
+                    Method getEnvMethod = null;
+                    try {
+                        getEnvMethod = System.class.getMethod("getenv", new Class[0]);
+                    } catch (NoSuchMethodException e) {
+                        throw new IllegalArgumentException("Importing environment variables only supported in JDK 1.5+." + e);
+                    }
+ 
+                    try {
+                        Map env = (Map)getEnvMethod.invoke(null, null);
+                        for (Iterator iterator = env.entrySet().iterator(); iterator.hasNext();) {
+                            Map.Entry entry = (Map.Entry) iterator.next();
+                            ivy.setVariable(envPrefix + entry.getKey(), (String)entry.getValue());
+                        }
+                    } catch (InvocationTargetException e) {
+                        throw new IllegalArgumentException("Failed to import environment variables." + e);
+                    } catch (IllegalAccessException e) {
+                        throw new IllegalArgumentException("Failed to import environment variables." + e);
+                    }
+                }
+
                 String propFilePath = ivy.substitute((String) attributes.get("file"));
-                String override = ivy.substitute((String) attributes.get("override"));
-                try {
-                    Message.verbose("loading properties: " + propFilePath);
-                    ivy.loadProperties(new File(propFilePath), override == null ? true : Boolean
-                            .valueOf(override).booleanValue());
-                } catch (Exception fileEx) {
-                    Message.verbose("failed to load properties as file: trying as url: "
-                            + propFilePath);
+                if (propFilePath != null) {
                     try {
-                        ivy.loadProperties(new URL(propFilePath), override == null ? true : Boolean
+                        Message.verbose("loading properties: " + propFilePath);
+                        ivy.loadProperties(new File(propFilePath), override == null ? true : Boolean
                                 .valueOf(override).booleanValue());
-                    } catch (Exception urlEx) {
-                        throw new IllegalArgumentException(
-                                "unable to load properties from "
-                                        + propFilePath
-                                        + ". Tried both as an url and a file, with no success. File exception: "
-                                        + fileEx + ". URL exception: " + urlEx);
+                    } catch (Exception fileEx) {
+                        Message.verbose("failed to load properties as file: trying as url: "
+                                + propFilePath);
+                        try {
+                            ivy.loadProperties(new URL(propFilePath), override == null ? true : Boolean
+                                    .valueOf(override).booleanValue());
+                        } catch (Exception urlEx) {
+                            throw new IllegalArgumentException(
+                                    "unable to load properties from "
+                                            + propFilePath
+                                            + ". Tried both as an url and a file, with no success. File exception: "
+                                            + fileEx + ". URL exception: " + urlEx);
+                        }
                     }
                 }
             } else if ("include".equals(qName)) {
Index: /home/jingxue/workspace/ivy.svn/test/java/org/apache/ivy/core/settings/ivysettings-environment.xml
===================================================================
--- /home/jingxue/workspace/ivy.svn/test/java/org/apache/ivy/core/settings/ivysettings-environment.xml	(revision 0)
+++ /home/jingxue/workspace/ivy.svn/test/java/org/apache/ivy/core/settings/ivysettings-environment.xml	(revision 0)
@@ -0,0 +1,21 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<ivysettings>
+    <properties environment="env"/>
+</ivysettings>

Property changes on: /home/jingxue/workspace/ivy.svn/test/java/org/apache/ivy/core/settings/ivysettings-environment.xml
___________________________________________________________________
Name: svn:eol-style
   + LF
Name: svn:executable
   + *
Name: svn:keywords
   + Id

Index: /home/jingxue/workspace/ivy.svn/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java
===================================================================
--- /home/jingxue/workspace/ivy.svn/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java	(revision 578532)
+++ /home/jingxue/workspace/ivy.svn/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java	(working copy)
@@ -23,6 +23,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.lang.SystemUtils;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.plugins.latest.LatestRevisionStrategy;
@@ -365,6 +366,25 @@
             ModuleDescriptorParserRegistry.getInstance().getParsers()[0].getClass().getName());
     }
 
+    public void testImportEnv() throws Exception {
+        IvySettings settings = new IvySettings();
+        XmlSettingsParser parser = new XmlSettingsParser(settings);
+
+        try {
+            parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-environment.xml"));
+        } catch (ParseException e) {
+            if (SystemUtils.JAVA_VERSION_FLOAT < 1.5f) {
+                assertTrue(e.getMessage().indexOf("Importing environment variables only supported in JDK 1.5+.") >= 0);
+            } else {
+                throw e;
+            }
+        }
+
+        if (SystemUtils.JAVA_VERSION_FLOAT >= 1.5f) {
+            assertNotNull(settings.getVariable("env.PATH"));
+        }
+    }
+
     public void testOutputter() throws Exception {
         IvySettings settings = new IvySettings();
         XmlSettingsParser parser = new XmlSettingsParser(settings);
