ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r615445 - in /ant/ivy/core/trunk: ./ doc/use/ src/example/chained-resolvers/ src/example/chained-resolvers/chainedresolvers-project/ src/example/dependence/dependee/ src/example/dependence/depender/ src/example/dual/ src/example/dual/projec...
Date Sat, 26 Jan 2008 11:33:15 GMT
Author: xavier
Date: Sat Jan 26 03:33:09 2008
New Revision: 615445

URL: http://svn.apache.org/viewvc?rev=615445&view=rev
Log:
IMPROVEMENT: Review settings loading in Ant (IVY-703)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/build.xml
    ant/ivy/core/trunk/doc/use/settings.html
    ant/ivy/core/trunk/src/example/chained-resolvers/build.xml
    ant/ivy/core/trunk/src/example/chained-resolvers/chainedresolvers-project/build.xml
    ant/ivy/core/trunk/src/example/dependence/dependee/build.xml
    ant/ivy/core/trunk/src/example/dependence/depender/build.xml
    ant/ivy/core/trunk/src/example/dual/build.xml
    ant/ivy/core/trunk/src/example/dual/project/build.xml
    ant/ivy/core/trunk/src/example/multi-project/common/common.xml
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyAntSettingsTest.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Sat Jan 26 03:33:09 2008
@@ -66,6 +66,7 @@
 - NEW: Add ability for buildlist task to start build from specified module in the list (IVY-697)
(thanks to Mirko Bulovic)
 - NEW: Cache dynamic revision resolution (IVY-694)
 
+- IMPROVEMENT: Review settings loading in Ant (IVY-703)
 - IMPROVEMENT: Move useOrigin to repository cache manager (IVY-700)
 - IMPROVEMENT: Make IBiblio resolver compatible with maven proxy (IVY-466)
 - IMPROVEMENT: Use namespace aware validation (IVY-553)

Modified: ant/ivy/core/trunk/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/build.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/build.xml (original)
+++ ant/ivy/core/trunk/build.xml Sat Jan 26 03:33:09 2008
@@ -47,7 +47,7 @@
             </classpath>
         </taskdef>
     	
-        <ivy:settings id="ivy.instance" />
+        <ivy:settings id="ivy.instance" override="true"/>
     </target>
     
     <target name="install" depends="init-ivy-home, jar" 

Modified: ant/ivy/core/trunk/doc/use/settings.html
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/doc/use/settings.html?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/doc/use/settings.html (original)
+++ ant/ivy/core/trunk/doc/use/settings.html Sat Jan 26 03:33:09 2008
@@ -33,7 +33,7 @@
 Multiple settings can be defined in a build script.  Every task can reference its own settings.
 
 All Ivy variables set during the settings are available in the Ant project as long as they
were not set in Ant before (Ant properties are immutable). 
-Moreover, the variables are exposed under two names: the variable name, and the variable
name suffixed by dot + the settings id (if any). 
+Moreover, the variables are exposed under two names: the variable name, and the variable
name suffixed by dot + the settings id. 
 For instance, if you load a settings with the id 'myid', and define a variable my.variable=my.value
in the Ivy settings, both my.variable and my.variable.myid will now be available as properties
in Ant and equal to 'my.value'. If you later load another settings with the id 'yourid', and
in this settings assign the variable 'my.variable' the value 'your.value', in the Ant project
you will have:
 <code>
 my.variable=my.value
@@ -47,10 +47,11 @@
     <tr><th class="ant-att">Attribute</th><th class="ant-desc">Description</th><th
class="ant-req">Required</th></tr>
 </thead>
 <tbody>
-    <tr><td>id</td><td>The settings id useable in the refId attributes
of the ivy task that needs a setting.  Note that the ivy tasks will search by default for
the settings with the id "ivy.instance".</td><td>Yes</td></tr>
+    <tr><td>id</td><td>The settings id useable in the settingsRef
attributes of the ivy task that needs a setting.  Note that the ivy tasks will search by default
for the settings with the id "ivy.instance", which is the default value.</td><td>No,
defaults to "ivy.instance"</td></tr>
     <tr><td>file</td><td>path to the settings file to use</td>
