1 18 package org.apache.tools.ant.taskdefs; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.types.ZipFileSet; 25 import org.apache.tools.ant.util.FileUtils; 26 import org.apache.tools.zip.ZipOutputStream; 27 28 35 public class Ear extends Jar { 36 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 37 38 private File deploymentDescriptor; 39 private boolean descriptorAdded; 40 41 44 public Ear() { 45 super(); 46 archiveType = "ear"; 47 emptyBehavior = "create"; 48 } 49 50 56 public void setEarfile(File earFile) { 57 setDestFile(earFile); 58 } 59 60 64 public void setAppxml(File descr) { 65 deploymentDescriptor = descr; 66 if (!deploymentDescriptor.exists()) { 67 throw new BuildException("Deployment descriptor: " 68 + deploymentDescriptor 69 + " does not exist."); 70 } 71 72 ZipFileSet fs = new ZipFileSet(); 74 fs.setFile(deploymentDescriptor); 75 fs.setFullpath("META-INF/application.xml"); 76 super.addFileset(fs); 77 } 78 79 80 85 public void addArchives(ZipFileSet fs) { 86 fs.setPrefix("/"); 89 super.addFileset(fs); 90 } 91 92 93 99 protected void initZipOutputStream(ZipOutputStream zOut) 100 throws IOException , BuildException { 101 if (deploymentDescriptor == null && !isInUpdateMode()) { 103 throw new BuildException("appxml attribute is required", getLocation()); 104 } 105 106 super.initZipOutputStream(zOut); 107 } 108 109 117 protected void zipFile(File file, ZipOutputStream zOut, String vPath, 118 int mode) 119 throws IOException { 120 if (vPath.equalsIgnoreCase("META-INF/application.xml")) { 126 if (deploymentDescriptor == null 127 || !FILE_UTILS.fileNameEquals(deploymentDescriptor, file) 128 || descriptorAdded) { 129 log("Warning: selected " + archiveType 130 + " files include a META-INF/application.xml which will" 131 + " be ignored (please use appxml attribute to " 132 + archiveType + " task)", Project.MSG_WARN); 133 } else { 134 super.zipFile(file, zOut, vPath, mode); 135 descriptorAdded = true; 136 } 137 } else { 138 super.zipFile(file, zOut, vPath, mode); 139 } 140 } 141 142 146 protected void cleanUp() { 147 descriptorAdded = false; 148 super.cleanUp(); 149 } 150 } 151 | Popular Tags |