Clover coverage report - Cactus 1.5 for J2EE API 1.3
Coverage timestamp: Wed Feb 18 2004 09:09:13 EST
file stats: LOC: 206   Methods: 6
NCLOC: 85   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Tomcat3xContainer.java 0% 0% 0% 0%
coverage
 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.IOException;
 61   
 
 62   
 import org.apache.cactus.integration.ant.util.ResourceUtils;
 63   
 import org.apache.tools.ant.BuildException;
 64   
 import org.apache.tools.ant.taskdefs.Java;
 65   
 import org.apache.tools.ant.types.FilterChain;
 66   
 import org.apache.tools.ant.types.Path;
 67   
 import org.apache.tools.ant.util.FileUtils;
 68   
 
 69   
 /**
 70   
  * Special container support for the Apache Tomcat 3.x servlet container.
 71   
  * 
 72   
  * @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
 73   
  *
 74   
  * @version $Id: Tomcat3xContainer.java,v 1.5.2.2 2003/10/23 18:20:44 vmassol Exp $
 75   
  */
 76   
 public class Tomcat3xContainer extends AbstractTomcatContainer
 77   
 {
 78   
 
 79   
     // Instance Variables ------------------------------------------------------
 80   
 
 81   
     /**
 82   
      * The temporary directory from which the container will be started.
 83   
      */
 84   
     private File tmpDir;
 85   
 
 86   
     // Public Methods ----------------------------------------------------------
 87   
 
 88   
     /**
 89   
      * Sets the temporary installation directory.
 90   
      * 
 91   
      * @param theTmpDir The temporary directory to set
 92   
      */
 93  0
     public final void setTmpDir(File theTmpDir)
 94   
     {
 95  0
         this.tmpDir = theTmpDir;
 96   
     }
 97   
 
 98   
     // AbstractContainer Implementation ----------------------------------------
 99   
 
 100   
     /**
 101   
      * @see org.apache.cactus.integration.ant.container.Container#getName
 102   
      */
 103  0
     public final String getName()
 104   
     {
 105  0
         return "Tomcat 3.x";
 106   
     }
 107   
 
 108   
     /**
 109   
      * @see org.apache.cactus.integration.ant.container.Container#startUp
 110   
      */
 111  0
     public final void startUp()
 112   
     {
 113  0
         try
 114   
         {
 115  0
             prepare("cactus/tomcat3x");
 116  0
             invoke("start");
 117   
         }
 118   
         catch (IOException ioe)
 119   
         {
 120  0
             getLog().error("Failed to startup the container", ioe);
 121  0
             throw new BuildException(ioe);
 122   
         }
 123   
     }
 124   
 
 125   
     /**
 126   
      * @see org.apache.cactus.integration.ant.container.Container#shutDown
 127   
      */
 128  0
     public final void shutDown()
 129   
     {
 130  0
         invoke("stop");
 131   
     }
 132   
 
 133   
     // Private Methods ---------------------------------------------------------
 134   
 
 135   
     /**
 136   
      * Invokes the Tomcat Main class to start or stop the container, depending
 137   
      * on the value of the provided argument.
 138   
      * 
 139   
      * @param theArg Either 'start' or 'stop'
 140   
      */
 141  0
     private void invoke(String theArg)
 142   
     {
 143  0
         Java java = null;
 144  0
         if ("start".equals(theArg))
 145   
         {
 146  0
             java = createJavaForStartUp();
 147   
         }
 148   
         else
 149   
         {
 150  0
             java = createJavaForShutDown();
 151   
         }
 152  0
         java.addSysproperty(createSysProperty("tomcat.install", getDir()));
 153  0
         java.addSysproperty(createSysProperty("tomcat.home", this.tmpDir));
 154  0
         Path classpath = java.createClasspath();
 155  0
         classpath.createPathElement().setLocation(
 156   
             new File(getDir(), "lib/tomcat.jar"));
 157  0
         java.setClassname("org.apache.tomcat.startup.Main");
 158  0
         java.createArg().setValue(theArg);
 159  0
         java.execute();
 160   
     }
 161   
     
 162   
     /**
 163   
      * Prepares a temporary installation of the container and deploys the 
 164   
      * web-application.
 165   
      * 
 166   
      * @param theDirName The name of the temporary container installation
 167   
      *        directory
 168   
      * @throws IOException If an I/O error occurs
 169   
      */
 170  0
     private void prepare(String theDirName) throws IOException
 171   
     {
 172  0
         FileUtils fileUtils = FileUtils.newFileUtils();
 173  0
         FilterChain filterChain = createFilterChain();
 174   
         
 175  0
         if (this.tmpDir == null)
 176   
         {
 177  0
             this.tmpDir = createTempDirectory(theDirName);
 178   
         }
 179   
 
 180   
         // copy configuration files into the temporary container directory
 181  0
         File confDir = createDirectory(tmpDir, "conf");
 182  0
         copyConfFiles(confDir);
 183  0
         if (getServerXml() == null)
 184   
         {
 185  0
             ResourceUtils.copyResource(getProject(),
 186   
                 RESOURCE_PATH + "tomcat3x/server.xml",
 187   
                 new File(confDir, "server.xml"), filterChain);
 188   
         }
 189   
         // TODO: only copy these files if they haven't been provided by the
 190   
         // user as a conf fileset
 191  0
         ResourceUtils.copyResource(getProject(),
 192   
             RESOURCE_PATH + "tomcat3x/tomcat-users.xml",
 193   
             new File(confDir, "tomcat-users.xml"));
 194  0
         ResourceUtils.copyResource(getProject(),
 195   
             RESOURCE_PATH + "tomcat3x/modules.xml",
 196   
             new File(confDir, "modules.xml"));
 197   
         
 198   
         // deploy the web-app by copying the WAR file
 199  0
         File webappsDir = createDirectory(tmpDir, "webapps");
 200  0
         fileUtils.copyFile(getDeployableFile().getFile(),
 201   
             new File(webappsDir, getDeployableFile().getFile().getName()), 
 202   
             null, true);
 203   
     }
 204   
 
 205   
 }
 206