|
|||||||||||||||||||
| 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 | |||||||||||||||
| Tomcat3xContainer.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2003 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 |
|
|
| 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 |
/**
|
|
| 33 |
* Special container support for the Apache Tomcat 3.x servlet container.
|
|
| 34 |
*
|
|
| 35 |
* @version $Id: Tomcat3xContainer.java 239003 2004-05-31 20:05:27Z vmassol $
|
|
| 36 |
*/
|
|
| 37 |
public class Tomcat3xContainer extends AbstractTomcatContainer |
|
| 38 |
{
|
|
| 39 |
|
|
| 40 |
// Instance Variables ------------------------------------------------------
|
|
| 41 |
|
|
| 42 |
/**
|
|
| 43 |
* The temporary directory from which the container will be started.
|
|
| 44 |
*/
|
|
| 45 |
private File tmpDir;
|
|
| 46 |
|
|
| 47 |
// Public Methods ----------------------------------------------------------
|
|
| 48 |
|
|
| 49 |
/**
|
|
| 50 |
* Sets the temporary installation directory.
|
|
| 51 |
*
|
|
| 52 |
* @param theTmpDir The temporary directory to set
|
|
| 53 |
*/
|
|
| 54 | 0 |
public final void setTmpDir(File theTmpDir) |
| 55 |
{
|
|
| 56 | 0 |
this.tmpDir = theTmpDir;
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
// AbstractContainer Implementation ----------------------------------------
|
|
| 60 |
|
|
| 61 |
/**
|
|
| 62 |
* @see org.apache.cactus.integration.ant.container.Container#getName
|
|
| 63 |
*/
|
|
| 64 | 0 |
public final String getName()
|
| 65 |
{
|
|
| 66 | 0 |
return "Tomcat 3.x"; |
| 67 |
} |
|
| 68 |
|
|
| 69 |
/**
|
|
| 70 |
* @see org.apache.cactus.integration.ant.container.Container#startUp
|
|
| 71 |
*/
|
|
| 72 | 0 |
public final void startUp() |
| 73 |
{
|
|
| 74 | 0 |
try
|
| 75 |
{
|
|
| 76 | 0 |
prepare("cactus/tomcat3x");
|
| 77 | 0 |
invoke("start");
|
| 78 |
} |
|
| 79 |
catch (IOException ioe)
|
|
| 80 |
{
|
|
| 81 | 0 |
getLog().error("Failed to startup the container", ioe);
|
| 82 | 0 |
throw new BuildException(ioe); |
| 83 |
} |
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
/**
|
|
| 87 |
* @see org.apache.cactus.integration.ant.container.Container#shutDown
|
|
| 88 |
*/
|
|
| 89 | 0 |
public final void shutDown() |
| 90 |
{
|
|
| 91 | 0 |
invoke("stop");
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
// Private Methods ---------------------------------------------------------
|
|
| 95 |
|
|
| 96 |
/**
|
|
| 97 |
* Invokes the Tomcat Main class to start or stop the container, depending
|
|
| 98 |
* on the value of the provided argument.
|
|
| 99 |
*
|
|
| 100 |
* @param theArg Either 'start' or 'stop'
|
|
| 101 |
*/
|
|
| 102 | 0 |
private void invoke(String theArg) |
| 103 |
{
|
|
| 104 | 0 |
Java java = null;
|
| 105 | 0 |
if ("start".equals(theArg)) |
| 106 |
{
|
|
| 107 | 0 |
java = createJavaForStartUp(); |
| 108 |
} |
|
| 109 |
else
|
|
| 110 |
{
|
|
| 111 | 0 |
java = createJavaForShutDown(); |
| 112 |
} |
|
| 113 | 0 |
java.addSysproperty(createSysProperty("tomcat.install", getDir()));
|
| 114 | 0 |
java.addSysproperty(createSysProperty("tomcat.home", this.tmpDir)); |
| 115 | 0 |
Path classpath = java.createClasspath(); |
| 116 | 0 |
classpath.createPathElement().setLocation( |
| 117 |
new File(getDir(), "lib/tomcat.jar")); |
|
| 118 |
|
|
| 119 |
// It seems that since Tomcat 3.3.2, the commons-logging jar is
|
|
| 120 |
// required in the Tomcat bootstrap classpath...
|
|
| 121 | 0 |
File commonsLoggingJarFile = |
| 122 |
new File(getDir(), "lib/common/commons-logging-api.jar"); |
|
| 123 | 0 |
if (commonsLoggingJarFile.exists())
|
| 124 |
{
|
|
| 125 | 0 |
classpath.createPathElement().setLocation(commonsLoggingJarFile); |
| 126 |
} |
|
| 127 |
|
|
| 128 | 0 |
java.setClassname("org.apache.tomcat.startup.Main");
|
| 129 | 0 |
java.createArg().setValue(theArg); |
| 130 | 0 |
java.execute(); |
| 131 |
} |
|
| 132 |
|
|
| 133 |
/**
|
|
| 134 |
* Prepares a temporary installation of the container and deploys the
|
|
| 135 |
* web-application.
|
|
| 136 |
*
|
|
| 137 |
* @param theDirName The name of the temporary container installation
|
|
| 138 |
* directory
|
|
| 139 |
* @throws IOException If an I/O error occurs
|
|
| 140 |
*/
|
|
| 141 | 0 |
private void prepare(String theDirName) throws IOException |
| 142 |
{
|
|
| 143 | 0 |
FileUtils fileUtils = FileUtils.newFileUtils(); |
| 144 | 0 |
FilterChain filterChain = createFilterChain(); |
| 145 |
|
|
| 146 | 0 |
this.tmpDir = setupTempDirectory(this.tmpDir, theDirName); |
| 147 | 0 |
cleanTempDirectory(this.tmpDir);
|
| 148 |
|
|
| 149 |
// copy configuration files into the temporary container directory
|
|
| 150 | 0 |
File confDir = createDirectory(tmpDir, "conf");
|
| 151 | 0 |
copyConfFiles(confDir); |
| 152 | 0 |
if (getServerXml() == null) |
| 153 |
{
|
|
| 154 | 0 |
ResourceUtils.copyResource(getProject(), |
| 155 |
RESOURCE_PATH + "tomcat3x/server.xml",
|
|
| 156 |
new File(confDir, "server.xml"), filterChain); |
|
| 157 |
} |
|
| 158 |
// TODO: only copy these files if they haven't been provided by the
|
|
| 159 |
// user as a conf fileset
|
|
| 160 | 0 |
ResourceUtils.copyResource(getProject(), |
| 161 |
RESOURCE_PATH + "tomcat3x/tomcat-users.xml",
|
|
| 162 |
new File(confDir, "tomcat-users.xml")); |
|
| 163 | 0 |
ResourceUtils.copyResource(getProject(), |
| 164 |
RESOURCE_PATH + "tomcat3x/modules.xml",
|
|
| 165 |
new File(confDir, "modules.xml")); |
|
| 166 |
|
|
| 167 |
// deploy the web-app by copying the WAR file
|
|
| 168 | 0 |
File webappsDir = createDirectory(tmpDir, "webapps");
|
| 169 | 0 |
fileUtils.copyFile(getDeployableFile().getFile(), |
| 170 |
new File(webappsDir, getDeployableFile().getFile().getName()),
|
|
| 171 |
null, true); |
|
| 172 |
} |
|
| 173 |
|
|
| 174 |
} |
|
| 175 |
|
|
||||||||||