ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r959019 - in /ant/core/trunk: ./ docs/manual/Tasks/ src/main/org/apache/tools/ant/ src/main/org/apache/tools/ant/property/ src/main/org/apache/tools/ant/taskdefs/ src/tests/antunit/taskdefs/
Date Tue, 29 Jun 2010 16:16:42 GMT
Author: bodewig
Date: Tue Jun 29 16:16:41 2010
New Revision: 959019

URL: http://svn.apache.org/viewvc?rev=959019&view=rev
Log:
reinstate prefix handling of property task at the expense of even more state in a thread-unfriendly
class and with a new attribute on two tasks to make everybody happy.  PR 49373.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/Tasks/loadproperties.html
    ant/core/trunk/docs/manual/Tasks/property.html
    ant/core/trunk/src/main/org/apache/tools/ant/Main.java
    ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java
    ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Jun 29 16:16:41 2010
@@ -32,6 +32,14 @@ Changes that could break older environme
    onMissingExtensionPoint attribute.
    Bugzilla Report 49473.   
 
+ * When using <property file="..." prefix="..."/> properties defined
+   inside the same file will only get used in expansions if the ${}
+   reference uses the same prefix.  This is different from Ant 1.8.1
+   but is the same behavior Ant 1.8.0 and earlier exhibited.
+   A new attribute prefixValues can be used to re-enable the behavior
+   of Ant 1.8.1.
+   Bugzilla Report 49373.
+
 Fixed bugs:
 -----------
 

Modified: ant/core/trunk/docs/manual/Tasks/loadproperties.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/Tasks/loadproperties.html?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/Tasks/loadproperties.html (original)
+++ ant/core/trunk/docs/manual/Tasks/loadproperties.html Tue Jun 29 16:16:41 2010
@@ -33,10 +33,11 @@ Also if the file is missing, the build i
 than a warning being printed.
 </p>
 
-<p>If you want to simulate <a href="property.html">property</a>'s
-prefix attribute, please use <a
-href="../Types/filterchain.html#prefixlines">prefixlines</a>
-filter.</p>
+<p><strong>Note:</strong> the default value of this
+task's <code>prefixValues</code> attribute is different from the
+default value of the same attribute in
+the <a href="property.html"><code>&lt;property&gt;</code></a>
+task.</p>
 
 <h3>Parameters</h3>
 <table border="1" cellpadding="2" cellspacing="0">
@@ -78,6 +79,13 @@ filter.</p>
       a "." is appended to the prefix if not specified. <em>Since Ant 1.8.1</em></td>
     <td align="center" valign="top">No</td>
   </tr>
+  <tr>
+    <td valign="top">prefixValues</td>
+    <td valign="top">Whether to apply the prefix when expanding the
+      right hand side of the properties.
+      <em>Since Ant 1.8.2</em></td>
+    <td align="center" valign="top">No (default=<tt>true</tt>)</td>
+  </tr>
 </table>
 
 <h3>Parameters specified as nested elements</h3>

Modified: ant/core/trunk/docs/manual/Tasks/property.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/Tasks/property.html?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/Tasks/property.html (original)
+++ ant/core/trunk/docs/manual/Tasks/property.html Tue Jun 29 16:16:41 2010
@@ -155,6 +155,14 @@ SYSTEM).
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
+    <td valign="top">prefixValues</td>
+    <td valign="top">Whether to apply the prefix when expanding the
+      right hand side of properties loaded using <code>file</code>,
+      <code>resource</code>, or <code>url</code>.
+      <em>Since Ant 1.8.2</em></td>
+    <td align="center" valign="top">No (default=<tt>false</tt>)</td>
+  </tr>
+  <tr>
     <td valign="top">relative</td>
     <td valign="top">If set to <tt>true</tt> the relative path
       to <tt>basedir</tt> is set.  <em>Since Ant 1.8.0</em></td>
@@ -198,7 +206,7 @@ to be your home directory.  Where the &q
 the file system depends on the operating system version and the JVM implementation.
 On Unix based systems, this will map to the user's home directory. On modern Windows
 variants, this will most likely resolve to the user's directory in the &quot;Documents
-and Settings&quot; folder. Older windows variants such as Windows 98/ME are less
+and Settings&quot; or &quot;Users&quot; folder. Older windows variants such as
Windows 98/ME are less
 predictable, as are other operating system/JVM combinations.</p>
 
 <pre>