-        <td rowspan="2">No. If a file is provided, url is ignored. If none are provided,
then it attempts to find a file at ${ivy.settings.file}, and if this file does not exist,
it uses a <a href="../tutorial/defaultconf.html">default settings file</a></td></tr>
+        <td rowspan="2">No. If a file is provided, url is ignored. If none are provided,
then it attempts to find a file at ${ivy.settings.file}, and if this file does not exist,
it uses a [[tutorial/defaultconf default settings file]]</td></tr>
     <tr><td>url</td><td>url of the settings file to use</td></tr>
+    <tr><td>override</td><td>Specify what to do when another settings
with the same id has already been loaded.<ul><li>true</li> the current settings
will take precedence over any previously defined setting with this id<li>false</li>
the current settings will not override a previously defined setting with this id<li>notallowed</li>an
error is raised if a settings has already been defined with this id</ul></td><td>No,
defaults to "notallowed"</td></tr>
     <tr><td>host</td><td>http authentication host</td><td
rowspan="4">No, unless authentication is required</td></tr>
     <tr><td>realm</td><td>http authentication realm</td></tr>
     <tr><td>username</td><td>http authentication user name</td></tr>
@@ -70,25 +71,28 @@
 
 <h2>Examples</h2>
 <h3>Simplest settings</h3>
-<code><ivy:settings id="ivy.instance"/></code>
+<code><ivy:settings /></code>
 Use either ${ivy.settings.file} if it exists, or the <a href="../samples/ivysettings-default.xml">default
settings file</a><br>
 This simplest setting is implicit.
 <h3>Configure with a file</h3>
-<code><ivy:settings id="ivy.instance" file="mysettings.xml" /></code>
+<code><ivy:settings file="mysettings.xml" /></code>
 <h3>Configure with an url</h3>
-<code><ivy:settings id="ivy.instance" url="http://mysite.com/mysettings.xml" /></code>
-<h3>Configure multiple URLs which require autentication</h3>
+<code><ivy:settings url="http://mysite.com/mysettings.xml" /></code>
+<h3>Configure multiple realms which require autentication</h3>
 <code>
-<ivy:settings id="authenticated.settings" file="path/to/my/ivysettings.xml">
+<ivy:settings file="path/to/my/ivysettings.xml">
   <credentials host="myhost.com" realm="My Realm" username="myuser" passwd="mypasswd"
/>
   <credentials host="yourhost.com" realm="Your Realm" username="myuser" passwd="myotherpasswd"
/>
-</ivy:configure> 
+</ivy:settings> 
 </code>
 <h3>Configure 2 different settings</h3>
-You can use multiple ivy settings during a build.  In that case, every ivy task has specify
the settings that it mmust use.
+You can use multiple ivy settings during a build. Then every ivy task should specify the
settings it uses using the settingsRef attribute.
 <code>
  <ivy:settings id="ivy.normal.settings" file="normal_settings.xml" />
  <ivy:settings id="ivy.release.settings" file="release_settings.xml" />
+
+ <ivy:resolve settingsRef="ivy.normal.settings" />
+ <ivy:resolve settingsRef="ivy.release.settings" />
 </code>
 </textarea>
 <script type="text/javascript">xooki.postProcess();</script>

Modified: ant/ivy/core/trunk/src/example/chained-resolvers/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/chained-resolvers/build.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/example/chained-resolvers/build.xml (original)
+++ ant/ivy/core/trunk/src/example/chained-resolvers/build.xml Sat Jan 26 03:33:09 2008
@@ -30,7 +30,7 @@
          ================================= -->
 	<target name="clean-cache" description="--> clean the ivy cache">
 		<property name="ivy.settings.dir" value="settings" />
-		<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" id="ivy.instance"/>
+		<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
 		<ivy:cleancache />
 	</target>
 	

