ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: Request: AntClassLoader.getResource()
Date Fri, 29 Jun 2001 02:50:57 GMT
Looks good to me, however I recall there being some issues in the past with 
ClassLoader. Can someone who has better memory determine if this patch will 
effect any of the inbuilt assumptions of any of the tasks/use cases.

On Fri, 29 Jun 2001 12:48, Herman, Dave wrote:
> Hello,
>
> I have a request for a new method in AntClassLoader. Here's the scenario:
> I'm running some JUnit tests within a <junit> task. These test classes are
> not necessarily found in the system class path, but my explicit <classpath>
> element nested within the junit task tells ant where to find the classes.
> As a result, they're not loaded with the system class loader, but by the
> AntClassLoader.
>
> These classes rely on external files, which they are trying to load via:
>
>     getClass().getResource(String fileName)
>
> The getResource method in a Class object first calls the getResource method
> in its class loader to try to find the resource, and if that fails, it then
> tries the system class loader. Because AntClassLoader has not overridden
> the getResource method, it doesn't search its class path correctly, and
> returns null. Then when the class tries the system class loader, since the
> class's directory is not in the system class path, it fails there as well.
> As a result, I get null.
>
> I'm proposing the following changes:
>
> 1. Get rid of the following method:
>        private InputStream getResourceStream(File file, String
> resourceName) 2. Create these two methods:
>        private URL getResourceURL(File file, String resourceName)
>        public URL getResource(String name)
> 3. Modify the following method:
>        public InputStream getResource(String name)
>    to call the getResourceURL method instead.
>
> I've attached a patch file (patch.txt) that can be applied to the version I
> downloaded from the web site, but I didn't know how to get into the CVS
> repository to get the very latest version. So this patch needs to be
> applied to the version that's available from:
>
> http://jakarta.apache.org/builds/jakarta-ant/release/v1.3/src/jakarta-ant-1
>. 3-src.zip
>
> In case this is totally useless, I've attached a more human-readable
> description of the changes I'm suggesting as well (description.txt).
>
> TIA for feedback or for the addition of the patch to the next release.
>
> Thanks,
> Dave Herman
> dherman@intrado.com

----------------------------------------
Content-Type: text/plain; charset="iso-8859-1"; name="patch.txt"
Content-Transfer-Encoding: quoted-printable
Content-Description: 
----------------------------------------

----------------------------------------
Content-Type: text/plain; charset="iso-8859-1"; name="description.txt"
Content-Transfer-Encoding: quoted-printable
Content-Description: 
----------------------------------------

-- 
Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*

Mime
View raw message