From 4f3d2075c5ff38cf24721983003db9a0747441ae Mon Sep 17 00:00:00 2001
From: David Turner <dturner@twitter.com>
Date: Wed, 23 Apr 2014 20:51:28 -0400
Subject: [PATCH] fix IVY-1399

---
 .../plugins/conflict/LatestConflictManager.java    | 10 +++++++
 .../conflict/LatestConflictManagerTest.java        | 31 ++++++++++++++++++++
 .../ivy/plugins/conflict/ivysettings-evicted.xml   | 29 +++++++++++++++++++
 test/repositories/IVY-1399/MyCompany/A/ivy-1.xml   | 32 +++++++++++++++++++++
 test/repositories/IVY-1399/MyCompany/A/lib/A-1.jar |  0
 test/repositories/IVY-1399/MyCompany/B/ivy-1.xml   | 33 ++++++++++++++++++++++
 test/repositories/IVY-1399/MyCompany/B/lib/B-1.jar |  0
 test/repositories/IVY-1399/MyCompany/C/ivy-1.xml   | 31 ++++++++++++++++++++
 test/repositories/IVY-1399/MyCompany/C/lib/C-1.jar |  0
 .../IVY-1399/MyCompany/target/ivy-1.xml            | 32 +++++++++++++++++++++
 .../IVY-1399/OtherCompany/prefers-later/ivy-1.xml  | 31 ++++++++++++++++++++
 .../prefers-later/lib/prefers-later-1.jar          |  0
 .../IVY-1399/conflicting-dependency/dep/ivy-1.xml  | 28 ++++++++++++++++++
 .../IVY-1399/conflicting-dependency/dep/ivy-2.xml  | 28 ++++++++++++++++++
 .../conflicting-dependency/dep/lib/dep-1.jar       |  0
 .../conflicting-dependency/dep/lib/dep-2.jar       |  0
 16 files changed, 285 insertions(+)
 create mode 100644 test/java/org/apache/ivy/plugins/conflict/ivysettings-evicted.xml
 create mode 100644 test/repositories/IVY-1399/MyCompany/A/ivy-1.xml
 create mode 100644 test/repositories/IVY-1399/MyCompany/A/lib/A-1.jar
 create mode 100644 test/repositories/IVY-1399/MyCompany/B/ivy-1.xml
 create mode 100644 test/repositories/IVY-1399/MyCompany/B/lib/B-1.jar
 create mode 100644 test/repositories/IVY-1399/MyCompany/C/ivy-1.xml
 create mode 100644 test/repositories/IVY-1399/MyCompany/C/lib/C-1.jar
 create mode 100644 test/repositories/IVY-1399/MyCompany/target/ivy-1.xml
 create mode 100644 test/repositories/IVY-1399/OtherCompany/prefers-later/ivy-1.xml
 create mode 100644 test/repositories/IVY-1399/OtherCompany/prefers-later/lib/prefers-later-1.jar
 create mode 100644 test/repositories/IVY-1399/conflicting-dependency/dep/ivy-1.xml
 create mode 100644 test/repositories/IVY-1399/conflicting-dependency/dep/ivy-2.xml
 create mode 100644 test/repositories/IVY-1399/conflicting-dependency/dep/lib/dep-1.jar
 create mode 100644 test/repositories/IVY-1399/conflicting-dependency/dep/lib/dep-2.jar

diff --git a/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java b/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java
index 7c851ac..aafe069 100644
--- a/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java
+++ b/src/java/org/apache/ivy/plugins/conflict/LatestConflictManager.java
@@ -103,6 +103,16 @@ public class LatestConflictManager extends AbstractConflictManager {
             }
         }
 
+        ArrayList unevicted = new ArrayList();
+        for (Iterator iter = conflicts.iterator(); iter.hasNext();) {
+            IvyNode node = (IvyNode) iter.next();
+            if (!node.isCompletelyEvicted())
+                unevicted.add(node);
+        }
+        if (unevicted.size() > 0) {
+            conflicts = unevicted;
+        }
+
         try {
             IvyNodeArtifactInfo latest = (IvyNodeArtifactInfo) getStrategy().findLatest(
                 toArtifactInfo(conflicts), null);
diff --git a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java
index 0da1c6e..2596e0a 100644
--- a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java
+++ b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java
@@ -187,6 +187,37 @@ public class LatestConflictManagerTest extends TestCase {
         }
     }
 
