You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ma...@apache.org on 2009/03/03 22:00:58 UTC

svn commit: r749749 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/core/settings/ test/java/org/apache/ivy/core/settings/

Author: maartenc
Date: Tue Mar  3 21:00:58 2009
New Revision: 749749

URL: http://svn.apache.org/viewvc?rev=749749&view=rev
Log:
IMPROVEMENT: ivy initialization shouldn't fail if properties file doesn't exist (IVY-1038)

Added:
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-properties-missing-file.xml   (with props)
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/XmlSettingsParserTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=749749&r1=749748&r2=749749&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Tue Mar  3 21:00:58 2009
@@ -85,6 +85,7 @@
 	
    trunk
 =====================================
+- IMPROVEMENT: ivy initialization shouldn't fail if properties file doesn't exist (IVY-1038)
 - IMPROVEMENT: ivy:resolve ant task does not support "branch" attribute (IVY-1035)
 - IMPROVEMENT: Ability to strip revConstraint attribute from delivered Ivy files (IVY-989)
 - IMPROVEMENT: enhanced error message when defining an artifact for an unknown configuration.

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=749749&r1=749748&r2=749749&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 Tue Mar  3 21:00:58 2009
@@ -18,6 +18,7 @@
 package org.apache.ivy.core.settings;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -431,7 +432,7 @@
      * 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 {
+    private URL urlFromFileAttribute(String filePath) throws IOException {
         try {
             return new URL(filePath);
         } catch (MalformedURLException e) {
@@ -440,10 +441,16 @@
         
         File incFile = new File(filePath);
         if (incFile.isAbsolute()) {
+            if (!incFile.exists()) {
+                throw new FileNotFoundException();
+            }
             return incFile.toURI().toURL();
         } else if ("file".equals(this.settings.getProtocol())) {
             try {
                 File settingsFile = new File(new URI(this.settings.toExternalForm()));
+                if (!settingsFile.exists()) {
+                    throw new FileNotFoundException();
+                }
                 return new File(settingsFile.getParentFile(), filePath).toURI().toURL();
             } catch (URISyntaxException e) {
                 return new URL(this.settings , filePath);
@@ -461,8 +468,12 @@
             boolean override = overrideStr == null ? true 
                                                    : Boolean.valueOf(overrideStr).booleanValue();
             Message.verbose("loading properties: " + propFilePath);
-            URL fileUrl = urlFromFileAttribute(propFilePath);
-            ivy.loadProperties(fileUrl, override);
+            try {
+                URL fileUrl = urlFromFileAttribute(propFilePath);
+                ivy.loadProperties(fileUrl, override);
+            } catch (FileNotFoundException e) {
+                // ignore...
+            }
         } else if (environmentPrefix != null) {
             ivy.getVariableContainer().setEnvironmentPrefix(environmentPrefix);
         } else {

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java?rev=749749&r1=749748&r2=749749&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java Tue Mar  3 21:00:58 2009
@@ -407,6 +407,18 @@
         assertEquals(testResolver, subresolvers.get(0));
     }
 
+    public void testPropertiesMissingFile() throws Exception {
+        IvySettings settings = new IvySettings();
+        XmlSettingsParser parser = new XmlSettingsParser(settings);
+        parser.parse(XmlSettingsParserTest.class.getResource(
+                                                "ivysettings-properties-missing-file.xml"));
+        
+        // no error must have been thrown, check that the parsing didn't stop...
+        DependencyResolver defaultResolver = settings.getDefaultResolver();
+        assertNotNull(defaultResolver);
+        assertEquals("libraries", defaultResolver.getName());
+    }
+    
     public void testInclude() throws Exception {
         IvySettings settings = new IvySettings();
         XmlSettingsParser parser = new XmlSettingsParser(settings);
@@ -463,7 +475,6 @@
         assertTrue(inc instanceof ChainResolver);
     }
 
-
     public void testIncludeMissingFile() throws Exception {
         IvySettings settings = new IvySettings();
         XmlSettingsParser parser = new XmlSettingsParser(settings);

Added: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-properties-missing-file.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-properties-missing-file.xml?rev=749749&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-properties-missing-file.xml (added)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-properties-missing-file.xml Tue Mar  3 21:00:58 2009
@@ -0,0 +1,52 @@
+<!--
+   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 file="missing-file.xml"/>
+
+    <property name="shared" value="${ivy.basedir}/sharedrep" override="false"/>
+    <properties file="ivysettings.properties" override="false" />
+    <settings defaultResolver="libraries" validate="false" />
+    <caches defaultCacheDir="${ivy.basedir}/mycache" checkUpToDate="false"
+            ivyPattern="[module]/ivys/ivy-[revision].xml" 
+            artifactPattern="[module]/[type]s/[artifact]-[revision].[ext]" />
+    <latest-strategies>
+        <latest-revision name="mylatest-revision">
+            <specialMeaning name="PRE" value="-2"/>
+            <specialMeaning name="QA" value="4"/>
+        </latest-revision>
+    </latest-strategies>
+    <resolvers>
+        <chain name="internal">
+            <filesystem name="int1" latest="latest-time">
+                <ivy pattern="${shared}/[organisation]/[module]/ivys/ivy-[revision].xml"/>
+                <artifact pattern="${shared}/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"/>
+            </filesystem>
+            <ibiblio name="int2"/>
+        </chain>
+        <filesystem name="libraries" latest="latest-revision">
+            <ivy pattern="${libraries.dir}/[organisation]/[module]/ivys/ivy-[revision].xml"/>
+            <artifact pattern="${libraries.dir}/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"/>
+        </filesystem>
+    </resolvers>
+    <modules>
+        <module organisation="apache" name="ivy*" revision="2*" matcher="glob" resolver="int2"/>
+        <module organisation="apache" name="ivy*" matcher="glob" resolver="int1"/>
+        <module organisation="apache" name=".*" resolver="internal"/>
+    </modules>
+</ivysettings>

Propchange: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-properties-missing-file.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain