|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractCatalinaContainer.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2003-2004 The Apache Software Foundation.
|
|
| 5 |
*
|
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 7 |
* you may not use this file except in compliance with the License.
|
|
| 8 |
* You may obtain a copy of the License at
|
|
| 9 |
*
|
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 11 |
*
|
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 15 |
* See the License for the specific language governing permissions and
|
|
| 16 |
* limitations under the License.
|
|
| 17 |
*
|
|
| 18 |
* ========================================================================
|
|
| 19 |
*/
|
|
| 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 |
/**
|
|
| 36 |
* Base support for Catalina based containers.
|
|
| 37 |
*
|
|
| 38 |
* @version $Id: AbstractCatalinaContainer.java 239003 2004-05-31 20:05:27Z vmassol $
|
|
| 39 |
*/
|
|
| 40 |
public abstract class AbstractCatalinaContainer extends AbstractTomcatContainer |
|
| 41 |
{
|
|
| 42 |
// Instance Variables ------------------------------------------------------
|
|
| 43 |
|
|
| 44 |
/**
|
|
| 45 |
* The temporary directory from which the container will be started.
|
|
| 46 |
*/
|
|
| 47 |
private File tmpDir;
|
|
| 48 |
|
|
| 49 |
/**
|
|
| 50 |
* The Catalina version detected by reading a property file in the
|
|
| 51 |
* installation directory.
|
|
| 52 |
*/
|
|
| 53 |
private String version;
|
|
| 54 |
|
|
| 55 |
// Public Methods ----------------------------------------------------------
|
|
| 56 |
|
|
| 57 |
/**
|
|
| 58 |
* Sets the temporary installation directory.
|
|
| 59 |
*
|
|
| 60 |
* @param theTmpDir The temporary directory to set
|
|
| 61 |
*/
|
|
| 62 | 0 |
public final void setTmpDir(File theTmpDir) |
| 63 |
{
|
|
| 64 | 0 |
this.tmpDir = theTmpDir;
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
// AbstractContainer Implementation ----------------------------------------
|
|
| 68 |
|
|
| 69 |
/**
|
|
| 70 |
* @see org.apache.cactus.integration.ant.container.Container#getName
|
|
| 71 |
*/
|
|
| 72 | 0 |
public final String getName()
|
| 73 |
{
|
|
| 74 | 0 |
return "Tomcat " + this.version; |
| 75 |
} |
|
| 76 |
|
|
| 77 |
/**
|
|
| 78 |
* @see org.apache.cactus.integration.ant.container.Container#init
|
|
| 79 |
*/
|
|
| 80 | 0 |
public void init() |
| 81 |
{
|
|
| 82 |
// Check the installation directory
|
|
| 83 | 0 |
this.version = getVersion();
|
| 84 | 0 |
if (this.version == null) |
| 85 |
{
|
|
| 86 | 0 |
throw new BuildException(getDir() |
| 87 |
+ " not recognized as a Tomcat 4.x installation");
|
|
| 88 |
} |
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
// Protected Methods -------------------------------------------------------
|
|
| 92 |
|
|
| 93 |
/**
|
|
| 94 |
* Returns the version of the Tomcat installation.
|
|
| 95 |
*
|
|
| 96 |
* @return The Tomcat version, or <code>null</code> if the verion number
|
|
| 97 |
* could not be retrieved
|
|
| 98 |
*/
|
|
| 99 | 0 |
protected final String getVersion()
|
| 100 |
{
|
|
| 101 | 0 |
if (this.version == null) |
| 102 |
{
|
|
| 103 | 0 |
try
|
| 104 |
{
|
|
| 105 |
// Unfortunately, there's no safe way to find out the version of
|
|
| 106 |
// a Catalina installation, so we need to try multiple paths
|
|
| 107 |
// here
|
|
| 108 |
|
|
| 109 |
// Tomcat 4.1.0 and later includes a ServerInfo.properties
|
|
| 110 |
// resource in catalina.jar that contains the version number. If
|
|
| 111 |
// that resource doesn't exist, we're on Tomcat 4.0.x
|
|
| 112 | 0 |
JarFile catalinaJar = new JarFile(
|
| 113 |
new File(getDir(), "server/lib/catalina.jar")); |
|
| 114 | 0 |
ZipEntry entry = catalinaJar.getEntry( |
| 115 |
"org/apache/catalina/util/ServerInfo.properties");
|
|
| 116 | 0 |
if (entry != null) |
| 117 |
{
|
|
| 118 | 0 |
Properties props = new Properties();
|
| 119 | 0 |
props.load(catalinaJar.getInputStream(entry)); |
| 120 | 0 |
String serverInfo = props.getProperty("server.info");
|
| 121 | 0 |
if (serverInfo.indexOf('/') > 0)
|
| 122 |
{
|
|
| 123 | 0 |
this.version =
|
| 124 |
serverInfo.substring(serverInfo.indexOf('/') + 1);
|
|
| 125 |
} |
|
| 126 |
} |
|
| 127 |
else
|
|
| 128 |
{
|
|
| 129 | 0 |
this.version = "4.0.x"; |
| 130 |
} |
|
| 131 |
} |
|
| 132 |
catch (IOException ioe)
|
|
| 133 |
{
|
|
| 134 | 0 |
getLog().warn("Couldn't retrieve Tomcat version information",
|
| 135 |
ioe); |
|
| 136 |
} |
|
| 137 |
} |
|
| 138 | 0 |
return this.version; |
| 139 |
} |
|
| 140 |
|
|
| 141 |
/**
|
|
| 142 |
* Invokes the Catalina Bootstrap class to start or stop the container,
|
|
| 143 |
* depending on the value of the provided argument.
|
|
| 144 |
*
|
|
| 145 |
* @param theArg Either 'start' or 'stop'
|
|
| 146 |
*/
|
|
| 147 | 0 |
protected final void invokeBootstrap(String theArg) |
| 148 |
{
|
|
| 149 | 0 |
Java java = null;
|
| 150 | 0 |
if ("start".equals(theArg)) |
| 151 |
{
|
|
| 152 | 0 |
java = createJavaForStartUp(); |
| 153 |
} |
|
| 154 |
else
|
|
| 155 |
{
|
|
| 156 | 0 |
java = createJavaForShutDown(); |
| 157 |
} |
|
| 158 | 0 |
java.addSysproperty(createSysProperty("catalina.home", getDir()));
|
| 159 | 0 |
java.addSysproperty(createSysProperty("catalina.base", getTmpDir()));
|
| 160 | 0 |
Path classpath = java.createClasspath(); |
| 161 | 0 |
classpath.createPathElement().setLocation( |
| 162 |
new File(getDir(), "bin/bootstrap.jar")); |
|
| 163 | 0 |
addToolsJarToClasspath(classpath); |
| 164 | 0 |
java.setClassname("org.apache.catalina.startup.Bootstrap");
|
| 165 | 0 |
java.createArg().setValue(theArg); |
| 166 | 0 |
java.execute(); |
| 167 |
} |
|
| 168 |
|
|
| 169 |
/**
|
|
| 170 |
* Prepares a temporary installation of the container and deploys the
|
|
| 171 |
* web-application.
|
|
| 172 |
*
|
|
| 173 |
* @param theResourcePrefix The prefix to use when looking up container
|
|
| 174 |
* resource in the JAR
|
|
| 175 |
* @param theDirName The name of the temporary container installation
|
|
| 176 |
* directory
|
|
| 177 |
* @throws IOException If an I/O error occurs
|
|
| 178 |
*/
|
|
| 179 | 0 |
protected void prepare(String theResourcePrefix, String theDirName) |
| 180 |
throws IOException
|
|
| 181 |
{
|
|
| 182 | 0 |
FileUtils fileUtils = FileUtils.newFileUtils(); |
| 183 | 0 |
FilterChain filterChain = createFilterChain(); |
| 184 |
|
|
| 185 | 0 |
setTmpDir(setupTempDirectory(getTmpDir(), theDirName)); |
| 186 | 0 |
cleanTempDirectory(getTmpDir()); |
| 187 |
|
|
| 188 | 0 |
File confDir = createDirectory(getTmpDir(), "conf");
|
| 189 |
|
|
| 190 |
// Copy first the default configuration files so that they can be
|
|
| 191 |
// overriden by the user-provided ones.
|
|
| 192 |
|
|
| 193 | 0 |
if (getServerXml() == null) |
| 194 |
{
|
|
| 195 | 0 |
ResourceUtils.copyResource(getProject(), |
| 196 |
RESOURCE_PATH + theResourcePrefix + "/server.xml",
|
|
| 197 |
new File(confDir, "server.xml"), filterChain); |
|
| 198 |
} |
|
| 199 |
|
|
| 200 | 0 |
ResourceUtils.copyResource(getProject(), |
| 201 |
RESOURCE_PATH + theResourcePrefix + "/tomcat-users.xml",
|
|
| 202 |
new File(confDir, "tomcat-users.xml")); |
|
| 203 | 0 |
fileUtils.copyFile(new File(getDir(), "conf/web.xml"), |
| 204 |
new File(confDir, "web.xml")); |
|
| 205 |
|
|
| 206 |
// deploy the web-app by copying the WAR file into the webapps
|
|
| 207 |
// directory
|
|
| 208 | 0 |
File webappsDir = createDirectory(getTmpDir(), "webapps");
|
| 209 | 0 |
fileUtils.copyFile(getDeployableFile().getFile(), |
| 210 |
new File(webappsDir, getDeployableFile().getFile().getName()),
|
|
| 211 |
null, true); |
|
| 212 |
|
|
| 213 |
// Copy user-provided configuration files into the temporary conf/
|
|
| 214 |
// container directory.
|
|
| 215 | 0 |
copyConfFiles(confDir); |
| 216 |
} |
|
| 217 |
|
|
| 218 |
/**
|
|
| 219 |
* @return The temporary directory from which the container will be
|
|
| 220 |
* started.
|
|
| 221 |
*/
|
|
| 222 | 0 |
protected final File getTmpDir()
|
| 223 |
{
|
|
| 224 | 0 |
return this.tmpDir; |
| 225 |
} |
|
| 226 |
} |
|
| 227 |
|
|
||||||||||