You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2018/05/20 17:33:56 UTC

[5/5] ant git commit: Merge branch '1.9.x'

Merge branch '1.9.x'


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

Branch: refs/heads/master
Commit: d345133b62623699928dc8a1cbbe4809704b5b47
Parents: e6b2030 fee6d73
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun May 20 18:56:30 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun May 20 18:56:30 2018 +0200

----------------------------------------------------------------------
 WHATSNEW                                        | 10 +++
 manual/Types/patternset.html                    |  5 ++
 manual/Types/resources.html                     |  9 +++
 src/etc/testcases/types/fileset.xml             | 40 +++++++++++
 .../org/apache/tools/ant/taskdefs/Delete.java   |  4 +-
 .../apache/tools/ant/taskdefs/MatchingTask.java |  4 +-
 .../apache/tools/ant/types/AbstractFileSet.java |  4 +-
 .../org/apache/tools/ant/types/PatternSet.java  | 74 +++++++++++++++++---
 .../apache/tools/ant/types/resources/Files.java |  4 +-
 .../tools/ant/types/resources/ResourceList.java | 22 ++++++
 src/tests/antunit/taskdefs/copy-test.xml        | 18 +++++
 .../org/apache/tools/ant/types/FileSetTest.java | 28 +++++++-
 .../apache/tools/ant/types/PatternSetTest.java  | 29 ++++++++
 13 files changed, 230 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/WHATSNEW
----------------------------------------------------------------------
diff --cc WHATSNEW
index 5bbd503,9e096c9..63bb359
--- a/WHATSNEW
+++ b/WHATSNEW
@@@ -55,12 -43,17 +55,22 @@@ Other changes
     availableProcessors, freeMemory, maxMemory and totalMemory methods
     of the Java Runtime class.
  
 + * linecontains filter now has a new "matchAny" attribute which when
 +   set to "true" allows any (instead of all) of the user-specified
 +   strings to be present in the line.
 +   Bugzilla Report 62313
 +
+  * <resourcelist> has a new basedir attribute that can be used to
+    resolve relative names and provides a root for the FileResources
+    generated.
+    Bugzilla Report 62379
+ 
+  * The <includesfile> and <excludesfile> nested elements of
+    <patternset> and <fileset> now support an encoding attribute that
+    can be used to specify the file's encoding.
+    Bugzilla Report 62379
+ 
 -Changes from Ant 1.9.10 TO Ant 1.9.11
 +Changes from Ant 1.10.2 TO Ant 1.10.3
  =====================================
  
  Changes that could break older environments:

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/manual/Types/patternset.html
----------------------------------------------------------------------
diff --cc manual/Types/patternset.html
index 837740b,1cfcb8f..9218a15
--- a/manual/Types/patternset.html
+++ b/manual/Types/patternset.html
@@@ -94,43 -96,49 +94,48 @@@ or <code>&lt;exclude&gt;</code> element
    </tr>
  </table>
  <h4><code>includesfile</code> and <code>excludesfile</code></h4>
 -<p>If you want to list the files to include or exclude external to
 -your build file, you should use the includesfile/excludesfile
 -attributes or elements.  Using the attribute, you can only specify a
 -single file of each type, while the nested elements can be specified
 -more than once - the nested elements also support if/unless attributes
 -you can use to test the existence of a property.</p>
 -<table border="1" cellpadding="2" cellspacing="0">
 +<p>If you want to list the files to include or exclude external to your build file, you should
 +use the <var>includesfile</var>/<var>excludesfile</var> attributes or elements.  Using the
 +attribute, you can only specify a single file of each type, while the nested elements can be
 +specified more than once&mdash;the nested elements also support <var>if</var>/<var>unless</var>
 +attributes you can use to test the existence of a property.</p>
 +<table class="attr">
    <tr>
 -    <td valign="top"><b>Attribute</b></td>
 -    <td valign="top"><b>Description</b></td>
 -    <td align="center" valign="top"><b>Required</b></td>
 +    <th scope="col">Attribute</th>
 +    <th scope="col">Description</th>
 +    <th scope="col">Required</th>
    </tr>
    <tr>
 -    <td valign="top">name</td>
 -    <td valign="top">the name of the file holding the patterns to
 -      in/exclude.</td>
 -    <td align="center" valign="top">Yes</td>
 +    <td>name</td>
 +    <td>the name of the file holding the patterns to in/exclude.</td>
 +    <td>Yes</td>
    </tr>
    <tr>
 -    <td valign="top">if</td>
 -    <td valign="top">Only read this file <a href="../properties.html#if+unless">if the named property is set</a>.</td>
 -    <td align="center" valign="top">No</td>
 +    <td>if</td>
 +    <td>Only read this file <a href="../properties.html#if+unless">if the named property is
 +    set</a>.</td>
 +    <td>No</td>
    </tr>
    <tr>
 -    <td valign="top">unless</td>
 -    <td valign="top">Only read this file <a href="../properties.html#if+unless">if the named property is
 -      <b>not</b> set</a>.</td>
 -    <td align="center" valign="top">No</td>
 +    <td>unless</td>
 +    <td>Only read this file <a href="../properties.html#if+unless">if the named property
 +    is <strong>not</strong> set</a>.</td>
 +    <td>No</td>
    </tr>
