bodewig 2004/01/12 02:15:56
Modified: . WHATSNEW
src/etc/testcases/taskdefs whichresource.xml
src/main/org/apache/tools/ant/taskdefs WhichResource.java
src/testcases/org/apache/tools/ant/taskdefs
WhichResourceTest.java
Log:
A leading slash in a resource name is only required for
Class.getResource*, not the corresponding ClassLoader methods. Adding
the slash makes the task completely useless.
Reported by: <koji underscore sekiguchi at excite dot co dot jp>,
Jack J. Woehr <jax at purematrix dot com>
Revision Changes Path
1.518 +2 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.517
retrieving revision 1.518
diff -u -r1.517 -r1.518
--- WHATSNEW 9 Jan 2004 17:52:24 -0000 1.517
+++ WHATSNEW 12 Jan 2004 10:15:55 -0000 1.518
@@ -16,6 +16,8 @@
* Fix jboss element of ejb task (introduced in ant 1.6.0).
+* <whichresource> failed to load classes correctly.
+
Other changes:
--------------
* Translate task logs a debug message specifying the number of files
1.2 +5 -0 ant/src/etc/testcases/taskdefs/whichresource.xml
Index: whichresource.xml
===================================================================
RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/whichresource.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- whichresource.xml 12 Jan 2004 10:07:23 -0000 1.1
+++ whichresource.xml 12 Jan 2004 10:15:55 -0000 1.2
@@ -12,4 +12,9 @@
<whichresource
resource="org/apache/tools/ant/taskdefs/defaults.properties"
property="defaults"/>
</target>
+
+ <target name="testResourcenameWithLeadingSlash">
+ <whichresource
resource="/org/apache/tools/ant/taskdefs/defaults.properties"
+ property="defaults"/>
+ </target>
</project>
1.7 +11 -7
ant/src/main/org/apache/tools/ant/taskdefs/WhichResource.java
Index: WhichResource.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/WhichResource.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WhichResource.java 12 Dec 2003 19:32:58 -0000 1.6
+++ WhichResource.java 12 Jan 2004 10:15:55 -0000 1.7
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
+ * Copyright (c) 2003-2004 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -168,13 +168,17 @@
String location = null;
if (classname != null) {
//convert a class name into a resource
- classname = classname.replace('.', '/');
- resource = "/" + classname + ".class";
- } else {
- if (!resource.startsWith("/")) {
- resource = "/" + resource;
- }
+ resource = classname.replace('.', '/') + ".class";
+ }
+
+ if (resource == null) {
+ throw new BuildException("One of class or resource is required");
}
+
+ if (resource.startsWith("/")) {
+ resource = resource.substring(1);
+ }
+
log("Searching for " + resource, Project.MSG_VERBOSE);
URL url;
url = loader.getResource(resource);
1.2 +5 -0
ant/src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java
Index: WhichResourceTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WhichResourceTest.java 12 Jan 2004 10:07:23 -0000 1.1
+++ WhichResourceTest.java 12 Jan 2004 10:15:55 -0000 1.2
@@ -77,4 +77,9 @@
executeTarget("testResourcename");
assertNotNull(getProject().getProperty("defaults"));
}
+
+ public void testResourcenameWithLeadingSlash() {
+ executeTarget("testResourcenameWithLeadingSlash");
+ assertNotNull(getProject().getProperty("defaults"));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]