ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Replace.java
Date Thu, 07 Nov 2002 15:17:52 GMT
bodewig     2002/11/07 07:17:52

  Modified:    .        Tag: ANT_15_BRANCH WHATSNEW
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Replace.java
  Log:
  Merge from HEAD
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.263.2.94 +2 -2      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.263.2.93
  retrieving revision 1.263.2.94
  diff -u -r1.263.2.93 -r1.263.2.94
  --- WHATSNEW	6 Nov 2002 12:57:48 -0000	1.263.2.93
  +++ WHATSNEW	7 Nov 2002 15:17:51 -0000	1.263.2.94
  @@ -18,8 +18,8 @@
   
   * <junit> will now produce output when a test times out as well.
   
  -  Other changes:
  -  --------------
  +* <replace> would count some internal character replacements when
  +  reporting the number of replaced tokens.
   
   
   Changes from Ant 1.5.1Beta1 to 1.5.1
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.30.2.3  +16 -14    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java
  
  Index: Replace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java,v
  retrieving revision 1.30.2.2
  retrieving revision 1.30.2.3
  diff -u -r1.30.2.2 -r1.30.2.3
  --- Replace.java	19 Jun 2002 06:19:19 -0000	1.30.2.2
  +++ Replace.java	7 Nov 2002 15:17:51 -0000	1.30.2.3
  @@ -183,8 +183,7 @@
           }
   
           /**
  -         * get the replacement value for this filter token
  -         * @return
  +         * Get the replacement value for this filter token.
            */
           public String getReplaceValue() {
               if (property != null) {
  @@ -318,21 +317,21 @@
           if (src == null && dir == null) {
               String message = "Either the file or the dir attribute " 
                   + "must be specified";
  -            throw new BuildException(message, location);
  +            throw new BuildException(message, getLocation());
           }
           if (propertyFile != null && !propertyFile.exists()) {
               String message = "Property file " + propertyFile.getPath() 
                   + " does not exist.";
  -            throw new BuildException(message, location);
  +            throw new BuildException(message, getLocation());
           }
           if (token == null && replacefilters.size() == 0) {
               String message = "Either token or a nested replacefilter "
                   + "must be specified";
  -            throw new BuildException(message, location);
  +            throw new BuildException(message, getLocation());
           }
           if (token != null && "".equals(token.getText())) {
               String message = "The token attribute must not be an empty string.";
  -            throw new BuildException(message, location);
  +            throw new BuildException(message, getLocation());
           }
       }
   
  @@ -387,7 +386,7 @@
       private void processFile(File src) throws BuildException {
           if (!src.exists()) {
               throw new BuildException("Replace: source file " + src.getPath() 
  -                                     + " doesn't exist", location);
  +                                     + " doesn't exist", getLocation());
           }
   
           File temp = fileUtils.createTempFile("rep", ".tmp", 
  @@ -431,14 +430,14 @@
                   // in order to compare with the file contents, replace them
                   // as needed
                   String val = stringReplace(value.getText(), "\n",
  -                                           StringUtils.LINE_SEP);
  +                                           StringUtils.LINE_SEP, false);
                   String tok = stringReplace(token.getText(), "\n",
  -                                           StringUtils.LINE_SEP);
  +                                           StringUtils.LINE_SEP, false);
                   
                   // for each found token, replace with value
                   log("Replacing in " + src.getPath() + ": " + token.getText() 
                       + " --> " + value.getText(), Project.MSG_VERBOSE);
  -                newString = stringReplace(newString, tok, val);
  +                newString = stringReplace(newString, tok, val, true);
               }
   
               if (replacefilters.size() > 0) {
  @@ -474,7 +473,7 @@
           } catch (IOException ioe) {
               throw new BuildException("IOException in " + src + " - " + 
                                        ioe.getClass().getName() + ":" 
  -                                     + ioe.getMessage(), ioe, location);
  +                                     + ioe.getMessage(), ioe, getLocation());
           } finally {
               if (reader != null) {
                   try {
  @@ -509,7 +508,7 @@
               log("Replacing in " + filename + ": " + filter.getToken() 
                   + " --> " + filter.getReplaceValue(), Project.MSG_VERBOSE);
               newString = stringReplace(newString, filter.getToken(), 
  -                                      filter.getReplaceValue());
  +                                      filter.getReplaceValue(), true);
           }
   
           return newString;
  @@ -629,7 +628,8 @@
       /**
        * Replace occurrences of str1 in string str with str2
        */    
  -    private String stringReplace(String str, String str1, String str2) {
  +    private String stringReplace(String str, String str1, String str2,
  +                                 boolean countReplaces) {
           StringBuffer ret = new StringBuffer();
           int start = 0;
           int found = str.indexOf(str1);
  @@ -647,7 +647,9 @@
               // search again
               start = found + str1.length();
               found = str.indexOf(str1, start);
  -            ++replaceCount;
  +            if (countReplaces) {
  +                ++replaceCount;
  +            }
           }
   
           // write the remaining characters
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message