Methods Summary |
---|
public void | addConfiguredAnt(org.apache.tools.ant.taskdefs.optional.extension.resolvers.AntResolver ant)Adds Ant resolver to run an Ant build file to generate a library.
resolvers.add(ant);
|
public void | addConfiguredExtension(ExtensionAdapter extension)Set the Extension looking for.
if (null != requiredExtension) {
final String message = "Can not specify extension to "
+ "resolve multiple times.";
throw new BuildException(message);
}
requiredExtension = extension.toExtension();
|
public void | addConfiguredLocation(org.apache.tools.ant.taskdefs.optional.extension.resolvers.LocationResolver loc)Adds location resolver to look for a library in a location
relative to project directory.
resolvers.add(loc);
|
public void | addConfiguredUrl(org.apache.tools.ant.taskdefs.optional.extension.resolvers.URLResolver url)Adds a URL resolver to download a library from a URL
to a local file.
resolvers.add(url);
|
private void | checkExtension(java.io.File file)Check if specified file satisfies extension.
If it does then set the relevent property
else throw a BuildException.
if (!file.exists()) {
final String message =
"File " + file + " does not exist";
throw new BuildException(message);
}
if (!file.isFile()) {
final String message =
"File " + file + " is not a file";
throw new BuildException(message);
}
if (!checkExtension) {
final String message = "Setting property to " + file
+ " without verifying library satisfies extension";
getProject().log(message, Project.MSG_VERBOSE);
setLibraryProperty(file);
} else {
getProject().log("Checking file " + file
+ " to see if it satisfies extension", Project.MSG_VERBOSE);
final Manifest manifest =
ExtensionUtil.getManifest(file);
final Extension[] extensions =
Extension.getAvailable(manifest);
for (int i = 0; i < extensions.length; i++) {
final Extension extension = extensions[ i ];
if (extension.isCompatibleWith(requiredExtension)) {
setLibraryProperty(file);
return;
}
}
getProject().log("File " + file + " skipped as it "
+ "does not satisfy extension", Project.MSG_VERBOSE);
final String message =
"File " + file + " does not satisfy extension";
throw new BuildException(message);
}
|
public void | execute()Execute the task.
validate();
getProject().log("Resolving extension: " + requiredExtension,
Project.MSG_VERBOSE);
String candidate =
getProject().getProperty(propertyName);
if (null != candidate) {
final String message = "Property Already set to: " + candidate;
if (failOnError) {
throw new BuildException(message);
}
getProject().log(message, Project.MSG_ERR);
return;
}
final int size = resolvers.size();
for (int i = 0; i < size; i++) {
final ExtensionResolver resolver =
(ExtensionResolver) resolvers.get(i);
getProject().log("Searching for extension using Resolver:" + resolver,
Project.MSG_VERBOSE);
try {
final File file =
resolver.resolve(requiredExtension, getProject());
try {
checkExtension(file);
return;
} catch (final BuildException be) {
final String message = "File " + file + " returned by "
+ "resolver failed to satisfy extension due to: "
+ be.getMessage();
getProject().log(message, Project.MSG_WARN);
}
} catch (final BuildException be) {
final String message = "Failed to resolve extension to file "
+ "using resolver " + resolver + " due to: " + be;
getProject().log(message, Project.MSG_WARN);
}
}
missingExtension();
|
private void | missingExtension()Utility method that will throw a {@link BuildException}
if {@link #failOnError} is true else it just displays
a warning.
final String message =
"Unable to resolve extension to a file";
if (failOnError) {
throw new BuildException(message);
}
getProject().log(message, Project.MSG_ERR);
|
public void | setCheckExtension(boolean checkExtension)Check nested libraries for extensions
this.checkExtension = checkExtension;
|
public void | setFailOnError(boolean failOnError)Set whether to fail if error.
this.failOnError = failOnError;
|
private void | setLibraryProperty(java.io.File file)Utility method to set the appropriate property
to indicate that specified file satisfies library
requirements.
getProject().setNewProperty(propertyName,
file.getAbsolutePath());
|
public void | setProperty(java.lang.String property)The name of the property in which the location of
library is stored.
this.propertyName = property;
|
private void | validate()Validate the tasks parameters.
if (null == propertyName) {
final String message = "Property attribute must be specified.";
throw new BuildException(message);
}
if (null == requiredExtension) {
final String message = "Extension element must be specified.";
throw new BuildException(message);
}
|