You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by xa...@apache.org on 2007/05/16 13:47:50 UTC

svn commit: r538591 [2/2] - in /incubator/ivy/core/trunk: ./ doc/ doc/doc/tutorial/ doc/doc/tutorial/build-repository/ doc/doc/use/ src/example/build-a-ivy-repository/ src/example/chained-resolvers/chainedresolvers-project/ src/example/dependence/confi...

Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java?view=auto&rev=538591
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java Wed May 16 06:47:47 2007
@@ -0,0 +1,73 @@
+/*
+ *  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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.util.Message;
+
+public class IvyVariableContainerImpl implements IvyVariableContainer {
+
+	
+	private HashMap _variables = new HashMap();
+
+	/* (non-Javadoc)
+	 * @see org.apache.ivy.core.settings.IvyVariableContainer#setVariable(java.lang.String, java.lang.String, boolean)
+	 */
+	public void setVariable(String varName, String value, boolean overwrite) {
+        if (overwrite || !_variables.containsKey(varName)) {
+            Message.debug("setting '"+varName+"' to '"+value+"'");
+            _variables.put(varName, substitute(value));
+        } else {
+            Message.debug("'"+varName+"' already set: discarding '"+value+"'");
+        }
+
+	}
+
+	private String substitute(String value) {
+		return IvyPatternHelper.substituteVariables(value, getVariables());
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.ivy.core.settings.IvyVariableContainer#getVariables()
+	 */
+	public Map getVariables() {
+		return _variables;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.ivy.core.settings.IvyVariableContainer#getVariable(java.lang.String)
+	 */
+	public String getVariable(String name) {
+		String val = (String)_variables.get(name);
+        return val==null?val:substitute(val);
+	}
+	
+	public Object clone() {
+		IvyVariableContainerImpl clone;
+		try {
+			clone = (IvyVariableContainerImpl) super.clone();
+		} catch (CloneNotSupportedException e) {
+			throw new RuntimeException("unable to clone a " + this.getClass());
+		}
+		clone._variables = (HashMap) _variables.clone();
+		return clone;
+	}
+}

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

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java?view=diff&rev=538591&r1=538590&r2=538591
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/XmlSettingsParser.java Wed May 16 06:47:47 2007
@@ -204,7 +204,7 @@
                     }
                 }
             } else if ("include".equals(qName)) {
-                Map variables = new HashMap(_ivy.getVariables());
+                IvyVariableContainer variables = (IvyVariableContainer) _ivy.getVariableContainer().clone();
                 try {
                     String propFilePath = _ivy.substitute((String)attributes.get("file"));
                     URL settingsURL = null; 
@@ -231,7 +231,7 @@
                     }
                     new XmlSettingsParser(_ivy).parse(_configurator, settingsURL);
                 } finally {
-                    _ivy.setVariables(variables);
+                    _ivy.setVariableContainer(variables);
                 }
             } else if ("settings".equals(qName) || "conf".equals(qName)) {
             	if ("conf".equals(qName)) {

Modified: incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java?view=diff&rev=538591&r1=538590&r2=538591
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java (original)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java Wed May 16 06:47:47 2007
@@ -28,9 +28,11 @@
 import org.apache.ivy.plugins.resolver.IvyRepResolver;
 import org.apache.tools.ant.Project;
 
-
+/**
+ * Test the deprecated IvyConfigureTest and the underlying implementation 
+ * AntIvySettings.  When IvyConfigure will be removed, this class should be renamed AntIvySettingsTest
+ */
 public class IvyConfigureTest extends TestCase {
-    private File _cache;
     private IvyConfigure _configure;
     
     protected void setUp() throws Exception {
@@ -41,6 +43,10 @@
         _configure.setProject(project);
     }
 
+    private Ivy getIvyInstance() {
+		return IvyAntSettings.getDefaultInstance(_configure.getProject()).getConfiguredIvyInstance();
+	}
+
     public void testDefault() throws Exception {
     	// by default configure look in the current directory for an ivysettings.xml file...
     	// but Ivy itself has one, and we don't want to use it
@@ -71,12 +77,13 @@
 		assertTrue(publicResolver instanceof IvyRepResolver);
     }
 
-    public void testFile() throws Exception {
+
+	public void testFile() throws Exception {
         _configure.setFile(new File("test/repositories/ivysettings.xml"));
         
         _configure.execute();
         
-        Ivy ivy = getIvyInstance();
+        Ivy ivy = _configure.getIvyInstance();
         assertNotNull(ivy);
 		IvySettings settings = ivy.getSettings();
         assertNotNull(settings);
@@ -98,7 +105,7 @@
         
         _configure.execute();
         
-        IvySettings settings = getIvyInstance().getSettings();
+        IvySettings settings = _configure.getIvyInstance().getSettings();
         
         assertEquals(new File("build/cache"), settings.getDefaultCache());
         assertEquals(confUrl, settings.getVariables().get("ivy.settings.url"));
@@ -112,7 +119,7 @@
         
         _configure.execute();
         
-        IvySettings settings = getIvyInstance().getSettings();
+        IvySettings settings = _configure.getIvyInstance().getSettings();
         assertNotNull(settings);
         
         assertEquals("myvalue", settings.getVariables().get("myproperty"));
@@ -125,14 +132,10 @@
         
         _configure.execute();
         
-        IvySettings settings = getIvyInstance().getSettings();
+        IvySettings settings = _configure.getIvyInstance().getSettings();
         assertNotNull(settings);
         
         assertEquals("lib/test/[artifact]-[revision].[ext]", settings.getVariables().get("ivy.retrieve.pattern"));
-    }
-
-    private Ivy getIvyInstance() {
-        return (Ivy)_configure.getProject().getReference("ivy.instance");
     }
 
 }

Added: incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyTaskTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyTaskTest.java?view=auto&rev=538591
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyTaskTest.java (added)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyTaskTest.java Wed May 16 06:47:47 2007
@@ -0,0 +1,72 @@
+package org.apache.ivy.ant;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import org.apache.ivy.Ivy;
+import org.apache.ivy.core.settings.IvySettings;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Reference;
+
+import junit.framework.TestCase;
+
+public class IvyTaskTest extends TestCase {
+
+	public void testDefaultSettings() throws MalformedURLException {
+		Project p = new Project();
+		p.setBasedir("test/repositories");
+		//p.setProperty("ivy.settings.file" , "ivysettings.xml");
+		p.setProperty("myproperty", "myvalue");
+		IvyTask task = new IvyTask() {
+			public void doExecute() throws BuildException {
+			}
+		};
+		task.setProject(p);
+		
+        Ivy ivy = task.getIvyInstance();
+        assertNotNull(ivy);
+		IvySettings settings = ivy.getSettings();
+        assertNotNull(settings);
+        
+        assertEquals(new File("build/cache"), settings.getDefaultCache());
+        //The next test doesn't always works on windows (mix C: and c: drive)
+        assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath().toUpperCase(), new File((String)settings.getVariables().get("ivy.settings.file")).getAbsolutePath().toUpperCase());
+        assertEquals(new File("test/repositories/ivysettings.xml").toURL().toExternalForm().toUpperCase(), ((String)settings.getVariables().get("ivy.settings.url")).toUpperCase());
+        assertEquals(new File("test/repositories").getAbsolutePath().toUpperCase(), ((String)settings.getVariables().get("ivy.settings.dir")).toUpperCase());
+        assertEquals("myvalue", settings.getVariables().get("myproperty"));
+	}
+
+	public void testReferencedSettings() throws MalformedURLException {
+		Project p = new Project();
+		//p.setBasedir("test/repositories");
+		//p.setProperty("ivy.settings.file" , "ivysettings.xml");
+		p.setProperty("myproperty", "myvalue");
+		
+        IvyAntSettings antSettings = new IvyAntSettings();
+        antSettings.setProject(p);
+        //antSettings.setId("mySettings");
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
+        p.addReference("mySettings", antSettings);
+        
+		IvyTask task = new IvyTask() {
+			public void doExecute() throws BuildException {
+			}
+		};
+		task.setProject(p);
+		task.setSettingsRef(new Reference(p,"mySettings"));
+        Ivy ivy = task.getIvyInstance();
+        assertNotNull(ivy);
+		IvySettings settings = ivy.getSettings();
+        assertNotNull(settings);
+        
+        assertEquals(new File("build/cache"), settings.getDefaultCache());
+        assertEquals(new File("test/repositories/ivysettings.xml").getAbsolutePath(), settings.getVariables().get("ivy.settings.file"));
+        assertEquals(new File("test/repositories/ivysettings.xml").toURL().toExternalForm(), settings.getVariables().get("ivy.settings.url"));
+        assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables().get("ivy.settings.dir"));
+        assertEquals("myvalue", settings.getVariables().get("myproperty"));
+
+	}
+
+
+}

Propchange: incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyTaskTest.java
------------------------------------------------------------------------------
    svn:eol-style = native