ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r644326 - in /ant/ivy/core/trunk: ./ src/java/org/apache/ivy/core/settings/ src/java/org/apache/ivy/plugins/resolver/ test/java/org/apache/ivy/core/resolve/ test/java/org/apache/ivy/core/settings/
Date Thu, 03 Apr 2008 14:26:29 GMT
Author: xavier
Date: Thu Apr  3 07:26:27 2008
New Revision: 644326

URL: http://svn.apache.org/viewvc?rev=644326&view=rev
Log:
FIX: No error or warning when a resolver references a non-existent cache (IVY-777)

Added:
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/Validatable.java   (with props)
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-cache-invalid.xml
  (with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.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=644326&r1=644325&r2=644326&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Thu Apr  3 07:26:27 2008
@@ -76,6 +76,7 @@
 - IMPROVEMENT: Change allownomd and skipbuildwithoutivy into a more semantically correct
name (IVY-297)
 - IMPROVEMENT: Smarter determination if an expression is exact or not for RegexpPatternMatcher
and GlobPatternMatcher
 
+- FIX: No error or warning when a resolver references a non-existent cache (IVY-777)
 - FIX: ivy properties defined in an include file not available in the file that includes
it (IVY-780)
 - FIX: SFTPRepository.list(String) hides exceptions (IVY-751)
 - FIX: Wrong error message for republishing a module (IVY-752)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java?rev=644326&r1=644325&r2=644326&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java Thu Apr  3 07:26:27
2008
@@ -675,6 +675,13 @@
     public void setDefaultCache(File cacheDirectory) {
         setVariable("ivy.cache.dir", cacheDirectory.getAbsolutePath(), false);
         defaultCache = cacheDirectory;
+        if (defaultRepositoryCacheManager != null) {
+            if ("default-cache".equals(defaultRepositoryCacheManager.getName())
+                    && defaultRepositoryCacheManager instanceof DefaultRepositoryCacheManager)
{
+                ((DefaultRepositoryCacheManager) defaultRepositoryCacheManager)
+                    .setBasedir(defaultCache);
+            }
+        }
     }
 
     public void setDefaultResolver(String resolverName) {
@@ -735,10 +742,21 @@
     
     public void setDefaultRepositoryCacheBasedir(String repositoryCacheRoot) {
         setVariable("ivy.cache.repository", repositoryCacheRoot, true);
+        if (defaultRepositoryCacheManager != null
+                && "default-cache".equals(defaultRepositoryCacheManager.getName())
+                && defaultRepositoryCacheManager instanceof DefaultRepositoryCacheManager)
{
+            ((DefaultRepositoryCacheManager) defaultRepositoryCacheManager)
+                .setBasedir(getDefaultRepositoryCacheBasedir());
+        }
     }
     
     public void setDefaultResolutionCacheBasedir(String resolutionCacheRoot) {
         setVariable("ivy.cache.resolution", resolutionCacheRoot, true);
+        if (resolutionCacheManager != null
+                && resolutionCacheManager instanceof DefaultResolutionCacheManager)
{
+            ((DefaultResolutionCacheManager) resolutionCacheManager)
+                .setBasedir(getDefaultResolutionCacheBasedir());
+        }
     }
     
     public File getDefaultRepositoryCacheBasedir() {
@@ -1329,5 +1347,41 @@
             + " setting on the cache implementation instead");
         setDefaultUseOrigin(true);
         
+    }
+    
+    /**
+     * Validates the settings, throwing an {@link IllegalStateException} if the current state
is not
+     * valid.
+     * 
+     * @throws IllegalStateException
+     *             if the settings is not valid.
+     */
+    public void validate() {
+        validateAll(resolversMap.values());
+        validateAll(conflictsManager.values());
+        validateAll(latestStrategies.values());
+        validateAll(lockStrategies.values());
+        validateAll(repositoryCacheManagers.values());
+        validateAll(reportOutputters.values());
+        validateAll(circularDependencyStrategies.values());
+        validateAll(versionMatchers.values());
+        validateAll(namespaces.values());
+    }
+
+    /**
+     * Validates all {@link Validatable} objects in the collection.
+     * 
+     * @param objects
+     *            the collection of objects to validate.
+     * @throws IllegalStateException
+     *             if any of the objects is not valid.
+     */
+    private void validateAll(Collection values) {
+        for (Iterator iterator = values.iterator(); iterator.hasNext();) {
+            Object object = (Object) iterator.next();
+            if (object instanceof Validatable) {
+                ((Validatable) object).validate();
+            }
+        }
     }
 }

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/Validatable.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/Validatable.java?rev=644326&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/Validatable.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/Validatable.java Thu Apr  3 07:26:27
2008
@@ -0,0 +1,32 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.core.settings;
+
+/**
+ * Implemented by settings element which need to perform validation when settings are loaded.
+ */
+public interface Validatable {
+    /**
+     * Validates the Validatable, throwing an {@link IllegalStateException} if the current
state is
+     * not valid.
+     * 
+     * @throws IllegalStateException
+     *             if the state of the {@link Validatable} is not valid.
+     */
+    public void validate();
+}

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/Validatable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/Validatable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=644326&r1=644325&r2=644326&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 Thu Apr
 3 07:26:27 2008