+    /*
+     * Test case for issue IVY-1399:
+     * Dependency tree:
+     * Mycompany#target;1
+     *     MyCompany#A;1
+     *         conflicting-dependency#dep;1
+     *         OtherCompany#prefers-later;1
+     *             conflicting-dependency#dep;2
+     *     MyCompany#B;1
+     *         MyCompany#A;1
+     *             ...
+     *         OtherCompany#prefers-later;1
+     *             ...
+     *         MyCompany#C;1
+     *             conflicting-dependency#dep;1
+     */
+    public void testEvictedModules() throws Exception {
+        ivy.configure(LatestConflictManagerTest.class
+                .getResource("ivysettings-evicted.xml"));
+
+        ivy.getSettings().setVariable("ivy.log.conflict.resolution", "true", true);
+        try {
+            ResolveReport report = ivy.resolve(
+                new File("test/repositories/IVY-1399/MyCompany/target/ivy-1.xml"),
+                getResolveOptions());
+            report.getConfigurationReport("all");
+        } catch (IllegalStateException e) {
+            fail("Resolving target should not throw an exception");
+        }
+    }
+
     private ResolveOptions getResolveOptions() {
         return new ResolveOptions().setValidate(false);
     }
diff --git a/test/java/org/apache/ivy/plugins/conflict/ivysettings-evicted.xml b/test/java/org/apache/ivy/plugins/conflict/ivysettings-evicted.xml
new file mode 100644
index 0000000..518c8bf
--- /dev/null
+++ b/test/java/org/apache/ivy/plugins/conflict/ivysettings-evicted.xml
@@ -0,0 +1,29 @@
+<!--
+   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.    
+-->
+<ivysettings>
+    <settings defaultCache="${ivy.basedir}/build/cache" defaultResolver="test" defaultConflictManager="latest-revision" />
+
+    <resolvers>
+       <filesystem name="test" latest="latest-revision" checkmodified="true">
+	<artifact pattern="${ivy.basedir}/test/repositories/IVY-1399/[organisation]/[module]/[type]/[artifact]-[revision].[ext]" />
+	<ivy pattern="${ivy.basedir}/test/repositories/IVY-1399/[organisation]/[module]/ivy-[revision].xml" />
+      </filesystem>
+   </resolvers>
+
+</ivysettings>
diff --git a/test/repositories/IVY-1399/MyCompany/A/ivy-1.xml b/test/repositories/IVY-1399/MyCompany/A/ivy-1.xml
new file mode 100644
index 0000000..8f9cd76
--- /dev/null
+++ b/test/repositories/IVY-1399/MyCompany/A/ivy-1.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="1.0">
+  <info organisation="MyCompany" module="A" revision="1" status="integration" publication="20140426010101"/>
+  <configurations>
+   <conf name="all"/>
+  </configurations>
+  <publications>
+    <artifact name="A" ext="jar" type="lib" conf="all"/>
+  </publications>
+  <dependencies>
+    <dependency org="conflicting-dependency" name="dep" rev="1" force="true"/>
+    <dependency org="OtherCompany" name="prefers-later" rev="1" force="true"/>
+  </dependencies>
+</ivy-module>
diff --git a/test/repositories/IVY-1399/MyCompany/A/lib/A-1.jar b/test/repositories/IVY-1399/MyCompany/A/lib/A-1.jar
new file mode 100644
index 0000000..e69de29
diff --git a/test/repositories/IVY-1399/MyCompany/B/ivy-1.xml b/test/repositories/IVY-1399/MyCompany/B/ivy-1.xml
new file mode 100644
index 0000000..eeab6ae
--- /dev/null
+++ b/test/repositories/IVY-1399/MyCompany/B/ivy-1.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="1.0">
+  <info organisation="MyCompany" module="B" revision="1" status="integration" publication="20140426010101"/>
+  <configurations>
+   <conf name="all"/>
+  </configurations>
+  <publications>
+    <artifact name="B" ext="jar" type="lib" conf="all"/>
+  </publications>
+  <dependencies>
+    <dependency org="MyCompany" name="A" rev="1" force="true"/>
+    <dependency org="OtherCompany" name="prefers-later" rev="1" force="true"/>
+    <dependency org="MyCompany" name="C" rev="1" force="true"/>
+  </dependencies>
+</ivy-module>
diff --git a/test/repositories/IVY-1399/MyCompany/B/lib/B-1.jar b/test/repositories/IVY-1399/MyCompany/B/lib/B-1.jar
new file mode 100644
index 0000000..e69de29
diff --git a/test/repositories/IVY-1399/MyCompany/C/ivy-1.xml b/test/repositories/IVY-1399/MyCompany/C/ivy-1.xml
new file mode 100644
index 0000000..8f09bb0
--- /dev/null
+++ b/test/repositories/IVY-1399/MyCompany/C/ivy-1.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="1.0">
+  <info organisation="MyCompany" module="C" revision="1" status="integration" publication="20140426010101"/>
+  <configurations>
+   <conf name="all"/>
+  </configurations>
+  <publications>
+    <artifact name="C" ext="jar" type="lib" conf="all"/>
+  </publications>
+  <dependencies>
+    <dependency org="conflicting-dependency" name="dep" rev="1" force="true"/>
+  </dependencies>
+</ivy-module>
diff --git a/test/repositories/IVY-1399/MyCompany/C/lib/C-1.jar b/test/repositories/IVY-1399/MyCompany/C/lib/C-1.jar
new file mode 100644
index 0000000..e69de29
diff --git a/test/repositories/IVY-1399/MyCompany/target/ivy-1.xml b/test/repositories/IVY-1399/MyCompany/target/ivy-1.xml
new file mode 100644
index 0000000..3201088
--- /dev/null
+++ b/test/repositories/IVY-1399/MyCompany/target/ivy-1.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="1.0">
+  <info organisation="MyCompany" module="target" revision="1" status="integration" publication="20140426010101"/>
+  <configurations>
+   <conf name="all"/>
+  </configurations>
+  <publications>
+    <artifact name="target" ext="jar" type="lib" conf="all"/>
+  </publications>
+  <dependencies>
+    <dependency org="MyCompany" name="A" rev="1" force="true"/>
+    <dependency org="MyCompany" name="B" rev="1" force="true"/>
+  </dependencies>
+</ivy-module>
diff --git a/test/repositories/IVY-1399/OtherCompany/prefers-later/ivy-1.xml b/test/repositories/IVY-1399/OtherCompany/prefers-later/ivy-1.xml
new file mode 100644
index 0000000..200f5f7
--- /dev/null
+++ b/test/repositories/IVY-1399/OtherCompany/prefers-later/ivy-1.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="1.0">
+  <info organisation="OtherCompany" module="prefers-later" revision="1" status="integration" publication="20140426010101"/>
+  <configurations>
+   <conf name="all"/>
+  </configurations>
+  <publications>
+    <artifact name="prefers-later" ext="jar" type="lib" conf="all"/>
+  </publications>
+  <dependencies>
+    <dependency org="conflicting-dependency" name="dep" rev="2" force="true" conf="all"/>
+  </dependencies>
+</ivy-module>
diff --git a/test/repositories/IVY-1399/OtherCompany/prefers-later/lib/prefers-later-1.jar b/test/repositories/IVY-1399/OtherCompany/prefers-later/lib/prefers-later-1.jar
new file mode 100644
index 0000000..e69de29
diff --git a/test/repositories/IVY-1399/conflicting-dependency/dep/ivy-1.xml b/test/repositories/IVY-1399/conflicting-dependency/dep/ivy-1.xml
new file mode 100644
index 0000000..80f2609
--- /dev/null
+++ b/test/repositories/IVY-1399/conflicting-dependency/dep/ivy-1.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="1.0">
+  <info organisation="conflicting-dependency" module="dep" revision="1" status="integration" publication="20140423010101"/>
+  <configurations>
+   <conf name="all"/>
+  </configurations>
+  <publications>
+    <artifact name="dep" ext="jar" type="lib" conf="all"/>
+  </publications>
+</ivy-module>
diff --git a/test/repositories/IVY-1399/conflicting-dependency/dep/ivy-2.xml b/test/repositories/IVY-1399/conflicting-dependency/dep/ivy-2.xml
new file mode 100644
index 0000000..bfc7e3e
--- /dev/null
+++ b/test/repositories/IVY-1399/conflicting-dependency/dep/ivy-2.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.    
+-->
+<ivy-module version="1.0">
+  <info organisation="conflicting-dependency" module="dep" revision="2" status="integration" publication="20140426010101"/>
+  <configurations>
+   <conf name="all"/>
+  </configurations>
+  <publications>
+    <artifact name="dep" ext="jar" type="lib" conf="all"/>
+  </publications>
+</ivy-module>
diff --git a/test/repositories/IVY-1399/conflicting-dependency/dep/lib/dep-1.jar b/test/repositories/IVY-1399/conflicting-dependency/dep/lib/dep-1.jar
new file mode 100644
index 0000000..e69de29
diff --git a/test/repositories/IVY-1399/conflicting-dependency/dep/lib/dep-2.jar b/test/repositories/IVY-1399/conflicting-dependency/dep/lib/dep-2.jar
new file mode 100644
index 0000000..e69de29
-- 
1.9.0.558.g83f887f.dirty

