ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject ant git commit: ensure defined order of filters in <replace>
Date Sun, 14 Feb 2016 09:49:11 GMT
Repository: ant
Updated Branches:
  refs/heads/master b25b8c4fa -> 4d0bbb440


ensure defined order of filters in <replace>

fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=58997


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/4d0bbb44
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/4d0bbb44
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/4d0bbb44

Branch: refs/heads/master
Commit: 4d0bbb44049a6add8043859c67253545e74c0c3a
Parents: b25b8c4
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun Feb 14 10:48:24 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun Feb 14 10:48:24 2016 +0100

----------------------------------------------------------------------
 WHATSNEW                                        |  5 +++++
 .../org/apache/tools/ant/taskdefs/Replace.java  | 23 +++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/4d0bbb44/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index 116ace1..3256f14 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -45,6 +45,11 @@ Fixed bugs:
    using different names.
    Bugzilla Report 57965
 
+ * <replace>'s result was undefined when using the replacefilterfile
+   attribute and some keys inside the properties files have been
+   substrings of other keys. Keys are now sorted by descending size.
+   Bugzilla Report 58997
+
 Other changes:
 --------------
 

http://git-wip-us.apache.org/repos/asf/ant/blob/4d0bbb44/src/main/org/apache/tools/ant/taskdefs/Replace.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java
index 9aa9fe8..31f24c7 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Replace.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java
@@ -31,8 +31,11 @@ import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.Iterator;
 import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
@@ -508,7 +511,7 @@ public class Replace extends MatchingTask {
         try {
             if (replaceFilterResource != null) {
                 Properties props = getProperties(replaceFilterResource);
-                Iterator e = props.keySet().iterator();
+                Iterator e = getOrderedIterator(props);
                 while (e.hasNext()) {
                     String tok =  e.next().toString();
                     Replacefilter replaceFilter = createReplacefilter();
@@ -952,4 +955,22 @@ public class Replace extends MatchingTask {
         }
     }
 
+    /**
+     * Sort keys by size so that tokens that are substrings of other
+     * strings are tried later.
+     */
+    private Iterator<Object> getOrderedIterator(Properties props) {
+        Set<Object> keys = new TreeSet(new Comparator<Object>() {
+                @Override
+                public int compare(Object key1, Object key2) {
+                    return compare(key1.toString(), key2.toString());
+                }
+
+                private int compare(String key1, String key2) {
+                    return key2.length() - key1.length();
+                }
+            });
+        keys.addAll(props.keySet());
+        return keys.iterator();
+    }
 }


Mime
View raw message