1 20 package org.apache.cactus.integration.ant.container.tomcat; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import org.apache.cactus.integration.ant.container.AbstractJavaContainer; 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.taskdefs.Copy; 31 import org.apache.tools.ant.types.FileSet; 32 import org.apache.tools.ant.util.FileUtils; 33 34 39 public abstract class AbstractTomcatContainer extends AbstractJavaContainer 40 { 41 42 44 47 private File dir; 48 49 53 private List confFileSets = new ArrayList (); 54 55 59 private File serverXml; 60 61 64 private int port = 8080; 65 66 68 73 public final void addConf(FileSet theConf) 74 { 75 theConf.createExclude().setName("**/server.xml"); 78 79 this.confFileSets.add(theConf); 80 } 81 82 87 public final File getDir() 88 { 89 return this.dir; 90 } 91 92 97 public final void setDir(File theDir) 98 { 99 this.dir = theDir; 100 } 101 102 105 public final File getServerXml() 106 { 107 return this.serverXml; 108 } 109 110 116 public final void setServerXml(File theServerXml) 117 { 118 this.serverXml = theServerXml; 119 } 120 121 126 public final void setPort(int thePort) 127 { 128 this.port = thePort; 129 } 130 131 133 138 public final int getPort() 139 { 140 return this.port; 141 } 142 143 146 public void init() 147 { 148 if (!this.dir.isDirectory()) 149 { 150 throw new BuildException(this.dir + " is not a directory"); 151 } 152 153 if (!getDeployableFile().isWar()) 154 { 155 throw new BuildException("Tomcat doesn't support the " 156 + "deployment of EAR files"); 157 } 158 } 159 160 162 168 protected final void copyConfFiles(File theConfDir) 169 { 170 if (getServerXml() != null) 171 { 172 FileUtils fileUtils = FileUtils.newFileUtils(); 173 try 174 { 175 fileUtils.copyFile(getServerXml(), 176 new File (theConfDir, "server.xml")); 177 } 178 catch (IOException ioe) 179 { 180 throw new BuildException("Could not copy " + getServerXml() 181 + " to directory " + theConfDir, ioe); 182 } 183 } 184 185 if (!this.confFileSets.isEmpty()) 186 { 187 Copy copy = (Copy) createAntTask("copy"); 188 copy.setTodir(theConfDir); 189 for (Iterator i = this.confFileSets.iterator(); i.hasNext();) 190 { 191 copy.addFileset((FileSet) i.next()); 192 } 193 copy.execute(); 194 } 195 } 196 197 } 198 | Popular Tags |