ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r649052 - in /ant/ivy/core/trunk/src/java/org/apache/ivy: core/settings/ plugins/parser/ plugins/parser/xml/ util/extendable/
Date Thu, 17 Apr 2008 10:59:42 GMT
Author: xavier
Date: Thu Apr 17 03:59:41 2008
New Revision: 649052

URL: http://svn.apache.org/viewvc?rev=649052&view=rev
Log:
add variable expansion in extra attributes (IVY-798)

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/ParserSettings.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java?rev=649052&r1=649051&r2=649052&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java Thu Apr 17 03:59:41
2008
@@ -31,6 +31,7 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -575,6 +576,24 @@
      */
     public String substitute(String str) {
         return IvyPatternHelper.substituteVariables(str, variableContainer);
+    }
+
+    /**
+     * Substitute variables in the given map values by their value found in the current set
of
+     * variables
+     * 
+     * @param strings
+     *            the map of strings in which substitution should be made
+     * @return a new map of strings in which all current ivy variables in values have been
+     *         substituted by their value
+     */
+    public Map/*<String, String>*/ substitute(Map/*<String, String>*/ strings)
{
+        Map substituted = new LinkedHashMap();
+        for (Iterator it = strings.entrySet().iterator(); it.hasNext();) {
+            Map.Entry entry = (Map.Entry) it.next();
+            substituted.put(entry.getKey(), substitute((String) entry.getValue()));
+        }
+        return substituted;
     }
 
     /**

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/ParserSettings.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/ParserSettings.java?rev=649052&r1=649051&r2=649052&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/ParserSettings.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/ParserSettings.java Thu Apr
17 03:59:41 2008
@@ -17,6 +17,8 @@
  */
 package org.apache.ivy.plugins.parser;
 
+import java.util.Map;
+
 import org.apache.ivy.core.RelativeUrlResolver;
 import org.apache.ivy.core.cache.ResolutionCacheManager;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
@@ -29,6 +31,8 @@
 public interface ParserSettings {
 
     String substitute(String value);
+    
+    Map/*<String, String>*/ substitute(Map/*<String, String>*/ strings);
     
     ResolutionCacheManager getResolutionCacheManager();
 

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java?rev=649052&r1=649051&r2=649052&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
Thu Apr 17 03:59:41 2008
@@ -450,7 +450,7 @@
                                             : visibility), ivy.substitute(attributes
                                     .getValue("description")), ext == null ? null : ext
                                     .split(","), transitive, deprecated);