@@ -146,6 +146,7 @@
             InputSource inSrc = new InputSource(stream);
             inSrc.setSystemId(settingsUrl.toExternalForm());
             SAXParserFactory.newInstance().newSAXParser().parse(settingsUrl.toExternalForm(),
this);
+            ivy.validate();
         } catch (IOException e) {
             throw e;
         } catch (Exception e) {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java?rev=644326&r1=644325&r2=644326&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java Thu
Apr  3 07:26:27 2008
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Map;
 
 import org.apache.ivy.core.IvyContext;
@@ -47,6 +48,7 @@
 import org.apache.ivy.core.search.ModuleEntry;
 import org.apache.ivy.core.search.OrganisationEntry;
 import org.apache.ivy.core.search.RevisionEntry;
+import org.apache.ivy.core.settings.Validatable;
 import org.apache.ivy.plugins.latest.LatestStrategy;
 import org.apache.ivy.plugins.namespace.NameSpaceHelper;
 import org.apache.ivy.plugins.namespace.Namespace;
@@ -57,7 +59,8 @@
 /**
  * This abstract resolver only provides handling for resolver name
  */
-public abstract class AbstractResolver implements DependencyResolver, HasLatestStrategy {
+public abstract class AbstractResolver 
+        implements DependencyResolver, HasLatestStrategy, Validatable {
 
     /**
      * True if parsed ivy files should be validated against xsd, false if they should not,
null if
@@ -196,24 +199,28 @@
 
     public LatestStrategy getLatestStrategy() {
         if (latestStrategy == null) {
-            if (getSettings() != null) {
-                if (latestStrategyName != null && !"default".equals(latestStrategyName))
{
-                    latestStrategy = getSettings().getLatestStrategy(latestStrategyName);
-                    if (latestStrategy == null) {
-                        Message.error("unknown latest strategy: " + latestStrategyName);
-                        latestStrategy = getSettings().getDefaultLatestStrategy();
-                    }
-                } else {
-                    latestStrategy = getSettings().getDefaultLatestStrategy();
-                    Message.debug(getName() + ": no latest strategy defined: using default");
+            initLatestStrategyFromSettings();
+        }
+        return latestStrategy;
+    }
+
+    private void initLatestStrategyFromSettings() {
+        if (getSettings() != null) {
+            if (latestStrategyName != null && !"default".equals(latestStrategyName))
{
+                latestStrategy = getSettings().getLatestStrategy(latestStrategyName);
+                if (latestStrategy == null) {
+                    throw new IllegalStateException(
+                        "unknown latest strategy '" + latestStrategyName + "'");
                 }
             } else {
-                throw new IllegalStateException(
-                    "no ivy instance found: "
-                    + "impossible to get a latest strategy without ivy instance");
+                latestStrategy = getSettings().getDefaultLatestStrategy();
+                Message.debug(getName() + ": no latest strategy defined: using default");
             }
+        } else {
+            throw new IllegalStateException(
+                "no ivy instance found: "
+                + "impossible to get a latest strategy without ivy instance");
         }
-        return latestStrategy;
     }
 
     public void setLatestStrategy(LatestStrategy latestStrategy) {
@@ -233,24 +240,28 @@
 
     public Namespace getNamespace() {
         if (namespace == null) {
-            if (getSettings() != null) {
-                if (namespaceName != null) {
-                    namespace = getSettings().getNamespace(namespaceName);
-                    if (namespace == null) {
-                        Message.error("unknown namespace: " + namespaceName);
-                        namespace = getSettings().getSystemNamespace();
-                    }
-                } else {
-                    namespace = getSettings().getSystemNamespace();
-                    Message.debug(getName() + ": no namespace defined: using system");
+            initNamespaceFromSettings();
+        }
+        return namespace;
+    }
+
+    private void initNamespaceFromSettings() {
+        if (getSettings() != null) {
+            if (namespaceName != null) {
+                namespace = getSettings().getNamespace(namespaceName);
+                if (namespace == null) {
+                    throw new IllegalStateException(
+                        "unknown namespace '" + namespaceName + "'");
                 }
             } else {
-                Message.verbose(getName()
-                        + ": no namespace defined nor ivy instance: using system namespace");
-                namespace = Namespace.SYSTEM_NAMESPACE;
+                namespace = getSettings().getSystemNamespace();
+                Message.debug(getName() + ": no namespace defined: using system");
             }
+        } else {
+            Message.verbose(getName()
+                    + ": no namespace defined nor ivy instance: using system namespace");
+            namespace = Namespace.SYSTEM_NAMESPACE;
         }
-        return namespace;
     }
 
     public void setNamespace(String namespaceName) {
@@ -324,16 +335,31 @@
     
     public RepositoryCacheManager getRepositoryCacheManager() {
         if (repositoryCacheManager == null) {
-            if (cacheManagerName == null) {
-                repositoryCacheManager = settings.getDefaultRepositoryCacheManager();
-            } else {
-                repositoryCacheManager = settings.getRepositoryCacheManager(cacheManagerName);
-            }
+            initRepositoryCacheManagerFromSettings();
         }
         return repositoryCacheManager;
     }
+
+    private void initRepositoryCacheManagerFromSettings() {
+        if (cacheManagerName == null) {
+            repositoryCacheManager = settings.getDefaultRepositoryCacheManager();
+            if (repositoryCacheManager == null) {
+                throw new IllegalStateException(
+                    "no default cache manager defined with current settings");
+            }
+        } else {
+            repositoryCacheManager = settings.getRepositoryCacheManager(cacheManagerName);
+            if (repositoryCacheManager == null) {
+                throw new IllegalStateException(
+                    "unknown cache manager '" + cacheManagerName 
+                    + "'. Available caches are " 
+                    + Arrays.asList(settings.getRepositoryCacheManagers()));
+            }
+        }
+    }
     
     public void setRepositoryCacheManager(RepositoryCacheManager repositoryCacheManager)
{
+        this.cacheManagerName = repositoryCacheManager.getName();
         this.repositoryCacheManager = repositoryCacheManager;
     }
     
@@ -347,6 +373,12 @@
     
     public EventManager getEventManager() {
         return eventManager;
+    }
+    
+    public void validate() {
+        initRepositoryCacheManagerFromSettings();
+        initNamespaceFromSettings();
+        initLatestStrategyFromSettings();
     }
 
     protected CacheMetadataOptions getCacheOptions(ResolveData data) {

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java?rev=644326&r1=644325&r2=644326&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java Thu Apr  3 07:26:27
2008
@@ -370,6 +370,7 @@
         Ivy ivy = new Ivy();
         ivy.configure(new File("test/repositories/bugIVY-56/ivysettings.xml"));
         ivy.getSettings().setDefaultCache(cache);
+        ivy.getSettings().validate();
 
         ResolveReport report = ivy.resolve(new File(
                 "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), getResolveOptions(ivy
@@ -682,6 +683,7 @@
             new File(ivy.getSettings().getDefaultCache(), "repository").getAbsolutePath());
         ivy.getSettings().setDefaultResolutionCacheBasedir(
             new File(ivy.getSettings().getDefaultCache(), "workspace").getAbsolutePath());
+        ivy.getSettings().validate();
         DefaultRepositoryCacheManager cacheMgr = 
             (DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager();
 

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=644326&r1=644325&r2=644326&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 Thu
Apr  3 07:26:27 2008
@@ -18,6 +18,7 @@
 package org.apache.ivy.core.settings;
 
 import java.io.File;
+import java.text.ParseException;
 import java.util.List;
 
 import junit.framework.TestCase;
@@ -219,6 +220,18 @@
         
         assertEquals(c2, settings.getResolver("A").getRepositoryCacheManager());
         assertEquals(c, settings.getResolver("B").getRepositoryCacheManager());
+    }
+
+    public void testInvalidCache() throws Exception {
+        IvySettings settings = new IvySettings();
+        XmlSettingsParser parser = new XmlSettingsParser(settings);
+        
+        try {
+            parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-cache-invalid.xml"));
+            fail("resolver referencing a non existent cache should raise an exception");
+        } catch (ParseException e) {
+            assertTrue(e.getMessage().indexOf("mycache") != -1);
+        }
     }
 
     public void testVersionMatchers1() throws Exception {

Added: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-cache-invalid.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-cache-invalid.xml?rev=644326&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-cache-invalid.xml
(added)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-cache-invalid.xml
Thu Apr  3 07:26:27 2008
@@ -0,0 +1,29 @@
+<!--
+   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>
+	<caches default="mycache2">
+		<cache name="mycache2" />
+	</caches>
+	<resolvers>
+		<filesystem name="B" cache="mycache">
+			<ivy pattern="${libraries.dir}/[organisation]/[module]/ivys/ivy-[revision].xml"/>
+			<artifact pattern="${libraries.dir}/[organisation]/[module]/[type]s/[artifact]-[revision].[type]"/>
+		</filesystem>
+	</resolvers>
+</ivysettings>

Propchange: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-cache-invalid.xml
------------------------------------------------------------------------------
    svn:eol-style = native

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



Mime
View raw message