FileDocCategorySizeDatePackage
JarLibAvailableTask.javaAPI DocApache Ant 1.705250Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.extension

JarLibAvailableTask

public class JarLibAvailableTask extends org.apache.tools.ant.Task
Checks whether an extension is present in a fileset or an extensionSet.
ant.task
name="jarlib-available"

Fields Summary
private File
libraryFile
The library to display information about.
private final Vector
extensionFileSets
Filesets specifying all the librarys to display information about.
private String
propertyName
The name of the property to set if extension is available.
private ExtensionAdapter
requiredExtension
The extension that is required.
Constructors Summary
Methods Summary
public voidaddConfiguredExtension(ExtensionAdapter extension)
Set the Extension looking for.

param
extension Set the Extension looking for.

        if (null != requiredExtension) {
            final String message = "Can not specify extension to "
                + "search for multiple times.";
            throw new BuildException(message);
        }
        requiredExtension = extension;
    
public voidaddConfiguredExtensionSet(ExtensionSet extensionSet)
Adds a set of extensions to search in.

param
extensionSet a set of extensions to search in.

        extensionFileSets.addElement(extensionSet);
    
public voidexecute()
Execute the task.

throws
BuildException if somethign goes wrong.

        validate();

        final Extension test = requiredExtension.toExtension();

        // Check if list of files to check has been specified
        if (!extensionFileSets.isEmpty()) {
            final Iterator iterator = extensionFileSets.iterator();
            while (iterator.hasNext()) {
                final ExtensionSet extensionSet
                    = (ExtensionSet) iterator.next();
                final Extension[] extensions =
                    extensionSet.toExtensions(getProject());
                for (int i = 0; i < extensions.length; i++) {
                    final Extension extension = extensions[ i ];
                    if (extension.isCompatibleWith(test)) {
                        getProject().setNewProperty(propertyName, "true");
                    }
                }
            }
        } else {
            final Manifest manifest = ExtensionUtil.getManifest(libraryFile);
            final Extension[] extensions = Extension.getAvailable(manifest);
            for (int i = 0; i < extensions.length; i++) {
                final Extension extension = extensions[ i ];
                if (extension.isCompatibleWith(test)) {
                    getProject().setNewProperty(propertyName, "true");
                }
            }
        }
    
public voidsetFile(java.io.File file)
The JAR library to check.

param
file The jar library to check.

        this.libraryFile = file;
    
public voidsetProperty(java.lang.String property)
The name of property to set if extensions are available.

param
property The name of property to set if extensions is available.


                               
         
        this.propertyName = property;
    
private voidvalidate()
Validate the tasks parameters.

throws
BuildException if invalid parameters found

        if (null == requiredExtension) {
            final String message = "Extension element must be specified.";
            throw new BuildException(message);
        }

        if (null == libraryFile && extensionFileSets.isEmpty()) {
            final String message = "File attribute not specified.";
            throw new BuildException(message);
        }
        if (null != libraryFile && !libraryFile.exists()) {
            final String message = "File '" + libraryFile + "' does not exist.";
            throw new BuildException(message);
        }
        if (null != libraryFile && !libraryFile.isFile()) {
            final String message = "\'" + libraryFile + "\' is not a file.";
            throw new BuildException(message);
        }