+   <tr>
 -    <td valign="top">encoding</td>
 -    <td valign="top">The encoding of the file. <em>Since Ant 1.9.12</em></td>
 -    <td valign="top" align="center">No, default is platform default</td>
++    <td>encoding</td>
++    <td>The encoding of the file. <em>Since Ant 1.10.4</em></td>
++    <td>No, default is platform default</td>
+   </tr>
  </table>
  <h4><code>patternset</code></h4>
 -<p>Patternsets may be nested within one another, adding the nested
 -patterns to the parent patternset.</p>
 +<p>Patternsets may be nested within one another, adding the nested patterns to the parent
 +patternset.</p>
  <h4><code>invert</code></h4>
 -<p>A nested patternset can be inverted using the <code>&lt;invert&gt;</code>
 -element. <em>Since Apache Ant 1.7.1</em></p>
 +<p><em>Since Apache Ant 1.7.1</em></p>
 +<p>A nested patternset can be inverted using the <code>&lt;invert&gt;</code> element.</p>
  <h3>Examples</h3>
 -<blockquote><pre>
 +<pre>
  &lt;patternset id=&quot;non.test.sources&quot;&gt;
    &lt;include name=&quot;**/*.java&quot;/&gt;
    &lt;exclude name=&quot;**/*Test*&quot;/&gt;

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/manual/Types/resources.html
----------------------------------------------------------------------
diff --cc manual/Types/resources.html
index 160c96f,5bdc231..b07f73b
--- a/manual/Types/resources.html
+++ b/manual/Types/resources.html
@@@ -1225,48 -1306,65 +1225,57 @@@ resources of <code>&lt;tars&gt;</code> 
  
  <p><em>Since Ant 1.8.0</em></p>
  
 -<p>This resource collection accepts an arbitrary number of nested
 -  resources, reads those resources and returns a resource for each
 -  line read.</p>
 +<p>This resource collection accepts an arbitrary number of nested resources, reads those
 +resources and returns a resource for each line read.</p>
  
 -<p>If the line contains a colon, Ant will try to use it as an URL and
 -  if that fails (or the line doesn't contain a colon) will return a
 -  file resource with the line's content as its name.</p>
 +<p>If the line contains a colon, Ant will try to use it as an URL and if that fails (or the line
 +doesn't contain a colon) will return a file resource with the line's content as its name.</p>
  
 -<p>Properties will be expanded for each line.  If the property
 -  expansion yields a resource object rather than a string (for example
 -  because of custom property helpers), the resources will be returned
 -  directly.</p>
 +<p>Properties will be expanded for each line.  If the property expansion yields a resource
 +object rather than a string (for example because of custom property helpers), the resources will
 +be returned directly.</p>
  
  <p><code>&lt;resourcelist&gt;</code> is a generalization
 -  of <a href="filelist.html"><code>&lt;filelist&gt;</code></a>.</p>
 +of <a href="filelist.html"><code>&lt;filelist&gt;</code></a>.</p>
  
 -<blockquote>
 -  <table border="1" cellpadding="2" cellspacing="0">
 -    <tr>
 -      <td valign="top"><b>Attribute</b></td>
 -      <td valign="top"><b>Description</b></td>
 -      <td align="center" valign="top"><b>Required</b></td>
 -    </tr>
 -    <tr>
 -      <td valign="top">encoding</td>
 -      <td valign="top">The encoding of the nested resources</td>
 -      <td valign="top" align="center">No, default is platform default</td>
 -    </tr>
 -    <tr>
 -      <td valign="top">basedir</td>
 -      <td valign="top">Base directory that is used to resolve
 -        relative file names against. Is also used to provide a base
 -        directory to the FileResources created by this resource
 -        collection. <em>Since Ant 1.9.12</em>
 -      </td>
 -      <td valign="top" align="center">No</td>
 -    </tr>
 -  </table>
 -</blockquote>
 +<table class="attr">
 +  <tr>
 +    <th scope="col">Attribute</th>
 +    <th scope="col">Description</th>
 +    <th scope="col">Required</th>
 +  </tr>
 +  <tr>
 +    <td>encoding</td>
 +    <td>The encoding of the nested resources</td>
 +    <td>No; default is default JVM character encoding</td>
 +  </tr>
++  <tr>
++    <td>basedir</td>
++    <td>Base directory that is used to resolve relative file names
++      against. Is also used to provide a base directory to the
++      FileResources created by this resource collection. <em>Since Ant
++      1.10.4</em>
++    </td>
++    <td>No</td>
++  </tr>
 +</table>
  
 -<blockquote>
 -  <h4>Parameters specified as nested elements</h4>
 +<h5>Parameters specified as nested elements</h5>
  
 -  <p><code>&lt;resourcelist&gt;</code> accepts arbitrary many
 -    resource(collection)s as nested elements.</p>
 +<p><code>&lt;resourcelist&gt;</code> accepts arbitrary many resource(collection)s as nested
 +elements.</p>
  
 -  <p>In addition <code>&lt;resourcelist&gt;</code> supports
 -    nested <code>&lt;filterchain&gt;</code> elements that can be used
 -    to filter/modify the read resources before their lines get
 -    expanded.  Such a nested element corresponds to
 -    a <a href="filterchain.html">filterchain</a>.</p>
 +<p>In addition <code>&lt;resourcelist&gt;</code> supports
 +nested <code>&lt;filterchain&gt;</code> elements that can be used to filter/modify the read
 +resources before their lines get expanded.  Such a nested element corresponds to
 +a <a href="filterchain.html">filterchain</a>.</p>
  
 -  <h4>Examples</h4>
 +<h5>Examples</h5>
  
 -  <p>The following example copies a file from the first URL of
 -    several alternatives that can actually be reached.  It assumes
 -    that the file mirrors.txt looks like</p>
 +<p>The following example copies a file from the first URL of several alternatives that can
 +actually be reached.  It assumes that the file <samp>mirrors.txt</samp> looks like</p>
  
 -  <pre>
 +<pre>
      mirrors.txt:
  http://best.mirror.example.org/
  http://second.best.mirror.example.org/mirror/of/best/

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/main/org/apache/tools/ant/taskdefs/Delete.java
----------------------------------------------------------------------
diff --cc src/main/org/apache/tools/ant/taskdefs/Delete.java
index b80c0f0,bf266a0..22eefa1
--- a/src/main/org/apache/tools/ant/taskdefs/Delete.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Delete.java
@@@ -254,9 -247,8 +254,9 @@@ public class Delete extends MatchingTas
  
      /**
       * add a name entry on the include files list
-      * @return a NameEntry object to be configured
+      * @return a PatternFileNameEntry object to be configured
       */
 +    @Override
      public PatternSet.NameEntry createIncludesFile() {
          usedMatchingTask = true;
          return super.createIncludesFile();
@@@ -274,9 -265,8 +274,9 @@@
  
      /**
       * add a name entry on the include files list
-      * @return a NameEntry object to be configured
+      * @return a PatternFileNameEntry object to be configured
       */
 +    @Override
      public PatternSet.NameEntry createExcludesFile() {
          usedMatchingTask = true;
          return super.createExcludesFile();

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/main/org/apache/tools/ant/types/AbstractFileSet.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/main/org/apache/tools/ant/types/PatternSet.java
----------------------------------------------------------------------
diff --cc src/main/org/apache/tools/ant/types/PatternSet.java
index 8a833c8,cd5797b..cc92a3e
--- a/src/main/org/apache/tools/ant/types/PatternSet.java
+++ b/src/main/org/apache/tools/ant/types/PatternSet.java
@@@ -19,13 -19,13 +19,16 @@@ package org.apache.tools.ant.types
  
  import java.io.BufferedReader;
  import java.io.File;
+ import java.io.FileInputStream;
  import java.io.FileReader;
  import java.io.IOException;
+ import java.io.InputStreamReader;
++import java.io.Reader;
  import java.util.ArrayList;
  import java.util.List;
 +import java.util.Objects;
  import java.util.StringTokenizer;
 +import java.util.function.Predicate;
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Project;
@@@ -39,10 -40,10 +42,10 @@@ import org.apache.tools.ant.PropertyHel
   *
   */
  public class PatternSet extends DataType implements Cloneable {
 -    private List<NameEntry> includeList = new ArrayList<NameEntry>();
 -    private List<NameEntry> excludeList = new ArrayList<NameEntry>();
 -    private List<PatternFileNameEntry> includesFileList = new ArrayList<PatternFileNameEntry>();
 -    private List<PatternFileNameEntry> excludesFileList = new ArrayList<PatternFileNameEntry>();
 +    private List<NameEntry> includeList = new ArrayList<>();
 +    private List<NameEntry> excludeList = new ArrayList<>();
-     private List<NameEntry> includesFileList = new ArrayList<>();
-     private List<NameEntry> excludesFileList = new ArrayList<>();
++    private List<PatternFileNameEntry> includesFileList = new ArrayList<>();
++    private List<PatternFileNameEntry> excludesFileList = new ArrayList<>();
  
      /**
       * inner class to hold a name on list.  "If" and "Unless" attributes
@@@ -178,6 -178,45 +181,45 @@@
          }
      }
  
+     /**
+      * Adds encoding support to {@link NameEntry}.
 -     * @since Ant 1.9.12
++     * @since Ant 1.10.4
+      */
+     public class PatternFileNameEntry extends NameEntry {
+         private String encoding;
+ 
+         /**
+          * Encoding to use when reading the file, defaults to the platform's default
+          * encoding.
+          *
+          * <p>
+          * For a list of possible values see
+          * <a href="https://docs.oracle.com/javase/1.5.0/docs/guide/intl/encoding.doc.html">
+          * https://docs.oracle.com/javase/1.5.0/docs/guide/intl/encoding.doc.html</a>.
+          * </p>
+          *
+          * @param encoding String
+          */
+         public final void setEncoding(String encoding) {
+             this.encoding = encoding;
+         }
+ 
+         /**
+          * Encoding to use when reading the file, defaults to the platform's default
+          * encoding.
+          */
+         public final String getEncoding() {
+             return encoding;
+         }
+ 
+         @Override
+         public String toString() {
+             String baseString = super.toString();
+             return encoding == null ? baseString
+                 : new StringBuilder(baseString).append(";encoding->").append(encoding).toString();
+         }
+     }
+ 
      private static final class InvertedPatternSet extends PatternSet {
          private InvertedPatternSet(PatternSet p) {
              setProject(p.getProject());
@@@ -360,11 -405,17 +411,12 @@@
       *  Reads path matching patterns from a file and adds them to the
       *  includes or excludes list (as appropriate).
       */
-     private void readPatterns(File patternfile, List<NameEntry> patternlist, Project p)
+     private void readPatterns(File patternfile, String encoding, List<NameEntry> patternlist, Project p)
              throws BuildException {
  
-         try (BufferedReader patternReader =
-             new BufferedReader(new FileReader(patternfile))) {
 -        BufferedReader patternReader = null;
 -        try {
 -            // Get a FileReader
 -            if (encoding == null) {
 -                patternReader = new BufferedReader(new FileReader(patternfile));
 -            } else {
 -                patternReader = new BufferedReader(new InputStreamReader(new FileInputStream(patternfile), encoding));
 -            }
++        try (Reader r = encoding == null ? new FileReader(patternfile)
++             : new InputStreamReader(new FileInputStream(patternfile), encoding);
++             BufferedReader patternReader = new BufferedReader(r)) {
  
              // Create one NameEntry in the appropriate pattern list for each
              // line in the file.
@@@ -469,8 -531,8 +521,8 @@@
       * Read includesfile ot excludesfile if not already done so.
       */
      private void readFiles(Project p) {
 -        if (includesFileList.size() > 0) {
 +        if (!includesFileList.isEmpty()) {
-             for (NameEntry ne : includesFileList) {
+             for (PatternFileNameEntry ne : includesFileList) {
                  String fileName = ne.evalName(p);
                  if (fileName != null) {
                      File inclFile = p.resolveFile(fileName);
@@@ -483,8 -545,8 +535,8 @@@
              }
              includesFileList.clear();
          }
 -        if (excludesFileList.size() > 0) {
 +        if (!excludesFileList.isEmpty()) {
-             for (NameEntry ne : excludesFileList) {
+             for (PatternFileNameEntry ne : excludesFileList) {
                  String fileName = ne.evalName(p);
                  if (fileName != null) {
                      File exclFile = p.resolveFile(fileName);

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/main/org/apache/tools/ant/types/resources/Files.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
----------------------------------------------------------------------
diff --cc src/main/org/apache/tools/ant/types/resources/ResourceList.java
index 3de8449,79cbbb5..9a5fef0
--- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java
+++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
@@@ -100,6 -102,21 +102,21 @@@ public class ResourceList extends DataT
      }
  
      /**
+      * Basedir to use for file resources read from nested resources -
+      * this allows the resources contained inside this collection to
+      * be considered relative to a certain base directory.
+      *
+      * @param basedir the basedir
 -     * @since Ant 1.9.12
++     * @since Ant 1.10.4
+      */
+     public final void setBasedir(File baseDir) {
+         if (isReference()) {
+             throw tooManyAttributes();
+         }
+         this.baseDir = baseDir;
+     }
+ 
+     /**
       * Makes this instance in effect a reference to another ResourceList
       * instance.
       *
@@@ -242,7 -267,11 +259,12 @@@
                  // resource
              }
          }
+         if (baseDir != null) {
+             FileResource fr = new FileResource(baseDir, expandedLine);
+             fr.setProject(getProject());
+             return fr;
+         }
          return new FileResource(getProject(), expandedLine);
      }
 +
  }

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/tests/antunit/taskdefs/copy-test.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ant/blob/d345133b/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
----------------------------------------------------------------------
diff --cc src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
index 1cd61e4,6baecbb..031c7ab
--- a/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
@@@ -20,14 -20,20 +20,21 @@@ package org.apache.tools.ant.types
  
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.Project;
+ import org.apache.tools.ant.util.FileUtils;
  import org.junit.Before;
 +import org.junit.Rule;
  import org.junit.Test;
 +import org.junit.rules.ExpectedException;
  
  import java.io.File;
+ import java.io.FileOutputStream;
+ import java.io.IOException;
+ import java.io.OutputStream;
+ import java.io.OutputStreamWriter;
+ import java.io.Writer;
  
+ import static org.junit.Assert.assertArrayEquals;
  import static org.junit.Assert.assertEquals;
 -import static org.junit.Assert.fail;
  
  /**
   * JUnit 4 testcases for org.apache.tools.ant.types.PatternSet.