Fields Summary |
---|
private String | propertyname of the property to set |
private File | filename of a file to turn into a URL |
private String | separatorseparator char |
private List | filesetsfilesets of nested files to add to this url |
private List | pathspaths to add |
private boolean | validatevalidation flag |
public static final String | ERROR_MISSING_FILEMissing file |
public static final String | ERROR_NO_PROPERTYNo property defined |
public static final String | ERROR_NO_FILESNo files defined |
Methods Summary |
---|
public void | addFileSet(org.apache.tools.ant.types.FileSet fileset)a fileset of jar files to include in the URL, each
separated by the separator
filesets.add(fileset);
|
public void | addPath(org.apache.tools.ant.types.Path path)add a path to the URL. All elements in the path
will be converted to individual URL entries
paths.add(path);
|
public void | execute()Create the url
validate();
//now exit here if the property is already set
if (getProject().getProperty(property) != null) {
return;
}
String url;
String filesetURL = filesetsToURL();
if (file != null) {
validateFile(file);
url = toURL(file);
//and add any files if also defined
if (filesetURL.length() > 0) {
url = url + separator + filesetURL;
}
} else {
url = filesetURL;
}
//add path URLs
String pathURL = pathsToURL();
if (pathURL.length() > 0) {
if (url.length() > 0) {
url = url + separator + pathURL;
} else {
url = pathURL;
}
}
log("Setting " + property + " to URL " + url, Project.MSG_VERBOSE);
getProject().setNewProperty(property, url);
|
private java.lang.String | filesetsToURL()convert the filesets to urls.
if (filesets.isEmpty()) {
return "";
}
int count = 0;
StringBuffer urls = new StringBuffer();
ListIterator list = filesets.listIterator();
while (list.hasNext()) {
FileSet set = (FileSet) list.next();
DirectoryScanner scanner = set.getDirectoryScanner(getProject());
String[] files = scanner.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
File f = new File(scanner.getBasedir(), files[i]);
validateFile(f);
String asUrl = toURL(f);
urls.append(asUrl);
log(asUrl, Project.MSG_DEBUG);
urls.append(separator);
count++;
}
}
//at this point there is one trailing space to remove, if the list is not empty.
return stripTrailingSeparator(urls, count);
|
private java.lang.String | pathsToURL()convert all paths to URLs
if (paths.isEmpty()) {
return "";
}
int count = 0;
StringBuffer urls = new StringBuffer();
ListIterator list = paths.listIterator();
while (list.hasNext()) {
Path path = (Path) list.next();
String[] elements = path.list();
for (int i = 0; i < elements.length; i++) {
File f = new File(elements[i]);
validateFile(f);
String asUrl = toURL(f);
urls.append(asUrl);
log(asUrl, Project.MSG_DEBUG);
urls.append(separator);
count++;
}
}
//at this point there is one trailing space to remove, if the list is not empty.
return stripTrailingSeparator(urls, count);
|
public void | setFile(java.io.File file)the name of a file to be converted into a URL
this.file = file;
|
public void | setProperty(java.lang.String property)set the name of a property to fill with the URL
this.property = property;
|
public void | setSeparator(java.lang.String separator)set the separator for the multi-url option.
this.separator = separator;
|
public void | setValidate(boolean validate)set this flag to trigger validation that every named file exists.
Optional: default=true
this.validate = validate;
|
private java.lang.String | stripTrailingSeparator(java.lang.StringBuffer urls, int count)convert the string buffer to a string, potentially stripping
out any trailing separator
if (count > 0) {
urls.delete(urls.length() - separator.length(), urls.length());
return new String(urls);
} else {
return "";
}
|
private java.lang.String | toURL(java.io.File fileToConvert)convert a file to a URL;
String url;
//create the URL
//ant equivalent of fileToConvert.toURI().toURL().toExternalForm();
url = FileUtils.getFileUtils().toURI(fileToConvert.getAbsolutePath());
return url;
|
private void | validate()check for errors
//validation
if (property == null) {
throw new BuildException(ERROR_NO_PROPERTY);
}
if (file == null && filesets.isEmpty() && paths.isEmpty()) {
throw new BuildException(ERROR_NO_FILES);
}
|
private void | validateFile(java.io.File fileToCheck)verify that the file exists, if {@link #validate} is set
if (validate && !fileToCheck.exists()) {
throw new BuildException(ERROR_MISSING_FILE + fileToCheck.toString());
}
|