ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/types FilterSetTest.java
Date Fri, 17 Aug 2001 15:10:32 GMT
conor       01/08/17 08:10:31

  Modified:    src/main/org/apache/tools/ant Tag: ANT_14_BRANCH
                        Project.java
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_14_BRANCH
                        Copy.java Move.java
               src/main/org/apache/tools/ant/types Tag: ANT_14_BRANCH
                        FilterSet.java
               src/main/org/apache/tools/ant/util Tag: ANT_14_BRANCH
                        FileUtils.java
  Added:       src/etc/testcases/types Tag: ANT_14_BRANCH filterset.xml
                        filterseta.txt filtersetb.txt filtersetc.txt
               src/etc/testcases/types/gold Tag: ANT_14_BRANCH
                        filterset1.txt filterset2.txt filterset3.txt
               src/main/org/apache/tools/ant/types Tag: ANT_14_BRANCH
                        FilterSetCollection.java
               src/testcases/org/apache/tools/ant/types Tag: ANT_14_BRANCH
                        FilterSetTest.java
  Log:
  Since filterset can have different start / end tokens, the filtersets
  need to remain distinct. Introduce FilterSetCollection as a wrapper
  to group the filtersets. Should use the Compositer pattern extract
  the common FilterSet/FilterSetCollection interface and pass that to the
  FileUtils - lets see.
  
  Added a set of test cases for the filtersets.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +37 -0     jakarta-ant/src/etc/testcases/types/Attic/filterset.xml
  
  
  
  
  1.1.2.1   +2 -0      jakarta-ant/src/etc/testcases/types/Attic/filterseta.txt
  
  
  
  
  1.1.2.1   +5 -0      jakarta-ant/src/etc/testcases/types/Attic/filtersetb.txt
  
  
  
  
  1.1.2.1   +7 -0      jakarta-ant/src/etc/testcases/types/Attic/filtersetc.txt
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +2 -0      jakarta-ant/src/etc/testcases/types/gold/Attic/filterset1.txt
  
  
  
  
  1.1.2.1   +5 -0      jakarta-ant/src/etc/testcases/types/gold/Attic/filterset2.txt
  
  
  
  
  1.1.2.1   +7 -0      jakarta-ant/src/etc/testcases/types/gold/Attic/filterset3.txt
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.74.2.2  +8 -6      jakarta-ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.74.2.1
  retrieving revision 1.74.2.2
  diff -u -r1.74.2.1 -r1.74.2.2
  --- Project.java	2001/08/14 13:16:52	1.74.2.1
  +++ Project.java	2001/08/17 15:09:27	1.74.2.2
  @@ -59,6 +59,7 @@
   import java.text.*;
   
   import org.apache.tools.ant.types.FilterSet; 
  +import org.apache.tools.ant.types.FilterSetCollection; 
   import org.apache.tools.ant.util.FileUtils; 
   
   /**
  @@ -108,6 +109,7 @@
       private Hashtable taskClassDefinitions = new Hashtable();
       private Hashtable targets = new Hashtable();
       private FilterSet globalFilterSet = new FilterSet();
  +    private FilterSetCollection globalFilters = new FilterSetCollection(globalFilterSet);
       private File baseDir;
   
       private Vector listeners = new Vector();
  @@ -671,7 +673,7 @@
        */
       public void copyFile(String sourceFile, String destFile, boolean filtering)
           throws IOException {
  -        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet : null);
  +        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilters : null);
       }
   
       /**
  @@ -685,7 +687,7 @@
        */
       public void copyFile(String sourceFile, String destFile, boolean filtering,
                            boolean overwrite) throws IOException {
  -        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet : null, overwrite);
  +        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilters : null, overwrite);
       }
   
        /**
  @@ -702,7 +704,7 @@
       public void copyFile(String sourceFile, String destFile, boolean filtering,
                            boolean overwrite, boolean preserveLastModified)
           throws IOException {
  -        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet : null, 
  +        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilters : null, 
                              overwrite, preserveLastModified);
       }
   
  @@ -728,7 +730,7 @@
        */
       public void copyFile(File sourceFile, File destFile, boolean filtering)
           throws IOException {
  -        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet : null);
  +        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilters : null);
       }
   
       /**
  @@ -742,7 +744,7 @@
        */
       public void copyFile(File sourceFile, File destFile, boolean filtering,
                            boolean overwrite) throws IOException {
  -        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet : null, overwrite);
  +        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilters : null, overwrite);
       }
   
       /**
  @@ -759,7 +761,7 @@
       public void copyFile(File sourceFile, File destFile, boolean filtering,
                            boolean overwrite, boolean preserveLastModified)
           throws IOException {
  -        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilterSet : null, 
  +        fileUtils.copyFile(sourceFile, destFile, filtering ? globalFilters : null, 
                              overwrite, preserveLastModified);
       }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.19.2.1  +4 -4      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java
  
  Index: Copy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
  retrieving revision 1.19
  retrieving revision 1.19.2.1
  diff -u -r1.19 -r1.19.2.1
  --- Copy.java	2001/08/07 05:49:48	1.19
  +++ Copy.java	2001/08/17 15:09:36	1.19.2.1
  @@ -365,14 +365,14 @@
                   try {
                       log("Copying " + fromFile + " to " + toFile, verbosity);
                       
  -                    FilterSet executionFilterSet = new FilterSet();
  +                    FilterSetCollection executionFilters = new FilterSetCollection();
                       if (filtering) {
  -                        executionFilterSet.addFilterSet(project.getGlobalFilterSet());
  +                        executionFilters.addFilterSet(project.getGlobalFilterSet());
                       }
                       for (Enumeration filterEnum = filterSets.elements(); filterEnum.hasMoreElements();)
{
  -                        executionFilterSet.addFilterSet((FilterSet)filterEnum.nextElement());
  +                        executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
                       }
  -                    fileUtils.copyFile(fromFile, toFile, executionFilterSet,
  +                    fileUtils.copyFile(fromFile, toFile, executionFilters,
                                          forceOverwrite, preserveLastModified);
                   } catch (IOException ioe) {
                       String msg = "Failed to copy " + fromFile + " to " + toFile
  
  
  
  1.7.2.1   +4 -4      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java
  
  Index: Move.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- Move.java	2001/08/07 06:59:35	1.7
  +++ Move.java	2001/08/17 15:09:43	1.7.2.1
  @@ -123,14 +123,14 @@
                       try {
                           log("Moving " + fromFile + " to " + toFile, verbosity);
                       
  -                        FilterSet executionFilterSet = new FilterSet();
  +                        FilterSetCollection executionFilters = new FilterSetCollection();
                           if (filtering) {
  -                            executionFilterSet.addFilterSet(project.getGlobalFilterSet());
  +                            executionFilters.addFilterSet(project.getGlobalFilterSet());
                           }
                           for (Enumeration filterEnum = getFilterSets().elements(); filterEnum.hasMoreElements();)
{
  -                            executionFilterSet.addFilterSet((FilterSet)filterEnum.nextElement());
  +                            executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
                           }
  -                        getFileUtils().copyFile(f, d, executionFilterSet,
  +                        getFileUtils().copyFile(f, d, executionFilters,
                                                   forceOverwrite);
                           
                           f = new File(fromFile);
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +35 -13    jakarta-ant/src/main/org/apache/tools/ant/types/FilterSet.java
  
  Index: FilterSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FilterSet.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- FilterSet.java	2001/08/06 12:49:40	1.2
  +++ FilterSet.java	2001/08/17 15:09:49	1.2.2.1
  @@ -176,8 +176,8 @@
       /** The default token end string */
       public static final String DEFAULT_TOKEN_END = "@";
       
  -    private String startOftoken = DEFAULT_TOKEN_START;
  -    private String endOftoken = DEFAULT_TOKEN_END;
  +    private String startOfToken = DEFAULT_TOKEN_START;
  +    private String endOfToken = DEFAULT_TOKEN_END;
       
       /**
        * List of ordered filters and filter files.
  @@ -245,9 +245,17 @@
           if (isReference()) {
               throw tooManyAttributes();
           }
  -        startOftoken = startOfToken;
  +        this.startOfToken = startOfToken;
       }
  +
  +    public String getBeginToken() {
  +        if (isReference()) {
  +            return getRef().getBeginToken();
  +        }
  +        return startOfToken;
  +    }
       
  +    
       /**
        * The string used to id the end of a token.
        *
  @@ -256,10 +264,18 @@
       public void setEndToken( String endOfToken ) {
           if (isReference()) {
               throw tooManyAttributes();
  +        }
  +        this.endOfToken = endOfToken;
  +    }
  +
  +    public String getEndToken() {
  +        if (isReference()) {
  +            return getRef().getEndToken();
           }
  -        endOftoken = endOfToken;
  +        return endOfToken;
       }
       
  +    
       /**
        * Read the filters from the given file.
        *
  @@ -268,6 +284,10 @@
        * file.
        */
       public void readFiltersFromFile(File filtersFile) throws BuildException {
  +        if (isReference()) {
  +            throw tooManyAttributes();
  +        }
  +
           if (filtersFile.isFile()) {
              log("Reading filters from " + filtersFile, Project.MSG_VERBOSE );
              FileInputStream in = null;
  @@ -310,7 +330,9 @@
        * @return      The string with the tokens replaced.
        */
       public String replaceTokens(String line) {
  -        int index = line.indexOf(startOftoken);
  +        String beginToken = getBeginToken();
  +        String endToken = getEndToken();
  +        int index = line.indexOf(beginToken);
           
           if (index > -1) {
               Hashtable tokens = getFilterHash();
  @@ -321,24 +343,24 @@
                   String value = null;
                   
                   do {
  -                    int endIndex = line.indexOf(endOftoken, index + startOftoken.length()
+ 1 );
  +                    int endIndex = line.indexOf(endToken, index + beginToken.length() +
1 );
                       if (endIndex == -1) {
                           break;
                       }
  -                    token = line.substring(index + startOftoken.length(), endIndex );
  +                    token = line.substring(index + beginToken.length(), endIndex );
                       b.append(line.substring(i, index));
                       if (tokens.containsKey(token)) {
                           value = (String)tokens.get(token);
  -                        log( "Replacing: " + startOftoken + token + endOftoken + " ->
" + value, Project.MSG_VERBOSE );
  +                        log( "Replacing: " + beginToken + token + endToken + " -> "
+ value, Project.MSG_VERBOSE );
                           b.append(value);
  -                        i = index + startOftoken.length() + token.length() + endOftoken.length();
  +                        i = index + beginToken.length() + token.length() + endToken.length();
                       }
                       else {
  -                        // just append startOftoken and search further
  -                        b.append(startOftoken);
  -                        i = index + startOftoken.length();
  +                        // just append beginToken and search further
  +                        b.append(beginToken);
  +                        i = index + beginToken.length();
                       }
  -                } while ((index = line.indexOf( startOftoken, i )) > -1 );
  +                } while ((index = line.indexOf( beginToken, i )) > -1 );
                   
                   b.append(line.substring(i));
                   return b.toString();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +127 -0    jakarta-ant/src/main/org/apache/tools/ant/types/Attic/FilterSetCollection.java
  
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.1   +14 -14    jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- FileUtils.java	2001/08/08 16:13:08	1.3
  +++ FileUtils.java	2001/08/17 15:10:13	1.3.2.1
  @@ -61,7 +61,7 @@
   
   import org.apache.tools.ant.BuildException; 
   import org.apache.tools.ant.Project; 
  -import org.apache.tools.ant.types.FilterSet; 
  +import org.apache.tools.ant.types.FilterSetCollection; 
   
   /**
    * This class also encapsulates methods which allow Files to be
  @@ -106,10 +106,10 @@
        *
        * @throws IOException
        */
  -    public void copyFile(String sourceFile, String destFile, FilterSet filterSet)
  +    public void copyFile(String sourceFile, String destFile, FilterSetCollection filters)
           throws IOException
       {
  -        copyFile(new File(sourceFile), new File(destFile), filterSet, false, false);
  +        copyFile(new File(sourceFile), new File(destFile), filters, false, false);
       }
   
       /**
  @@ -119,9 +119,9 @@
        *
        * @throws IOException 
        */
  -    public void copyFile(String sourceFile, String destFile, FilterSet filterSet,
  +    public void copyFile(String sourceFile, String destFile, FilterSetCollection filters,
                            boolean overwrite) throws IOException {
  -        copyFile(new File(sourceFile), new File(destFile), filterSet, 
  +        copyFile(new File(sourceFile), new File(destFile), filters, 
                    overwrite, false);
       }
   
  @@ -134,10 +134,10 @@
        *
        * @throws IOException 
        */
  -    public void copyFile(String sourceFile, String destFile, FilterSet filterSet,
  +    public void copyFile(String sourceFile, String destFile, FilterSetCollection filters,
                            boolean overwrite, boolean preserveLastModified)
           throws IOException {
  -        copyFile(new File(sourceFile), new File(destFile), filterSet, 
  +        copyFile(new File(sourceFile), new File(destFile), filters, 
                    overwrite, preserveLastModified);
       }
   
  @@ -157,9 +157,9 @@
        *
        * @throws IOException
        */
  -    public void copyFile(File sourceFile, File destFile, FilterSet filterSet)
  +    public void copyFile(File sourceFile, File destFile, FilterSetCollection filters)
           throws IOException {
  -        copyFile(sourceFile, destFile, filterSet, false, false);
  +        copyFile(sourceFile, destFile, filters, false, false);
       }
   
       /**
  @@ -169,9 +169,9 @@
        *
        * @throws IOException 
        */
  -    public void copyFile(File sourceFile, File destFile, FilterSet filterSet,
  +    public void copyFile(File sourceFile, File destFile, FilterSetCollection filters,
                            boolean overwrite) throws IOException {
  -        copyFile(sourceFile, destFile, filterSet, overwrite, false);
  +        copyFile(sourceFile, destFile, filters, overwrite, false);
       }
   
       /**
  @@ -183,7 +183,7 @@
        *
        * @throws IOException 
        */
  -    public void copyFile(File sourceFile, File destFile, FilterSet filterSet,
  +    public void copyFile(File sourceFile, File destFile, FilterSetCollection filters,
                            boolean overwrite, boolean preserveLastModified)
           throws IOException {
           
  @@ -201,7 +201,7 @@
                   parent.mkdirs();
               }
   
  -            if (filterSet != null && filterSet.hasFilters()) {
  +            if (filters != null && filters.hasFilters()) {
                   BufferedReader in = new BufferedReader(new FileReader(sourceFile));
                   BufferedWriter out = new BufferedWriter(new FileWriter(destFile));
   
  @@ -212,7 +212,7 @@
                       if (line.length() == 0) {
                           out.newLine();
                       } else {
  -                        newline = filterSet.replaceTokens(line);
  +                        newline = filters.replaceTokens(line);
                           out.write(newline);
                           out.newLine();
                       }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +144 -0    jakarta-ant/src/testcases/org/apache/tools/ant/types/Attic/FilterSetTest.java
  
  
  
  

Mime
View raw message