Modified: ant/ivy/core/trunk/src/example/chained-resolvers/chainedresolvers-project/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/chained-resolvers/chainedresolvers-project/build.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/example/chained-resolvers/chainedresolvers-project/build.xml (original)
+++ ant/ivy/core/trunk/src/example/chained-resolvers/chainedresolvers-project/build.xml Sat
Jan 26 03:33:09 2008
@@ -34,7 +34,7 @@
         <path location="${build.dir}" />
     </path>
     
-    <ivy:settings file="${ivy.settings.dir}/ivysettings.xml" id="ivy.instance"/>
+    <ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
     
     <!-- ================================= 
           target: resolve              

Modified: ant/ivy/core/trunk/src/example/dependence/dependee/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/dependence/dependee/build.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/example/dependence/dependee/build.xml (original)
+++ ant/ivy/core/trunk/src/example/dependence/dependee/build.xml Sat Jan 26 03:33:09 2008
@@ -36,7 +36,7 @@
         <path location="${classes.dir}" />
     </path>
     
-    <ivy:settings id="ivy.instance" file="${ivy.settings.dir}/ivysettings.xml" />
+    <ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
     
     <!-- ================================= 
           target: resolve              

Modified: ant/ivy/core/trunk/src/example/dependence/depender/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/dependence/depender/build.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/example/dependence/depender/build.xml (original)
+++ ant/ivy/core/trunk/src/example/dependence/depender/build.xml Sat Jan 26 03:33:09 2008
@@ -36,7 +36,7 @@
         <path location="${classes.dir}" />
     </path>
 
-    <ivy:settings file="${ivy.settings.dir}/ivysettings.xml" id="ivy.instance"/>
+    <ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
     
     <!-- ================================= 
           target: resolve              

Modified: ant/ivy/core/trunk/src/example/dual/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/dual/build.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/example/dual/build.xml (original)
+++ ant/ivy/core/trunk/src/example/dual/build.xml Sat Jan 26 03:33:09 2008
@@ -30,7 +30,7 @@
          ================================= -->
 	<target name="clean-cache" description="--> clean the ivy cache">
 		<property name="ivy.settings.dir" value="settings" />
-		<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" id="ivy.instance"/>
+		<ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
 		<ivy:cleancache />
 	</target>
 	

Modified: ant/ivy/core/trunk/src/example/dual/project/build.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/dual/project/build.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/example/dual/project/build.xml (original)
+++ ant/ivy/core/trunk/src/example/dual/project/build.xml Sat Jan 26 03:33:09 2008
@@ -34,7 +34,7 @@
         <path location="${build.dir}" />
     </path>
     
-    <ivy:settings file="${ivy.settings.dir}/ivysettings.xml" id="ivy.instance"/>
+    <ivy:settings file="${ivy.settings.dir}/ivysettings.xml" />
     
     <!-- ================================= 
           target: resolve              

Modified: ant/ivy/core/trunk/src/example/multi-project/common/common.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/example/multi-project/common/common.xml?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/example/multi-project/common/common.xml (original)
+++ ant/ivy/core/trunk/src/example/multi-project/common/common.xml Sat Jan 26 03:33:09 2008
@@ -71,7 +71,7 @@
 	<property name="ivy.shared.default.root" value="${repository.dir}/shared"/>
 
    	<!-- here is how we would have configured ivy if we had our own ivysettings file
-    <ivy:settings file="${common.dir}/ivysettings.xml" id="ivy.instance" />
+    <ivy:settings file="${common.dir}/ivysettings.xml" />
     -->
 
 	

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyAntSettings.java Sat Jan 26 03:33:09
2008
@@ -23,6 +23,8 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.ParseException;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Properties;
 
 import org.apache.ivy.Ivy;
@@ -35,9 +37,10 @@
 import org.apache.ivy.util.url.URLHandlerRegistry;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.DataType;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Property;
 
