Browse Source

Bugzilla 33604: classconstants filter broken

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@447159 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 19 years ago
parent
commit
d9d9e2f86f
5 changed files with 54 additions and 20 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +29
    -9
      docs/manual/CoreTypes/filterchain.html
  5. +17
    -11
      src/main/org/apache/tools/ant/filters/ClassConstants.java

+ 1
- 0
CONTRIBUTORS View File

@@ -210,6 +210,7 @@ Robin Green
Rob Oxspring
Rob van Oostrum
Roger Vaughn
Ronen Mashal
Russell Gold
Sam Ruby
Scott Carlson


+ 3
- 0
WHATSNEW View File

@@ -4,6 +4,9 @@ Changes from Ant 1.7.0Beta2 to current SVN version
Changes that could break older environments:
-------------------------------------------

* <classconstants> filter reader uses ISO-8879-1 encoding to read
the java class file. Bugzilla report 33604.

Fixed bugs:
-----------



+ 4
- 0
contributors.xml View File

@@ -839,6 +839,10 @@
<first>Roger</first>
<last>Vaughn</last>
</name>
<name>
<first>Ronen</first>
<last>Mashal</last>
</name>
<name>
<first>Russell</first>
<last>Gold</last>


+ 29
- 9
docs/manual/CoreTypes/filterchain.html View File

@@ -162,30 +162,50 @@ distribution.

<h3><a name="classconstants">ClassConstants</a></h3>
<p>
This filters basic constants defined in a Java Class,
and outputs them in lines composed of the format <i>name</i>=<i>value</i>.
See <a href="../install.html#librarydependencies">Library Dependencies</a>.
This filters basic constants defined in a Java Class,
and outputs them in lines composed of the format <i>name</i>=<i>value</i>.
This filter uses the <em>bcel</em> library to understand the Java Class file.
See <a href="../install.html#librarydependencies">Library Dependencies</a>.
<p>
<p>
<em><b>Important:</b></em>
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, <em>since Ant 1.7</em>, the character
encoding <b>ISO-8859-1</b> is used to convert from characters back to
bytes, so one <b>has</b> to use this encoding for reading the java
class file.
<h4>Example:</h4>

This loads the basic constants defined in a Java class as Ant properties.

<blockquote><pre>
&lt;loadproperties srcfile=&quot;foo.class&quot;&gt;
&lt;loadproperties srcfile="foo.class" encoding="ISO-8859-1"&gt;
&lt;filterchain&gt;
&lt;filterreader classname=&quot;org.apache.tools.ant.filters.ClassConstants&quot;/&gt;
&lt;classconstants/&gt;
&lt;/filterchain&gt;
&lt;/loadproperties&gt;
</pre></blockquote>

Convenience method:
<blockquote><pre>
&lt;loadproperties srcfile=&quot;foo.class&quot;&gt;
This loads the constants from a Java class file as Ant properties,
prepending the names with a prefix.

<blockquote><pre>
&lt;loadproperties srcfile="build/classes/org/acme/bar.class"
encoding="ISO-8859-1"&gt;
&lt;filterchain&gt;
&lt;classconstants/&gt;
&lt;prefixlines prefix="ini."/&gt;
&lt;/filterchain&gt;
&lt;/loadproperties&gt;
</pre></blockquote>

<h3><a name="escapeunicode">EscapeUnicode</a></h3>
<p>
This filter converts its input by changing all non US-ASCII characters


+ 17
- 11
src/main/org/apache/tools/ant/filters/ClassConstants.java View File

@@ -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);
}
}
}


Loading…
Cancel
Save