diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 3e0c0ec0d..883d354ce 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -210,6 +210,7 @@ Robin Green Rob Oxspring Rob van Oostrum Roger Vaughn +Ronen Mashal Russell Gold Sam Ruby Scott Carlson diff --git a/WHATSNEW b/WHATSNEW index 111133b43..87927e2b9 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -4,6 +4,9 @@ Changes from Ant 1.7.0Beta2 to current SVN version Changes that could break older environments: ------------------------------------------- +* filter reader uses ISO-8879-1 encoding to read + the java class file. Bugzilla report 33604. + Fixed bugs: ----------- diff --git a/contributors.xml b/contributors.xml index c5b95829d..b88f78399 100644 --- a/contributors.xml +++ b/contributors.xml @@ -839,6 +839,10 @@ Roger Vaughn + + Ronen + Mashal + Russell Gold diff --git a/docs/manual/CoreTypes/filterchain.html b/docs/manual/CoreTypes/filterchain.html index 8b3d95813..a835be495 100644 --- a/docs/manual/CoreTypes/filterchain.html +++ b/docs/manual/CoreTypes/filterchain.html @@ -162,30 +162,50 @@ distribution.

ClassConstants

-This filters basic constants defined in a Java Class, -and outputs them in lines composed of the format name=value. -See Library Dependencies. + This filters basic constants defined in a Java Class, + and outputs them in lines composed of the format name=value. + This filter uses the bcel library to understand the Java Class file. + See Library Dependencies.

+

+ Important: + This filter is different from most of the other filters. + Most of the filters operate on a sequence of characters. + This filter operates on the sequence of bytes that makes up + a class. However the bytes arrive to the filter as a sequence + of characters. This means that one must be careful on the + choice of character encoding to use. Most encoding lose information + on conversion from an arbitary sequence of bytes to characters + and back again to bytes. In particular the usual default + character encodings (CP152 and UTF-8) do. + For this reason, since Ant 1.7, the character + encoding ISO-8859-1 is used to convert from characters back to + bytes, so one has to use this encoding for reading the java + class file.

Example:

This loads the basic constants defined in a Java class as Ant properties. +
-<loadproperties srcfile="foo.class">
+<loadproperties srcfile="foo.class" encoding="ISO-8859-1">
   <filterchain>
-    <filterreader classname="org.apache.tools.ant.filters.ClassConstants"/>
+    <classconstants/>
   </filterchain>
 </loadproperties>
 
-Convenience method: -
-<loadproperties srcfile="foo.class">
+This loads the constants from a Java class file as Ant properties,
+prepending the names with a prefix.
+
+    
+<loadproperties srcfile="build/classes/org/acme/bar.class"
+                encoding="ISO-8859-1">
   <filterchain>
     <classconstants/>
+    <prefixlines prefix="ini."/>
   </filterchain>
 </loadproperties>
 
-

EscapeUnicode

This filter converts its input by changing all non US-ASCII characters diff --git a/src/main/org/apache/tools/ant/filters/ClassConstants.java b/src/main/org/apache/tools/ant/filters/ClassConstants.java index 65b84f90c..960f6b9ce 100644 --- a/src/main/org/apache/tools/ant/filters/ClassConstants.java +++ b/src/main/org/apache/tools/ant/filters/ClassConstants.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.Reader; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.apache.tools.ant.BuildException; /** @@ -103,7 +104,7 @@ public final class ClassConstants if (clazz == null) { ch = -1; } else { - final byte[] bytes = clazz.getBytes(); + final byte[] bytes = clazz.getBytes("ISO-8859-1"); try { final Class javaClassHelper = Class.forName(JAVA_CLASS_HELPER); @@ -125,16 +126,21 @@ public final class ClassConstants return read(); } } - } catch (ClassNotFoundException cnfe) { - throw new IOException(cnfe.getMessage()); - } catch (NoSuchMethodException nsme) { - throw new IOException(nsme.getMessage()); - } catch (IllegalAccessException iae) { - throw new IOException(iae.getMessage()); - } catch (IllegalArgumentException iarge) { - throw new IOException(iarge.getMessage()); - } catch (InvocationTargetException ite) { - throw new IOException(ite.getMessage()); + } catch (NoClassDefFoundError ex) { + throw ex; + } catch (RuntimeException ex) { + throw ex; + } catch (InvocationTargetException ex) { + Throwable t = ex.getTargetException(); + if (t instanceof NoClassDefFoundError) { + throw (NoClassDefFoundError) t; + } + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + throw new BuildException(t); + } catch (Exception ex) { + throw new BuildException(ex); } } }