diff options
author | Stefan Bodewig <bodewig@apache.org> | 2004-01-12 10:15:55 +0000 |
---|---|---|
committer | Stefan Bodewig <bodewig@apache.org> | 2004-01-12 10:15:55 +0000 |
commit | 73d92708f6b3752bff36a4d425f57ae84e5be0a6 (patch) | |
tree | 0e6a0b4904c0412eb4da455e968856441bc72f15 /src | |
parent | 07e9f9859fe3e73d8edde727250d94e51c0d0e13 (diff) | |
download | ant-73d92708f6b3752bff36a4d425f57ae84e5be0a6.tar.gz |
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>
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275895 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
3 files changed, 21 insertions, 7 deletions
diff --git a/src/etc/testcases/taskdefs/whichresource.xml b/src/etc/testcases/taskdefs/whichresource.xml index eed770b88..b2094bdcb 100644 --- a/src/etc/testcases/taskdefs/whichresource.xml +++ b/src/etc/testcases/taskdefs/whichresource.xml @@ -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>
\ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/WhichResource.java b/src/main/org/apache/tools/ant/taskdefs/WhichResource.java index e8a2fc2b3..aa2714d50 100644 --- a/src/main/org/apache/tools/ant/taskdefs/WhichResource.java +++ b/src/main/org/apache/tools/ant/taskdefs/WhichResource.java @@ -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 @@ public class WhichResource extends Task { 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); diff --git a/src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java b/src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java index fbd635251..d2faa454a 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java @@ -77,4 +77,9 @@ public class WhichResourceTest extends BuildFileTest { executeTarget("testResourcename"); assertNotNull(getProject().getProperty("defaults")); } + + public void testResourcenameWithLeadingSlash() { + executeTarget("testResourcenameWithLeadingSlash"); + assertNotNull(getProject().getProperty("defaults")); + } } |