Bug 32551 - "Run Ant" causes ClassCastException with filesets
diff --git a/ant/org.eclipse.ant.core/lib/antsupportlib.jar b/ant/org.eclipse.ant.core/lib/antsupportlib.jar
index 4229a58..879132d 100644
--- a/ant/org.eclipse.ant.core/lib/antsupportlib.jar
+++ b/ant/org.eclipse.ant.core/lib/antsupportlib.jar
Binary files differ
diff --git a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalProject.java b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalProject.java
index 8dff895..9a60232 100644
--- a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalProject.java
+++ b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalProject.java
@@ -76,21 +76,20 @@
/**
* A subclass of Project to facilitate "faster" parsing with
- * less garbage generated.
+ * less garbage generated. This class is not used on Ant 1.6 and newer
+ * due to the improvements in lazy loading of these Ant versions.
*
* Only three tasks are loaded (property, taskdef and
* typedef: three tasks that can be defined outside of a target on Ant 1.5.1 or older).
*
- * Datatypes are loaded as required.
+ * Datatypes are loaded if requested.
*
* Derived from the original Ant Project class
*/
public class InternalProject extends Project {
- Hashtable typeNameToClassName = null;
- /**
- *
- */
+ private Hashtable typeNameToClass = null;
+
public InternalProject() {
super();
}
@@ -121,18 +120,12 @@
* @see org.apache.tools.ant.Project#createDataType(java.lang.String)
*/
public Object createDataType(String typeName) throws BuildException {
- if (typeNameToClassName == null) {
+ if (typeNameToClass == null) {
initializeTypes();
}
- String className = (String) typeNameToClassName.get(typeName);
+ Class typeClass = (Class) typeNameToClass.get(typeName);
- Class c = null;
- try {
- c = Class.forName(className);
- } catch (ClassNotFoundException e) {
- }
-
- if (c == null) {
+ if (typeClass == null) {
return null;
}
@@ -142,10 +135,10 @@
// DataType can have a "no arg" constructor or take a single
// Project argument.
try {
- ctor = c.getConstructor(new Class[0]);
+ ctor = typeClass.getConstructor(new Class[0]);
noArg = true;
} catch (NoSuchMethodException nse) {
- ctor = c.getConstructor(new Class[] { Project.class });
+ ctor = typeClass.getConstructor(new Class[] { Project.class });
noArg = false;
}
@@ -170,7 +163,7 @@
* Initialize the mapping of data type name to data type classname
*/
private void initializeTypes() {
- typeNameToClassName = new Hashtable(18);
+ typeNameToClass = new Hashtable(18);
String dataDefs = "/org/apache/tools/ant/types/defaults.properties"; //$NON-NLS-1$
try {
Properties props = new Properties();
@@ -183,9 +176,17 @@
Enumeration enum = props.propertyNames();
while (enum.hasMoreElements()) {
- String key = (String) enum.nextElement();
- String value = props.getProperty(key);
- typeNameToClassName.put(key, value);
+ String typeName = (String) enum.nextElement();
+ String className = props.getProperty(typeName);
+ try {
+ Class typeClass= Class.forName(className);
+ typeNameToClass.put(typeName, typeClass);
+ } catch (NoClassDefFoundError e) {
+ throw new BuildException(InternalAntMessages.getString("InternalAntRunner.Missing_Class"), e); //$NON-NLS-1$
+ } catch (ClassNotFoundException c) {
+ throw new BuildException(InternalAntMessages.getString("InternalAntRunner.Missing_Class"), c); //$NON-NLS-1$
+ }
+
}
} catch (IOException ioe) {
return;
@@ -197,9 +198,9 @@
* @see org.apache.tools.ant.Project#getDataTypeDefinitions()
*/
public Hashtable getDataTypeDefinitions() {
- if (typeNameToClassName == null) {
+ if (typeNameToClass == null) {
initializeTypes();
}
- return typeNameToClassName;
+ return typeNameToClass;
}
}
diff --git a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java
index bb008cf..c2c3e5b 100644
--- a/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java
+++ b/ant/org.eclipse.ant.tests.core/tests/org/eclipse/ant/tests/core/tests/TargetTests.java
Binary files differ
diff --git a/ant/org.eclipse.ant.tests.core/testscripts/Bug32551.xml b/ant/org.eclipse.ant.tests.core/testscripts/Bug32551.xml
new file mode 100644
index 0000000..f67354a
--- /dev/null
+++ b/ant/org.eclipse.ant.tests.core/testscripts/Bug32551.xml
@@ -0,0 +1,15 @@
+<project name="bug" default="all">
+ <path id="myclasspath">
+ <fileset dir="..\lib">
+ <include name="antTestsSupport.jar" />
+ </fileset>
+ </path>
+
+ <taskdef name="hello" classname="org.eclipse.ant.tests.core.tasks.AntTestTask">
+ <classpath refid="myclasspath" />
+ </taskdef>
+
+ <target name="all">
+ <hello />
+ </target>
+ </project>
\ No newline at end of file