From a2957640c363e2138970cf95bce17329f4c9d919 Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Fri, 30 Sep 2005 14:51:53 +0000 Subject: [PATCH] FIX: private conf not accessible from other modules (IVY-76) git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/trunk@484043 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../jayasoft/ivy/DefaultModuleDescriptor.java | 11 +++ src/java/fr/jayasoft/ivy/Ivy.java | 75 +++++++++---------- src/java/fr/jayasoft/ivy/IvyNode.java | 55 +++++++++++++- .../fr/jayasoft/ivy/ModuleDescriptor.java | 1 + test/java/fr/jayasoft/ivy/ResolveTest.java | 23 ++++++ test/repositories/2/mod8.1/a-1.0.txt | 1 + test/repositories/2/mod8.1/a-private-1.0.txt | 1 + test/repositories/2/mod8.1/ivy-1.0.xml | 16 ++++ test/repositories/2/mod8.2/ivy-1.0.xml | 15 ++++ test/repositories/2/mod8.3/ivy-1.0.xml | 15 ++++ test/repositories/2/mod8.4/ivy-1.0.xml | 14 ++++ .../IVY-84/repo/test/a/ivy-1.0.1.xml | 2 +- .../IVY-84/repo/test/a/ivy-1.0.2.xml | 2 +- .../IVY-84/repo/test/b/ivy-1.0.1.xml | 2 +- .../IVY-84/repo/test/b/ivy-1.0.2.xml | 2 +- .../IVY-84/repo/test/c/ivy-1.0.1.xml | 2 +- .../IVY-84/repo/test/c/ivy-1.0.2.xml | 2 +- 18 files changed, 192 insertions(+), 48 deletions(-) create mode 100644 test/repositories/2/mod8.1/a-1.0.txt create mode 100644 test/repositories/2/mod8.1/a-private-1.0.txt create mode 100644 test/repositories/2/mod8.1/ivy-1.0.xml create mode 100644 test/repositories/2/mod8.2/ivy-1.0.xml create mode 100644 test/repositories/2/mod8.3/ivy-1.0.xml create mode 100644 test/repositories/2/mod8.4/ivy-1.0.xml diff --git a/CHANGES.txt b/CHANGES.txt index da6f1cfe..07d49cf4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,4 @@ +- FIX: private conf not accessible from other modules (IVY-76) - FIX: root module configurations isolation bug fixed (IVY-84) - FIX: changed the place where ivy stores master ivy files in cache to not overlap with dependencies one (IVY-85) diff --git a/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java b/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java index 70728816..9ef8b072 100644 --- a/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java +++ b/src/java/fr/jayasoft/ivy/DefaultModuleDescriptor.java @@ -165,6 +165,17 @@ public class DefaultModuleDescriptor implements ModuleDescriptor { return (String[])_configurations.keySet().toArray(new String[_configurations.size()]); } + public String[] getPublicConfigurationsNames() { + List ret = new ArrayList(); + for (Iterator iter = _configurations.values().iterator(); iter.hasNext();) { + Configuration conf = (Configuration)iter.next(); + if (conf.getVisibility() == Configuration.Visibility.PUBLIC) { + ret.add(conf.getName()); + } + } + return (String[])ret.toArray(new String[ret.size()]); + } + /** * Returns the configuration object with the given name in the current module descriptor, null * if not found. diff --git a/src/java/fr/jayasoft/ivy/Ivy.java b/src/java/fr/jayasoft/ivy/Ivy.java index c730ab29..594fbb94 100644 --- a/src/java/fr/jayasoft/ivy/Ivy.java +++ b/src/java/fr/jayasoft/ivy/Ivy.java @@ -781,9 +781,9 @@ public class Ivy implements TransferListener { } ResolveData data = new ResolveData(this, cache, date, confReport, validate, dependenciesMap); - IvyNode node = new IvyNode(data, md, confs[i]); + IvyNode node = new IvyNode(data, md, confs[i], true); node.setRootModuleConf(confs[i]); - fetchDependencies(node, confs[i], false); + fetchDependencies(node, confs[i]); } } @@ -837,7 +837,7 @@ public class Ivy implements TransferListener { - private void fetchDependencies(IvyNode node, String conf, boolean shouldBePublic) { + private void fetchDependencies(IvyNode node, String conf) { resolveConflict(node, node.getParent(), Collections.EMPTY_SET); if (node.loadData(conf)) { @@ -847,10 +847,10 @@ public class Ivy implements TransferListener { if ("*".equals(conf)) { String[] confs = node.getDescriptor().getConfigurationsNames(); for (int i = 0; i < confs.length; i++) { - doFetchDependencies(node, confs[i], shouldBePublic); + doFetchDependencies(node, confs[i]); } } else { - doFetchDependencies(node, conf, shouldBePublic); + doFetchDependencies(node, conf); } } } @@ -859,49 +859,44 @@ public class Ivy implements TransferListener { IvyNode.EvictionData ed = node.getEvictedData(node.getRootModuleConf()); for (Iterator iter = ed.getSelected().iterator(); iter.hasNext();) { IvyNode selected = (IvyNode)iter.next(); - fetchDependencies(selected, conf, shouldBePublic); + fetchDependencies(selected, conf); } } } - private void doFetchDependencies(IvyNode node, String conf, boolean shouldBePublic) { + private void doFetchDependencies(IvyNode node, String conf) { Configuration c = node.getConfiguration(conf); - if (c == null) { - Message.error("configuration not found in "+node+": "+conf+". It was required from "+node.getParent()+" "+node.getParentConf()); - } else if (c.getVisibility() != Configuration.Visibility.PUBLIC && shouldBePublic) { - Message.error("configuration not public in "+node+": "+c+". It was required from "+node.getParent()+" "+node.getParentConf()); - } else { - // we handle the case where the asked configuration extends others: - // we have to first fetch the extended configurations - String[] extendedConfs = c.getExtends(); - if (extendedConfs.length > 0) { - node.updateConfsToFetch(Arrays.asList(extendedConfs)); - } - for (int i = 0; i < extendedConfs.length; i++) { - fetchDependencies(node, extendedConfs[i], false); - } - - if (node.getDependencyDescriptor() == null || node.getDependencyDescriptor().isTransitive()) { - Collection dependencies = node.getDependencies(conf, true); - for (Iterator iter = dependencies.iterator(); iter.hasNext();) { - IvyNode dep = (IvyNode)iter.next(); - if (dep.isCircular()) { - Message.warn("circular dependency found ! "+node.getId()+" depends on "+dep.getId()+" which is already on the same branch of dependency"); - continue; - } - String[] confs = dep.getRequiredConfigurations(node, conf); - for (int i = 0; i < confs.length; i++) { - fetchDependencies(dep, confs[i], shouldBePublic); - } - // if there are still confs to fetch (usually because they have - // been updated when evicting another module), we fetch them now - confs = dep.getConfsToFetch(); - for (int i = 0; i < confs.length; i++) { - fetchDependencies(dep, confs[i], shouldBePublic); - } + // we handle the case where the asked configuration extends others: + // we have to first fetch the extended configurations + String[] extendedConfs = c.getExtends(); + if (extendedConfs.length > 0) { + node.updateConfsToFetch(Arrays.asList(extendedConfs)); + } + for (int i = 0; i < extendedConfs.length; i++) { + fetchDependencies(node, extendedConfs[i]); + } + + if (node.getDependencyDescriptor() == null || node.getDependencyDescriptor().isTransitive()) { + Collection dependencies = node.getDependencies(conf, true); + for (Iterator iter = dependencies.iterator(); iter.hasNext();) { + IvyNode dep = (IvyNode)iter.next(); + if (dep.isCircular()) { + Message.warn("circular dependency found ! "+node.getId()+" depends on "+dep.getId()+" which is already on the same branch of dependency"); + continue; + } + String[] confs = dep.getRequiredConfigurations(node, conf); + for (int i = 0; i < confs.length; i++) { + fetchDependencies(dep, confs[i]); + } + // if there are still confs to fetch (usually because they have + // been updated when evicting another module), we fetch them now + confs = dep.getConfsToFetch(); + for (int i = 0; i < confs.length; i++) { + fetchDependencies(dep, confs[i]); } } } + } diff --git a/src/java/fr/jayasoft/ivy/IvyNode.java b/src/java/fr/jayasoft/ivy/IvyNode.java index 96de6c76..70d6c438 100644 --- a/src/java/fr/jayasoft/ivy/IvyNode.java +++ b/src/java/fr/jayasoft/ivy/IvyNode.java @@ -224,6 +224,8 @@ public class IvyNode { private Map _requiredConfs = new HashMap(); // Map (NodeConf in -> Set(String conf)) + private boolean _isRoot = false; + public IvyNode(ResolveData data, DependencyDescriptor dd) { _id = dd.getDependencyRevisionId(); @@ -233,9 +235,14 @@ public class IvyNode { } public IvyNode(ResolveData data, ModuleDescriptor md, String conf) { + this(data, md, conf, false); + } + + public IvyNode(ResolveData data, ModuleDescriptor md, String conf, boolean isRoot) { _id = md.getModuleRevisionId(); _md = md; _confsToFetch.add(conf); + _isRoot = true; // we do not register nodes created from ModuleDescriptor, cause they are // the root of resolve @@ -509,11 +516,23 @@ public class IvyNode { } if ("*".equals(conf)) { if (_md != null) { - _fetchedConfigurations.addAll(Arrays.asList(_md.getConfigurationsNames())); + _fetchedConfigurations.addAll(Arrays.asList(_md.getPublicConfigurationsNames())); _confsToFetch.clear(); - addRootModuleConfigurations(_rootModuleConf, _md.getConfigurationsNames()); + addRootModuleConfigurations(_rootModuleConf, _md.getPublicConfigurationsNames()); } } else { + if (_md != null) { + Configuration c = _md.getConfiguration(conf); + if (c == null) { + Message.error("configuration not found in "+this+": "+conf+". It was required from "+getParent()+" "+getParentConf()); + _confsToFetch.remove(conf); + return false; + } else if (!isRoot() && c.getVisibility() != Configuration.Visibility.PUBLIC) { + Message.error("configuration not public in "+this+": "+c+". It was required from "+getParent()+" "+getParentConf()); + _confsToFetch.remove(conf); + return false; + } + } if (loaded) { _fetchedConfigurations.add(conf); _confsToFetch.remove(conf); @@ -528,6 +547,10 @@ public class IvyNode { } + private boolean isRoot() { + return _isRoot ; + } + public IvyNode getRealNode() { IvyNode node = _data.getNode(getId()); return node == null ? this : node; @@ -725,6 +748,33 @@ public class IvyNode { return (String[]) depConfs.toArray(new String[depConfs.size()]); } + public void discardConf(String conf) { + discardConf(_rootModuleConf, conf); + } + + private void discardConf(String rootModuleConf, String conf) { + Set depConfs = (Set) _rootModuleConfs.get(rootModuleConf); + if (depConfs == null) { + depConfs = new HashSet(); + _rootModuleConfs.put(rootModuleConf, depConfs); + } + if (_md != null) { + // remove all given dependency configurations to the set + extended ones + Configuration c = _md.getConfiguration(conf); + if (conf != null) { + String[] exts = c.getExtends(); + for (int i = 0; i < exts.length; i++) { + discardConf(rootModuleConf, exts[i]); // recursive remove of extended configurations + } + depConfs.remove(c.getName()); + } else { + Message.warn("unknown configuration in "+getId()+": "+conf); + } + } else { + depConfs.remove(conf); + } + } + private void addRootModuleConfigurations(String rootModuleConf, String[] dependencyConfs) { Set depConfs = (Set) _rootModuleConfs.get(rootModuleConf); if (depConfs == null) { @@ -1009,4 +1059,5 @@ public class IvyNode { public boolean isFetched(String conf) { return _fetchedConfigurations.contains(conf); } + } diff --git a/src/java/fr/jayasoft/ivy/ModuleDescriptor.java b/src/java/fr/jayasoft/ivy/ModuleDescriptor.java index 8f084302..4a6e03c1 100644 --- a/src/java/fr/jayasoft/ivy/ModuleDescriptor.java +++ b/src/java/fr/jayasoft/ivy/ModuleDescriptor.java @@ -64,6 +64,7 @@ public interface ModuleDescriptor { */ Configuration[] getConfigurations(); String[] getConfigurationsNames(); + String[] getPublicConfigurationsNames(); Artifact[] getArtifacts(String conf); DependencyDescriptor[] getDependencies(); diff --git a/test/java/fr/jayasoft/ivy/ResolveTest.java b/test/java/fr/jayasoft/ivy/ResolveTest.java index 7cff71be..1fb67768 100644 --- a/test/java/fr/jayasoft/ivy/ResolveTest.java +++ b/test/java/fr/jayasoft/ivy/ResolveTest.java @@ -822,6 +822,29 @@ public class ResolveTest extends TestCase { assertTrue(!ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists()); } + public void testVisibility1() throws Exception { + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod8.2/ivy-1.0.xml").toURL(), + null, new String[] {"*"}, _cache, null, true); + + assertFalse(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a-private", "txt", "txt").exists()); + } + + public void testVisibility2() throws Exception { + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod8.3/ivy-1.0.xml").toURL(), + null, new String[] {"private"}, _cache, null, true); + + assertFalse(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a-private", "txt", "txt").exists()); + assertTrue(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a", "txt", "txt").exists()); + } + + public void testVisibility3() throws Exception { + ResolveReport report = _ivy.resolve(new File("test/repositories/2/mod8.4/ivy-1.0.xml").toURL(), + null, new String[] {"*"}, _cache, null, true); + + assertFalse(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a-private", "txt", "txt").exists()); + assertTrue(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a", "txt", "txt").exists()); + } + /////////////////////////////////////////////////////////// // here comes a series of test provided by Chris Rudd // about configuration mapping and eviction diff --git a/test/repositories/2/mod8.1/a-1.0.txt b/test/repositories/2/mod8.1/a-1.0.txt new file mode 100644 index 00000000..3cf20d57 --- /dev/null +++ b/test/repositories/2/mod8.1/a-1.0.txt @@ -0,0 +1 @@ +- \ No newline at end of file diff --git a/test/repositories/2/mod8.1/a-private-1.0.txt b/test/repositories/2/mod8.1/a-private-1.0.txt new file mode 100644 index 00000000..3cf20d57 --- /dev/null +++ b/test/repositories/2/mod8.1/a-private-1.0.txt @@ -0,0 +1 @@ +- \ No newline at end of file diff --git a/test/repositories/2/mod8.1/ivy-1.0.xml b/test/repositories/2/mod8.1/ivy-1.0.xml new file mode 100644 index 00000000..f72ca85f --- /dev/null +++ b/test/repositories/2/mod8.1/ivy-1.0.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/repositories/2/mod8.2/ivy-1.0.xml b/test/repositories/2/mod8.2/ivy-1.0.xml new file mode 100644 index 00000000..44006505 --- /dev/null +++ b/test/repositories/2/mod8.2/ivy-1.0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/test/repositories/2/mod8.3/ivy-1.0.xml b/test/repositories/2/mod8.3/ivy-1.0.xml new file mode 100644 index 00000000..e6c57c3c --- /dev/null +++ b/test/repositories/2/mod8.3/ivy-1.0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/test/repositories/2/mod8.4/ivy-1.0.xml b/test/repositories/2/mod8.4/ivy-1.0.xml new file mode 100644 index 00000000..2a0c19c2 --- /dev/null +++ b/test/repositories/2/mod8.4/ivy-1.0.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml b/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml index f1bcfa31..9ea456cd 100644 --- a/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml +++ b/test/repositories/IVY-84/repo/test/a/ivy-1.0.1.xml @@ -5,7 +5,7 @@ - + diff --git a/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml b/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml index d877ba63..9b9d3e1f 100644 --- a/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml +++ b/test/repositories/IVY-84/repo/test/a/ivy-1.0.2.xml @@ -5,7 +5,7 @@ - + diff --git a/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml b/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml index a8bd572f..5426f62b 100644 --- a/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml +++ b/test/repositories/IVY-84/repo/test/b/ivy-1.0.1.xml @@ -5,7 +5,7 @@ - + diff --git a/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml b/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml index 181bef41..9cd5d371 100644 --- a/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml +++ b/test/repositories/IVY-84/repo/test/b/ivy-1.0.2.xml @@ -5,7 +5,7 @@ - + diff --git a/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml b/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml index 328bd642..01d283e9 100644 --- a/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml +++ b/test/repositories/IVY-84/repo/test/c/ivy-1.0.1.xml @@ -5,7 +5,7 @@ - + diff --git a/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml b/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml index 7745b65d..0de01ab3 100644 --- a/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml +++ b/test/repositories/IVY-84/repo/test/c/ivy-1.0.2.xml @@ -5,7 +5,7 @@ - +