diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java index 63e730685..ee3b8162e 100644 --- a/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/src/main/org/apache/tools/ant/AntClassLoader.java @@ -536,6 +536,8 @@ public class AntClassLoader extends ClassLoader implements BuildListener { * * @param theClass The class to initialize. * Must not be null. + * + * @deprecated use Class.forName instead. */ public static void initializeClass(Class theClass) { // ***HACK*** We ask the VM to create an instance diff --git a/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java b/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java index 7267d7505..0a845e864 100644 --- a/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java +++ b/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java @@ -174,8 +174,7 @@ public final class ChainReaderHelper { } else { AntClassLoader al = project.createClassLoader(classpath); - clazz = al.loadClass(className); - AntClassLoader.initializeClass(clazz); + clazz = Class.forName(className, true, al); } if (clazz != null) { if (!FilterReader.class.isAssignableFrom(clazz)) { diff --git a/src/main/org/apache/tools/ant/taskdefs/Available.java b/src/main/org/apache/tools/ant/taskdefs/Available.java index 505ec350f..a90c0ae4e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Available.java +++ b/src/main/org/apache/tools/ant/taskdefs/Available.java @@ -486,12 +486,11 @@ public class Available extends Task implements Condition { // Can return null to represent the bootstrap class loader. // see API docs of Class.getClassLoader. if (l != null) { - requiredClass = l.loadClass(classname); + requiredClass = Class.forName(classname, true, l); } else { requiredClass = Class.forName(classname); } } - AntClassLoader.initializeClass(requiredClass); return true; } catch (ClassNotFoundException e) { log("class \"" + classname + "\" was not found", diff --git a/src/main/org/apache/tools/ant/taskdefs/Definer.java b/src/main/org/apache/tools/ant/taskdefs/Definer.java index cecb7989f..3b3ecd05f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Definer.java +++ b/src/main/org/apache/tools/ant/taskdefs/Definer.java @@ -513,18 +513,15 @@ public abstract class Definer extends Task { try { try { if (onError != OnError.IGNORE) { - cl = al.loadClass(classname); - AntClassLoader.initializeClass(cl); + cl = Class.forName(classname, true, al); } if (adapter != null) { - adapterClass = al.loadClass(adapter); - AntClassLoader.initializeClass(adapterClass); + adapterClass = Class.forName(adapter, true, al); } if (adaptTo != null) { - adaptToClass = al.loadClass(adaptTo); - AntClassLoader.initializeClass(adaptToClass); + adaptToClass = Class.forName(adaptTo, true, al); } AntTypeDefinition def = new AntTypeDefinition(); diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java index 58170c527..9755edd4d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java @@ -138,8 +138,8 @@ public class ExecuteJava implements Runnable, TimeoutObserver { loader.addJavaLibraries(); loader.setIsolated(true); loader.setThreadContextLoader(); - target = loader.forceLoadClass(classname); - AntClassLoader.initializeClass(target); + loader.forceLoadClass(classname); + target = Class.forName(classname, true, loader); } main = target.getMethod("main", param); if (main == null) { diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index 9df8446b9..546d05994 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -421,8 +421,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { return Class.forName(classname); } else { AntClassLoader al = getProject().createClassLoader(classpath); - Class c = al.loadClass(classname); - AntClassLoader.initializeClass(c); + Class c = Class.forName(classname, true, al); return c; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java index 7c90eb402..50590e142 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java @@ -235,7 +235,7 @@ public class XMLValidateTask extends Task { * Add an attribute nested element. This is used for setting arbitrary * features of the SAX parser. * Valid attributes - * include + * include * @since ant1.6 */ public Attribute createAttribute() { @@ -323,8 +323,7 @@ public class XMLValidateTask extends Task { if (classpath != null) { AntClassLoader loader = getProject().createClassLoader(classpath); - readerClass = loader.loadClass(readerClassName); - AntClassLoader.initializeClass(readerClass); + readerClass = Class.forName(readerClassName, true, loader); } else { readerClass = Class.forName(readerClassName); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java index 99474b443..72af3c2a8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java @@ -65,7 +65,7 @@ import org.apache.tools.ant.types.EnumeratedAttribute; /** *

A wrapper for the implementations of JUnitResultFormatter. * In particular, used as a nested <formatter> element in a <junit> task. - *

For example, + *

For example, *

  *       <junit printsummary="no" haltonfailure="yes" fork="false">
  *           <formatter type="plain" usefile="false" />
@@ -74,7 +74,7 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
  * adds a plain type implementation (PlainJUnitResultFormatter) to display the results of the test.
  *
  * 

Either the type or the classname attribute - * must be set. + * must be set. * * @author Stefan Bodewig * @author Eli Tucker @@ -179,14 +179,14 @@ public class FormatterElement { /** * 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 */ public void setIf(String ifProperty) { this.ifProperty = ifProperty; } - + /** * Set whether this formatter should NOT be used. 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 * on it with if and unless properties. - */ + */ public boolean shouldUse(Task t) { if (ifProperty != null && t.getProject().getProperty(ifProperty) == null) { return false; - } else if (unlessProperty != null && + } else if (unlessProperty != null && t.getProject().getProperty(unlessProperty) != null) { return false; } @@ -223,20 +223,19 @@ public class FormatterElement { /** * @since Ant 1.6 */ - JUnitResultFormatter createFormatter(ClassLoader loader) + JUnitResultFormatter createFormatter(ClassLoader loader) throws BuildException { if (classname == null) { throw new BuildException("you must specify type or classname"); } - + Class f = null; try { if (loader == null) { f = Class.forName(classname); } else { - f = loader.loadClass(classname); - AntClassLoader.initializeClass(f); + f = Class.forName(classname, true, loader); } } catch (ClassNotFoundException e) { throw new BuildException(e); @@ -252,7 +251,7 @@ public class FormatterElement { } if (!(o instanceof JUnitResultFormatter)) { - throw new BuildException(classname + throw new BuildException(classname + " is not a JUnitResultFormatter"); } @@ -271,7 +270,7 @@ public class FormatterElement { /** *

Enumerated attribute with the values "plain", "xml" and "brief". - * + * *

Use to enumerate options for type attribute. */ public static class TypeAttribute extends EnumeratedAttribute { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java index 3fe11dfc4..37894ec76 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java @@ -84,7 +84,7 @@ import org.apache.tools.ant.util.TeeOutputStream; * *

This TestRunner expects a name of a TestCase class as its * 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 *


  *     public static junit.framework.Test suite()
  * 
@@ -92,7 +92,7 @@ import org.apache.tools.ant.util.TeeOutputStream; *

If no such method exists, all public methods starting with * "test" and taking no argument will be run. * - *

Summary output is generated at the end. + *

Summary output is generated at the end. * * @author Stefan Bodewig * @author Erik Hatcher @@ -131,7 +131,7 @@ public class JUnitTestRunner implements TestListener { * Do we filter junit.*.* stack frames out of failure and error exceptions. */ private static boolean filtertrace = true; - + /** * 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." }; - + /** * Do we stop on errors. */ @@ -182,27 +182,27 @@ public class JUnitTestRunner implements TestListener { /** output written during the test */ private PrintStream systemError; - + /** Error output during the test */ - private PrintStream systemOut; - + private PrintStream systemOut; + /** is this runner running in forked mode? */ private boolean forked = false; /** * 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) { this(test, haltOnError, filtertrace, haltOnFailure, false); } /** * 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 showOutput) { 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. */ - public JUnitTestRunner(JUnitTest test, boolean haltOnError, - boolean filtertrace, boolean haltOnFailure, + public JUnitTestRunner(JUnitTest test, boolean haltOnError, + boolean filtertrace, boolean haltOnFailure, ClassLoader 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. */ - public JUnitTestRunner(JUnitTest test, boolean haltOnError, - boolean filtertrace, boolean haltOnFailure, + public JUnitTestRunner(JUnitTest test, boolean haltOnError, + boolean filtertrace, boolean haltOnFailure, boolean showOutput, ClassLoader loader) { this.filtertrace = filtertrace; this.junitTest = test; @@ -234,10 +234,9 @@ public class JUnitTestRunner implements TestListener { if (loader == null) { testClass = Class.forName(test.getName()); } else { - testClass = loader.loadClass(test.getName()); - AntClassLoader.initializeClass(testClass); + testClass = Class.forName(test.getName(), true, loader); } - + Method suiteMethod = null; try { // 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 suite = new TestSuite(testClass); } - + } catch (Exception e) { retCode = ERRORS; exception = e; @@ -277,7 +276,7 @@ public class JUnitTestRunner implements TestListener { fireStartTestSuite(); if (exception != null) { // had an exception in the constructor for (int i = 0; i < formatters.size(); i++) { - ((TestListener) formatters.elementAt(i)).addError(null, + ((TestListener) formatters.elementAt(i)).addError(null, exception); } junitTest.setCounts(1, 0, 1); @@ -287,7 +286,7 @@ public class JUnitTestRunner implements TestListener { ByteArrayOutputStream errStrm = new ByteArrayOutputStream(); systemError = new PrintStream(errStrm); - + ByteArrayOutputStream outStrm = new ByteArrayOutputStream(); systemOut = new PrintStream(outStrm); @@ -306,13 +305,13 @@ public class JUnitTestRunner implements TestListener { ) ); System.setErr(new PrintStream( - new TeeOutputStream(savedErr, + new TeeOutputStream(savedErr, systemError) ) ); } } - + try { suite.run(res); @@ -323,7 +322,7 @@ public class JUnitTestRunner implements TestListener { if (savedErr != null) { System.setErr(savedErr); } - + systemError.close(); systemError = null; systemOut.close(); @@ -331,7 +330,7 @@ public class JUnitTestRunner implements TestListener { sendOutAndErr(new String(outStrm.toByteArray()), new String(errStrm.toByteArray())); - junitTest.setCounts(res.runCount(), res.failureCount(), + junitTest.setCounts(res.runCount(), res.failureCount(), res.errorCount()); junitTest.setRunTime(System.currentTimeMillis() - start); } @@ -404,40 +403,40 @@ public class JUnitTestRunner implements TestListener { systemOut.println(line); } } - + /** * @see Task#handleInput(byte[], int, int) - * + * * @since Ant 1.6 */ - protected int handleInput(byte[] buffer, int offset, int length) + protected int handleInput(byte[] buffer, int offset, int length) throws IOException { return -1; } - + protected void handleErrorOutput(String line) { if (systemError != null) { systemError.println(line); } } - + protected void handleFlush(String line) { if (systemOut != null) { systemOut.print(line); } } - + protected void handleErrorFlush(String line) { if (systemError != null) { systemError.print(line); } } - + private void sendOutAndErr(String out, String err) { for (int i = 0; i < formatters.size(); i++) { - JUnitResultFormatter formatter = + JUnitResultFormatter formatter = ((JUnitResultFormatter) formatters.elementAt(i)); - + formatter.setSystemOutput(out); formatter.setSystemError(err); } @@ -483,7 +482,7 @@ public class JUnitTestRunner implements TestListener { * showoutputsend output to System.err/.out as * well as to the formatters?false * - * + * */ public static void main(String[] args) throws IOException { boolean haltError = false; @@ -520,9 +519,9 @@ public class JUnitTestRunner implements TestListener { showOut = Project.toBoolean(args[i].substring(11)); } } - + JUnitTest t = new JUnitTest(args[0]); - + // Add/overlay system properties on the properties from the Ant project Hashtable p = System.getProperties(); for (Enumeration enum = p.keys(); enum.hasMoreElements();) { @@ -563,7 +562,7 @@ public class JUnitTestRunner implements TestListener { } fromCmdLine.addElement(fe.createFormatter()); } - + /** * Returns a filtered stack trace. * This is ripped out of junit.runner.BaseTestRunner. @@ -607,5 +606,5 @@ public class JUnitTestRunner implements TestListener { } return false; } - + } // JUnitTestRunner diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java b/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java index dc68a56db..8f709c8f4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java @@ -81,8 +81,7 @@ public class WLRmic extends DefaultRmicAdapter { } else { loader = 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", new Class [] { String[].class }); diff --git a/src/main/org/apache/tools/ant/types/Mapper.java b/src/main/org/apache/tools/ant/types/Mapper.java index 7420e7b32..ac4b1c2b6 100644 --- a/src/main/org/apache/tools/ant/types/Mapper.java +++ b/src/main/org/apache/tools/ant/types/Mapper.java @@ -199,8 +199,7 @@ public class Mapper extends DataType implements Cloneable { c = Class.forName(classname); } else { AntClassLoader al = getProject().createClassLoader(classpath); - c = al.loadClass(classname); - AntClassLoader.initializeClass(c); + c = Class.forName(classname, true, al); } FileNameMapper m = (FileNameMapper) c.newInstance(); diff --git a/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java b/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java index 05e8bacc2..125d9a277 100644 --- a/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java +++ b/src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java @@ -104,8 +104,7 @@ public class ExtendSelector extends BaseSelector { } else { AntClassLoader al = getProject().createClassLoader(classpath); - c = al.loadClass(classname); - AntClassLoader.initializeClass(c); + c = Class.forName(classname, true, al); } dynselector = (FileSelector) c.newInstance(); final Project project = getProject();