You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gs...@apache.org on 2008/07/20 11:50:36 UTC

svn commit: r678264 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/core/settings/XmlSettingsParser.java test/java/org/apache/ivy/core/settings/ivysettings-ref.xml test/java/org/apache/ivy/core/settings/ivysettings-test.xml

Author: gscokart
Date: Sun Jul 20 02:50:36 2008
New Revision: 678264

URL: http://svn.apache.org/viewvc?rev=678264&view=rev
Log:
(IVY-89) properties from referenced from settings file are now relative to the location of the settings file, not relative to the execution directory)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-test.xml

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=678264&r1=678263&r2=678264&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Sun Jul 20 02:50:36 2008
@@ -160,6 +160,7 @@
 - FIX: Relative include in a settings must be evaluated relatively to the settings file (IVY-372)
 - FIX: The Bundle-Version is 0.0.0 in the build artifacts (IVY-802)
 - FIX: Fix the encoding used in XML reports (IVY-816)
+- FIX: Properties tag in ivy conf do not support relative path (IVY-89)
 
 - DOCUMENTATION: Fixed more than a hundred (100+) obsolete "configuration" references; replaced with "settings" (IVY-863) (thanks to Sakari Maaranen)
 - DOCUMENTATION: Elaborated documentation of ivy files and deliver/publish tasks (IVY-847) (thanks to Sakari Maaranen)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java?rev=678264&r1=678263&r2=678264&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java Sun Jul 20 02:50:36 2008
@@ -380,14 +380,11 @@
                     ivy.setSettingsVariables(settingsURL);
                 }
             } else {
-                File incFile = new File(propFilePath);
-                if (incFile.isAbsolute()) {
-                    settingsURL = incFile.toURI().toURL();
-                } else {
-                    settingsURL = new URL(this.settings , propFilePath);
-                }
+                settingsURL = urlFromFileAttribute(propFilePath);
                 Message.verbose("including file: " + settingsURL);
-                ivy.setSettingsVariables(incFile);
+                ivy.setSettingsVariables(new File(propFilePath));
+                //We can not use the setSettingsVariables(URL) because that would put different
+                //values for the properties.  I'm not sure what would be the regression...
             }
             new XmlSettingsParser(ivy).parse(configurator, settingsURL);
         } finally {
@@ -395,29 +392,29 @@
         }
     }
 
-    private void propertiesStarted(Map attributes) {
+    /** Provide an URL referencing the given filepath.  If filePath is an absolute path, then
+     * the resulting URL point to a local file, otherwise, the filepath is evaluated relatively
+     * to the URL of the current settings file (can be local file or remote URL).
+     */
+    private URL urlFromFileAttribute(String filePath) throws MalformedURLException {
+        File incFile = new File(filePath);
+        if (incFile.isAbsolute()) {
+            return incFile.toURI().toURL();
+        } else {
+            return new URL(this.settings , filePath);
+        }      
+    }
+
+    private void propertiesStarted(Map attributes) throws IOException {
         String propFilePath = (String) attributes.get("file");
         String environmentPrefix = (String) attributes.get("environment");
         if (propFilePath != null) {
-            String override = (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);
-                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);
-                }
-            }
+            String overrideStr = (String) attributes.get("override");
+            boolean override = overrideStr == null ? true 
+                                                   : Boolean.valueOf(overrideStr).booleanValue();
+            Message.verbose("loading properties: " + propFilePath);
+            URL fileUrl = urlFromFileAttribute(propFilePath);
+            ivy.loadProperties(fileUrl, override);
         } else if (environmentPrefix != null) {
             ivy.getVariableContainer().setEnvironmentPrefix(environmentPrefix);
         } else {

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml?rev=678264&r1=678263&r2=678264&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-ref.xml Sun Jul 20 02:50:36 2008
@@ -17,7 +17,7 @@
    under the License.    
 -->
 <ivysettings>
-	<properties file="test/java/org/apache/ivy/core/settings/ivysettings.properties"/>
+	<properties file="ivysettings.properties"/>
 	<settings   defaultCache="mycache"/>
 	<resolvers>
 		<filesystem name="fs" latest="latest-time">

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-test.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-test.xml?rev=678264&r1=678263&r2=678264&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-test.xml (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-test.xml Sun Jul 20 02:50:36 2008
@@ -18,7 +18,7 @@
 -->
 <ivysettings>
 	<property name="shared" value="sharedrep"/>
-	<properties file="test/java/org/apache/ivy/core/settings/ivysettings.properties"/>
+	<properties file="ivysettings.properties"/>
 	<settings defaultResolver="libraries" validate="false" />
 	<caches defaultCacheDir="mycache" checkUpToDate="false"
 			ivyPattern="[module]/ivys/ivy-[revision].xml"