Repository: ant-ivy
Updated Branches:
  refs/heads/master 66da0319a -> df5930892


IVY-1447 Add "overwriteMode" option to Ivy command line for retrieve task


Project: http://git-wip-us.apache.org/repos/asf/ant-ivy/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-ivy/commit/df593089
Tree: http://git-wip-us.apache.org/repos/asf/ant-ivy/tree/df593089
Diff: http://git-wip-us.apache.org/repos/asf/ant-ivy/diff/df593089

Branch: refs/heads/master
Commit: df5930892d9c6eda392b96bdae2e7afd342f7866
Parents: 66da031
Author: Jaikiran Pai <jaiki...@apache.org>
Authored: Fri Jul 28 18:56:32 2017 +0530
Committer: Jaikiran Pai <jaiki...@apache.org>
Committed: Fri Jul 28 18:56:32 2017 +0530

----------------------------------------------------------------------
 asciidoc/release-notes.adoc            |  2 ++
 asciidoc/standalone.adoc               |  3 ++-
 src/java/org/apache/ivy/Main.java      |  7 +++++--
 test/java/org/apache/ivy/MainTest.java | 29 +++++++++++++++++++++++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/df593089/asciidoc/release-notes.adoc
----------------------------------------------------------------------
diff --git a/asciidoc/release-notes.adoc b/asciidoc/release-notes.adoc
index 5f541c6..cdad6e8 100644
--- a/asciidoc/release-notes.adoc
+++ b/asciidoc/release-notes.adoc
@@ -74,12 +74,14 @@ For details about the following changes, check our JIRA 
install at link:https://
 - IMPROVEMENT: Optimization: limit the revision numbers scanned if revision 
