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>
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275895 13f79535-47bb-0310-9956-ffa450edef68
master
| @@ -16,6 +16,8 @@ Fixed bugs: | |||||
| * Fix jboss element of ejb task (introduced in ant 1.6.0). | * Fix jboss element of ejb task (introduced in ant 1.6.0). | ||||
| * <whichresource> failed to load classes correctly. | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| * Translate task logs a debug message specifying the number of files | * Translate task logs a debug message specifying the number of files | ||||
| @@ -12,4 +12,9 @@ | |||||
| <whichresource resource="org/apache/tools/ant/taskdefs/defaults.properties" | <whichresource resource="org/apache/tools/ant/taskdefs/defaults.properties" | ||||
| property="defaults"/> | property="defaults"/> | ||||
| </target> | </target> | ||||
| <target name="testResourcenameWithLeadingSlash"> | |||||
| <whichresource resource="/org/apache/tools/ant/taskdefs/defaults.properties" | |||||
| property="defaults"/> | |||||
| </target> | |||||
| </project> | </project> | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
| @@ -168,13 +168,17 @@ public class WhichResource extends Task { | |||||
| String location = null; | String location = null; | ||||
| if (classname != null) { | if (classname != null) { | ||||
| //convert a class name into a resource | //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); | log("Searching for " + resource, Project.MSG_VERBOSE); | ||||
| URL url; | URL url; | ||||
| url = loader.getResource(resource); | url = loader.getResource(resource); | ||||
| @@ -77,4 +77,9 @@ public class WhichResourceTest extends BuildFileTest { | |||||
| executeTarget("testResourcename"); | executeTarget("testResourcename"); | ||||
| assertNotNull(getProject().getProperty("defaults")); | assertNotNull(getProject().getProperty("defaults")); | ||||
| } | } | ||||
| public void testResourcenameWithLeadingSlash() { | |||||
| executeTarget("testResourcenameWithLeadingSlash"); | |||||
| assertNotNull(getProject().getProperty("defaults")); | |||||
| } | |||||
| } | } | ||||