This is an automated email from the ASF dual-hosted git repository. jaikiran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ant-ivy.git
The following commit(s) were added to refs/heads/master by this push: new 370e52b IVY-1618 Don't change the dependency resolver configure on Ivy settings when setting the one on ResolveEngine 370e52b is described below commit 370e52b74af57333960b3bdcb01063f6c46ed357 Author: Jaikiran Pai <jaiki...@apache.org> AuthorDate: Mon Mar 29 09:33:15 2021 +0530 IVY-1618 Don't change the dependency resolver configure on Ivy settings when setting the one on ResolveEngine --- src/java/org/apache/ivy/core/resolve/IvyNode.java | 8 +++++- .../org/apache/ivy/core/resolve/ResolveEngine.java | 1 - .../apache/ivy/core/resolve/ResolveEngineTest.java | 30 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/ivy/core/resolve/IvyNode.java b/src/java/org/apache/ivy/core/resolve/IvyNode.java index b3da8c1..273488e 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNode.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNode.java @@ -165,7 +165,13 @@ public class IvyNode implements Comparable<IvyNode> { } else { markRootModuleConfLoaded(rootModuleConf); if (md == null) { - DependencyResolver resolver = data.getSettings().getResolver(getId()); + ResolveEngine engine = IvyContext.getContext().getIvy().getResolveEngine(); + // get the resolver configured on the engine and if none is configured then + // get the one configured in ivy settings + DependencyResolver resolver = engine.getDictatorResolver(); + if (resolver == null) { + resolver = data.getSettings().getResolver(getId()); + } if (resolver == null) { Message.error("no resolver found for " + getModuleId() + ": check your configuration"); diff --git a/src/java/org/apache/ivy/core/resolve/ResolveEngine.java b/src/java/org/apache/ivy/core/resolve/ResolveEngine.java index eb12618..7333e32 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolveEngine.java +++ b/src/java/org/apache/ivy/core/resolve/ResolveEngine.java @@ -126,7 +126,6 @@ public class ResolveEngine { */ public void setDictatorResolver(DependencyResolver dictatorResolver) { this.dictatorResolver = dictatorResolver; - settings.setDictatorResolver(dictatorResolver); } public ResolveReport resolve(File ivySource) throws ParseException, IOException { diff --git a/test/java/org/apache/ivy/core/resolve/ResolveEngineTest.java b/test/java/org/apache/ivy/core/resolve/ResolveEngineTest.java index 8fe5275..243e411 100644 --- a/test/java/org/apache/ivy/core/resolve/ResolveEngineTest.java +++ b/test/java/org/apache/ivy/core/resolve/ResolveEngineTest.java @@ -28,9 +28,11 @@ import org.apache.ivy.core.module.id.ModuleRevisionId; import org.apache.ivy.core.report.ArtifactDownloadReport; import org.apache.ivy.core.report.DownloadStatus; import org.apache.ivy.core.report.ResolveReport; +import org.apache.ivy.plugins.resolver.FileSystemResolver; import org.apache.ivy.util.CacheCleaner; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -87,6 +89,34 @@ public class ResolveEngineTest { "jar", "jar"), new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar")); } + /** + * Tests that setting the dictator resolver on the resolve engine doesn't change the + * dependency resolver set in the Ivy settings. See IVY-1618 for details. + */ + @Test + public void testSetDictatorResolver() throws Exception { + final Ivy current = Ivy.newInstance(); + current.configure(new File("test/repositories/ivysettings.xml")); + final FileSystemResolver settingsResolver = new FileSystemResolver(); + settingsResolver.setName("resolver-1"); + current.getSettings().setDictatorResolver(settingsResolver); + + final ResolveEngine engine = new ResolveEngine(current.getSettings(), current.getEventManager(), + current.getSortEngine()); + final FileSystemResolver engineResolver = new FileSystemResolver(); + engineResolver.setName("resolver-2"); + engine.setDictatorResolver(engineResolver); + + Assert.assertNotNull("Resolver is null on engine", engine.getDictatorResolver()); + Assert.assertSame("Unexpected resolver on engine", engineResolver, engine.getDictatorResolver()); + + final ModuleRevisionId dummy = ModuleRevisionId.newInstance("foo", "bar", "1.2.3"); + Assert.assertNotNull("Resolver is null on Ivy settings", current.getSettings().getResolver(dummy)); + Assert.assertSame("Unexpected resolver on Ivy settings", settingsResolver, + current.getSettings().getResolver(dummy)); + + } + private void testLocateThenDownload(ResolveEngine engine, Artifact artifact, File artifactFile) { ArtifactOrigin origin = engine.locate(artifact); assertNotNull(origin);