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
This commit is contained in:
Xavier Hanin 2005-09-30 14:51:53 +00:00
parent 9c621e90fe
commit a2957640c3
18 changed files with 192 additions and 48 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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]);
}
}
}
}

View File

@ -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);
}
}

View File

@ -64,6 +64,7 @@ public interface ModuleDescriptor {
*/
Configuration[] getConfigurations();
String[] getConfigurationsNames();
String[] getPublicConfigurationsNames();
Artifact[] getArtifacts(String conf);
DependencyDescriptor[] getDependencies();

View File

@ -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

View File

@ -0,0 +1 @@
-

View File

@ -0,0 +1 @@
-

View File

@ -0,0 +1,16 @@
<ivy-module version="1.0">
<info organisation="org8"
module="mod8.1"
revision="1.0"
status="integration"
publication="20050930110000"
/>
<configurations>
<conf name="default"/>
<conf name="private" extends="default" visibility="private"/>
</configurations>
<publications>
<artifact name="a" type="txt" conf="default"/>
<artifact name="a-private" type="txt" conf="private"/>
</publications>
</ivy-module>

View File

@ -0,0 +1,15 @@
<ivy-module version="1.0">
<info organisation="org8"
module="mod8.2"
revision="1.0"
status="integration"
publication="20050930110000"
/>
<configurations>
<conf name="default"/>
<conf name="private" extends="default" visibility="private"/>
</configurations>
<dependencies>
<dependency name="mod8.1" rev="1.0" conf="default->private"/>
</dependencies>
</ivy-module>

View File

@ -0,0 +1,15 @@
<ivy-module version="1.0">
<info organisation="org8"
module="mod8.3"
revision="1.0"
status="integration"
publication="20050930110000"
/>
<configurations>
<conf name="default"/>
<conf name="private" extends="default" visibility="private"/>
</configurations>
<dependencies>
<dependency name="mod8.1" rev="1.0" conf="private->default"/>
</dependencies>
</ivy-module>

View File

@ -0,0 +1,14 @@
<ivy-module version="1.0">
<info organisation="org8"
module="mod8.4"
revision="1.0"
status="integration"
publication="20050930110000"
/>
<configurations>
<conf name="default"/>
</configurations>
<dependencies>
<dependency name="mod8.1" rev="1.0" conf="default->*"/>
</dependencies>
</ivy-module>

View File

@ -5,7 +5,7 @@
<configurations>
<conf name="default"/>
<conf name="global" extends="default" visibility="private"/>
<conf name="buildtime" visibility="private"/>
<conf name="buildtime"/>
<conf name="test" visibility="private"/>
</configurations>
<publications>

View File

@ -5,7 +5,7 @@
<configurations>
<conf name="default"/>
<conf name="global" extends="default" visibility="private"/>
<conf name="buildtime" visibility="private"/>
<conf name="buildtime"/>
<conf name="test" visibility="private"/>
</configurations>
<publications>

View File

@ -5,7 +5,7 @@
<configurations>
<conf name="default"/>
<conf name="global" extends="default" visibility="private"/>
<conf name="buildtime" visibility="private"/>
<conf name="buildtime"/>
<conf name="test" visibility="private"/>
</configurations>
<publications>

View File

@ -5,7 +5,7 @@
<configurations>
<conf name="default"/>
<conf name="global" extends="default" visibility="private"/>
<conf name="buildtime" visibility="private"/>
<conf name="buildtime"/>
<conf name="test" visibility="private"/>
</configurations>
<publications>

View File

@ -5,7 +5,7 @@
<configurations>
<conf name="default"/>
<conf name="global" extends="default" visibility="private"/>
<conf name="buildtime" visibility="private"/>
<conf name="buildtime"/>
<conf name="test" visibility="private"/>
</configurations>
<publications>

View File

@ -5,7 +5,7 @@
<configurations>
<conf name="default"/>
<conf name="global" extends="default" visibility="private"/>
<conf name="buildtime" visibility="private"/>
<conf name="buildtime"/>
<conf name="test" visibility="private"/>
</configurations>
<publications>