ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r644284 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/core/settings/XmlSettingsParser.java test/java/org/apache/ivy/core/settings/XmlSettingsParserTest.java test/java/org/apache/ivy/core/settings/ivysettings-macro.xml
Date Thu, 03 Apr 2008 12:34:25 GMT
Author: xavier
Date: Thu Apr  3 05:34:23 2008
New Revision: 644284

URL: http://svn.apache.org/viewvc?rev=644284&view=rev
Log:
FIX: ivy properties defined in an include file not available in the file that includes it
(IVY-780)

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
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=644284&r1=644283&r2=644284&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Thu Apr  3 05:34:23 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: 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)
 - FIX: resolve fails to put metadata in cache (IVY-779)

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=644284&r1=644283&r2=644284&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 05:34:23 2008
@@ -24,6 +24,7 @@
 import java.net.URL;
 import java.text.ParseException;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -50,6 +51,50 @@
 /**
  */
 public class XmlSettingsParser extends DefaultHandler {
+    /**
+     * Wraps an {@link IvyVariableContainer} delegating most method calls to the wrapped
instance,
+     * except for a set of variables which are only stored locally in the wrapper, and not
+     * propagated to the wrapped instance.
+     */
+    private static final class IvyVariableContainerWrapper implements IvyVariableContainer
{
+        private static final Collection SETTINGS_VARIABLES = Arrays.asList(new String[] {
+                "ivy.settings.dir", "ivy.settings.url", "ivy.settings.file",
+                "ivy.conf.dir", "ivy.conf.url", "ivy.conf.file"});
+        
+        private final IvyVariableContainer variables;
+
+        private Map localVariables = new HashMap();
+
+        private IvyVariableContainerWrapper(IvyVariableContainer variables) {
+            this.variables = variables;
+        }
+
+        public void setVariable(String varName, String value, boolean overwrite) {
+            if (SETTINGS_VARIABLES.contains(varName)) {
+                if (!localVariables.containsKey(varName) || overwrite) {
+                    localVariables.put(varName, value);
+                }
+            } else {
+                variables.setVariable(varName, value, overwrite);
+            }
+        }
+
+        public void setEnvironmentPrefix(String prefix) {
+            variables.setEnvironmentPrefix(prefix);
+        }
+
+        public String getVariable(String name) {
+            if (localVariables.containsKey(name)) {
+                return (String) localVariables.get(name);
+            }
+            return variables.getVariable(name);
+        }
+
+        public Object clone() {
+            throw new UnsupportedOperationException();
+        }
+    }
+
     private Configurator configurator;
 
     private List configuratorTags = Arrays.asList(new String[] {"resolvers", "namespaces",
@@ -307,8 +352,8 @@
     }
 
     private void includeStarted(Map attributes) throws IOException, ParseException {
-        IvyVariableContainer variables = (IvyVariableContainer) ivy.getVariableContainer()
-                .clone();
+        final IvyVariableContainer variables = (IvyVariableContainer) ivy.getVariableContainer();
+        ivy.setVariableContainer(new IvyVariableContainerWrapper(variables));
         try {
             String propFilePath = (String) attributes.get("file");
             URL settingsURL = null;

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=644284&r1=644283&r2=644284&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 05:34:23 2008
@@ -399,6 +399,9 @@
         assertEquals(1, ivyPatterns.size());
         assertEquals("included/myrep/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]",
             ivyPatterns.get(0));
+        
+        // properties defined in included file should be available to including file (IVY-780)
+        assertEquals("myvalue", settings.getVariable("ivy.test.prop"));
     }
 
     public void testParser() throws Exception {

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml?rev=644284&r1=644283&r2=644284&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/settings/ivysettings-macro.xml Thu Apr
 3 05:34:23 2008
@@ -17,6 +17,7 @@
    under the License.    
 -->
 <ivysettings>
+	<property name="ivy.test.prop" value="myvalue" />
 	<macrodef name="mymacro">
 		<attribute name="mymainrep"/>
 		<attribute name="mysecondrep"/>



Mime
View raw message