From 390132ed5509768adfd5a6b2810da2420696334f Mon Sep 17 00:00:00 2001 From: Stephane Bailliez Date: Sun, 3 Feb 2002 22:21:08 +0000 Subject: [PATCH] Add a getResource method. I would rather prefer to load resource this way than assuming the JVM is the root directory. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271133 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/BuildFileTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/testcases/org/apache/tools/ant/BuildFileTest.java b/src/testcases/org/apache/tools/ant/BuildFileTest.java index aa0d26ae4..3b9255ed1 100644 --- a/src/testcases/org/apache/tools/ant/BuildFileTest.java +++ b/src/testcases/org/apache/tools/ant/BuildFileTest.java @@ -57,6 +57,7 @@ package org.apache.tools.ant; import junit.framework.*; import org.apache.tools.ant.*; import java.io.*; +import java.net.URL; /** * A BuildFileTest is a TestCase which executes targets from an Ant buildfile @@ -256,9 +257,20 @@ public abstract class BuildFileTest extends TestCase { expectPropertySet(target, property, null); } - + /** + * Retrieve a resource from the caller classloader to avoid + * assuming a vm working directory. The resource path must be + * relative to the package name or absolute from the root path. + * @param resource the resource to retrieve its url. + * @throws AssertionFailureException if resource is not found. + */ + protected URL getResource(String resource){ + URL url = getClass().getResource(resource); + assertNotNull("Could not find resource :" + resource, url); + return url; + } - private class AntOutputStream extends java.io.OutputStream { + private class AntOutputStream extends java.io.OutputStream { public void write(int b) { outBuffer.append((char)b); }