|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| AbstractJavaContainer.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;
|
|
| 58 |
|
|
| 59 |
import java.io.File;
|
|
| 60 |
import java.io.FileNotFoundException;
|
|
| 61 |
|
|
| 62 |
import org.apache.tools.ant.taskdefs.Java;
|
|
| 63 |
import org.apache.tools.ant.types.Path;
|
|
| 64 |
import org.apache.tools.ant.types.Environment.Variable;
|
|
| 65 |
|
|
| 66 |
/**
|
|
| 67 |
* Abstract base class for containers that perform the starting and stopping
|
|
| 68 |
* of the server by executing Java classes in a forked JVM.
|
|
| 69 |
*
|
|
| 70 |
* @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
|
|
| 71 |
*
|
|
| 72 |
* @version $Id: AbstractJavaContainer.java,v 1.2.2.1 2003/10/23 18:20:43 vmassol Exp $
|
|
| 73 |
*/
|
|
| 74 |
public abstract class AbstractJavaContainer extends AbstractContainer |
|
| 75 |
{
|
|
| 76 |
// Instance Variables ------------------------------------------------------
|
|
| 77 |
|
|
| 78 |
/**
|
|
| 79 |
* The file to which output of the container should be written.
|
|
| 80 |
*/
|
|
| 81 |
private File output;
|
|
| 82 |
|
|
| 83 |
/**
|
|
| 84 |
* Whether output of the container should be appended to an existing file,
|
|
| 85 |
* or the existing file should be truncated.
|
|
| 86 |
*/
|
|
| 87 |
private boolean append; |
|
| 88 |
|
|
| 89 |
// Public Methods ----------------------------------------------------------
|
|
| 90 |
|
|
| 91 |
/**
|
|
| 92 |
* Sets the file to which output of the container should be written.
|
|
| 93 |
*
|
|
| 94 |
* @param theOutput The output file to set
|
|
| 95 |
*/
|
|
| 96 | 0 |
public final void setOutput(File theOutput) |
| 97 |
{
|
|
| 98 | 0 |
this.output = theOutput;
|
| 99 |
} |
|
| 100 |
|
|
| 101 |
/**
|
|
| 102 |
* Sets whether output of the container should be appended to an existing
|
|
| 103 |
* file, or the existing file should be truncated.
|
|
| 104 |
*
|
|
| 105 |
* @param isAppend Whether output should be appended
|
|
| 106 |
*/
|
|
| 107 | 0 |
public final void setAppend(boolean isAppend) |
| 108 |
{
|
|
| 109 | 0 |
this.append = isAppend;
|
| 110 |
} |
|
| 111 |
|
|
| 112 |
// Protected Methods -------------------------------------------------------
|
|
| 113 |
|
|
| 114 |
/**
|
|
| 115 |
* Creates a preinitialized instance of the Ant Java task to be used for
|
|
| 116 |
* shutting down the container.
|
|
| 117 |
*
|
|
| 118 |
* @return The created task instance
|
|
| 119 |
*/
|
|
| 120 | 0 |
protected final Java createJavaForShutDown()
|
| 121 |
{
|
|
| 122 | 0 |
Java java = (Java) createAntTask("java");
|
| 123 | 0 |
java.setFork(true);
|
| 124 | 0 |
return java;
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/**
|
|
| 128 |
* Creates a preinitialized instance of the Ant Java task to be used for
|
|
| 129 |
* starting down the container.
|
|
| 130 |
*
|
|
| 131 |
* @return The created task instance
|
|
| 132 |
*/
|
|
| 133 | 0 |
protected final Java createJavaForStartUp()
|
| 134 |
{
|
|
| 135 | 0 |
Java java = (Java) createAntTask("java");
|
| 136 | 0 |
java.setFork(true);
|
| 137 | 0 |
java.setOutput(this.output);
|
| 138 | 0 |
java.setAppend(this.append);
|
| 139 |
|
|
| 140 |
// Add Cactus properties for the server side
|
|
| 141 | 0 |
for (int i = 0; i < getSystemProperties().length; i++) |
| 142 |
{
|
|
| 143 | 0 |
java.addSysproperty( |
| 144 |
createSysProperty(getSystemProperties()[i].getKey(), |
|
| 145 |
getSystemProperties()[i].getValue())); |
|
| 146 |
} |
|
| 147 |
|
|
| 148 | 0 |
return java;
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
/**
|
|
| 152 |
* Convenience method to create an Ant environment variable that points to
|
|
| 153 |
* a file.
|
|
| 154 |
*
|
|
| 155 |
* @param theKey The key or name of the variable
|
|
| 156 |
* @param theFile The file the variable should point to
|
|
| 157 |
* @return The created environment variable
|
|
| 158 |
*/
|
|
| 159 | 0 |
protected final Variable createSysProperty(String theKey, File theFile)
|
| 160 |
{
|
|
| 161 | 0 |
Variable var = new Variable();
|
| 162 | 0 |
var.setKey(theKey); |
| 163 | 0 |
var.setFile(theFile); |
| 164 | 0 |
return var;
|
| 165 |
} |
|
| 166 |
|
|
| 167 |
/**
|
|
| 168 |
* Convenience method to create an Ant environment variable that contains
|
|
| 169 |
* a path.
|
|
| 170 |
*
|
|
| 171 |
* @param theKey The key or name of the variable
|
|
| 172 |
* @param thePath The path
|
|
| 173 |
* @return The created environment variable
|
|
| 174 |
*/
|
|
| 175 | 0 |
protected final Variable createSysProperty(String theKey, Path thePath)
|
| 176 |
{
|
|
| 177 | 0 |
Variable var = new Variable();
|
| 178 | 0 |
var.setKey(theKey); |
| 179 | 0 |
var.setPath(thePath); |
| 180 | 0 |
return var;
|
| 181 |
} |
|
| 182 |
|
|
| 183 |
/**
|
|
| 184 |
* Convenience method to create an Ant environment variable that contains a
|
|
| 185 |
* string.
|
|
| 186 |
*
|
|
| 187 |
* @param theKey The key or name of the variable
|
|
| 188 |
* @param theValue The value
|
|
| 189 |
* @return The created environment variable
|
|
| 190 |
*/
|
|
| 191 | 0 |
protected final Variable createSysProperty(String theKey, String theValue)
|
| 192 |
{
|
|
| 193 | 0 |
Variable var = new Variable();
|
| 194 | 0 |
var.setKey(theKey); |
| 195 | 0 |
var.setValue(theValue); |
| 196 | 0 |
return var;
|
| 197 |
} |
|
| 198 |
|
|
| 199 |
/**
|
|
| 200 |
* Returns the file containing the JDK tools (such as the compiler).
|
|
| 201 |
*
|
|
| 202 |
* @return The tools.jar file
|
|
| 203 |
* @throws FileNotFoundException If the tools.jar file could not be found
|
|
| 204 |
*/
|
|
| 205 | 0 |
protected final File getToolsJar()
|
| 206 |
throws FileNotFoundException
|
|
| 207 |
{
|
|
| 208 | 0 |
String javaHome = System.getProperty("java.home");
|
| 209 |
// TODO: Fix this as it fails on Max OSX (which doesn't have a
|
|
| 210 |
// tools.jar file).
|
|
| 211 | 0 |
File toolsJar = new File(javaHome + "/../lib/tools.jar"); |
| 212 | 0 |
if (!toolsJar.isFile())
|
| 213 |
{
|
|
| 214 | 0 |
throw new FileNotFoundException(toolsJar.getAbsolutePath()); |
| 215 |
} |
|
| 216 | 0 |
return toolsJar;
|
| 217 |
} |
|
| 218 |
} |
|
| 219 |
|
|
||||||||||