From c64c262ae46099d38b16b71fb9564e613fec5047 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 1 Feb 2001 17:14:06 +0000 Subject: [PATCH] perform property expansion on the patterns read from files specified as includesfile or excludesfile attributes. Suggested by: Jason Rosenberg git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268558 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ .../org/apache/tools/ant/types/FileSet.java | 2 +- .../apache/tools/ant/types/PatternSet.java | 35 +++++++++++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 5992b8419..d6d89defc 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -64,6 +64,9 @@ Other changes: * Added classpath attribute and nested classpath element to to make the resource attribute more powerful. +* ${} property expansion will now be performed on the patterns read + from files specified as includesfile or excludesfile attributes. + Fixed bugs: ----------- diff --git a/src/main/org/apache/tools/ant/types/FileSet.java b/src/main/org/apache/tools/ant/types/FileSet.java index 33469a303..b7f1f27b7 100644 --- a/src/main/org/apache/tools/ant/types/FileSet.java +++ b/src/main/org/apache/tools/ant/types/FileSet.java @@ -93,7 +93,7 @@ public class FileSet extends DataType { * this element if you make it a reference.

*/ public void setRefid(Reference r) throws BuildException { - if (dir != null || defaultPatterns.countPatterns() > 0) { + if (dir != null || defaultPatterns.hasPatterns()) { throw tooManyAttributes(); } if (!additionalPatterns.isEmpty()) { diff --git a/src/main/org/apache/tools/ant/types/PatternSet.java b/src/main/org/apache/tools/ant/types/PatternSet.java index 0ee7416b6..bb47032aa 100644 --- a/src/main/org/apache/tools/ant/types/PatternSet.java +++ b/src/main/org/apache/tools/ant/types/PatternSet.java @@ -55,6 +55,7 @@ package org.apache.tools.ant.types; import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.BuildException; import java.io.*; @@ -79,6 +80,9 @@ public class PatternSet extends DataType { private Vector includeList = new Vector(); private Vector excludeList = new Vector(); + private File incl = null; + private File excl = null; + /** * inner class to hold a name on list. "If" and "Unless" attributes * may be used to invalidate the entry based on the existence of a @@ -214,9 +218,8 @@ public class PatternSet extends DataType { if (!incl.exists()) { throw new BuildException("Includesfile "+incl.getAbsolutePath() +" not found."); - } else { - readPatterns(incl, includeList); } + this.incl = incl; } /** @@ -231,16 +234,15 @@ public class PatternSet extends DataType { if (!excl.exists()) { throw new BuildException("Excludesfile "+excl.getAbsolutePath() +" not found."); - } else { - readPatterns(excl, excludeList); } + this.excl = excl; } /** * Reads path matching patterns from a file and adds them to the * includes or excludes list (as appropriate). */ - private void readPatterns(File patternfile, Vector patternlist) + private void readPatterns(File patternfile, Vector patternlist, Project p) throws BuildException { try { @@ -253,6 +255,8 @@ public class PatternSet extends DataType { String line = patternReader.readLine(); while (line != null) { if (line.length() > 0) { + line = ProjectHelper.replaceProperties(p, line, + p.getProperties()); addPatternToList(patternlist).setName(line); } line = patternReader.readLine(); @@ -294,6 +298,7 @@ public class PatternSet extends DataType { if (isReference()) { return getRef(p).getIncludePatterns(p); } else { + readFiles(p); return makeArray(includeList, p); } } @@ -305,6 +310,7 @@ public class PatternSet extends DataType { if (isReference()) { return getRef(p).getExcludePatterns(p); } else { + readFiles(p); return makeArray(excludeList, p); } } @@ -312,8 +318,9 @@ public class PatternSet extends DataType { /** * helper for FileSet. */ - int countPatterns() { - return includeList.size() + excludeList.size(); + boolean hasPatterns() { + return incl != null || excl != null + || includeList.size() > 0 || excludeList.size() > 0; } /** @@ -356,4 +363,18 @@ public class PatternSet extends DataType { return result; } + /** + * Read includefile ot excludefile if not already done so. + */ + private void readFiles(Project p) { + if (incl != null) { + readPatterns(incl, includeList, p); + incl = null; + } + if (excl != null) { + readPatterns(excl, excludeList, p); + excl = null; + } + } + }