1 16 17 import java.io.File ; 18 import java.io.FileWriter ; 19 import java.io.IOException ; 20 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.Task; 23 24 31 public final class ManifestToolTask extends Task { 32 33 private String directory; 34 private String manifest; 35 36 public void setDirectory(String directory) { 37 this.directory = directory; 38 } 39 40 public void setManifest(String manifest) { 41 this.manifest = manifest; 42 } 43 44 public void execute() throws BuildException { 45 if (this.manifest == null) { 46 throw new BuildException("manifest attribute is required", this.getLocation()); 47 } 48 if (this.directory == null) { 49 throw new BuildException("directory attribute is required", this.getLocation()); 50 } 51 52 try { 53 this.process(this.getProject().resolveFile(this.directory)); 55 } catch (IOException ioe) { 56 throw new BuildException("IOException: " + ioe); 57 } 58 } 59 60 63 private void process(final File directoryFile) 64 throws IOException , BuildException { 65 66 System.out.println("Writing: " + manifest); 67 FileWriter w = new FileWriter (this.getProject().resolveFile(manifest)); 68 w.write("Manifest-Version: 1.0\n"); 69 70 if (directoryFile.exists() && directoryFile.isDirectory() ) { 71 w.write("Cocoon-Libs: "); 72 73 final File [] files = directoryFile.listFiles(); 74 for(int i = 0; i < files.length; i++) { 75 if (files[i].getName().endsWith(".jar")) { 76 w.write(files[i].getName()); 77 w.write(" "); 78 } 79 } 80 w.write("\n"); 81 82 for(int i = 0; i < files.length; i++) { 83 if (files[i].getName().endsWith(".jar")) { 84 w.write("Cocoon-Lib-"); 85 String s = files[i].getName().replace('.', '_'); 86 w.write(s); 87 w.write(": "); 88 w.write(String.valueOf(files[i].lastModified())); 89 w.write("\n"); 90 } 91 } 92 } 93 w.close(); 94 } 95 } 96 | Popular Tags |