-                    ExtendableItemHelper.fillExtraAttributes(configuration, attributes,
+                    ExtendableItemHelper.fillExtraAttributes(ivy, configuration, attributes,
                         new String[] {"name", "visibility", "extends", "transitive",
                                 "description", "deprecated"});
                     getMd().addConfiguration(configuration);
@@ -511,7 +511,7 @@
             String revConstraint = ivy.substitute(attributes.getValue("revConstraint"));
             revConstraint = revConstraint == null ? rev : revConstraint;
             Map extraAttributes = ExtendableItemHelper.getExtraAttributes(
-                attributes, DEPENDENCY_REGULAR_ATTRIBUTES);
+                ivy, attributes, DEPENDENCY_REGULAR_ATTRIBUTES);
             dd = new DefaultDependencyDescriptor(
                 getMd(), 
                 ModuleRevisionId.newInstance(org, name, branch, rev, extraAttributes), 
@@ -536,7 +536,7 @@
                 ext = ext != null ? ext : type;
                 String url = ivy.substitute(attributes.getValue("url"));
                 artifact = new MDArtifact(getMd(), artName, type, ext, url == null ? null
-                        : new URL(url), ExtendableItemHelper.getExtraAttributes(attributes,
+                        : new URL(url), ExtendableItemHelper.getExtraAttributes(ivy, attributes,
                     new String[] {"ext", "type", "name", "conf"}));
                 String confs = ivy.substitute(attributes.getValue("conf"));
                 // only add confs if they are specified. if they aren't, endElement will
@@ -597,7 +597,7 @@
             String revision = ivy.substitute(attributes.getValue("revision"));
             String branch = ivy.substitute(attributes.getValue("branch"));
             getMd().setModuleRevisionId(ModuleRevisionId.newInstance(org, module, branch,
-                revision, ExtendableItemHelper.getExtraAttributes(attributes, new String[]
{
+                revision, ExtendableItemHelper.getExtraAttributes(ivy, attributes, new String[]
{
                         "organisation", "module", "revision", "status", "publication",
                         "branch", "namespace", "default", "resolver"})));
 
@@ -691,8 +691,8 @@
             ext = ext != null ? ext : type;
             if (state == DEP_ARTIFACT) {
                 String url = ivy.substitute(attributes.getValue("url"));
-                Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[]
{
-                        "name", "type", "ext", "url", "conf"});
+                Map extraAtt = ExtendableItemHelper.getExtraAttributes(ivy, attributes, 
+                    new String[] {"name", "type", "ext", "url", "conf"});
                 confAware = new DefaultDependencyArtifactDescriptor(dd, name, type, ext,
                         url == null ? null : new URL(url), extraAtt);
             } else if (state == ARTIFACT_INCLUDE) {
@@ -702,8 +702,8 @@
                 String module = ivy.substitute(attributes.getValue("module"));
                 module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
                 ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
-                Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[]
{
-                        "org", "module", "name", "type", "ext", "matcher", "conf"});
+                Map extraAtt = ExtendableItemHelper.getExtraAttributes(ivy, attributes, 
+                    new String[] {"org", "module", "name", "type", "ext", "matcher", "conf"});
                 confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
             } else { // _state == ARTIFACT_EXCLUDE || EXCLUDE
                 PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
@@ -712,8 +712,8 @@
                 String module = ivy.substitute(attributes.getValue("module"));
                 module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
                 ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
-                Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[]
{
-                        "org", "module", "name", "type", "ext", "matcher", "conf"});
+                Map extraAtt = ExtendableItemHelper.getExtraAttributes(ivy, attributes, 
+                    new String[] {"org", "module", "name", "type", "ext", "matcher", "conf"});
                 confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
             }
             String confs = ivy.substitute(attributes.getValue("conf"));

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java?rev=649052&r1=649051&r2=649052&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
Thu Apr 17 03:59:41 2008
@@ -367,7 +367,7 @@
             
             String revision = substitute(settings, attributes.getValue("rev"));
             String revisionConstraint = substitute(settings, attributes.getValue("revConstraint"));
-            Map extraAttributes = ExtendableItemHelper.getExtraAttributes(attributes,
+            Map extraAttributes = ExtendableItemHelper.getExtraAttributes(settings, attributes,
                 XmlModuleDescriptorParser.DEPENDENCY_REGULAR_ATTRIBUTES);
             ModuleRevisionId localMrid = ModuleRevisionId.newInstance(org, module, branch,
                 revision, extraAttributes);
@@ -513,7 +513,7 @@
                 rev = substitute(settings, attributes.getValue("revision"));
             }
             ModuleRevisionId localMid = ModuleRevisionId.newInstance(organisation, module,
null,
-                rev, ExtendableItemHelper.getExtraAttributes(attributes,
+                rev, ExtendableItemHelper.getExtraAttributes(settings, attributes,
                     new String[] {"organisation", "module", "revision", "status", "publication",
                         "namespace"}));
             ModuleRevisionId systemMid = ns == null ? localMid : ns.getToSystemTransformer()

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java?rev=649052&r1=649051&r2=649052&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/extendable/ExtendableItemHelper.java Thu
Apr 17 03:59:41 2008
@@ -23,6 +23,7 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.ivy.plugins.parser.ParserSettings;
 import org.xml.sax.Attributes;
 
 public final class ExtendableItemHelper {
@@ -39,20 +40,21 @@
         return ret;
     }
 
-    public static Map getExtraAttributes(Attributes attributes, String[] ignoredAttNames)
{
+    public static Map getExtraAttributes(
+            ParserSettings settings, Attributes attributes, String[] ignoredAttNames) {
         Map ret = new HashMap();
         Collection ignored = Arrays.asList(ignoredAttNames);
         for (int i = 0; i < attributes.getLength(); i++) {
             if (!ignored.contains(attributes.getQName(i))) {
-                ret.put(attributes.getQName(i), attributes.getValue(i));
+                ret.put(attributes.getQName(i), settings.substitute(attributes.getValue(i)));
             }
         }
         return ret;
     }
 
-    public static void fillExtraAttributes(DefaultExtendableItem item, Attributes attributes,
-            String[] ignoredAttNames) {
-        Map att = getExtraAttributes(attributes, ignoredAttNames);
+    public static void fillExtraAttributes(ParserSettings settings, DefaultExtendableItem
item, 
+            Attributes attributes,  String[] ignoredAttNames) {
+        Map att = getExtraAttributes(settings, attributes, ignoredAttNames);
         for (Iterator iter = att.keySet().iterator(); iter.hasNext();) {
             String attName = (String) iter.next();
             String attValue = (String) att.get(attName);



Mime
View raw message