1 package org.apache.beehive.controls.runtime.packaging; 2 3 20 21 import java.io.File ; 22 import java.io.FileInputStream ; 23 import java.io.InputStreamReader ; 24 import java.io.IOException ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Vector ; 28 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.taskdefs.Jar; 31 import org.apache.tools.ant.taskdefs.Manifest; 32 import org.apache.tools.ant.taskdefs.ManifestException; 33 import org.apache.tools.ant.types.Resource; 34 import org.apache.tools.ant.types.FileSet; 35 import org.apache.tools.ant.util.FileUtils; 36 import org.apache.tools.zip.ZipOutputStream; 37 38 42 public class ControlJarTask extends Jar 43 { 44 private static FileUtils fileUtils = FileUtils.newFileUtils(); 45 46 52 protected Resource[][] grabResources(FileSet[] filesets) 53 { 54 Resource [][] resources = super.grabResources(filesets); 58 59 for (int i = 0; i < filesets.length; i++) 64 { 65 if (resources[i].length == 0) 66 continue; 67 68 File base = filesets[i].getDir(getProject()); 69 Resource [] setResources = resources[i]; 70 71 for (int j = 0; j < setResources.length; j++) 72 { 73 File manifestFile = 74 fileUtils.resolveFile(base, setResources[j].getName() + ".manifest"); 75 if (manifestFile.exists()) 76 manifestFiles.add(manifestFile); 77 } 78 } 79 80 return resources; 81 } 82 83 87 protected void initZipOutputStream(ZipOutputStream zOut) throws IOException , BuildException 88 { 89 if (manifestFiles.size() != 0) 90 { 91 Manifest mergeManifest = Manifest.getDefaultManifest(); 95 96 for (File manifestFile : manifestFiles) 101 { 102 FileInputStream fis = null; 103 try 104 { 105 fis = new FileInputStream (manifestFile); 106 Manifest resourceManifest = new Manifest(new InputStreamReader (fis)); 107 mergeManifest.merge(resourceManifest); 108 } 109 catch (IOException ioe) 110 { 111 throw new BuildException("Unable to read manifest file:" + manifestFile, ioe); 112 } 113 catch (ManifestException me) 114 { 115 throw new BuildException("Unable to process manifest file: "+ manifestFile, me); 116 } 117 finally 118 { 119 if (fis != null) fis.close(); 120 } 121 } 122 123 try 129 { 130 addConfiguredManifest(mergeManifest); 131 } 132 catch (ManifestException me) 133 { 134 throw new BuildException("Unable to add new manifest entries:" + me); 135 } 136 } 137 138 super.initZipOutputStream(zOut); 139 } 140 141 protected void addToManifest(Manifest jarManifest, List <File > mergeList) 142 { 143 } 144 145 148 protected void cleanUp() 149 { 150 manifestFiles = new Vector <File >(); 151 } 152 153 156 private List <File > manifestFiles = new Vector <File >(); 157 } 158 | Popular Tags |