Browse Source

Remove use of InitializeClass now that we are JDK 1.2+

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274814 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
2450ee6bbf
12 changed files with 64 additions and 74 deletions
  1. +2
    -0
      src/main/org/apache/tools/ant/AntClassLoader.java
  2. +1
    -2
      src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
  3. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/Available.java
  4. +3
    -6
      src/main/org/apache/tools/ant/taskdefs/Definer.java
  5. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
  6. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  7. +2
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  8. +11
    -12
      src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
  9. +38
    -39
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  10. +1
    -2
      src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java
  11. +1
    -2
      src/main/org/apache/tools/ant/types/Mapper.java
  12. +1
    -2
      src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java

+ 2
- 0
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -536,6 +536,8 @@ public class AntClassLoader extends ClassLoader implements BuildListener {
* *
* @param theClass The class to initialize. * @param theClass The class to initialize.
* Must not be <code>null</code>. * Must not be <code>null</code>.
*
* @deprecated use Class.forName instead.
*/ */
public static void initializeClass(Class theClass) { public static void initializeClass(Class theClass) {
// ***HACK*** We ask the VM to create an instance // ***HACK*** We ask the VM to create an instance


+ 1
- 2
src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java View File

@@ -174,8 +174,7 @@ public final class ChainReaderHelper {
} else { } else {
AntClassLoader al AntClassLoader al
= project.createClassLoader(classpath); = project.createClassLoader(classpath);
clazz = al.loadClass(className);
AntClassLoader.initializeClass(clazz);
clazz = Class.forName(className, true, al);
} }
if (clazz != null) { if (clazz != null) {
if (!FilterReader.class.isAssignableFrom(clazz)) { if (!FilterReader.class.isAssignableFrom(clazz)) {


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -486,12 +486,11 @@ public class Available extends Task implements Condition {
// Can return null to represent the bootstrap class loader. // Can return null to represent the bootstrap class loader.
// see API docs of Class.getClassLoader. // see API docs of Class.getClassLoader.
if (l != null) { if (l != null) {
requiredClass = l.loadClass(classname);
requiredClass = Class.forName(classname, true, l);
} else { } else {
requiredClass = Class.forName(classname); requiredClass = Class.forName(classname);
} }
} }
AntClassLoader.initializeClass(requiredClass);
return true; return true;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
log("class \"" + classname + "\" was not found", log("class \"" + classname + "\" was not found",


+ 3
- 6
src/main/org/apache/tools/ant/taskdefs/Definer.java View File

@@ -513,18 +513,15 @@ public abstract class Definer extends Task {
try { try {
try { try {
if (onError != OnError.IGNORE) { if (onError != OnError.IGNORE) {
cl = al.loadClass(classname);
AntClassLoader.initializeClass(cl);
cl = Class.forName(classname, true, al);
} }


if (adapter != null) { if (adapter != null) {
adapterClass = al.loadClass(adapter);
AntClassLoader.initializeClass(adapterClass);
adapterClass = Class.forName(adapter, true, al);
} }


if (adaptTo != null) { if (adaptTo != null) {
adaptToClass = al.loadClass(adaptTo);
AntClassLoader.initializeClass(adaptToClass);
adaptToClass = Class.forName(adaptTo, true, al);
} }


AntTypeDefinition def = new AntTypeDefinition(); AntTypeDefinition def = new AntTypeDefinition();


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java View File

@@ -138,8 +138,8 @@ public class ExecuteJava implements Runnable, TimeoutObserver {
loader.addJavaLibraries(); loader.addJavaLibraries();
loader.setIsolated(true); loader.setIsolated(true);
loader.setThreadContextLoader(); loader.setThreadContextLoader();
target = loader.forceLoadClass(classname);
AntClassLoader.initializeClass(target);
loader.forceLoadClass(classname);
target = Class.forName(classname, true, loader);
} }
main = target.getMethod("main", param); main = target.getMethod("main", param);
if (main == null) { if (main == null) {


+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -421,8 +421,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
return Class.forName(classname); return Class.forName(classname);
} else { } else {
AntClassLoader al = getProject().createClassLoader(classpath); AntClassLoader al = getProject().createClassLoader(classpath);
Class c = al.loadClass(classname);
AntClassLoader.initializeClass(c);
Class c = Class.forName(classname, true, al);
return c; return c;
} }
} }


+ 2
- 3
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -235,7 +235,7 @@ public class XMLValidateTask extends Task {
* Add an attribute nested element. This is used for setting arbitrary * Add an attribute nested element. This is used for setting arbitrary
* features of the SAX parser. * features of the SAX parser.
* Valid attributes * Valid attributes
* <a href=http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description">include</a>
* <a href="http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html#package_description">include</a>
* @since ant1.6 * @since ant1.6
*/ */
public Attribute createAttribute() { public Attribute createAttribute() {
@@ -323,8 +323,7 @@ public class XMLValidateTask extends Task {
if (classpath != null) { if (classpath != null) {
AntClassLoader loader AntClassLoader loader
= getProject().createClassLoader(classpath); = getProject().createClassLoader(classpath);
readerClass = loader.loadClass(readerClassName);
AntClassLoader.initializeClass(readerClass);
readerClass = Class.forName(readerClassName, true, loader);
} else { } else {
readerClass = Class.forName(readerClassName); readerClass = Class.forName(readerClassName);
} }


+ 11
- 12
src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java View File

@@ -65,7 +65,7 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
/** /**
* <p> A wrapper for the implementations of <code>JUnitResultFormatter</code>. * <p> A wrapper for the implementations of <code>JUnitResultFormatter</code>.
* In particular, used as a nested <code>&lt;formatter&gt;</code> element in a <code>&lt;junit&gt;</code> task. * In particular, used as a nested <code>&lt;formatter&gt;</code> element in a <code>&lt;junit&gt;</code> task.
* <p> For example,
* <p> For example,
* <code><pre> * <code><pre>
* &lt;junit printsummary="no" haltonfailure="yes" fork="false"&gt; * &lt;junit printsummary="no" haltonfailure="yes" fork="false"&gt;
* &lt;formatter type="plain" usefile="false" /&gt; * &lt;formatter type="plain" usefile="false" /&gt;
@@ -74,7 +74,7 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* adds a <code>plain</code> type implementation (<code>PlainJUnitResultFormatter</code>) to display the results of the test. * adds a <code>plain</code> type implementation (<code>PlainJUnitResultFormatter</code>) to display the results of the test.
* *
* <p> Either the <code>type</code> or the <code>classname</code> attribute * <p> Either the <code>type</code> or the <code>classname</code> attribute
* must be set.
* must be set.
* *
* @author Stefan Bodewig * @author Stefan Bodewig
* @author <a href="http://nerdmonkey.com">Eli Tucker</a> * @author <a href="http://nerdmonkey.com">Eli Tucker</a>
@@ -179,14 +179,14 @@ public class FormatterElement {


/** /**
* Set whether this formatter should be used. It will be * Set whether this formatter should be used. It will be
* used if the property has been set, otherwise it won't.
* used if the property has been set, otherwise it won't.
* @param ifProperty name of property * @param ifProperty name of property
*/ */
public void setIf(String ifProperty) public void setIf(String ifProperty)
{ {
this.ifProperty = ifProperty; this.ifProperty = ifProperty;
} }
/** /**
* Set whether this formatter should NOT be used. It * Set whether this formatter should NOT be used. It
* will not be used if the property has been set, orthwise it * will not be used if the property has been set, orthwise it
@@ -201,11 +201,11 @@ public class FormatterElement {
/** /**
* Ensures that the selector passes the conditions placed * Ensures that the selector passes the conditions placed
* on it with <code>if</code> and <code>unless</code> properties. * on it with <code>if</code> and <code>unless</code> properties.
*/
*/
public boolean shouldUse(Task t) { public boolean shouldUse(Task t) {
if (ifProperty != null && t.getProject().getProperty(ifProperty) == null) { if (ifProperty != null && t.getProject().getProperty(ifProperty) == null) {
return false; return false;
} else if (unlessProperty != null &&
} else if (unlessProperty != null &&
t.getProject().getProperty(unlessProperty) != null) { t.getProject().getProperty(unlessProperty) != null) {
return false; return false;
} }
@@ -223,20 +223,19 @@ public class FormatterElement {
/** /**
* @since Ant 1.6 * @since Ant 1.6
*/ */
JUnitResultFormatter createFormatter(ClassLoader loader)
JUnitResultFormatter createFormatter(ClassLoader loader)
throws BuildException { throws BuildException {


if (classname == null) { if (classname == null) {
throw new BuildException("you must specify type or classname"); throw new BuildException("you must specify type or classname");
} }
Class f = null; Class f = null;
try { try {
if (loader == null) { if (loader == null) {
f = Class.forName(classname); f = Class.forName(classname);
} else { } else {
f = loader.loadClass(classname);
AntClassLoader.initializeClass(f);
f = Class.forName(classname, true, loader);
} }
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new BuildException(e); throw new BuildException(e);
@@ -252,7 +251,7 @@ public class FormatterElement {
} }


if (!(o instanceof JUnitResultFormatter)) { if (!(o instanceof JUnitResultFormatter)) {
throw new BuildException(classname
throw new BuildException(classname
+ " is not a JUnitResultFormatter"); + " is not a JUnitResultFormatter");
} }


@@ -271,7 +270,7 @@ public class FormatterElement {


/** /**
* <p> Enumerated attribute with the values "plain", "xml" and "brief". * <p> Enumerated attribute with the values "plain", "xml" and "brief".
*
*
* <p> Use to enumerate options for <code>type</code> attribute. * <p> Use to enumerate options for <code>type</code> attribute.
*/ */
public static class TypeAttribute extends EnumeratedAttribute { public static class TypeAttribute extends EnumeratedAttribute {


+ 38
- 39
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -84,7 +84,7 @@ import org.apache.tools.ant.util.TeeOutputStream;
* *
* <p>This TestRunner expects a name of a TestCase class as its * <p>This TestRunner expects a name of a TestCase class as its
* argument. If this class provides a static suite() method it will be * argument. If this class provides a static suite() method it will be
* called and the resulting Test will be run. So, the signature should be
* called and the resulting Test will be run. So, the signature should be
* <pre><code> * <pre><code>
* public static junit.framework.Test suite() * public static junit.framework.Test suite()
* </code></pre> * </code></pre>
@@ -92,7 +92,7 @@ import org.apache.tools.ant.util.TeeOutputStream;
* <p> If no such method exists, all public methods starting with * <p> If no such method exists, all public methods starting with
* "test" and taking no argument will be run. * "test" and taking no argument will be run.
* *
* <p> Summary output is generated at the end.
* <p> Summary output is generated at the end.
* *
* @author Stefan Bodewig * @author Stefan Bodewig
* @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a> * @author <a href="mailto:ehatcher@apache.org">Erik Hatcher</a>
@@ -131,7 +131,7 @@ public class JUnitTestRunner implements TestListener {
* Do we filter junit.*.* stack frames out of failure and error exceptions. * Do we filter junit.*.* stack frames out of failure and error exceptions.
*/ */
private static boolean filtertrace = true; private static boolean filtertrace = true;
/** /**
* Do we send output to System.out/.err in addition to the formatters? * Do we send output to System.out/.err in addition to the formatters?
*/ */
@@ -149,7 +149,7 @@ public class JUnitTestRunner implements TestListener {
"org.apache.tools.ant." "org.apache.tools.ant."
}; };


/** /**
* Do we stop on errors. * Do we stop on errors.
*/ */
@@ -182,27 +182,27 @@ public class JUnitTestRunner implements TestListener {


/** output written during the test */ /** output written during the test */
private PrintStream systemError; private PrintStream systemError;
/** Error output during the test */ /** Error output during the test */
private PrintStream systemOut;
private PrintStream systemOut;
/** is this runner running in forked mode? */ /** is this runner running in forked mode? */
private boolean forked = false; private boolean forked = false;


/** /**
* Constructor for fork=true or when the user hasn't specified a * Constructor for fork=true or when the user hasn't specified a
* classpath.
* classpath.
*/ */
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
boolean filtertrace, boolean haltOnFailure) { boolean filtertrace, boolean haltOnFailure) {
this(test, haltOnError, filtertrace, haltOnFailure, false); this(test, haltOnError, filtertrace, haltOnFailure, false);
} }


/** /**
* Constructor for fork=true or when the user hasn't specified a * Constructor for fork=true or when the user hasn't specified a
* classpath.
* classpath.
*/ */
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
boolean filtertrace, boolean haltOnFailure, boolean filtertrace, boolean haltOnFailure,
boolean showOutput) { boolean showOutput) {
this(test, haltOnError, filtertrace, haltOnFailure, showOutput, null); this(test, haltOnError, filtertrace, haltOnFailure, showOutput, null);
@@ -211,8 +211,8 @@ public class JUnitTestRunner implements TestListener {
/** /**
* Constructor to use when the user has specified a classpath. * Constructor to use when the user has specified a classpath.
*/ */
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
boolean filtertrace, boolean haltOnFailure,
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
boolean filtertrace, boolean haltOnFailure,
ClassLoader loader) { ClassLoader loader) {
this(test, haltOnError, filtertrace, haltOnFailure, false, loader); this(test, haltOnError, filtertrace, haltOnFailure, false, loader);
} }
@@ -220,8 +220,8 @@ public class JUnitTestRunner implements TestListener {
/** /**
* Constructor to use when the user has specified a classpath. * Constructor to use when the user has specified a classpath.
*/ */
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
boolean filtertrace, boolean haltOnFailure,
public JUnitTestRunner(JUnitTest test, boolean haltOnError,
boolean filtertrace, boolean haltOnFailure,
boolean showOutput, ClassLoader loader) { boolean showOutput, ClassLoader loader) {
this.filtertrace = filtertrace; this.filtertrace = filtertrace;
this.junitTest = test; this.junitTest = test;
@@ -234,10 +234,9 @@ public class JUnitTestRunner implements TestListener {
if (loader == null) { if (loader == null) {
testClass = Class.forName(test.getName()); testClass = Class.forName(test.getName());
} else { } else {
testClass = loader.loadClass(test.getName());
AntClassLoader.initializeClass(testClass);
testClass = Class.forName(test.getName(), true, loader);
} }
Method suiteMethod = null; Method suiteMethod = null;
try { try {
// check if there is a suite method // check if there is a suite method
@@ -258,7 +257,7 @@ public class JUnitTestRunner implements TestListener {
// this will generate warnings if the class is no suitable Test // this will generate warnings if the class is no suitable Test
suite = new TestSuite(testClass); suite = new TestSuite(testClass);
} }
} catch (Exception e) { } catch (Exception e) {
retCode = ERRORS; retCode = ERRORS;
exception = e; exception = e;
@@ -277,7 +276,7 @@ public class JUnitTestRunner implements TestListener {
fireStartTestSuite(); fireStartTestSuite();
if (exception != null) { // had an exception in the constructor if (exception != null) { // had an exception in the constructor
for (int i = 0; i < formatters.size(); i++) { for (int i = 0; i < formatters.size(); i++) {
((TestListener) formatters.elementAt(i)).addError(null,
((TestListener) formatters.elementAt(i)).addError(null,
exception); exception);
} }
junitTest.setCounts(1, 0, 1); junitTest.setCounts(1, 0, 1);
@@ -287,7 +286,7 @@ public class JUnitTestRunner implements TestListener {


ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); ByteArrayOutputStream errStrm = new ByteArrayOutputStream();
systemError = new PrintStream(errStrm); systemError = new PrintStream(errStrm);
ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); ByteArrayOutputStream outStrm = new ByteArrayOutputStream();
systemOut = new PrintStream(outStrm); systemOut = new PrintStream(outStrm);


@@ -306,13 +305,13 @@ public class JUnitTestRunner implements TestListener {
) )
); );
System.setErr(new PrintStream( System.setErr(new PrintStream(
new TeeOutputStream(savedErr,
new TeeOutputStream(savedErr,
systemError) systemError)
) )
); );
} }
} }


try { try {
suite.run(res); suite.run(res);
@@ -323,7 +322,7 @@ public class JUnitTestRunner implements TestListener {
if (savedErr != null) { if (savedErr != null) {
System.setErr(savedErr); System.setErr(savedErr);
} }
systemError.close(); systemError.close();
systemError = null; systemError = null;
systemOut.close(); systemOut.close();
@@ -331,7 +330,7 @@ public class JUnitTestRunner implements TestListener {
sendOutAndErr(new String(outStrm.toByteArray()), sendOutAndErr(new String(outStrm.toByteArray()),
new String(errStrm.toByteArray())); new String(errStrm.toByteArray()));


junitTest.setCounts(res.runCount(), res.failureCount(),
junitTest.setCounts(res.runCount(), res.failureCount(),
res.errorCount()); res.errorCount());
junitTest.setRunTime(System.currentTimeMillis() - start); junitTest.setRunTime(System.currentTimeMillis() - start);
} }
@@ -404,40 +403,40 @@ public class JUnitTestRunner implements TestListener {
systemOut.println(line); systemOut.println(line);
} }
} }
/** /**
* @see Task#handleInput(byte[], int, int) * @see Task#handleInput(byte[], int, int)
*
*
* @since Ant 1.6 * @since Ant 1.6
*/ */
protected int handleInput(byte[] buffer, int offset, int length)
protected int handleInput(byte[] buffer, int offset, int length)
throws IOException { throws IOException {
return -1; return -1;
} }
protected void handleErrorOutput(String line) { protected void handleErrorOutput(String line) {
if (systemError != null) { if (systemError != null) {
systemError.println(line); systemError.println(line);
} }
} }
protected void handleFlush(String line) { protected void handleFlush(String line) {
if (systemOut != null) { if (systemOut != null) {
systemOut.print(line); systemOut.print(line);
} }
} }
protected void handleErrorFlush(String line) { protected void handleErrorFlush(String line) {
if (systemError != null) { if (systemError != null) {
systemError.print(line); systemError.print(line);
} }
} }
private void sendOutAndErr(String out, String err) { private void sendOutAndErr(String out, String err) {
for (int i = 0; i < formatters.size(); i++) { for (int i = 0; i < formatters.size(); i++) {
JUnitResultFormatter formatter =
JUnitResultFormatter formatter =
((JUnitResultFormatter) formatters.elementAt(i)); ((JUnitResultFormatter) formatters.elementAt(i));
formatter.setSystemOutput(out); formatter.setSystemOutput(out);
formatter.setSystemError(err); formatter.setSystemError(err);
} }
@@ -483,7 +482,7 @@ public class JUnitTestRunner implements TestListener {
* <tr><td>showoutput</td><td>send output to System.err/.out as * <tr><td>showoutput</td><td>send output to System.err/.out as
* well as to the formatters?</td><td>false</td></tr> * well as to the formatters?</td><td>false</td></tr>
* *
* </table>
* </table>
*/ */
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
boolean haltError = false; boolean haltError = false;
@@ -520,9 +519,9 @@ public class JUnitTestRunner implements TestListener {
showOut = Project.toBoolean(args[i].substring(11)); showOut = Project.toBoolean(args[i].substring(11));
} }
} }
JUnitTest t = new JUnitTest(args[0]); JUnitTest t = new JUnitTest(args[0]);
// Add/overlay system properties on the properties from the Ant project // Add/overlay system properties on the properties from the Ant project
Hashtable p = System.getProperties(); Hashtable p = System.getProperties();
for (Enumeration enum = p.keys(); enum.hasMoreElements();) { for (Enumeration enum = p.keys(); enum.hasMoreElements();) {
@@ -563,7 +562,7 @@ public class JUnitTestRunner implements TestListener {
} }
fromCmdLine.addElement(fe.createFormatter()); fromCmdLine.addElement(fe.createFormatter());
} }
/** /**
* Returns a filtered stack trace. * Returns a filtered stack trace.
* This is ripped out of junit.runner.BaseTestRunner. * This is ripped out of junit.runner.BaseTestRunner.
@@ -607,5 +606,5 @@ public class JUnitTestRunner implements TestListener {
} }
return false; return false;
} }
} // JUnitTestRunner } // JUnitTestRunner

+ 1
- 2
src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java View File

@@ -81,8 +81,7 @@ public class WLRmic extends DefaultRmicAdapter {
} else { } else {
loader loader
= getRmic().getProject().createClassLoader(getRmic().getClasspath()); = getRmic().getProject().createClassLoader(getRmic().getClasspath());
c = loader.loadClass("weblogic.rmic");
AntClassLoader.initializeClass(c);
c = Class.forName("weblogic.rmic", true, loader);
} }
Method doRmic = c.getMethod("main", Method doRmic = c.getMethod("main",
new Class [] { String[].class }); new Class [] { String[].class });


+ 1
- 2
src/main/org/apache/tools/ant/types/Mapper.java View File

@@ -199,8 +199,7 @@ public class Mapper extends DataType implements Cloneable {
c = Class.forName(classname); c = Class.forName(classname);
} else { } else {
AntClassLoader al = getProject().createClassLoader(classpath); AntClassLoader al = getProject().createClassLoader(classpath);
c = al.loadClass(classname);
AntClassLoader.initializeClass(c);
c = Class.forName(classname, true, al);
} }


FileNameMapper m = (FileNameMapper) c.newInstance(); FileNameMapper m = (FileNameMapper) c.newInstance();


+ 1
- 2
src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java View File

@@ -104,8 +104,7 @@ public class ExtendSelector extends BaseSelector {
} else { } else {
AntClassLoader al AntClassLoader al
= getProject().createClassLoader(classpath); = getProject().createClassLoader(classpath);
c = al.loadClass(classname);
AntClassLoader.initializeClass(c);
c = Class.forName(classname, true, al);
} }
dynselector = (FileSelector) c.newInstance(); dynselector = (FileSelector) c.newInstance();
final Project project = getProject(); final Project project = getProject();


Loading…
Cancel
Save