prefix is specified (Thanks to Ernestas Vaiciukevi&#269;ius)
 - IMPROVEMENT: Update bouncycastle to 1.52 (jira:IVY-1521[]) (Thanks to Michal 
Srb)
 - IMPROVEMENT: `symlinkmass` option of retrieve task has been deprecated in 
this release and will no longer be supported since, starting this version of 
Ivy, Ivy uses Java standard API(s) for symlink management and as such doesn't 
spawn a process to execute symlink creation shell commands, like it used to do 
eariler. The `symlinkmass` option was previously there to launch just one 
single process instead of multiple processes for symlink creation. Now with the 
usage of the Java standard API(s), this option no longer is relevant.
+- IMPROVEMENT: Ivy command line now supports passing `overwriteMode` option to 
`retrieve` task (jira:IVY-1447[])
 
 
 - NEW: Lets ssh-based resolvers use an ~/.ssh/config file to find 
username/hostname/keyfile options (Thanks to Colin Stanfill)
 - NEW: Add ivy.maven.lookup.sources and ivy.maven.lookup.javadoc variables to 
control the lookup of the additional artifacts. Defaults to true, for backward 
compatibility (jira:IVY-1529[])
 - NEW: Add (conditional) support for SHA-256 SHA-512 and SHA-384 checksum 
algorithms (jira:IVY-1554[]) (Thanks to Jaikiran Pai)
 
+
 ////
  Samples :
 - NEW: bla bla bla (jira:IVY-1234[]) (Thanks to Jane Doe)

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/df593089/asciidoc/standalone.adoc
----------------------------------------------------------------------
diff --git a/asciidoc/standalone.adoc b/asciidoc/standalone.adoc
index 9ed1a2f..1f7dfb2 100644
--- a/asciidoc/standalone.adoc
+++ b/asciidoc/standalone.adoc
@@ -46,7 +46,7 @@ usage: ivy
                               use this instead of ivy file to do the rest of 
the
                                work with this as a dependency.
  -confs <configurations>      resolve given configurations
- -types <types>               comma separated list of accepted artifact types
+ -types <types>               accepted artifact types
  -mode <resolvemode>          the resolve mode to use
  -notransitive                do not resolve dependencies transitively
 
@@ -55,6 +55,7 @@ usage: ivy
  -ivypattern <pattern>        use given pattern to copy the ivy files
  -sync                        use sync mode for retrieve
  -symlink                     create symbolic links
+ -overwriteMode <overwriteMode> use given overwrite mode for retrieve
 
 ==== cache path options
  -cachepath <cachepathfile>   outputs a classpath consisting of all 
dependencies

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/df593089/src/java/org/apache/ivy/Main.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/Main.java 
b/src/java/org/apache/ivy/Main.java
index c1d71a7..44eacc4 100644
--- a/src/java/org/apache/ivy/Main.java
+++ b/src/java/org/apache/ivy/Main.java
@@ -81,7 +81,7 @@ public final class Main {
                     new OptionBuilder("novalidate").description(
                         "do not validate ivy files against xsd").create())
                 .addOption(
-                    new OptionBuilder("m2compatible").description("use maven2 
compatibility")
+                    new OptionBuilder("m2compatible").description("use Maven 2 
compatibility")
                             .create())
                 .addOption(
                     new OptionBuilder("conf").arg("settingsfile").deprecated()
@@ -134,7 +134,9 @@ public final class Main {
                     new OptionBuilder("sync").description("use sync mode for 
retrieve").create())
                 .addOption(
                     new OptionBuilder("symlink").description("create symbolic 
links").create())
-
+                .addOption(new 
OptionBuilder("overwriteMode").arg("overwriteMode")
+                        .description("use given overwrite mode for retrieve")
+                        .create())
                 .addCategory("cache path options")
                 .addOption(
                     new OptionBuilder("cachepath")
@@ -330,6 +332,7 @@ public final class Main {
                         .setUseOrigin(line.hasOption("useOrigin"))
                         .setDestArtifactPattern(retrievePattern)
                         .setDestIvyPattern(ivyPattern)
+                        .setOverwriteMode(line.getOptionValue("overwriteMode"))
                         .setArtifactFilter(
                             
FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")))
                         .setMakeSymlinks(line.hasOption("symlink"))

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/df593089/test/java/org/apache/ivy/MainTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/MainTest.java 
b/test/java/org/apache/ivy/MainTest.java
index 0219f7f..427f97c 100644
--- a/test/java/org/apache/ivy/MainTest.java
+++ b/test/java/org/apache/ivy/MainTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ivy;
 
+import org.apache.ivy.core.retrieve.RetrieveOptions;
 import org.apache.ivy.util.CacheCleaner;
 import org.apache.ivy.util.cli.CommandLine;
 import org.apache.ivy.util.cli.ParseException;
@@ -27,6 +28,9 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -153,6 +157,31 @@ public class MainTest {
         assertTrue("jar type is missing from the parsed types argument", 
uniqueParsedTypes.contains("source"));
     }
 
+    /**
+     * Tests that the {@code overwriteMode} passed for the retrieve command 
works as expected
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testRetrieveOverwriteMode() throws Exception {
+        final String[] args = new String[]{"-settings", 
"test/repositories/ivysettings.xml", "-retrieve",
+                "build/test/main/retrieve/overwrite-test/[artifact].[ext]",
+                "-overwriteMode", "different",
+                "-ivy", "test/repositories/1/org/mod1/ivys/ivy-5.0.xml"};
+        final CommandLine parsedCommand = Main.getParser().parse(args);
+        final String parsedOverwriteMode = 
parsedCommand.getOptionValue("overwriteMode");
+        assertEquals("Unexpected overwriteMode parsed", 
RetrieveOptions.OVERWRITEMODE_DIFFERENT, parsedOverwriteMode);
+        // create a dummy file which we expect the retrieve task to overwrite
+        final Path retrieveArtifactPath = 
Paths.get("build/test/main/retrieve/overwrite-test/foo-bar.jar");
+        Files.createDirectories(retrieveArtifactPath.getParent());
+        Files.write(retrieveArtifactPath, new byte[0]);
+        assertEquals("Unexpected content at " + retrieveArtifactPath, 0, 
Files.readAllBytes(retrieveArtifactPath).length);
+        // issue the retrieve (which retrieves the org:foo-bar:2.3.4 artifact)
+        run(args);
+        // expect the existing jar to be overwritten
+        assertTrue("Content at " + retrieveArtifactPath + " was not 
overwritten by retrieve task", Files.readAllBytes(retrieveArtifactPath).length 
> 0);
+    }
+
     private void run(String[] args) throws Exception {
         Main.run(Main.getParser(), args);
     }

Reply via email to