-public class IvyAntSettings extends DataType {
+public class IvyAntSettings extends Task {
 
     public static class Credentials {
         private String realm;
@@ -81,6 +84,24 @@
         }
     }
 
+    /**
+     * Use to override a previous definition of settings with the same id 
+     */
+    public static final String OVERRIDE_TRUE = "true";
+    /**
+     * Use to avoid overriding a previous definition of settings with the same id
+     */
+    public static final String OVERRIDE_FALSE = "false";
+    /**
+     * Use to raise an error if attempting to override a previous definition of settings
with the
+     * same id
+     */
+    public static final String OVERRIDE_NOT_ALLOWED = "notallowed";
+
+    private static final Collection OVERRIDE_VALUES = Arrays.asList(new String[] {
+            OVERRIDE_TRUE, OVERRIDE_FALSE, OVERRIDE_NOT_ALLOWED
+    });
+
     private Ivy ivyEngine = null;
 
     private File file = null;
@@ -95,7 +116,9 @@
 
     private String passwd = null;
     
-    private String id = null;
+    private String id = "ivy.instance";
+
+    private String override = OVERRIDE_NOT_ALLOWED;
 
     /**
      * Returns the default ivy settings of this classloader. If it doesn't exist yet, a new
one is
@@ -123,16 +146,11 @@
                     + "A default instance will be used", Project.MSG_INFO);
             IvyAntSettings defaultInstance = new IvyAntSettings();
             defaultInstance.setProject(project);
-            defaultInstance.registerAsDefault();
+            defaultInstance.perform();
             return defaultInstance;
         } else {
             return (IvyAntSettings) defaultInstanceObj;
         }
-
-    }
-
-    protected void registerAsDefault() {
-        getProject().addReference("ivy.instance", this);
     }
 
     public File getFile() {
@@ -192,6 +210,14 @@
     public void setUrl(String confUrl) throws MalformedURLException {
         this.url = new URL(confUrl);
     }
+
+    public void setOverride(String override) {
+        if (!OVERRIDE_VALUES.contains(override)) {
+            throw new IllegalArgumentException("invalid override value '" + override + "'.
"
+                + "Valid values are " + OVERRIDE_VALUES);
+        }
+        this.override = override;
+    }
     
     /*
      * This is usually not necessary to define a reference in Ant, but it's the only
@@ -200,6 +226,10 @@
     public void setId(String id) {
         this.id = id;
     }
+    
+    public String getId() {
+        return id;
+    }
 
     /*
      * public void execute() throws BuildException { 
@@ -216,19 +246,40 @@
      */
     public Ivy getConfiguredIvyInstance() {
         if (ivyEngine == null) {
-            ivyEngine = createIvyEngine();
+            perform();
         }
         return ivyEngine;
     }
 
-    private Ivy createIvyEngine() {
+    public void execute() throws BuildException {
+        if (!OVERRIDE_TRUE.equals(override)) {
+            if (getProject().getReference(id) != null) {
+                if (OVERRIDE_FALSE.equals(override)) {
+                    verbose("a settings definition is already available for " + id + ": skipping");
+                    return;
+                } else {
+                    // OVERRIDE_NOT_ALLOWED
+                    throw new BuildException(
+                        "overriding a previous definition of ivy:settings with the id '"
+ id + "'" 
+                        + " is not allowed when using override='" + OVERRIDE_NOT_ALLOWED
+ "'.");
+                }
+            }
+        }
+        getProject().addReference(id, this);
+        Property prop = new Property() {
+            public void execute() throws BuildException {
+                addProperties(getDefaultProperties());
+            }
+        };
+        prop.setProject(getProject());
+        prop.execute();
+        createIvyEngine();
+    }
+
+    private void createIvyEngine() {
         IvyAntVariableContainer ivyAntVariableContainer = new IvyAntVariableContainer(getProject());
 
         IvySettings settings = new IvySettings(ivyAntVariableContainer);
-        // NB: It is already done in the ivy.configure, but it is required for
-        // defineDefaultSettingFile (that should be done before the ivy.configure
-        settings.addAllVariables(getDefaultProperties(), false);
-
         
         if (file == null && url == null) {
             defineDefaultSettingFile(ivyAntVariableContainer);
@@ -253,6 +304,7 @@
                 ivy.configure(url);
             }
             ivyAntVariableContainer.updateProject(id);
+            ivyEngine = ivy;
         } catch (ParseException e) {
             throw new BuildException("impossible to configure ivy:settings with given "
                     + (file != null ? "file: " + file : "url :" + url) + " :" + e, e);
@@ -262,7 +314,6 @@
         } finally {
             ivy.getLoggerEngine().popLogger();
         }
-        return ivy;
     }
 
     protected Properties getDefaultProperties() {
@@ -286,7 +337,7 @@
     }
 
     /**
-     * Set _file or _url to its default value
+     * Set file or url to its default value
      * 
      * @param variableContainer
      */

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyConfigure.java Sat Jan 26 03:33:09 2008
@@ -17,85 +17,23 @@
  */
 package org.apache.ivy.ant;
 
-import java.io.File;
-import java.net.MalformedURLException;
-import java.util.Properties;
-
 import org.apache.ivy.Ivy;
-import org.apache.ivy.ant.IvyAntSettings.Credentials;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.Property;
 
 /**
  * Configure Ivy with an ivysettings.xml file
  * 
  * @deprecated Use the IvyAntSettings instead.
  */
-public class IvyConfigure extends Task {
-
-    private IvyAntSettings antSettings = new IvyAntSettings();
-
+public class IvyConfigure extends IvyAntSettings {
     public void execute() throws BuildException {
         log("ivy:configure is deprecated, please use the data type ivy:settings instead",
             Project.MSG_WARN);
-        // ivyConfigure used to export properties in the ant script.
-        // ivy:settings doesn't.
-        try {
-            loadDefaultProperties();
-        } catch (Exception ex) {
-            throw new BuildException("impossible to load ivy default properties file: " +
ex, ex);
-        }
-        antSettings.registerAsDefault();
-    }
-
-    private void loadDefaultProperties() {
-        Property prop = new Property() {
-            public void execute() throws BuildException {
-                Properties props = antSettings.getDefaultProperties();
-                addProperties(props);
-            }
-        };
-        prop.setProject(getProject());
-        prop.execute();
-    }
-
-    public void addConfiguredCredentials(Credentials c) {
-        antSettings.addConfiguredCredentials(c);
-    }
-
-    public void setFile(File file) {
-        antSettings.setFile(file);
-    }
-
-    public void setHost(String host) {
-        antSettings.setHost(host);
-    }
-
-    public void setPasswd(String passwd) {
-        antSettings.setPasswd(passwd);
-    }
-
-    public void setProject(Project prj) {
-        super.setProject(prj);
-        antSettings.setProject(prj);
-    }
-
-    public void setRealm(String realm) {
-        antSettings.setRealm(realm);
-    }
-
-    public void setUrl(String confUrl) throws MalformedURLException {
-        antSettings.setUrl(confUrl);
-    }
-
-    public void setUsername(String userName) {
-        antSettings.setUsername(userName);
+        super.execute();
     }
 
     public Ivy getIvyInstance() {
-        return antSettings.getConfiguredIvyInstance();
+        return getConfiguredIvyInstance();
     }
-
 }

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyAntSettingsTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyAntSettingsTest.java?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyAntSettingsTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyAntSettingsTest.java Sat Jan 26 03:33:09
2008
@@ -19,28 +19,139 @@
 
 import java.io.File;
 
+import org.apache.ivy.Ivy;
+import org.apache.ivy.core.settings.IvySettings;
+import org.apache.ivy.plugins.resolver.DependencyResolver;
+import org.apache.ivy.plugins.resolver.IBiblioResolver;
+import org.apache.ivy.plugins.resolver.IvyRepResolver;
+import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 
 import junit.framework.TestCase;
 
 public class IvyAntSettingsTest extends TestCase {
     private IvyAntSettings antSettings;
+    private Project project;
 
     protected void setUp() throws Exception {
-        Project project = new Project();
+        project = new Project();
         project.setProperty("myproperty", "myvalue");
 
         antSettings = new IvyAntSettings();
         antSettings.setProject(project);
     }
+    
+    private Ivy getIvyInstance() {
+        return antSettings.getConfiguredIvyInstance();
+    }
+
+    public void testDefault() throws Exception {
+        // by default settings look in the current directory for an ivysettings.xml file...
+        // but Ivy itself has one, and we don't want to use it
+        antSettings.getProject()
+                .setProperty("ivy.settings.file", "no/settings/will/use/default.xml");
+        antSettings.execute();
+
+        IvySettings settings = getIvyInstance().getSettings();
+        assertNotNull(settings.getDefaultResolver());
+
+        DependencyResolver publicResolver = settings.getResolver("public");
+        assertNotNull(publicResolver);
+        assertTrue(publicResolver instanceof IBiblioResolver);
+        IBiblioResolver ibiblio = (IBiblioResolver) publicResolver;
+        assertTrue(ibiblio.isM2compatible());
+    }
+
+    public void testDefault14() throws Exception {
+        // by default settings look in the current directory for an ivysettings.xml file...
+        // but Ivy itself has one, and we don't want to use it
+        antSettings.getProject()
+                .setProperty("ivy.settings.file", "no/settings/will/use/default.xml");
+        antSettings.getProject().setProperty("ivy.14.compatible", "true");
+        antSettings.execute();
+
+        IvySettings settings = getIvyInstance().getSettings();
+        assertNotNull(settings.getDefaultResolver());
+
+        DependencyResolver publicResolver = settings.getResolver("public");
+        assertTrue(publicResolver instanceof IvyRepResolver);
+    }
+
+    public void testFile() throws Exception {
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
+
+        antSettings.execute();
+
+        Ivy ivy = 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().getVariable("ivy.settings.file"));
+        assertEquals(new File("test/repositories/ivysettings.xml").toURL().toExternalForm(),
+            settings.getVariables().getVariable("ivy.settings.url"));
+        assertEquals(new File("test/repositories").getAbsolutePath(), settings.getVariables().getVariable(
+            "ivy.settings.dir"));
+        assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
+    }
+
+    public void testURL() throws Exception {
+        String confUrl = new File("test/repositories/ivysettings.xml").toURL().toExternalForm();
+        String confDirUrl = new File("test/repositories").toURL().toExternalForm();
+        if (confDirUrl.endsWith("/")) {
+            confDirUrl = confDirUrl.substring(0, confDirUrl.length() - 1);
+        }
+        antSettings.setUrl(confUrl);
+
+        antSettings.execute();
+
+        IvySettings settings = getIvyInstance().getSettings();
+
+        assertEquals(new File("build/cache"), settings.getDefaultCache());
+        assertEquals(confUrl, settings.getVariables().getVariable("ivy.settings.url"));
+        assertEquals(confDirUrl, settings.getVariables().getVariable("ivy.settings.dir"));
+        assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
+    }
+
+    public void testAntProperties() throws Exception {
+        String confUrl = IvyConfigureTest.class.getResource("ivysettings-test.xml")
+                .toExternalForm();
+        antSettings.setUrl(confUrl);
+
+        antSettings.execute();
+
+        IvySettings settings = getIvyInstance().getSettings();
+        assertNotNull(settings);
+
+        assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
+        assertEquals("myvalue", settings.getDefaultCache().getName());
+    }
+
+    public void testOverrideVariables() throws Exception {
+        String confUrl = IvyConfigureTest.class.getResource("ivysettings-props.xml")
+                .toExternalForm();
+        antSettings.setUrl(confUrl);
+
+        antSettings.execute();
+
+        IvySettings settings = getIvyInstance().getSettings();
+        assertNotNull(settings);
+
+        assertEquals("lib/test/[artifact]-[revision].[ext]", 
+            settings.getVariables().getVariable("ivy.retrieve.pattern"));
+    }
 
     public void testExposeAntProperties() throws Exception {
         String confUrl = IvyConfigureTest.class.getResource("ivysettings-props.xml")
                 .toExternalForm();
         antSettings.setUrl(confUrl);
         antSettings.setId("this.id");
+        
+        antSettings.execute();
 
-        assertNotNull(antSettings.getConfiguredIvyInstance());
+        assertNotNull(getIvyInstance());
 
         assertEquals("value", 
             antSettings.getProject().getProperty("ivy.test.variable"));
@@ -51,10 +162,74 @@
     public void testIncludeTwice() throws Exception {
         // IVY-601
         antSettings.setFile(new File("test/java/org/apache/ivy/ant/ivysettings-include-twice.xml"));
-        antSettings.setId("this.id");
+        
+        antSettings.execute();
+
+        assertNotNull(getIvyInstance());
+    }
+
+    public void testOverrideTrue() throws Exception {
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
+        antSettings.execute();
 
-        assertNotNull(antSettings.getConfiguredIvyInstance());
+        Ivy ivy = getIvyInstance();
+        assertNotNull(ivy);
+
+        antSettings = new IvyAntSettings();
+        antSettings.setProject(project);
+        antSettings.setOverride(IvyAntSettings.OVERRIDE_TRUE);
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
+        antSettings.execute();
+        assertNotNull(getIvyInstance());
+        
+        assertTrue(ivy != getIvyInstance());
+    }
+
+    public void testOverrideFalse() throws Exception {
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
+        antSettings.execute();
+
+        Ivy ivy = getIvyInstance();
+        assertNotNull(ivy);
+
+        IvyAntSettings newAntSettings = new IvyAntSettings();
+        newAntSettings.setProject(project);
+        newAntSettings.setOverride(IvyAntSettings.OVERRIDE_FALSE);
+        newAntSettings.setFile(new File("test/repositories/ivysettings.xml"));
+        newAntSettings.execute();
+        
+        assertTrue(antSettings == project.getReference(newAntSettings.getId()));
+    }
+
+    public void testOverrideNotAllowed() throws Exception {
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
+        antSettings.execute();
+
+        Ivy ivy = getIvyInstance();
+        assertNotNull(ivy);
+
+        antSettings = new IvyAntSettings();
+        antSettings.setProject(project);
+        antSettings.setOverride(IvyAntSettings.OVERRIDE_NOT_ALLOWED);
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
+        
+        try {
+            antSettings.execute();
+            fail("calling settings twice with the same id with "
+                    + "override=notallowed should raise an exception");
+        } catch (BuildException e) {
+            assertTrue(e.getMessage().indexOf("notallowed") != -1);
+            assertTrue(e.getMessage().indexOf(antSettings.getId()) != -1);
+        }
     }
 
+    public void testInvalidOverride() throws Exception {
+        try {
+            antSettings.setOverride("unknown");
+            fail("settings override with invalid value should raise an exception");
+        } catch (Exception e) {
+            assertTrue(e.getMessage().indexOf("unknown") != -1);
+        }
+    }
 
 }

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCleanCacheTest.java Sat Jan 26 03:33:09
2008
@@ -37,9 +37,12 @@
         p.setProperty("cache", cacheDir.getAbsolutePath());
         cleanCache = new IvyCleanCache();
         cleanCache.setProject(p);
-        IvyAntSettings settings = IvyAntSettings.getDefaultInstance(p);
+        IvyAntSettings settings = new IvyAntSettings();
+        settings.setProject(p);
         settings.setUrl(
             IvyCleanCacheTest.class.getResource("ivysettings-cleancache.xml").toExternalForm());
+        settings.perform();
+        
         resolutionCache = new File(cacheDir, "resolution");
         repoCache = new File(cacheDir, "repository");
         repoCache2 = new File(cacheDir, "repository2");

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java?rev=615445&r1=615444&r2=615445&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyConfigureTest.java Sat Jan 26 03:33:09
2008
@@ -33,27 +33,26 @@
  * IvyConfigure will be removed, this class should be renamed AntIvySettingsTest
  */
 public class IvyConfigureTest extends TestCase {
-    private IvyConfigure configure;
+    private IvyAntSettings antSettings;
 
     protected void setUp() throws Exception {
         Project project = new Project();
         project.setProperty("myproperty", "myvalue");
 
-        configure = new IvyConfigure();
-        configure.setProject(project);
+        antSettings = new IvyAntSettings();
+        antSettings.setProject(project);
     }
 
     private Ivy getIvyInstance() {
-        return IvyAntSettings.getDefaultInstance(configure.getProject())
-                .getConfiguredIvyInstance();
+        return antSettings.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
-        configure.getProject()
+        antSettings.getProject()
                 .setProperty("ivy.settings.file", "no/settings/will/use/default.xml");
-        configure.execute();
+        antSettings.execute();
 
         IvySettings settings = getIvyInstance().getSettings();
         assertNotNull(settings.getDefaultResolver());
@@ -68,10 +67,10 @@
     public void testDefault14() 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
-        configure.getProject()
+        antSettings.getProject()
                 .setProperty("ivy.settings.file", "no/settings/will/use/default.xml");
-        configure.getProject().setProperty("ivy.14.compatible", "true");
-        configure.execute();
+        antSettings.getProject().setProperty("ivy.14.compatible", "true");
+        antSettings.execute();
 
         IvySettings settings = getIvyInstance().getSettings();
         assertNotNull(settings.getDefaultResolver());
@@ -81,11 +80,11 @@
     }
 
     public void testFile() throws Exception {
-        configure.setFile(new File("test/repositories/ivysettings.xml"));
+        antSettings.setFile(new File("test/repositories/ivysettings.xml"));
 
-        configure.execute();
+        antSettings.execute();
 
-        Ivy ivy = configure.getIvyInstance();
+        Ivy ivy = getIvyInstance();
         assertNotNull(ivy);
         IvySettings settings = ivy.getSettings();
         assertNotNull(settings);
@@ -107,11 +106,11 @@
         if (confDirUrl.endsWith("/")) {
             confDirUrl = confDirUrl.substring(0, confDirUrl.length() - 1);
         }
-        configure.setUrl(confUrl);
+        antSettings.setUrl(confUrl);
 
-        configure.execute();
+        antSettings.execute();
 
-        IvySettings settings = configure.getIvyInstance().getSettings();
+        IvySettings settings = getIvyInstance().getSettings();
 
         assertEquals(new File("build/cache"), settings.getDefaultCache());
         assertEquals(confUrl, settings.getVariables().getVariable("ivy.settings.url"));
@@ -122,11 +121,11 @@
     public void testAntProperties() throws Exception {
         String confUrl = IvyConfigureTest.class.getResource("ivysettings-test.xml")
                 .toExternalForm();
-        configure.setUrl(confUrl);
+        antSettings.setUrl(confUrl);
 
-        configure.execute();
+        antSettings.execute();
 
-        IvySettings settings = configure.getIvyInstance().getSettings();
+        IvySettings settings = getIvyInstance().getSettings();
         assertNotNull(settings);
 
         assertEquals("myvalue", settings.getVariables().getVariable("myproperty"));
@@ -136,27 +135,27 @@
     public void testExposeAntProperties() throws Exception {
         String confUrl = IvyConfigureTest.class.getResource("ivysettings-props.xml")
                 .toExternalForm();
-        configure.setUrl(confUrl);
+        antSettings.setUrl(confUrl);
         
-        configure.execute();
+        antSettings.execute();
 
-        assertNotNull(configure.getIvyInstance());
+        assertNotNull(getIvyInstance());
 
         assertEquals("value", 
-            configure.getProject().getProperty("ivy.test.variable"));
+            antSettings.getProject().getProperty("ivy.test.variable"));
 
-        assertEquals(configure.getIvyInstance().getSettings().getDefaultCache().getAbsolutePath(),

-            configure.getProject().getProperty("ivy.cache.dir"));
+        assertEquals(getIvyInstance().getSettings().getDefaultCache().getAbsolutePath(),

+            antSettings.getProject().getProperty("ivy.cache.dir"));
     }
 
     public void testOverrideVariables() throws Exception {
         String confUrl = IvyConfigureTest.class.getResource("ivysettings-props.xml")
                 .toExternalForm();
-        configure.setUrl(confUrl);
+        antSettings.setUrl(confUrl);
 
-        configure.execute();
+        antSettings.execute();
 
-        IvySettings settings = configure.getIvyInstance().getSettings();
+        IvySettings settings = getIvyInstance().getSettings();
         assertNotNull(settings);
 
         assertEquals("lib/test/[artifact]-[revision].[ext]", 



Mime
View raw message