1 18 package org.apache.tools.ant.taskdefs.optional.extension; 19 20 import java.io.File ; 21 import java.util.Iterator ; 22 import java.util.Vector ; 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.DirectoryScanner; 25 import org.apache.tools.ant.Task; 26 import org.apache.tools.ant.types.FileSet; 27 28 41 public class JarLibDisplayTask extends Task { 42 45 private File libraryFile; 46 47 51 private final Vector libraryFileSets = new Vector (); 52 53 58 public void setFile(final File file) { 59 this.libraryFile = file; 60 } 61 62 67 public void addFileset(final FileSet fileSet) { 68 libraryFileSets.addElement(fileSet); 69 } 70 71 76 public void execute() throws BuildException { 77 validate(); 78 79 final LibraryDisplayer displayer = new LibraryDisplayer(); 80 if (!libraryFileSets.isEmpty()) { 82 final Iterator iterator = libraryFileSets.iterator(); 83 while (iterator.hasNext()) { 84 final FileSet fileSet = (FileSet) iterator.next(); 85 final DirectoryScanner scanner 86 = fileSet.getDirectoryScanner(getProject()); 87 final File basedir = scanner.getBasedir(); 88 final String [] files = scanner.getIncludedFiles(); 89 for (int i = 0; i < files.length; i++) { 90 final File file = new File (basedir, files[ i ]); 91 displayer.displayLibrary(file); 92 } 93 } 94 } else { 95 displayer.displayLibrary(libraryFile); 96 } 97 } 98 99 104 private void validate() throws BuildException { 105 if (null == libraryFile && libraryFileSets.isEmpty()) { 106 final String message = "File attribute not specified."; 107 throw new BuildException(message); 108 } 109 if (null != libraryFile && !libraryFile.exists()) { 110 final String message = "File '" + libraryFile + "' does not exist."; 111 throw new BuildException(message); 112 } 113 if (null != libraryFile && !libraryFile.isFile()) { 114 final String message = "\'" + libraryFile + "\' is not a file."; 115 throw new BuildException(message); 116 } 117 } 118 } 119 | Popular Tags |