public final class Locator
extends java.lang.Object
It is used at boot time in the launcher, and cannot make use of any of Ant's other classes.
This is a surprisingly brittle piece of code, and has had lots of bugs filed against it: running ant off a network share can cause Ant to fail, use File.toURI().toURL().toExternalForm(), Locator implementation not encoding URI strings properly: spaces in paths. It also breaks Eclipse 3.3 Betas: Exception if installation path has spaces.
Be very careful when making changes to this class, as a break will upset a lot of people.
| Modifier and Type | Field and Description | 
|---|---|
static java.lang.String | 
ERROR_NOT_FILE_URI
Error string used when an invalid uri is seen 
 | 
static java.lang.String | 
URI_ENCODING
encoding used to represent URIs 
 | 
| Modifier and Type | Method and Description | 
|---|---|
static java.lang.String | 
decodeUri(java.lang.String uri)
Decodes an Uri with % characters. 
 | 
static java.lang.String | 
encodeURI(java.lang.String path)
Encodes an Uri with % characters. 
 | 
static java.net.URL | 
fileToURL(java.io.File file)
Deprecated. 
 
since 1.9, use  
FileUtils.getFileURL(File) | 
static java.lang.String | 
fromJarURI(java.lang.String uri)
Crack a JAR URI. 
 | 
static java.lang.String | 
fromURI(java.lang.String uri)
Constructs a file path from a  
file: URI. | 
static java.io.File | 
getClassSource(java.lang.Class<?> c)
Find the directory or jar file the class has been loaded from. 
 | 
static java.net.URL[] | 
getLocationURLs(java.io.File location)
Get an array of URLs representing all of the jar files in the
 given location. 
 | 
static java.net.URL[] | 
getLocationURLs(java.io.File location,
               java.lang.String[] extensions)
Get an array of URLs representing all of the files of a given set of
 extensions in the given location. 
 | 
static java.io.File | 
getResourceSource(java.lang.ClassLoader c,
                 java.lang.String resource)
Find the directory or jar a given resource has been loaded from. 
 | 
static java.io.File | 
getToolsJar()
Get the File necessary to load the Sun compiler tools. 
 | 
public static final java.lang.String URI_ENCODING
public static final java.lang.String ERROR_NOT_FILE_URI
public static java.io.File getClassSource(java.lang.Class<?> c)
c - the class whose location is required.public static java.io.File getResourceSource(java.lang.ClassLoader c,
                                             java.lang.String resource)
c - the classloader to be consulted for the source.resource - the resource whose location is required.public static java.lang.String fromURI(java.lang.String uri)
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.java.lang.IllegalArgumentException - if the URI is malformed or not a legal file: URLpublic static java.lang.String fromJarURI(java.lang.String uri)
uri - uri to expand; contains jar: somewhere in itpublic static java.lang.String decodeUri(java.lang.String uri)
                                  throws java.io.UnsupportedEncodingException
uri - String with the uri possibly containing % characters.java.io.UnsupportedEncodingException - if UTF-8 is not availablepublic static java.lang.String encodeURI(java.lang.String path)
                                  throws java.io.UnsupportedEncodingException
path - String to encode.java.io.UnsupportedEncodingException - if UTF-8 is not available@Deprecated
public static java.net.URL fileToURL(java.io.File file)
                                          throws java.net.MalformedURLException
FileUtils.getFileURL(File)file - the file to convertjava.net.MalformedURLException - on errorpublic static java.io.File getToolsJar()
public static java.net.URL[] getLocationURLs(java.io.File location)
                                      throws java.net.MalformedURLException
location - the location to scan for Jars.java.net.MalformedURLException - if the URLs for the jars cannot be
            formed.public static java.net.URL[] getLocationURLs(java.io.File location,
                                             java.lang.String[] extensions)
                                      throws java.net.MalformedURLException
location - the location to scan for files.extensions - an array of extension that are to match in the
        directory search.java.net.MalformedURLException - if the URLs for the files cannot be
            formed.