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.Properties ; 25 import java.util.jar.JarFile ; 26 import java.util.zip.ZipEntry ; 27 28 import org.apache.cactus.integration.ant.util.ResourceUtils; 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.taskdefs.Java; 31 import org.apache.tools.ant.types.FilterChain; 32 import org.apache.tools.ant.types.Path; 33 import org.apache.tools.ant.util.FileUtils; 34 35 40 public abstract class AbstractCatalinaContainer extends AbstractTomcatContainer 41 { 42 44 47 private File tmpDir; 48 49 53 private String version; 54 55 57 62 public final void setTmpDir(File theTmpDir) 63 { 64 this.tmpDir = theTmpDir; 65 } 66 67 69 72 public final String getName() 73 { 74 return "Tomcat " + this.version; 75 } 76 77 80 public void init() 81 { 82 this.version = getVersion(); 84 if (this.version == null) 85 { 86 throw new BuildException(getDir() 87 + " not recognized as a Tomcat 4.x installation"); 88 } 89 } 90 91 93 99 protected final String getVersion() 100 { 101 if (this.version == null) 102 { 103 try 104 { 105 109 JarFile catalinaJar = new JarFile ( 113 new File (getDir(), "server/lib/catalina.jar")); 114 ZipEntry entry = catalinaJar.getEntry( 115 "org/apache/catalina/util/ServerInfo.properties"); 116 if (entry != null) 117 { 118 Properties props = new Properties (); 119 props.load(catalinaJar.getInputStream(entry)); 120 String serverInfo = props.getProperty("server.info"); 121 if (serverInfo.indexOf('/') > 0) 122 { 123 this.version = 124 serverInfo.substring(serverInfo.indexOf('/') + 1); 125 } 126 } 127 else 128 { 129 this.version = "4.0.x"; 130 } 131 } 132 catch (IOException ioe) 133 { 134 getLog().warn("Couldn't retrieve Tomcat version information", 135 ioe); 136 } 137 } 138 return this.version; 139 } 140 141 147 protected final void invokeBootstrap(String theArg) 148 { 149 Java java = null; 150 if ("start".equals(theArg)) 151 { 152 java = createJavaForStartUp(); 153 } 154 else 155 { 156 java = createJavaForShutDown(); 157 } 158 java.addSysproperty(createSysProperty("catalina.home", getDir())); 159 java.addSysproperty(createSysProperty("catalina.base", getTmpDir())); 160 Path classpath = java.createClasspath(); 161 classpath.createPathElement().setLocation( 162 new File (getDir(), "bin/bootstrap.jar")); 163 addToolsJarToClasspath(classpath); 164 java.setClassname("org.apache.catalina.startup.Bootstrap"); 165 java.createArg().setValue(theArg); 166 java.execute(); 167 } 168 169 179 protected void prepare(String theResourcePrefix, String theDirName) 180 throws IOException 181 { 182 FileUtils fileUtils = FileUtils.newFileUtils(); 183 FilterChain filterChain = createFilterChain(); 184 185 setTmpDir(setupTempDirectory(getTmpDir(), theDirName)); 186 cleanTempDirectory(getTmpDir()); 187 188 File confDir = createDirectory(getTmpDir(), "conf"); 189 190 193 if (getServerXml() == null) 194 { 195 ResourceUtils.copyResource(getProject(), 196 RESOURCE_PATH + theResourcePrefix + "/server.xml", 197 new File (confDir, "server.xml"), filterChain); 198 } 199 200 ResourceUtils.copyResource(getProject(), 201 RESOURCE_PATH + theResourcePrefix + "/tomcat-users.xml", 202 new File (confDir, "tomcat-users.xml")); 203 fileUtils.copyFile(new File (getDir(), "conf/web.xml"), 204 new File (confDir, "web.xml")); 205 206 File webappsDir = createDirectory(getTmpDir(), "webapps"); 209 fileUtils.copyFile(getDeployableFile().getFile(), 210 new File (webappsDir, getDeployableFile().getFile().getName()), 211 null, true); 212 213 copyConfFiles(confDir); 216 } 217 218 222 protected final File getTmpDir() 223 { 224 return this.tmpDir; 225 } 226 } 227 | Popular Tags |