|
|||||||||||||||||||
| 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 | |||||||||||||||
| AbstractResinContainer.java | 12.5% | 9.3% | 33.3% | 13.5% |
|
||||||||||||||
| 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.resin;
|
|
| 21 |
|
|
| 22 |
import java.io.File;
|
|
| 23 |
import java.io.IOException;
|
|
| 24 |
|
|
| 25 |
import org.apache.cactus.integration.ant.container.AbstractJavaContainer;
|
|
| 26 |
import org.apache.cactus.integration.ant.util.ResourceUtils;
|
|
| 27 |
import org.apache.tools.ant.BuildException;
|
|
| 28 |
import org.apache.tools.ant.taskdefs.Java;
|
|
| 29 |
import org.apache.tools.ant.types.FileSet;
|
|
| 30 |
import org.apache.tools.ant.types.FilterChain;
|
|
| 31 |
import org.apache.tools.ant.types.Path;
|
|
| 32 |
import org.apache.tools.ant.util.FileUtils;
|
|
| 33 |
|
|
| 34 |
/**
|
|
| 35 |
* Common support for all Resin container versions.
|
|
| 36 |
*
|
|
| 37 |
* @version $Id: AbstractResinContainer.java 239003 2004-05-31 20:05:27Z vmassol $
|
|
| 38 |
*/
|
|
| 39 |
public abstract class AbstractResinContainer extends AbstractJavaContainer |
|
| 40 |
{
|
|
| 41 |
// Instance Variables ------------------------------------------------------
|
|
| 42 |
|
|
| 43 |
/**
|
|
| 44 |
* The mandatory Resin installation directory.
|
|
| 45 |
*/
|
|
| 46 |
private File dir;
|
|
| 47 |
|
|
| 48 |
/**
|
|
| 49 |
* A user-specific resin.conf configuration file. If this variable is not
|
|
| 50 |
* set, the default configuration file from the JAR resources will be used.
|
|
| 51 |
*/
|
|
| 52 |
private File resinConf;
|
|
| 53 |
|
|
| 54 |
/**
|
|
| 55 |
* The port to which the container should be bound.
|
|
| 56 |
*/
|
|
| 57 |
private int port = 8080; |
|
| 58 |
|
|
| 59 |
/**
|
|
| 60 |
* The temporary directory from which the container will be started.
|
|
| 61 |
*/
|
|
| 62 |
private File tmpDir;
|
|
| 63 |
|
|
| 64 |
// Public Methods ----------------------------------------------------------
|
|
| 65 |
|
|
| 66 |
/**
|
|
| 67 |
* Sets the Resin installation directory.
|
|
| 68 |
*
|
|
| 69 |
* @param theDir The directory to set
|
|
| 70 |
*/
|
|
| 71 | 1 |
public final void setDir(File theDir) |
| 72 |
{
|
|
| 73 | 1 |
this.dir = theDir;
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
/**
|
|
| 77 |
* Sets the temporary directory from which the container is run.
|
|
| 78 |
*
|
|
| 79 |
* @param theTmpDir The temporary directory to set
|
|
| 80 |
*/
|
|
| 81 | 0 |
public final void setTmpDir(File theTmpDir) |
| 82 |
{
|
|
| 83 | 0 |
this.tmpDir = theTmpDir;
|
| 84 |
} |
|
| 85 |
|
|
| 86 |
/**
|
|
| 87 |
* Sets the configuration file to use for the test installation of Resin
|
|
| 88 |
*
|
|
| 89 |
* @param theResinConf The resin.conf file
|
|
| 90 |
*/
|
|
| 91 | 0 |
public final void setResinConf(File theResinConf) |
| 92 |
{
|
|
| 93 | 0 |
this.resinConf = theResinConf;
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/**
|
|
| 97 |
* Sets the port to which the container should listen.
|
|
| 98 |
*
|
|
| 99 |
* @param thePort The port to set
|
|
| 100 |
*/
|
|
| 101 | 1 |
public final void setPort(int thePort) |
| 102 |
{
|
|
| 103 | 1 |
this.port = thePort;
|
| 104 |
} |
|
| 105 |
|
|
| 106 |
/**
|
|
| 107 |
* Checks if all mandatory properties have been set and that they
|
|
| 108 |
* contain valid values.
|
|
| 109 |
*/
|
|
| 110 | 1 |
public void verify() |
| 111 |
{
|
|
| 112 | 1 |
if (getDir() == null) |
| 113 |
{
|
|
| 114 | 1 |
throw new BuildException( |
| 115 |
"You must specify the mandatory [dir] attribute");
|
|
| 116 |
} |
|
| 117 |
|
|
| 118 | 0 |
if (!getDir().isDirectory())
|
| 119 |
{
|
|
| 120 | 0 |
throw new BuildException("[" + getDir() + "] is not a directory"); |
| 121 |
} |
|
| 122 |
} |
|
| 123 |
|
|
| 124 |
// AbstractContainer Implementation ----------------------------------------
|
|
| 125 |
|
|
| 126 |
/**
|
|
| 127 |
* Returns the port to which the container should listen.
|
|
| 128 |
*
|
|
| 129 |
* @return The port
|
|
| 130 |
*/
|
|
| 131 | 0 |
public final int getPort() |
| 132 |
{
|
|
| 133 | 0 |
return this.port; |
| 134 |
} |
|
| 135 |
|
|
| 136 |
/**
|
|
| 137 |
* @see org.apache.cactus.integration.ant.container.Container#init
|
|
| 138 |
*/
|
|
| 139 | 0 |
public final void init() |
| 140 |
{
|
|
| 141 | 0 |
verify(); |
| 142 |
} |
|
| 143 |
|
|
| 144 |
/**
|
|
| 145 |
* @see org.apache.cactus.integration.ant.container.Container#startUp
|
|
| 146 |
*/
|
|
| 147 | 0 |
public final void startUp() |
| 148 |
{
|
|
| 149 | 0 |
try
|
| 150 |
{
|
|
| 151 | 0 |
File installDir = setupTempDirectory(getTmpDir(), |
| 152 |
"cactus/" + getContainerDirName());
|
|
| 153 | 0 |
cleanTempDirectory(installDir); |
| 154 |
|
|
| 155 | 0 |
prepare(installDir); |
| 156 |
|
|
| 157 |
// Invoke the main class
|
|
| 158 | 0 |
Java java = createJavaForStartUp(); |
| 159 | 0 |
java.addSysproperty(createSysProperty("resin.home", installDir));
|
| 160 | 0 |
Path classpath = java.createClasspath(); |
| 161 | 0 |
classpath.createPathElement().setLocation( |
| 162 |
ResourceUtils.getResourceLocation("/"
|
|
| 163 |
+ ResinRun.class.getName().replace('.', '/') + ".class")); |
|
| 164 | 0 |
FileSet fileSet = new FileSet();
|
| 165 | 0 |
fileSet.setDir(getDir()); |
| 166 | 0 |
fileSet.createInclude().setName("lib/*.jar");
|
| 167 | 0 |
classpath.addFileset(fileSet); |
| 168 | 0 |
java.setClassname(ResinRun.class.getName());
|
| 169 | 0 |
java.createArg().setValue("-start");
|
| 170 | 0 |
java.createArg().setValue("-conf");
|
| 171 | 0 |
java.createArg().setFile(new File(installDir, "resin.conf")); |
| 172 |
|
|
| 173 |
// Add settings specific to a given container version
|
|
| 174 | 0 |
startUpAdditions(java, classpath); |
| 175 |
|
|
| 176 | 0 |
java.execute(); |
| 177 |
} |
|
| 178 |
catch (IOException ioe)
|
|
| 179 |
{
|
|
| 180 | 0 |
getLog().error("Failed to startup the container", ioe);
|
| 181 | 0 |
throw new BuildException(ioe); |
| 182 |
} |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/**
|
|
| 186 |
* @see org.apache.cactus.integration.ant.container.Container#shutDown
|
|
| 187 |
*/
|
|
| 188 | 0 |
public final void shutDown() |
| 189 |
{
|
|
| 190 | 0 |
File installDir = setupTempDirectory(getTmpDir(), |
| 191 |
"cactus/" + getContainerDirName());
|
|
| 192 |
|
|
| 193 |
// Invoke the main class
|
|
| 194 | 0 |
Java java = createJavaForShutDown(); |
| 195 | 0 |
java.setFork(true);
|
| 196 | 0 |
java.addSysproperty(createSysProperty("resin.home", installDir));
|
| 197 | 0 |
Path classpath = java.createClasspath(); |
| 198 | 0 |
classpath.createPathElement().setLocation( |
| 199 |
ResourceUtils.getResourceLocation("/"
|
|
| 200 |
+ ResinRun.class.getName().replace('.', '/') + ".class")); |
|
| 201 | 0 |
FileSet fileSet = new FileSet();
|
| 202 | 0 |
fileSet.setDir(getDir()); |
| 203 | 0 |
fileSet.createInclude().setName("lib/*.jar");
|
| 204 | 0 |
classpath.addFileset(fileSet); |
| 205 | 0 |
java.setClassname(ResinRun.class.getName());
|
| 206 | 0 |
java.createArg().setValue("-stop");
|
| 207 | 0 |
java.execute(); |
| 208 |
} |
|
| 209 |
|
|
| 210 |
// Protected Methods -------------------------------------------------------
|
|
| 211 |
|
|
| 212 |
/**
|
|
| 213 |
* Allow specific version implementations to add custom settings to the
|
|
| 214 |
* Java container that will be started.
|
|
| 215 |
*
|
|
| 216 |
* @param theJavaContainer the Ant Java object that will start the container
|
|
| 217 |
* @param theClasspath the classpath that will be used to start the
|
|
| 218 |
* container
|
|
| 219 |
*/
|
|
| 220 |
protected abstract void startUpAdditions(Java theJavaContainer, |
|
| 221 |
Path theClasspath); |
|
| 222 |
|
|
| 223 |
/**
|
|
| 224 |
* Allow specific version implementations to add custom preparation steps
|
|
| 225 |
* before the container is started.
|
|
| 226 |
*
|
|
| 227 |
* @param theInstallDir The directory in which to create the temporary
|
|
| 228 |
* container installation
|
|
| 229 |
* @param theFilterChain the filter chain used to replace Ant tokens in
|
|
| 230 |
* configuration
|
|
| 231 |
* @exception IOException in case of an error
|
|
| 232 |
*/
|
|
| 233 |
protected abstract void prepareAdditions(File theInstallDir, |
|
| 234 |
FilterChain theFilterChain) throws IOException;
|
|
| 235 |
|
|
| 236 |
/**
|
|
| 237 |
* @return the name of the directory where the container will be set up
|
|
| 238 |
*/
|
|
| 239 |
protected abstract String getContainerDirName();
|
|
| 240 |
|
|
| 241 |
/**
|
|
| 242 |
* @return the directory where Resin is installed
|
|
| 243 |
*/
|
|
| 244 | 1 |
protected final File getDir()
|
| 245 |
{
|
|
| 246 | 1 |
return this.dir; |
| 247 |
} |
|
| 248 |
|
|
| 249 |
/**
|
|
| 250 |
* @return The temporary directory from which the container will be
|
|
| 251 |
* started.
|
|
| 252 |
*/
|
|
| 253 | 0 |
protected final File getTmpDir()
|
| 254 |
{
|
|
| 255 | 0 |
return this.tmpDir; |
| 256 |
} |
|
| 257 |
|
|
| 258 |
// Private Methods ---------------------------------------------------------
|
|
| 259 |
|
|
| 260 |
/**
|
|
| 261 |
* Prepares a temporary installation of the container and deploys the
|
|
| 262 |
* web-application.
|
|
| 263 |
*
|
|
| 264 |
* @param theInstallDir The directory in which to create the temporary
|
|
| 265 |
* container installation
|
|
| 266 |
* @throws IOException If an I/O error occurs
|
|
| 267 |
*/
|
|
| 268 | 0 |
private void prepare(File theInstallDir) throws IOException |
| 269 |
{
|
|
| 270 | 0 |
FileUtils fileUtils = FileUtils.newFileUtils(); |
| 271 | 0 |
FilterChain filterChain = createFilterChain(); |
| 272 |
|
|
| 273 |
// Copy configuration files into the temporary container directory
|
|
| 274 | 0 |
if (this.resinConf != null) |
| 275 |
{
|
|
| 276 | 0 |
fileUtils.copyFile(this.resinConf,
|
| 277 |
new File(theInstallDir, "resin.conf")); |
|
| 278 |
} |
|
| 279 |
else
|
|
| 280 |
{
|
|
| 281 | 0 |
ResourceUtils.copyResource(getProject(), |
| 282 |
RESOURCE_PATH + getContainerDirName() + "/resin.conf",
|
|
| 283 |
new File(theInstallDir, "resin.conf"), filterChain); |
|
| 284 |
} |
|
| 285 |
|
|
| 286 |
// Deploy the web-app by copying the WAR file into the webapps
|
|
| 287 |
// directory
|
|
| 288 | 0 |
if (getDeployableFile() != null) |
| 289 |
{
|
|
| 290 | 0 |
File webappsDir = createDirectory(theInstallDir, "webapps");
|
| 291 | 0 |
fileUtils.copyFile(getDeployableFile().getFile(), |
| 292 |
new File(webappsDir, getDeployableFile().getFile().getName()),
|
|
| 293 |
null, true); |
|
| 294 |
} |
|
| 295 |
|
|
| 296 |
// Add preparation steps specific to a given container version
|
|
| 297 | 0 |
prepareAdditions(theInstallDir, filterChain); |
| 298 |
} |
|
| 299 |
} |
|
| 300 |
|
|
||||||||||