Browse Source

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
master
Stefan Bodewig 21 years ago
parent
commit
73d92708f6
4 changed files with 23 additions and 7 deletions
  1. +2
    -0
      WHATSNEW
  2. +5
    -0
      src/etc/testcases/taskdefs/whichresource.xml
  3. +11
    -7
      src/main/org/apache/tools/ant/taskdefs/WhichResource.java
  4. +5
    -0
      src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java

+ 2
- 0
WHATSNEW View File

@@ -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


+ 5
- 0
src/etc/testcases/taskdefs/whichresource.xml View File

@@ -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>

+ 11
- 7
src/main/org/apache/tools/ant/taskdefs/WhichResource.java View File

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


+ 5
- 0
src/testcases/org/apache/tools/ant/taskdefs/WhichResourceTest.java View File

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

Loading…
Cancel
Save