FileDocCategorySizeDatePackage
LibraryDisplayer.javaAPI DocApache Ant 1.705244Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.extension

LibraryDisplayer

public class LibraryDisplayer extends Object
Utility class to output the information in a jar relating to "Optional Packages" (formely known as "Extensions") and Package Specifications.

Fields Summary
Constructors Summary
Methods Summary
voiddisplayLibrary(java.io.File file)
Display the extensions and specifications contained within specified file.

param
file the file
throws
BuildException if fail to read file

        final Manifest manifest = ExtensionUtil.getManifest(file);
        displayLibrary(file, manifest);
    
voiddisplayLibrary(java.io.File file, java.util.jar.Manifest manifest)
Display the extensions and specifications contained within specified file.

param
file the file to use while reporting
param
manifest the manifest of file
throws
BuildException if fail to read file

        final Extension[] available = Extension.getAvailable(manifest);
        final Extension[] required = Extension.getRequired(manifest);
        final Extension[] options = Extension.getOptions(manifest);
        final Specification[] specifications = getSpecifications(manifest);

        if (0 == available.length && 0 == required.length && 0 == options.length
            && 0 == specifications.length) {
            return;
        }

        final String message = "File: " + file;
        final int size = message.length();
        printLine(size);
        System.out.println(message);
        printLine(size);
        if (0 != available.length) {
            System.out.println("Extensions Supported By Library:");
            for (int i = 0; i < available.length; i++) {
                final Extension extension = available[ i ];
                System.out.println(extension.toString());
            }
        }

        if (0 != required.length) {
            System.out.println("Extensions Required By Library:");
            for (int i = 0; i < required.length; i++) {
                final Extension extension = required[ i ];
                System.out.println(extension.toString());
            }
        }

        if (0 != options.length) {
            System.out.println("Extensions that will be used by Library if present:");
            for (int i = 0; i < options.length; i++) {
                final Extension extension = options[ i ];
                System.out.println(extension.toString());
            }
        }

        if (0 != specifications.length) {
            System.out.println("Specifications Supported By Library:");
            for (int i = 0; i < specifications.length; i++) {
                final Specification specification = specifications[ i ];
                displaySpecification(specification);
            }
        }
    
private voiddisplaySpecification(Specification specification)
Print out specification details.

param
specification the specification

        final String[] sections = specification.getSections();
        if (null != sections) {
            final StringBuffer sb = new StringBuffer("Sections: ");
            for (int i = 0; i < sections.length; i++) {
                sb.append(" ");
                sb.append(sections[ i ]);
            }
            System.out.println(sb);
        }
        System.out.println(specification.toString());
    
private Specification[]getSpecifications(java.util.jar.Manifest manifest)
Get specifications from manifest.

param
manifest the manifest
return
the specifications or null if none
throws
BuildException if malformed specification sections

        try {
            return Specification.getSpecifications(manifest);
        } catch (final ParseException pe) {
            throw new BuildException(pe.getMessage(), pe);
        }
    
private voidprintLine(int size)
Print out a line of '-'s equal to specified size.

param
size the number of dashes to printout

        for (int i = 0; i < size; i++) {
            System.out.print("-");
        }
        System.out.println();