Clover coverage report - Cactus 1.5 for J2EE API 1.2
Coverage timestamp: Wed Feb 18 2004 09:04:33 EST
file stats: LOC: 318   Methods: 10
NCLOC: 145   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WebLogic7xContainer.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.weblogic;
 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.Jar;
 66   
 import org.apache.tools.ant.taskdefs.Java;
 67   
 import org.apache.tools.ant.types.FilterChain;
 68   
 import org.apache.tools.ant.types.Path;
 69   
 import org.apache.tools.ant.types.ZipFileSet;
 70   
 
 71   
 /**
 72   
  * Special container support for the Bea WebLogic 7.x application server.
 73   
  * 
 74   
  * TODO: this doesn't work for me on JDK 1.3.1 and WL 7.0 SP2
 75   
  * 
 76   
  * @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
 77   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
 78   
  * 
 79   
  * @version $Id: WebLogic7xContainer.java,v 1.5.2.4 2003/10/23 18:20:44 vmassol Exp $
 80   
  */
 81   
 public class WebLogic7xContainer extends AbstractJavaContainer
 82   
 {
 83   
 
 84   
     // Instance Variables ------------------------------------------------------
 85   
 
 86   
     /**
 87   
      * The Bea home directory.
 88   
      */
 89   
     private File beaHome;
 90   
 
 91   
     /**
 92   
      * The WebLogic 7.x installation directory. For example:
 93   
      * "c:\bea\weblogic700".
 94   
      */
 95   
     private File dir;
 96   
 
 97   
     /**
 98   
      * The port to which the container should be bound.
 99   
      */
 100   
     private int port = 8080;
 101   
 
 102   
     /**
 103   
      * The temporary directory from which the container will be started.
 104   
      */
 105   
     private File tmpDir;
 106   
 
 107   
     // Public Methods ----------------------------------------------------------
 108   
 
 109   
     /**
 110   
      * Sets the Bea home directory.
 111   
      * 
 112   
      * @param theBeaHome The BEA home directory
 113   
      */
 114  0
     public final void setBeaHome(File theBeaHome)
 115   
     {
 116  0
         this.beaHome = theBeaHome;
 117   
     }
 118   
 
 119   
     /**
 120   
      * Sets the WebLogic 7.x installation directory.
 121   
      * 
 122   
      * @param theDir The directory to set
 123   
      */
 124  0
     public final void setDir(File theDir)
 125   
     {
 126  0
         this.dir = theDir;
 127   
     }
 128   
 
 129   
     /**
 130   
      * Sets the port to which the container should listen.
 131   
      * 
 132   
      * @param thePort The port to set
 133   
      */
 134  0
     public final void setPort(int thePort)
 135   
     {
 136  0
         this.port = thePort;
 137   
     }
 138   
 
 139   
     /**
 140   
      * Sets the temporary installation directory.
 141   
      * 
 142   
      * @param theTmpDir The temporary directory to set
 143   
      */
 144  0
     public final void setTmpDir(File theTmpDir)
 145   
     {
 146  0
         this.tmpDir = theTmpDir;
 147   
     }
 148   
 
 149   
     // AbstractContainer Implementation ----------------------------------------
 150   
 
 151   
     /**
 152   
      * @see org.apache.cactus.integration.ant.container.Container#getName
 153   
      */
 154  0
     public final String getName()
 155   
     {
 156  0
         return "WebLogic 7.x";
 157   
     }
 158   
 
 159   
     /**
 160   
      * Returns the port to which the container should listen.
 161   
      * 
 162   
      * @return The port
 163   
      */
 164  0
     public final int getPort()
 165   
     {
 166  0
         return this.port;
 167   
     }
 168   
 
 169   
     /**
 170   
      * @see org.apache.cactus.integration.ant.container.Container#init
 171   
      */
 172  0
     public final void init()
 173   
     {
 174  0
         if (!this.dir.isDirectory())
 175   
         {
 176  0
             throw new BuildException(this.dir + " is not a directory");
 177   
         }
 178   
 
 179   
         // If the beaHome attribute is not set, guess the bea home
 180   
         // directory using the parent directory of this.dir 
 181  0
         if (this.beaHome == null)
 182   
         {
 183  0
             getLog().debug("Extrapolating beaHome to be ["
 184   
                 + this.dir.getParentFile() + "]");
 185  0
             this.beaHome = this.dir.getParentFile();
 186   
         }
 187   
     }
 188   
 
 189   
     /**
 190   
      * @see org.apache.cactus.integration.ant.container.Container#startUp
 191   
      */
 192  0
     public final void startUp()
 193   
     {
 194  0
         try
 195   
         {
 196  0
             prepare("cactus/weblogic7x");
 197   
             
 198  0
             Java java = createJavaForStartUp();
 199  0
             java.setDir(new File(this.tmpDir, "testdomain"));
 200   
             
 201  0
             java.createJvmarg().setValue("-hotspot");
 202  0
             java.createJvmarg().setValue("-Xms32m");
 203  0
             java.createJvmarg().setValue("-Xmx200m");
 204   
             
 205  0
             File serverDir = new File(this.dir, "server");
 206   
             
 207  0
             java.addSysproperty(
 208   
                 createSysProperty("weblogic.Name", "testserver"));
 209  0
             java.addSysproperty(
 210   
                 createSysProperty("bea.home", this.beaHome));
 211  0
             java.addSysproperty(
 212   
                 createSysProperty("weblogic.management.username", "weblogic"));
 213  0
             java.addSysproperty(
 214   
                 createSysProperty("weblogic.management.password", "weblogic"));
 215  0
             java.addSysproperty(
 216   
                 createSysProperty("java.security.policy",
 217   
                     "=./server/lib/weblogic.policy"));
 218   
 
 219  0
             Path classpath = java.createClasspath();
 220  0
             classpath.createPathElement().setLocation(
 221   
                 new File(serverDir, "lib/weblogic_sp.jar"));
 222  0
             classpath.createPathElement().setLocation(
 223   
                 new File(serverDir, "lib/weblogic.jar"));
 224   
 
 225  0
             java.setClassname("weblogic.Server");
 226  0
             java.execute();
 227   
         }
 228   
         catch (IOException ioe)
 229   
         {
 230  0
             getLog().error("Failed to startup the container", ioe);
 231  0
             throw new BuildException(ioe);
 232   
         }
 233   
     }
 234   
 
 235   
     /**
 236   
      * @see org.apache.cactus.integration.ant.container.Container#shutDown
 237   
      */
 238  0
     public final void shutDown()
 239   
     {
 240  0
         Java java = createJavaForShutDown();
 241   
             
 242  0
         File serverDir = new File(this.dir, "server");
 243   
 
 244  0
         Path classpath = java.createClasspath();
 245  0
         classpath.createPathElement().setLocation(
 246   
             new File(serverDir, "lib/weblogic_sp.jar"));
 247  0
         classpath.createPathElement().setLocation(
 248   
             new File(serverDir, "lib/weblogic.jar"));
 249   
 
 250  0
         java.setClassname("weblogic.Admin");
 251  0
         java.createArg().setValue("-url");
 252  0
         java.createArg().setValue("t3://localhost:" + getPort());
 253  0
         java.createArg().setValue("-username");
 254  0
         java.createArg().setValue("weblogic");
 255  0
         java.createArg().setValue("-password");
 256  0
         java.createArg().setValue("weblogic");
 257  0
         java.createArg().setValue("SHUTDOWN");
 258  0
         java.execute();
 259   
     }
 260   
 
 261   
     // Private Methods ---------------------------------------------------------
 262   
 
 263   
     /**
 264   
      * Prepares a temporary installation of the container and deploys the 
 265   
      * web-application.
 266   
      * 
 267   
      * @param theDirName The name of the temporary container installation
 268   
      *        directory
 269   
      * @throws IOException If an I/O error occurs
 270   
      */
 271  0
     private void prepare(String theDirName) throws IOException
 272   
     {
 273  0
         FilterChain filterChain = createFilterChain();
 274   
         
 275  0
         if (this.tmpDir == null)
 276   
         {
 277  0
             this.tmpDir = createTempDirectory(theDirName);
 278   
         }
 279   
 
 280  0
         File testDomainDir = createDirectory(this.tmpDir, "testdomain");
 281  0
         ResourceUtils.copyResource(getProject(),
 282   
             RESOURCE_PATH + "weblogic7x/config.xml",
 283   
             new File(testDomainDir, "config.xml"),
 284   
             filterChain);
 285  0
         ResourceUtils.copyResource(getProject(),
 286   
             RESOURCE_PATH + "weblogic7x/DefaultAuthenticatorInit.ldift",
 287   
             new File(testDomainDir, "DefaultAuthenticatorInit.ldift"),
 288   
             filterChain);
 289   
 
 290   
         // TODO: For improvement, do not copy the weblogic.xml file
 291   
         // in the tmpdir.
 292   
         
 293   
         // Extract the weblogic.xml descriptor
 294  0
         File weblogicXml = new File(this.tmpDir, "weblogic.xml");
 295  0
         ResourceUtils.copyResource(getProject(),
 296   
             RESOURCE_PATH + "weblogic7x/weblogic.xml",
 297   
             weblogicXml, filterChain);
 298   
 
 299   
         // deploy the web-app by copying the WAR file into the applications
 300   
         // directory, adding the weblogic.xml descriptor in WEB-INF
 301  0
         File applicationsDir =
 302   
             createDirectory(testDomainDir, "applications");
 303  0
         Jar jar = (Jar) createAntTask("jar");
 304  0
         jar.setDestFile(new File(applicationsDir,
 305   
             getDeployableFile().getFile().getName()));
 306  0
         ZipFileSet zip = new ZipFileSet();
 307  0
         zip.setSrc(getDeployableFile().getFile());
 308  0
         jar.addZipfileset(zip);
 309  0
         ZipFileSet fileSet = new ZipFileSet();
 310  0
         fileSet.setDir(this.tmpDir);
 311  0
         fileSet.createInclude().setName("weblogic.xml");
 312  0
         fileSet.setPrefix("WEB-INF");
 313  0
         jar.addZipfileset(fileSet);
 314  0
         jar.execute();
 315   
     }
 316   
 
 317   
 }
 318