|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AbstractCatalinaContainer.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* ====================================================================
|
|
3 |
*
|
|
4 |
* The Apache Software License, Version 1.1
|
|
5 |
*
|
|
6 |
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
|
7 |
* reserved.
|
|
8 |
*
|
|
9 |
* Redistribution and use in source and binary forms, with or without
|
|
10 |
* modification, are permitted provided that the following conditions
|
|
11 |
* are met:
|
|
12 |
*
|
|
13 |
* 1. Redistributions of source code must retain the above copyright
|
|
14 |
* notice, this list of conditions and the following disclaimer.
|
|
15 |
*
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer in
|
|
18 |
* the documentation and/or other materials provided with the
|
|
19 |
* distribution.
|
|
20 |
*
|
|
21 |
* 3. The end-user documentation included with the redistribution, if
|
|
22 |
* any, must include the following acknowlegement:
|
|
23 |
* "This product includes software developed by the
|
|
24 |
* Apache Software Foundation (http://www.apache.org/)."
|
|
25 |
* Alternately, this acknowlegement may appear in the software itself,
|
|
26 |
* if and wherever such third-party acknowlegements normally appear.
|
|
27 |
*
|
|
28 |
* 4. The names "The Jakarta Project", "Cactus" and "Apache Software
|
|
29 |
* Foundation" must not be used to endorse or promote products
|
|
30 |
* derived from this software without prior written permission. For
|
|
31 |
* written permission, please contact apache@apache.org.
|
|
32 |
*
|
|
33 |
* 5. Products derived from this software may not be called "Apache"
|
|
34 |
* nor may "Apache" appear in their names without prior written
|
|
35 |
* permission of the Apache Group.
|
|
36 |
*
|
|
37 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
38 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
39 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
40 |
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
41 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
42 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
43 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
44 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
45 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
46 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
47 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
48 |
* SUCH DAMAGE.
|
|
49 |
* ====================================================================
|
|
50 |
*
|
|
51 |
* This software consists of voluntary contributions made by many
|
|
52 |
* individuals on behalf of the Apache Software Foundation. For more
|
|
53 |
* information on the Apache Software Foundation, please see
|
|
54 |
* <http://www.apache.org/>.
|
|
55 |
*
|
|
56 |
*/
|
|
57 |
package org.apache.cactus.integration.ant.container.tomcat;
|
|
58 |
|
|
59 |
import java.io.File;
|
|
60 |
import java.io.FileNotFoundException;
|
|
61 |
import java.io.IOException;
|
|
62 |
import java.util.Properties;
|
|
63 |
import java.util.jar.JarFile;
|
|
64 |
import java.util.zip.ZipEntry;
|
|
65 |
|
|
66 |
import org.apache.cactus.integration.ant.util.ResourceUtils;
|
|
67 |
import org.apache.tools.ant.BuildException;
|
|
68 |
import org.apache.tools.ant.taskdefs.Java;
|
|
69 |
import org.apache.tools.ant.types.FilterChain;
|
|
70 |
import org.apache.tools.ant.types.Path;
|
|
71 |
import org.apache.tools.ant.util.FileUtils;
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Base support for Catalina based containers.
|
|
75 |
*
|
|
76 |
* @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
|
|
77 |
*
|
|
78 |
* @version $Id: AbstractCatalinaContainer.java,v 1.4.2.3 2003/11/23 17:17:16 vmassol Exp $
|
|
79 |
*/
|
|
80 |
public abstract class AbstractCatalinaContainer extends AbstractTomcatContainer |
|
81 |
{ |
|
82 |
// Instance Variables ------------------------------------------------------
|
|
83 |
|
|
84 |
/**
|
|
85 |
* The temporary directory from which the container will be started.
|
|
86 |
*/
|
|
87 |
private File tmpDir;
|
|
88 |
|
|
89 |
/**
|
|
90 |
* The Catalina version detected by reading a property file in the
|
|
91 |
* installation directory.
|
|
92 |
*/
|
|
93 |
private String version;
|
|
94 |
|
|
95 |
// Public Methods ----------------------------------------------------------
|
|
96 |
|
|
97 |
/**
|
|
98 |
* Sets the temporary installation directory.
|
|
99 |
*
|
|
100 |
* @param theTmpDir The temporary directory to set
|
|
101 |
*/
|
|
102 | 0 |
public final void setTmpDir(File theTmpDir) |
103 |
{ |
|
104 | 0 |
this.tmpDir = theTmpDir;
|
105 |
} |
|
106 |
|
|
107 |
// AbstractContainer Implementation ----------------------------------------
|
|
108 |
|
|
109 |
/**
|
|
110 |
* @see org.apache.cactus.integration.ant.container.Container#getName
|
|
111 |
*/
|
|
112 | 0 |
public final String getName()
|
113 |
{ |
|
114 | 0 |
return "Tomcat " + this.version; |
115 |
} |
|
116 |
|
|
117 |
/**
|
|
118 |
* @see org.apache.cactus.integration.ant.container.Container#init
|
|
119 |
*/
|
|
120 | 0 |
public void init() |
121 |
{ |
|
122 |
// Check the installation directory
|
|
123 | 0 |
this.version = getVersion();
|
124 | 0 |
if (this.version == null) |
125 |
{ |
|
126 | 0 |
throw new BuildException(getDir() |
127 |
+ " not recognized as a Tomcat 4.x installation");
|
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
// Protected Methods -------------------------------------------------------
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Returns the version of the Tomcat installation.
|
|
135 |
*
|
|
136 |
* @return The Tomcat version, or <code>null</code> if the verion number
|
|
137 |
* could not be retrieved
|
|
138 |
*/
|
|
139 | 0 |
protected final String getVersion()
|
140 |
{ |
|
141 | 0 |
if (this.version == null) |
142 |
{ |
|
143 | 0 |
try
|
144 |
{ |
|
145 |
// Unfortunately, there's no safe way to find out the version of
|
|
146 |
// a Catalina installation, so we need to try multiple paths
|
|
147 |
// here
|
|
148 |
|
|
149 |
// Tomcat 4.1.0 and later includes a ServerInfo.properties
|
|
150 |
// resource in catalina.jar that contains the version number. If
|
|
151 |
// that resource doesn't exist, we're on Tomcat 4.0.x
|
|
152 | 0 |
JarFile catalinaJar = new JarFile(
|
153 |
new File(getDir(), "server/lib/catalina.jar")); |
|
154 | 0 |
ZipEntry entry = catalinaJar.getEntry( |
155 |
"org/apache/catalina/util/ServerInfo.properties");
|
|
156 | 0 |
if (entry != null) |
157 |
{ |
|
158 | 0 |
Properties props = new Properties();
|
159 | 0 |
props.load(catalinaJar.getInputStream(entry)); |
160 | 0 |
String serverInfo = props.getProperty("server.info");
|
161 | 0 |
if (serverInfo.indexOf('/') > 0)
|
162 |
{ |
|
163 | 0 |
this.version =
|
164 |
serverInfo.substring(serverInfo.indexOf('/') + 1); |
|
165 |
} |
|
166 |
} |
|
167 |
else
|
|
168 |
{ |
|
169 | 0 |
this.version = "4.0.x"; |
170 |
} |
|
171 |
} |
|
172 |
catch (IOException ioe)
|
|
173 |
{ |
|
174 | 0 |
getLog().warn("Couldn't retrieve Tomcat version information",
|
175 |
ioe); |
|
176 |
} |
|
177 |
} |
|
178 | 0 |
return this.version; |
179 |
} |
|
180 |
|
|
181 |
/**
|
|
182 |
* Invokes the Catalina Bootstrap class to start or stop the container,
|
|
183 |
* depending on the value of the provided argument.
|
|
184 |
*
|
|
185 |
* @param theArg Either 'start' or 'stop'
|
|
186 |
*/
|
|
187 | 0 |
protected final void invokeBootstrap(String theArg) |
188 |
{ |
|
189 | 0 |
Java java = null;
|
190 | 0 |
if ("start".equals(theArg)) |
191 |
{ |
|
192 | 0 |
java = createJavaForStartUp(); |
193 |
} |
|
194 |
else
|
|
195 |
{ |
|
196 | 0 |
java = createJavaForShutDown(); |
197 |
} |
|
198 | 0 |
java.addSysproperty(createSysProperty("catalina.home", getDir()));
|
199 | 0 |
java.addSysproperty(createSysProperty("catalina.base", this.tmpDir)); |
200 | 0 |
Path classpath = java.createClasspath(); |
201 | 0 |
classpath.createPathElement().setLocation( |
202 |
new File(getDir(), "bin/bootstrap.jar")); |
|
203 | 0 |
try
|
204 |
{ |
|
205 | 0 |
classpath.createPathElement().setLocation(getToolsJar()); |
206 |
} |
|
207 |
catch (FileNotFoundException fnfe)
|
|
208 |
{ |
|
209 | 0 |
getLog().warn( |
210 |
"Couldn't find tools.jar (needed for JSP compilation)");
|
|
211 |
} |
|
212 | 0 |
java.setClassname("org.apache.catalina.startup.Bootstrap");
|
213 | 0 |
java.createArg().setValue(theArg); |
214 | 0 |
java.execute(); |
215 |
} |
|
216 |
|
|
217 |
/**
|
|
218 |
* Prepares a temporary installation of the container and deploys the
|
|
219 |
* web-application.
|
|
220 |
*
|
|
221 |
* @param theResourcePrefix The prefix to use when looking up container
|
|
222 |
* resource in the JAR
|
|
223 |
* @param theDirName The name of the temporary container installation
|
|
224 |
* directory
|
|
225 |
* @throws IOException If an I/O error occurs
|
|
226 |
*/
|
|
227 | 0 |
protected final void prepare(String theResourcePrefix, String theDirName) |
228 |
throws IOException
|
|
229 |
{ |
|
230 | 0 |
FileUtils fileUtils = FileUtils.newFileUtils(); |
231 | 0 |
FilterChain filterChain = createFilterChain(); |
232 |
|
|
233 | 0 |
if (this.tmpDir == null) |
234 |
{ |
|
235 | 0 |
this.tmpDir = createTempDirectory(theDirName);
|
236 |
} |
|
237 |
|
|
238 | 0 |
File confDir = createDirectory(tmpDir, "conf");
|
239 |
|
|
240 |
// Copy first the default configuration files so that they can be
|
|
241 |
// overriden by the user-provided ones.
|
|
242 |
|
|
243 | 0 |
if (getServerXml() == null) |
244 |
{ |
|
245 | 0 |
ResourceUtils.copyResource(getProject(), |
246 |
RESOURCE_PATH + theResourcePrefix + "/server.xml",
|
|
247 |
new File(confDir, "server.xml"), filterChain); |
|
248 |
} |
|
249 |
|
|
250 | 0 |
ResourceUtils.copyResource(getProject(), |
251 |
RESOURCE_PATH + theResourcePrefix + "/tomcat-users.xml",
|
|
252 |
new File(confDir, "tomcat-users.xml")); |
|
253 | 0 |
fileUtils.copyFile(new File(getDir(), "conf/web.xml"), |
254 |
new File(confDir, "web.xml")); |
|
255 |
|
|
256 |
// Copy user-provided configuration files into the temporary container
|
|
257 |
// directory
|
|
258 |
|
|
259 | 0 |
copyConfFiles(confDir); |
260 |
|
|
261 |
// deploy the web-app by copying the WAR file into the webapps
|
|
262 |
// directory
|
|
263 | 0 |
File webappsDir = createDirectory(tmpDir, "webapps");
|
264 | 0 |
fileUtils.copyFile(getDeployableFile().getFile(), |
265 |
new File(webappsDir, getDeployableFile().getFile().getName()),
|
|
266 |
null, true); |
|
267 |
} |
|
268 |
|
|
269 |
} |
|
270 |
|
|