1 18 package org.apache.tools.ant.taskdefs.optional.extension; 19 20 import java.io.File ; 21 import java.text.ParseException ; 22 import java.util.jar.Manifest ; 23 import org.apache.tools.ant.BuildException; 24 25 31 class LibraryDisplayer { 32 39 void displayLibrary(final File file) 40 throws BuildException { 41 final Manifest manifest = ExtensionUtil.getManifest(file); 42 displayLibrary(file, manifest); 43 } 44 45 53 void displayLibrary(final File file, 54 final Manifest manifest) 55 throws BuildException { 56 final Extension[] available = Extension.getAvailable(manifest); 57 final Extension[] required = Extension.getRequired(manifest); 58 final Extension[] options = Extension.getOptions(manifest); 59 final Specification[] specifications = getSpecifications(manifest); 60 61 if (0 == available.length && 0 == required.length && 0 == options.length 62 && 0 == specifications.length) { 63 return; 64 } 65 66 final String message = "File: " + file; 67 final int size = message.length(); 68 printLine(size); 69 System.out.println(message); 70 printLine(size); 71 if (0 != available.length) { 72 System.out.println("Extensions Supported By Library:"); 73 for (int i = 0; i < available.length; i++) { 74 final Extension extension = available[ i ]; 75 System.out.println(extension.toString()); 76 } 77 } 78 79 if (0 != required.length) { 80 System.out.println("Extensions Required By Library:"); 81 for (int i = 0; i < required.length; i++) { 82 final Extension extension = required[ i ]; 83 System.out.println(extension.toString()); 84 } 85 } 86 87 if (0 != options.length) { 88 System.out.println("Extensions that will be used by Library if present:"); 89 for (int i = 0; i < options.length; i++) { 90 final Extension extension = options[ i ]; 91 System.out.println(extension.toString()); 92 } 93 } 94 95 if (0 != specifications.length) { 96 System.out.println("Specifications Supported By Library:"); 97 for (int i = 0; i < specifications.length; i++) { 98 final Specification specification = specifications[ i ]; 99 displaySpecification(specification); 100 } 101 } 102 } 103 104 109 private void printLine(final int size) { 110 for (int i = 0; i < size; i++) { 111 System.out.print("-"); 112 } 113 System.out.println(); 114 } 115 116 123 private Specification[] getSpecifications(final Manifest manifest) 124 throws BuildException { 125 try { 126 return Specification.getSpecifications(manifest); 127 } catch (final ParseException pe) { 128 throw new BuildException(pe.getMessage(), pe); 129 } 130 } 131 132 137 private void displaySpecification(final Specification specification) { 138 final String [] sections = specification.getSections(); 139 if (null != sections) { 140 final StringBuffer sb = new StringBuffer ("Sections: "); 141 for (int i = 0; i < sections.length; i++) { 142 sb.append(" "); 143 sb.append(sections[ i ]); 144 } 145 System.out.println(sb); 146 } 147 System.out.println(specification.toString()); 148 } 149 } 150 | Popular Tags |