|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| Resin2xContainer.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.resin;
|
|
| 58 |
|
|
| 59 |
import java.io.File;
|
|
| 60 |
import java.io.IOException;
|
|
| 61 |
|
|
| 62 |
import org.apache.cactus.integration.ant.container.AbstractJavaContainer;
|
|
| 63 |
import org.apache.cactus.integration.ant.util.ResourceUtils;
|
|
| 64 |
import org.apache.tools.ant.BuildException;
|
|
| 65 |
import org.apache.tools.ant.taskdefs.Java;
|
|
| 66 |
import org.apache.tools.ant.types.FileSet;
|
|
| 67 |
import org.apache.tools.ant.types.FilterChain;
|
|
| 68 |
import org.apache.tools.ant.types.Path;
|
|
| 69 |
import org.apache.tools.ant.util.FileUtils;
|
|
| 70 |
|
|
| 71 |
/**
|
|
| 72 |
* Special container support for the Caucho Resin 2.x servlet container.
|
|
| 73 |
*
|
|
| 74 |
* @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
|
|
| 75 |
*
|
|
| 76 |
* @version $Id: Resin2xContainer.java,v 1.5.2.2 2003/10/23 18:20:46 vmassol Exp $
|
|
| 77 |
*/
|
|
| 78 |
public class Resin2xContainer extends AbstractJavaContainer |
|
| 79 |
{
|
|
| 80 |
|
|
| 81 |
// Instance Variables ------------------------------------------------------
|
|
| 82 |
|
|
| 83 |
/**
|
|
| 84 |
* The Resin 2.x installation directory.
|
|
| 85 |
*/
|
|
| 86 |
private File dir;
|
|
| 87 |
|
|
| 88 |
/**
|
|
| 89 |
* A user-specific resin.conf configuration file. If this variable is not
|
|
| 90 |
* set, the default configuration file from the JAR resources will be used.
|
|
| 91 |
*/
|
|
| 92 |
private File resinConf;
|
|
| 93 |
|
|
| 94 |
/**
|
|
| 95 |
* The port to which the container should be bound.
|
|
| 96 |
*/
|
|
| 97 |
private int port = 8080; |
|
| 98 |
|
|
| 99 |
/**
|
|
| 100 |
* The temporary directory from which the container will be started.
|
|
| 101 |
*/
|
|
| 102 |
private File tmpDir;
|
|
| 103 |
|
|
| 104 |
// Public Methods ----------------------------------------------------------
|
|
| 105 |
|
|
| 106 |
/**
|
|
| 107 |
* Sets the Resin installation directory.
|
|
| 108 |
*
|
|
| 109 |
* @param theDir The directory to set
|
|
| 110 |
*/
|
|
| 111 | 0 |
public final void setDir(File theDir) |
| 112 |
{
|
|
| 113 | 0 |
this.dir = theDir;
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/**
|
|
| 117 |
* Sets the configuration file to use for the test installation of Resin
|
|
| 118 |
* 2.x.
|
|
| 119 |
*
|
|
| 120 |
* @param theResinConf The resin.conf file
|
|
| 121 |
*/
|
|
| 122 | 0 |
public final void setResinConf(File theResinConf) |
| 123 |
{
|
|
| 124 | 0 |
this.resinConf = theResinConf;
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/**
|
|
| 128 |
* Sets the port to which the container should listen.
|
|
| 129 |
*
|
|
| 130 |
* @param thePort The port to set
|
|
| 131 |
*/
|
|
| 132 | 0 |
public final void setPort(int thePort) |
| 133 |
{
|
|
| 134 | 0 |
this.port = thePort;
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
/**
|
|
| 138 |
* Sets the temporary directory from which the container is run.
|
|
| 139 |
*
|
|
| 140 |
* @param theTmpDir The temporary directory to set
|
|
| 141 |
*/
|
|
| 142 | 0 |
public final void setTmpDir(File theTmpDir) |
| 143 |
{
|
|
| 144 | 0 |
this.tmpDir = theTmpDir;
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
// AbstractContainer Implementation ----------------------------------------
|
|
| 148 |
|
|
| 149 |
/**
|
|
| 150 |
* @see org.apache.cactus.integration.ant.container.Container#getName
|
|
| 151 |
*/
|
|
| 152 | 0 |
public final String getName()
|
| 153 |
{
|
|
| 154 | 0 |
return "Resin 2.x"; |
| 155 |
} |
|
| 156 |
|
|
| 157 |
/**
|
|
| 158 |
* Returns the port to which the container should listen.
|
|
| 159 |
*
|
|
| 160 |
* @return The port
|
|
| 161 |
*/
|
|
| 162 | 0 |
public final int getPort() |
| 163 |
{
|
|
| 164 | 0 |
return this.port; |
| 165 |
} |
|
| 166 |
|
|
| 167 |
/**
|
|
| 168 |
* @see org.apache.cactus.integration.ant.container.Container#init
|
|
| 169 |
*/
|
|
| 170 | 0 |
public final void init() |
| 171 |
{
|
|
| 172 | 0 |
if (!this.dir.isDirectory()) |
| 173 |
{
|
|
| 174 | 0 |
throw new BuildException(this.dir + " is not a directory"); |
| 175 |
} |
|
| 176 |
} |
|
| 177 |
|
|
| 178 |
/**
|
|
| 179 |
* @see org.apache.cactus.integration.ant.container.Container#startUp
|
|
| 180 |
*/
|
|
| 181 | 0 |
public final void startUp() |
| 182 |
{
|
|
| 183 | 0 |
try
|
| 184 |
{
|
|
| 185 | 0 |
prepare("cactus/resin2x");
|
| 186 |
|
|
| 187 |
// invoke the main class
|
|
| 188 | 0 |
Java java = createJavaForStartUp(); |
| 189 | 0 |
java.addSysproperty(createSysProperty("resin.home", this.tmpDir)); |
| 190 | 0 |
Path classpath = java.createClasspath(); |
| 191 | 0 |
classpath.createPathElement().setLocation( |
| 192 |
ResourceUtils.getResourceLocation("/"
|
|
| 193 |
+ ResinRun.class.getName().replace('.', '/') + ".class")); |
|
| 194 | 0 |
FileSet fileSet = new FileSet();
|
| 195 | 0 |
fileSet.setDir(this.dir);
|
| 196 | 0 |
fileSet.createInclude().setName("lib/*.jar");
|
| 197 | 0 |
classpath.addFileset(fileSet); |
| 198 | 0 |
java.setClassname(ResinRun.class.getName());
|
| 199 | 0 |
java.createArg().setValue("-start");
|
| 200 | 0 |
java.createArg().setValue("-conf");
|
| 201 | 0 |
java.createArg().setFile(new File(tmpDir, "resin.conf")); |
| 202 | 0 |
java.execute(); |
| 203 |
} |
|
| 204 |
catch (IOException ioe)
|
|
| 205 |
{
|
|
| 206 | 0 |
getLog().error("Failed to startup the container", ioe);
|
| 207 | 0 |
throw new BuildException(ioe); |
| 208 |
} |
|
| 209 |
} |
|
| 210 |
|
|
| 211 |
/**
|
|
| 212 |
* @see org.apache.cactus.integration.ant.container.Container#shutDown
|
|
| 213 |
*/
|
|
| 214 | 0 |
public final void shutDown() |
| 215 |
{
|
|
| 216 |
// invoke the main class
|
|
| 217 | 0 |
Java java = createJavaForShutDown(); |
| 218 | 0 |
java.setFork(true);
|
| 219 | 0 |
java.addSysproperty(createSysProperty("resin.home", this.tmpDir)); |
| 220 | 0 |
Path classpath = java.createClasspath(); |
| 221 | 0 |
classpath.createPathElement().setLocation( |
| 222 |
ResourceUtils.getResourceLocation("/"
|
|
| 223 |
+ ResinRun.class.getName().replace('.', '/') + ".class")); |
|
| 224 | 0 |
FileSet fileSet = new FileSet();
|
| 225 | 0 |
fileSet.setDir(this.dir);
|
| 226 | 0 |
fileSet.createInclude().setName("lib/*.jar");
|
| 227 | 0 |
classpath.addFileset(fileSet); |
| 228 | 0 |
java.setClassname(ResinRun.class.getName());
|
| 229 | 0 |
java.createArg().setValue("-stop");
|
| 230 | 0 |
java.execute(); |
| 231 |
} |
|
| 232 |
|
|
| 233 |
// Private Methods ---------------------------------------------------------
|
|
| 234 |
|
|
| 235 |
/**
|
|
| 236 |
* Prepares a temporary installation of the container and deploys the
|
|
| 237 |
* web-application.
|
|
| 238 |
*
|
|
| 239 |
* @param theDirName The name of the temporary container installation
|
|
| 240 |
* directory
|
|
| 241 |
* @throws IOException If an I/O error occurs
|
|
| 242 |
*/
|
|
| 243 | 0 |
private void prepare(String theDirName) throws IOException |
| 244 |
{
|
|
| 245 | 0 |
FileUtils fileUtils = FileUtils.newFileUtils(); |
| 246 | 0 |
FilterChain filterChain = createFilterChain(); |
| 247 |
|
|
| 248 | 0 |
if (this.tmpDir == null) |
| 249 |
{
|
|
| 250 | 0 |
this.tmpDir = createTempDirectory(theDirName);
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
// copy configuration files into the temporary container directory
|
|
| 254 | 0 |
if (this.resinConf != null) |
| 255 |
{
|
|
| 256 | 0 |
fileUtils.copyFile(this.resinConf, new File(tmpDir, "resin.conf")); |
| 257 |
} |
|
| 258 |
else
|
|
| 259 |
{
|
|
| 260 | 0 |
ResourceUtils.copyResource(getProject(), |
| 261 |
RESOURCE_PATH + "resin2x/resin.conf",
|
|
| 262 |
new File(tmpDir, "resin.conf"), filterChain); |
|
| 263 |
} |
|
| 264 |
|
|
| 265 | 0 |
fileUtils.copyFile(getDeployableFile().getFile(), |
| 266 |
new File(tmpDir, getDeployableFile().getFile().getName()),
|
|
| 267 |
null, true); |
|
| 268 |
} |
|
| 269 |
|
|
| 270 |
} |
|
| 271 |
|
|
||||||||||