Browse Source

Javadoc

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277611 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
bcce5f6e12
1 changed files with 15 additions and 26 deletions
  1. +15
    -26
      src/main/org/apache/tools/ant/launch/Locator.java

+ 15
- 26
src/main/org/apache/tools/ant/launch/Locator.java View File

@@ -27,7 +27,7 @@ import java.util.Locale;


/** /**
* The Locator is a utility class which is used to find certain items * The Locator is a utility class which is used to find certain items
* in the environment
* in the environment.
* *
* @since Ant 1.6 * @since Ant 1.6
*/ */
@@ -53,9 +53,9 @@ public final class Locator {
} }


/** /**
* Find the directory or jar a give resource has been loaded from.
* Find the directory or jar a given resource has been loaded from.
* *
* @param c the classloader to be consulted for the source
* @param c the classloader to be consulted for the source.
* @param resource the resource whose location is required. * @param resource the resource whose location is required.
* *
* @return the file with the resource source or null if * @return the file with the resource source or null if
@@ -67,7 +67,6 @@ public final class Locator {
if (c == null) { if (c == null) {
c = Locator.class.getClassLoader(); c = Locator.class.getClassLoader();
} }

URL url = null; URL url = null;
if (c == null) { if (c == null) {
url = ClassLoader.getSystemResource(resource); url = ClassLoader.getSystemResource(resource);
@@ -115,7 +114,6 @@ public final class Locator {
if (buf.length() > 0) { if (buf.length() > 0) {
buf.insert(0, File.separatorChar).insert(0, File.separatorChar); buf.insert(0, File.separatorChar).insert(0, File.separatorChar);
} }

String file = url.getFile(); String file = url.getFile();
int queryPos = file.indexOf('?'); int queryPos = file.indexOf('?');
buf.append((queryPos < 0) ? file : file.substring(0, queryPos)); buf.append((queryPos < 0) ? file : file.substring(0, queryPos));
@@ -126,7 +124,6 @@ public final class Locator {
&& Character.isLetter(uri.charAt(1)) && uri.lastIndexOf(':') > -1) { && Character.isLetter(uri.charAt(1)) && uri.lastIndexOf(':') > -1) {
uri = uri.substring(1); uri = uri.substring(1);
} }

StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
CharacterIterator iter = new StringCharacterIterator(uri); CharacterIterator iter = new StringCharacterIterator(uri);
for (char c = iter.first(); c != CharacterIterator.DONE; for (char c = iter.first(); c != CharacterIterator.DONE;
@@ -145,24 +142,21 @@ public final class Locator {
sb.append(c); sb.append(c);
} }
} }

String path = sb.toString(); String path = sb.toString();
return path; return path;
} }



/** /**
* Get the File necessary to load the Sun compiler tools. If the classes * 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 * 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 * null is returned. This may be because the classes are explicitly in the
* class path or provided by the JVM directly
* class path or provided by the JVM directly.
* *
* @return the tools jar as a File if required, null otherwise
* @return the tools jar as a File if required, null otherwise.
*/ */
public static File getToolsJar() { public static File getToolsJar() {
// firstly check if the tools jar is already in the classpath // firstly check if the tools jar is already in the classpath
boolean toolsJarAvailable = false; boolean toolsJarAvailable = false;

try { try {
// just check whether this throws an exception // just check whether this throws an exception
Class.forName("com.sun.tools.javac.Main"); Class.forName("com.sun.tools.javac.Main");
@@ -175,11 +169,9 @@ public final class Locator {
// ignore // ignore
} }
} }

if (toolsJarAvailable) { if (toolsJarAvailable) {
return null; return null;
} }

// couldn't find compiler - try to find tools.jar // couldn't find compiler - try to find tools.jar
// based on java.home setting // based on java.home setting
String javaHome = System.getProperty("java.home"); String javaHome = System.getProperty("java.home");
@@ -196,17 +188,17 @@ public final class Locator {
} }


/** /**
* Get an array or URLs representing all of the jar files in the
* 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 * 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 * element of the array. If the location is a directory, it is scanned for
* jar files
* jar files.
* *
* @param location the location to scan for Jars
* @param location the location to scan for Jars.
* *
* @return an array of URLs for all jars in the given location. * @return an array of URLs for all jars in the given location.
* *
* @exception MalformedURLException if the URLs for the jars cannot be * @exception MalformedURLException if the URLs for the jars cannot be
* formed
* formed.
*/ */
public static URL[] getLocationURLs(File location) public static URL[] getLocationURLs(File location)
throws MalformedURLException { throws MalformedURLException {
@@ -214,18 +206,18 @@ public final class Locator {
} }


/** /**
* Get an array or URLs representing all of the files of a given set of
* 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 * 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 * returned as the only element of the array. If the location is a
* directory, it is scanned for matching files
* directory, it is scanned for matching files.
* *
* @param location the location to scan for files
* @param location the location to scan for files.
* @param extensions an array of extension that are to match in the * @param extensions an array of extension that are to match in the
* directory search
* directory search.
* *
* @return an array of URLs of matching files
* @return an array of URLs of matching files.
* @exception MalformedURLException if the URLs for the files cannot be * @exception MalformedURLException if the URLs for the files cannot be
* formed
* formed.
*/ */
public static URL[] getLocationURLs(File location, public static URL[] getLocationURLs(File location,
final String[] extensions) final String[] extensions)
@@ -235,7 +227,6 @@ public final class Locator {
if (!location.exists()) { if (!location.exists()) {
return urls; return urls;
} }

if (!location.isDirectory()) { if (!location.isDirectory()) {
urls = new URL[1]; urls = new URL[1];
String path = location.getPath(); String path = location.getPath();
@@ -247,7 +238,6 @@ public final class Locator {
} }
return urls; return urls;
} }

File[] matches = location.listFiles( File[] matches = location.listFiles(
new FilenameFilter() { new FilenameFilter() {
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
@@ -259,7 +249,6 @@ public final class Locator {
return false; return false;
} }
}); });

urls = new URL[matches.length]; urls = new URL[matches.length];
for (int i = 0; i < matches.length; ++i) { for (int i = 0; i < matches.length; ++i) {
urls[i] = matches[i].toURL(); urls[i] = matches[i].toURL();


Loading…
Cancel
Save