org.apache.tools.ant.launch
Class Locator
java.lang.Object
org.apache.tools.ant.launch.Locator
public final class Locator
extends java.lang.Object
The Locator is a utility class which is used to find certain items
in the environment.
static String | decodeUri(String uri) - Decodes an Uri with % characters.
|
static String | encodeURI(String path) - Encodes an Uri with % characters.
|
static URL | fileToURL(File file) - Convert a File to a URL.
|
static String | fromURI(String uri) - Constructs a file path from a
file: URI.
|
static File | getClassSource(Class c) - Find the directory or jar file the class has been loaded from.
|
static URL[] | getLocationURLs(File location) - Get an array of URLs representing all of the jar files in the
given location.
|
static URL[] | getLocationURLs(File location, String[] extensions) - Get an array of URLs representing all of the files of a given set of
extensions in the given location.
|
static File | getResourceSource(ClassLoader c, String resource) - Find the directory or jar a given resource has been loaded from.
|
static File | getToolsJar() - Get the File necessary to load the Sun compiler tools.
|
URI_ENCODING
public static final String URI_ENCODING
encoding used to represent URIs
decodeUri
public static String decodeUri(String uri)
throws UnsupportedEncodingException
Decodes an Uri with % characters.
The URI is escaped
uri
- String with the uri possibly containing % characters.
encodeURI
public static String encodeURI(String path)
throws UnsupportedEncodingException
Encodes an Uri with % characters.
The URI is escaped
- The encoded string, according to URI norms
fileToURL
public static URL fileToURL(File file)
throws MalformedURLException
Convert a File to a URL.
File.toURL() does not encode characters like #.
File.toURI() has been introduced in java 1.4, so
ANT cannot use it (except by reflection)
FileUtils.toURI() cannot be used by Locator.java
Implemented this way.
File.toURL() adds file: and changes '\' to '/' for dos OSes
encodeURI converts characters like ' ' and '#' to %DD
file
- the file to convert
fromURI
public static String fromURI(String uri)
Constructs a file path from a
file:
URI.
Will be an absolute path if the given URI is absolute.
Prior to Java 1.4,
swallows '%' that are not followed by two characters.
See
dt-sysid
which makes some mention of how
characters not supported by URI Reference syntax should be escaped.
uri
- the URI designating a file in the local filesystem.
- the local file system path for the file.
getClassSource
public static File getClassSource(Class c)
Find the directory or jar file the class has been loaded from.
c
- the class whose location is required.
- the file or jar with the class or null if we cannot
determine the location.
getLocationURLs
public static URL[] getLocationURLs(File location)
throws MalformedURLException
Get an array of URLs representing all of the jar files in the
given location. If the location is a file, it is returned as the only
element of the array. If the location is a directory, it is scanned for
jar files.
location
- the location to scan for Jars.
- an array of URLs for all jars in the given location.
getLocationURLs
public static URL[] getLocationURLs(File location,
String[] extensions)
throws MalformedURLException
Get an array of URLs representing all of the files of a given set of
extensions in the given location. If the location is a file, it is
returned as the only element of the array. If the location is a
directory, it is scanned for matching files.
location
- the location to scan for files.extensions
- an array of extension that are to match in the
directory search.
- an array of URLs of matching files.
getResourceSource
public static File getResourceSource(ClassLoader c,
String resource)
Find the directory or jar a given resource has been loaded from.
c
- the classloader to be consulted for the source.resource
- the resource whose location is required.
- the file with the resource source or null if
we cannot determine the location.
getToolsJar
public static File getToolsJar()
Get the File necessary to load the Sun compiler tools. If the classes
are available to this class, then no additional URL is required and
null is returned. This may be because the classes are explicitly in the
class path or provided by the JVM directly.
- the tools jar as a File if required, null otherwise.