diff --git a/WHATSNEW b/WHATSNEW index e5a220f4c..e13babb97 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -1,5 +1,19 @@ -Changes from Ant 1.5.4 to current CVS version -============================================= +Changes from Ant 1.6 to current cvs version +=========================================== + +Changes that could break older environments: +-------------------------------------------- + +Fixed bugs: +----------- +* Translate task does not remove tokens when a key is not found. + It logs a verbose message. Bugzilla Report 13936. + +Other changes: +-------------- + +Changes from Ant 1.5.4 to Ant 1.6Beta1 +====================================== Changes that could break older environments: -------------------------------------------- diff --git a/src/etc/testcases/taskdefs/optional/i18n/translate/expected/de/template.txt b/src/etc/testcases/taskdefs/optional/i18n/translate/expected/de/template.txt index cead46bd3..9a7af4e22 100644 --- a/src/etc/testcases/taskdefs/optional/i18n/translate/expected/de/template.txt +++ b/src/etc/testcases/taskdefs/optional/i18n/translate/expected/de/template.txt @@ -1 +1 @@ -Diese ist eine Demo Datei für die translate_Aufgabe. +Diese ist eine Demo Datei für die translate_Aufgabe @missing_token@. diff --git a/src/etc/testcases/taskdefs/optional/i18n/translate/input/template.txt b/src/etc/testcases/taskdefs/optional/i18n/translate/input/template.txt index 3dca142a5..cda413bd7 100644 --- a/src/etc/testcases/taskdefs/optional/i18n/translate/input/template.txt +++ b/src/etc/testcases/taskdefs/optional/i18n/translate/input/template.txt @@ -1 +1 @@ -@This@ @is@ @a@ @demo@ @file@ @for@ @the@ translate@_task@. +@This@ @is@ @a@ @demo@ @file@ @for@ @the@ translate@_task@ @missing_token@. diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java index a12703ca8..a7d58963d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java @@ -577,66 +577,66 @@ public class Translate extends MatchingTask { lineTokenizer.setIncludeDelims(true); line = lineTokenizer.getToken(in); while ((line) != null) { - // 2003-02-21 new replace algorithm by tbee (tbee@tbee.org) - // because it wasn't able to replace something like "@aaa;@bbb;" - - // is there a startToken - // and there is still stuff following the startToken - int startIndex = line.indexOf(startToken); - while (startIndex >= 0 - && (startIndex + startToken.length()) <= line.length()) { - // the new value, this needs to be here - // because it is required to calculate the next position to search from - // at the end of the loop - String replace = null; - - // we found a starttoken, is there an endtoken following? - // start at token+tokenlength because start and end - // token may be indentical - int endIndex = line.indexOf(endToken, startIndex + startToken.length()); - if (endIndex < 0) { - startIndex += 1; - } else { - // grab the token - String token - = line.substring(startIndex + startToken.length(), endIndex); - - // If there is a white space or = or :, then - // it isn't to be treated as a valid key. - boolean validToken = true; - for (int k = 0; k < token.length() && validToken; k++) { - char c = token.charAt(k); - if (c == ':' || c == '=' - || Character.isSpaceChar(c)) { - validToken = false; - } - } - if (!validToken) { + // 2003-02-21 new replace algorithm by tbee (tbee@tbee.org) + // because it wasn't able to replace something like "@aaa;@bbb;" + + // is there a startToken + // and there is still stuff following the startToken + int startIndex = line.indexOf(startToken); + while (startIndex >= 0 + && (startIndex + startToken.length()) <= line.length()) { + // the new value, this needs to be here + // because it is required to calculate the next position to search from + // at the end of the loop + String replace = null; + + // we found a starttoken, is there an endtoken following? + // start at token+tokenlength because start and end + // token may be indentical + int endIndex = line.indexOf(endToken, startIndex + startToken.length()); + if (endIndex < 0) { startIndex += 1; } else { - // find the replace string - if (resourceMap.containsKey(token)) { - replace = (String) resourceMap.get(token); + // grab the token + String token + = line.substring(startIndex + startToken.length(), endIndex); + + // If there is a white space or = or :, then + // it isn't to be treated as a valid key. + boolean validToken = true; + for (int k = 0; k < token.length() && validToken; k++) { + char c = token.charAt(k); + if (c == ':' || c == '=' + || Character.isSpaceChar(c)) { + validToken = false; + } + } + if (!validToken) { + startIndex += 1; } else { - replace = token; + // find the replace string + if (resourceMap.containsKey(token)) { + replace = (String) resourceMap.get(token); + } else { + log("Replacement string missing for: " + + token, Project.MSG_VERBOSE); + replace = startToken + token + endToken; + } + + + // generate the new line + line = line.substring(0, startIndex) + + replace + + line.substring(endIndex + endToken.length()); + + // set start position for next search + startIndex += replace.length(); } - - - // generate the new line - line = line.substring(0, startIndex) - + replace - + line.substring(endIndex + endToken.length()); - - // set start position for next search - startIndex += replace.length(); } - } - - // find next starttoken - startIndex = line.indexOf(startToken, startIndex); - } - + // find next starttoken + startIndex = line.indexOf(startToken, startIndex); + } out.write(line); line = lineTokenizer.getToken(in); }