1 20 package org.apache.cactus.integration.ant.container.tomcat; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 25 import org.apache.cactus.integration.ant.util.ResourceUtils; 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.taskdefs.Java; 28 import org.apache.tools.ant.types.FilterChain; 29 import org.apache.tools.ant.types.Path; 30 import org.apache.tools.ant.util.FileUtils; 31 32 37 public class Tomcat3xContainer extends AbstractTomcatContainer 38 { 39 40 42 45 private File tmpDir; 46 47 49 54 public final void setTmpDir(File theTmpDir) 55 { 56 this.tmpDir = theTmpDir; 57 } 58 59 61 64 public final String getName() 65 { 66 return "Tomcat 3.x"; 67 } 68 69 72 public final void startUp() 73 { 74 try 75 { 76 prepare("cactus/tomcat3x"); 77 invoke("start"); 78 } 79 catch (IOException ioe) 80 { 81 getLog().error("Failed to startup the container", ioe); 82 throw new BuildException(ioe); 83 } 84 } 85 86 89 public final void shutDown() 90 { 91 invoke("stop"); 92 } 93 94 96 102 private void invoke(String theArg) 103 { 104 Java java = null; 105 if ("start".equals(theArg)) 106 { 107 java = createJavaForStartUp(); 108 } 109 else 110 { 111 java = createJavaForShutDown(); 112 } 113 java.addSysproperty(createSysProperty("tomcat.install", getDir())); 114 java.addSysproperty(createSysProperty("tomcat.home", this.tmpDir)); 115 Path classpath = java.createClasspath(); 116 classpath.createPathElement().setLocation( 117 new File (getDir(), "lib/tomcat.jar")); 118 119 File commonsLoggingJarFile = 122 new File (getDir(), "lib/common/commons-logging-api.jar"); 123 if (commonsLoggingJarFile.exists()) 124 { 125 classpath.createPathElement().setLocation(commonsLoggingJarFile); 126 } 127 128 java.setClassname("org.apache.tomcat.startup.Main"); 129 java.createArg().setValue(theArg); 130 java.execute(); 131 } 132 133 141 private void prepare(String theDirName) throws IOException 142 { 143 FileUtils fileUtils = FileUtils.newFileUtils(); 144 FilterChain filterChain = createFilterChain(); 145 146 this.tmpDir = setupTempDirectory(this.tmpDir, theDirName); 147 cleanTempDirectory(this.tmpDir); 148 149 File confDir = createDirectory(tmpDir, "conf"); 151 copyConfFiles(confDir); 152 if (getServerXml() == null) 153 { 154 ResourceUtils.copyResource(getProject(), 155 RESOURCE_PATH + "tomcat3x/server.xml", 156 new File (confDir, "server.xml"), filterChain); 157 } 158 ResourceUtils.copyResource(getProject(), 161 RESOURCE_PATH + "tomcat3x/tomcat-users.xml", 162 new File (confDir, "tomcat-users.xml")); 163 ResourceUtils.copyResource(getProject(), 164 RESOURCE_PATH + "tomcat3x/modules.xml", 165 new File (confDir, "modules.xml")); 166 167 File webappsDir = createDirectory(tmpDir, "webapps"); 169 fileUtils.copyFile(getDeployableFile().getFile(), 170 new File (webappsDir, getDeployableFile().getFile().getName()), 171 null, true); 172 } 173 174 } 175 | Popular Tags |