@@ -247,8 +255,12 @@ project, that team members can customize
 <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)">by
Sun</a>.
 This makes it hard for Team Ant to field bug reports about it.
 <li>Trailing spaces are not stripped. It may have been what you wanted.
-<li>Want unusual characters? Escape them \u0456 or \" style.
-<li>Ant Properties are expanded in the file.
+<li>Want unusual characters? Escape them \u0456 or \&quot; style.
+<li>Ant Properties are expanded in the file
+<li>If you want to expand properties defined inside the same file and
+  you use the prefix attribute of the task, you must use the same
+  prefix when expanding the properties or
+  set <code>prefixValues</code> to true.</li>
 </ol>
 In-file property expansion is very cool. Learn to use it.
 <p>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Main.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Main.java?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Main.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Main.java Tue Jun 29 16:16:41 2010
@@ -769,7 +769,7 @@ public class Main implements AntMain {
                 HashMap props = new HashMap(definedProps);
                 new ResolvePropertyMap(project, propertyHelper,
                                        propertyHelper.getExpanders())
-                    .resolveAllProperties(props, null);
+                    .resolveAllProperties(props, null, false);
 
                 // set user-define properties
                 for (Iterator e = props.entrySet().iterator(); e.hasNext(); ) {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/property/ResolvePropertyMap.java Tue Jun
29 16:16:41 2010
@@ -36,6 +36,12 @@ public class ResolvePropertyMap implemen
     private final GetProperty master;
     private Map map;
     private String prefix;
+    // whether properties of the value side of the map should be
+    // expanded
+    private boolean prefixValues = false;
+    // whether the current getProperty call is expanding the key side
+    // of the map
+    private boolean expandingLHS = true;
 
     /**
      * Constructor with a master getproperty and a collection of expanders.
@@ -59,19 +65,20 @@ public class ResolvePropertyMap implemen
                 "Property " + name + " was circularly " + "defined.");
         }
 
-        // if the property has already been set to the name it will
-        // have in the end, then return the existing value to ensure
-        // properties remain immutable
-        String masterPropertyName = name;
-        if (prefix != null) {
-            masterPropertyName = prefix + name;
-        }
-        Object masterProperty = master.getProperty(masterPropertyName);
-        if (masterProperty != null) {
-            return masterProperty;
-        }
-
         try {
+            String fullKey = name;
+            if (prefix != null && prefixValues) {
+                fullKey = prefix + name;
+            }
+            Object masterValue = expandingLHS
+                ? null : master.getProperty(fullKey);
+            // if the property is defined outside of this map don't
+            // consult the map at all.
+            if (masterValue != null) {
+                return masterValue;
+            }
+
+            expandingLHS = false;
             seen.add(name);
             return parseProperties.parseProperties((String) map.get(name));
         } finally {
@@ -82,10 +89,10 @@ public class ResolvePropertyMap implemen
     /**
      * The action method - resolves all the properties in a map.
      * @param map the map to resolve properties in.
-     * @deprecated since Ant 1.8.1, use the two-arg method instead.
+     * @deprecated since Ant 1.8.2, use the three-arg method instead.
      */
     public void resolveAllProperties(Map map) {
-        resolveAllProperties(map, null);
+        resolveAllProperties(map, null, false);
     }
 
     /**
@@ -93,13 +100,44 @@ public class ResolvePropertyMap implemen
      * @param map the map to resolve properties in.
      * @param prefix the prefix the properties defined inside the map
      * will finally receive - may be null.
+     * @deprecated since Ant 1.8.2, use the three-arg method instead.
      */
     public void resolveAllProperties(Map map, String prefix) {
-        this.map = map; // The map gets used in the getProperty callback
+        resolveAllProperties(map, null, false);
+    }
+
+    /**
+     * The action method - resolves all the properties in a map.
+     * @param map the map to resolve properties in.
+     * @param prefix the prefix the properties defined inside the map
+     * will finally receive - may be null.
+     * @param prefixValues - whether the prefix will be applied
+     * to properties on the value side of the map as well.
+     */
+    public void resolveAllProperties(Map map, String prefix,
+                                     boolean prefixValues) {
+        // The map, prefix and prefixValues flag get used in the
+        // getProperty callback
+        this.map = map;
         this.prefix = prefix;
+        this.prefixValues = prefixValues;
+
         for (Iterator i = map.keySet().iterator(); i.hasNext();) {
+            expandingLHS = true;
             String key = (String) i.next();
-            Object result = getProperty(key);
+
+            // if the property has already been set to the name it
+            // will have in the end, then return the existing value to
+            // ensure properties remain immutable
+            String fullKey = key;
+            if (prefix != null) {
+                fullKey = prefix + key;
+            }
+            Object result = master.getProperty(fullKey);
+
+            if (result == null) {
+                result = getProperty(key);
+            }
             String value = result == null ? "" : result.toString();
             map.put(key, value);
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java Tue Jun 29 16:16:41
2010
@@ -66,6 +66,7 @@ public class LoadProperties extends Task
      * Prefix for loaded properties.
      */
     private String prefix = null;
+    private boolean prefixValues = true;
 
     /**
      * Set the file to load.
@@ -142,6 +143,16 @@ public class LoadProperties extends Task
     }
 
     /**
+     * Whether to apply the prefix when expanding properties on the
+     * right hand side of a properties file as well.
+     *
+     * @since Ant 1.8.2
+     */
+    public void setPrefixValues(boolean b) {
+        prefixValues = b;
+    }
+
+    /**
      * load Ant properties from the source file or resource
      *
      * @exception BuildException if something goes wrong with the build
@@ -189,6 +200,7 @@ public class LoadProperties extends Task
                 Property propertyTask = new Property();
                 propertyTask.bindToOwner(this);
                 propertyTask.setPrefix(prefix);
+                propertyTask.setPrefixValues(prefixValues);
                 propertyTask.addProperties(props);
             }
         } catch (final IOException ioe) {

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java Tue Jun 29 16:16:41
2010
@@ -94,6 +94,7 @@ public class Property extends Task {
     private boolean valueAttributeUsed = false;
     private boolean relative = false;
     private File basedir;
+    private boolean prefixValues = false;
 
     protected boolean userProperty; // set read-only properties
     // CheckStyle:VisibilityModifier ON
@@ -294,6 +295,26 @@ public class Property extends Task {
     }
 
     /**
+     * Whether to apply the prefix when expanding properties on the
+     * right hand side of a properties file as well.
+     *
+     * @since Ant 1.8.2
+     */
+    public void setPrefixValues(boolean b) {
+        prefixValues = b;
+    }
+
+    /**
+     * Whether to apply the prefix when expanding properties on the
+     * right hand side of a properties file as well.
+     *
+     * @since Ant 1.8.2
+     */
+    public boolean getPrefixValues() {
+        return prefixValues;
+    }
+
+    /**
      * Sets a reference to an Ant datatype
      * declared elsewhere.
      * Only yields reasonable results for references
@@ -716,7 +737,7 @@ public class Property extends Task {
                                getProject(),
                                propertyHelper,
                                propertyHelper.getExpanders())
-            .resolveAllProperties(props, prefix);
+            .resolveAllProperties(props, getPrefix(), getPrefixValues());
     }
 
 }

Modified: ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml?rev=959019&r1=959018&r2=959019&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml Tue Jun 29 16:16:41 2010
@@ -93,7 +93,7 @@ y=$${x}
 ]]></echo>
     <property file="${input}/y.properties" prefix="foo"/>
     <!-- passes in Ant 1.8.0 and 1.7.1, fails in 1.8.1 -->
-    <!--au:assertPropertyEquals name="foo.y" value="x"/-->
+    <au:assertPropertyEquals name="foo.y" value="x"/>
     <echo file="${input}/z.properties"><![CDATA[
 x=y
 y=$${bar.x}
@@ -121,8 +121,8 @@ x=3
     <au:assertPropertyEquals name="foo.x" value="3"/>
   </target>
 
-    <!-- passes in Ant 1.7.1 and 1.8.0, fails in 1.8.1 -->
-  <target name="NOtestNestedExpansionDoesntUsePrefix"
+  <!-- passes in Ant 1.7.1 and 1.8.0, fails in 1.8.1 -->
+  <target name="testNestedExpansionDoesntUsePrefix"
           description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49373">
     <mkdir dir="${input}"/>
     <property name="x" value="x"/>



Mime
View raw message