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.
* Must not be <code>null</code>.
*
* @deprecated use Class.forName instead.
*/
public static void initializeClass(Class theClass) {
// ***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 {
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)) {


+ 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.
// 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",


+ 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 {
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();


+ 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.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) {


+ 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);
} else {
AntClassLoader al = getProject().createClassLoader(classpath);
Class c = al.loadClass(classname);
AntClassLoader.initializeClass(c);
Class c = Class.forName(classname, true, al);
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
* features of the SAX parser.
* 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
*/
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);
}


+ 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>.
* 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>
* &lt;junit printsummary="no" haltonfailure="yes" fork="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.
*
* <p> Either the <code>type</code> or the <code>classname</code> attribute
* must be set.
* must be set.
*
* @author Stefan Bodewig
* @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
* 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 <code>if</code> and <code>unless</code> 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 {

/**
* <p> Enumerated attribute with the values "plain", "xml" and "brief".
*
*
* <p> Use to enumerate options for <code>type</code> attribute.
*/
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
* 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>
* public static junit.framework.Test suite()
* </code></pre>
@@ -92,7 +92,7 @@ import org.apache.tools.ant.util.TeeOutputStream;
* <p> If no such method exists, all public methods starting with
* "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 <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.
*/
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 {
* <tr><td>showoutput</td><td>send output to System.err/.out as
* well as to the formatters?</td><td>false</td></tr>
*
* </table>
* </table>
*/
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

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

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


+ 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);
} else {
AntClassLoader al = getProject().createClassLoader(classpath);
c = al.loadClass(classname);
AntClassLoader.initializeClass(c);
c = Class.forName(classname, true, al);
}

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 {
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();


Loading…
Cancel
Save