From ffa3cf166b0ac97da2c896842cfcd02110152834 Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Fri, 28 Apr 2006 12:59:21 +0000 Subject: [PATCH] IMPROVE: add wildcard support for extending configurations (IVY-235) (thanks to Maarten Coene) git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/trunk@484317 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + src/java/fr/jayasoft/ivy/Configuration.java | 38 +++++++++++++++++++ .../ivy/xml/XmlModuleDescriptorParser.java | 11 +++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index acb57b04..5d0b834e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -32,6 +32,7 @@ for detailed view of each issue, please consult http://jira.jayasoft.org/ - NEW: add option to cachepath task to create a path with local artifact paths (IVY-221) - NEW: allow extending configurations to override the mapping of their super configurations (IVY-218) + - IMPROVE: add wildcard support for extending configurations (IVY-235) - IMPROVE: add support for xslt parameters in the report task (IVY-227) - IMPROVE: comments now aren't lost when delivering ivy files (IVY-226) - IMPROVE: add sort of 'fallback'-mapping to the defaultconfmapping attribute (IVY-215) diff --git a/src/java/fr/jayasoft/ivy/Configuration.java b/src/java/fr/jayasoft/ivy/Configuration.java index 4530a635..6a025de9 100644 --- a/src/java/fr/jayasoft/ivy/Configuration.java +++ b/src/java/fr/jayasoft/ivy/Configuration.java @@ -5,6 +5,9 @@ */ package fr.jayasoft.ivy; +import java.util.LinkedHashSet; +import java.util.Set; + import fr.jayasoft.ivy.extendable.DefaultExtendableItem; @@ -132,4 +135,39 @@ public class Configuration extends DefaultExtendableItem { public int hashCode() { return getName().hashCode(); } + + public void replaceWildcards(ModuleDescriptor md) { + if (this != md.getConfiguration(_name)) { + throw new IllegalArgumentException( + "The given ModuleDescriptor doesn't own this configuration!"); + } + + Configuration[] configs = md.getConfigurations(); + + Set newExtends = new LinkedHashSet(); + for (int j = 0; j < _extends.length; j++) { + if ("*".equals(_extends[j])) { + addOther(configs, null, newExtends); + } else if ("*(public)".equals(_extends[j])) { + addOther(configs, Visibility.PUBLIC, newExtends); + } else if ("*(private)".equals(_extends[j])) { + addOther(configs, Visibility.PRIVATE, newExtends); + } else { + newExtends.add(_extends[j]); + } + } + + this._extends = (String[]) newExtends.toArray(new String[newExtends.size()]); + } + + private void addOther(Configuration[] allConfigs, Visibility visibility, Set configs) { + for (int i = 0; i < allConfigs.length; i++) { + String currentName = allConfigs[i].getName(); + if (!_name.equals(currentName) + && ((visibility == null) || visibility.equals(allConfigs[i].getVisibility()))) { + configs.add(currentName); + } + } + } + } diff --git a/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java b/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java index 09c3d772..6102d92c 100644 --- a/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java +++ b/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorParser.java @@ -474,9 +474,18 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser { private void checkConfigurations() { if (_md.getConfigurations().length == 0) { _md.addConfiguration(new Configuration("default")); + } else { + replaceConfigurationWildcards(); } } - + + private void replaceConfigurationWildcards() { + Configuration[] configs = _md.getConfigurations(); + for (int i = 0; i < configs.length; i++) { + configs[i].replaceWildcards(_md); + } + } + }