From 3eef3cd67eabcd699debf9e83f3ea717e75ea1ad Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Sat, 1 Mar 2008 13:01:45 +0000 Subject: [PATCH] IMPROVEMENT: add branch attribute in ivy:install task (IVY-727) git-svn-id: https://svn.apache.org/repos/asf/ant/ivy/core/trunk@632587 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + doc/use/install.html | 2 + src/java/org/apache/ivy/ant/IvyInstall.java | 20 +++++++++- .../org/apache/ivy/ant/IvyInstallTest.java | 38 +++++++++++-------- test/repositories/branches/ivysettings.xml | 4 ++ 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ceace23e..9b3d0629 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -65,6 +65,7 @@ for detailed view of each issue, please consult http://issues.apache.org/jira/br trunk version ===================================== - IMPROVEMENT: Make Ivy standalone runnable with no required dependencies (IVY-757) +- IMPROVEMENT: add branch attribute in ivy:install task (IVY-727) - FIX: XML schema ambiguity (IVY-750) - FIX: ivy-resolve fails when a project has different dependencies in different branches (IVY-717) diff --git a/doc/use/install.html b/doc/use/install.html index 3004f79a..3c83c19f 100644 --- a/doc/use/install.html +++ b/doc/use/install.html @@ -46,6 +46,8 @@ For more details about this task and its usage see the since 2.0 + No, defaults to default branch with exact matcher, '*' with any other matcher revisionthe revision of the module to install Yes validatetrue to force ivy files validation against ivy.xsd, false to force no validation diff --git a/src/java/org/apache/ivy/ant/IvyInstall.java b/src/java/org/apache/ivy/ant/IvyInstall.java index 68c1b6c5..686f9370 100644 --- a/src/java/org/apache/ivy/ant/IvyInstall.java +++ b/src/java/org/apache/ivy/ant/IvyInstall.java @@ -20,6 +20,7 @@ package org.apache.ivy.ant; import java.io.File; import org.apache.ivy.Ivy; +import org.apache.ivy.core.module.id.ModuleId; import org.apache.ivy.core.module.id.ModuleRevisionId; import org.apache.ivy.core.report.ResolveReport; import org.apache.ivy.core.settings.IvySettings; @@ -37,6 +38,8 @@ public class IvyInstall extends IvyTask { private String revision; + private String branch; + private boolean overwrite = false; private String from; @@ -76,6 +79,11 @@ public class IvyInstall extends IvyTask { } else if (revision == null && !PatternMatcher.EXACT.equals(matcher)) { revision = PatternMatcher.ANY_EXPRESSION; } + if (branch == null && PatternMatcher.EXACT.equals(matcher)) { + branch = settings.getDefaultBranch(ModuleId.newInstance(organisation, module)); + } else if (branch == null && !PatternMatcher.EXACT.equals(matcher)) { + branch = PatternMatcher.ANY_EXPRESSION; + } if (from == null) { throw new BuildException( "no from resolver name: please provide it through parameter 'from'"); @@ -84,7 +92,9 @@ public class IvyInstall extends IvyTask { throw new BuildException( "no to resolver name: please provide it through parameter 'to'"); } - ModuleRevisionId mrid = ModuleRevisionId.newInstance(organisation, module, revision); + ModuleRevisionId mrid = + ModuleRevisionId.newInstance(organisation, module, branch, revision); + ResolveReport report; try { report = ivy.install(mrid, from, to, transitive, doValidate(settings), overwrite, @@ -119,6 +129,14 @@ public class IvyInstall extends IvyTask { this.module = module; } + public String getBranch() { + return branch; + } + + public void setBranch(String branch) { + this.branch = branch; + } + public String getOrganisation() { return organisation; } diff --git a/test/java/org/apache/ivy/ant/IvyInstallTest.java b/test/java/org/apache/ivy/ant/IvyInstallTest.java index 1992072e..c3ec4f8a 100644 --- a/test/java/org/apache/ivy/ant/IvyInstallTest.java +++ b/test/java/org/apache/ivy/ant/IvyInstallTest.java @@ -21,9 +21,9 @@ import java.io.File; import junit.framework.TestCase; +import org.apache.ivy.util.FileUtil; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Delete; public class IvyInstallTest extends TestCase { private File cache; @@ -34,7 +34,7 @@ public class IvyInstallTest extends TestCase { protected void setUp() throws Exception { createCache(); - cleanTestLib(); + cleanInstall(); project = new Project(); project.setProperty("ivy.settings.file", "test/repositories/ivysettings.xml"); @@ -50,21 +50,29 @@ public class IvyInstallTest extends TestCase { protected void tearDown() throws Exception { cleanCache(); - cleanTestLib(); + cleanInstall(); } private void cleanCache() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(cache); - del.execute(); + FileUtil.forceDelete(cache); } - private void cleanTestLib() { - Delete del = new Delete(); - del.setProject(new Project()); - del.setDir(new File("build/test/lib")); - del.execute(); + private void cleanInstall() { + FileUtil.forceDelete(new File("build/test/install")); + } + + public void testInstallWithBranch() { + project.setProperty("ivy.settings.file", "test/repositories/branches/ivysettings.xml"); + install.setOrganisation("foo"); + install.setModule("foo1"); + install.setBranch("branch1"); + install.setRevision("2"); + install.setFrom("default"); + install.setTo("install"); + + install.execute(); + + assertTrue(new File("build/test/install/foo/foo1/branch1/ivy-2.xml").exists()); } public void testDependencyNotFoundFailure() { @@ -72,11 +80,11 @@ public class IvyInstallTest extends TestCase { install.setModule("yyy"); install.setRevision("zzz"); install.setFrom("test"); - install.setTo("1"); + install.setTo("install"); try { install.execute(); - fail("unknown dependency, failure expected (haltunresolved=true)"); + fail("unknown dependency, failure expected (haltonfailure=true)"); } catch (BuildException be) { // success } @@ -93,7 +101,7 @@ public class IvyInstallTest extends TestCase { try { install.execute(); } catch (BuildException be) { - fail("unknown dependency, failure unexepected (haltunresolved=false)"); + fail("unknown dependency, failure unexpected (haltonfailure=false). Failure: " + be); } } } diff --git a/test/repositories/branches/ivysettings.xml b/test/repositories/branches/ivysettings.xml index 9b910f72..0fe30bfe 100644 --- a/test/repositories/branches/ivysettings.xml +++ b/test/repositories/branches/ivysettings.xml @@ -23,5 +23,9 @@ + + + +