Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 225   Methods: 8
NCLOC: 78   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Ejbc.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000,2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.ejb;
 55   
 
 56   
 import java.io.File;
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.DirectoryScanner;
 59   
 import org.apache.tools.ant.taskdefs.Java;
 60   
 import org.apache.tools.ant.taskdefs.MatchingTask;
 61   
 import org.apache.tools.ant.types.Commandline;
 62   
 import org.apache.tools.ant.types.Path;
 63   
 
 64   
 /**
 65   
  * Builds EJB support classes using WebLogic's ejbc tool from a directory containing
 66   
  * a set of deployment descriptors.
 67   
  *
 68   
  *
 69   
  * @author Conor MacNeill, Cortex ebusiness Pty Limited
 70   
  */
 71   
 public class Ejbc extends MatchingTask {
 72   
     /**
 73   
      * The root directory of the tree containing the serialised deployment desciptors. The actual
 74   
      * deployment descriptor files are selected using include and exclude constructs
 75   
      * on the ejbc task provided by the MatchingTask superclass.
 76   
      */
 77   
     private File descriptorDirectory;
 78   
 
 79   
     /**
 80   
      * The directory where generated files are placed.
 81   
      */
 82   
     private File generatedFilesDirectory;
 83   
 
 84   
     /**
 85   
      * The name of the manifest file generated for the EJB jar.
 86   
      */
 87   
     private File generatedManifestFile;
 88   
 
 89   
     /**
 90   
      * The classpath to be used in the weblogic ejbc calls. It must contain the weblogic
 91   
      * classes <b>and</b> the implementation classes of the home and remote interfaces.
 92   
      */
 93   
     private String classpath;
 94   
 
 95   
     /**
 96   
      * The source directory for the home and remote interfaces. This is used to determine if
 97   
      * the generated deployment classes are out of date.
 98   
      */
 99   
     private File sourceDirectory;
 100   
 
 101   
     public boolean keepgenerated;
 102   
 
 103   
     /**
 104   
      * Do the work.
 105   
      *
 106   
      * The work is actually done by creating a separate JVM to run a helper task.
 107   
      * This approach allows the classpath of the helper task to be set. Since the
 108   
      * weblogic tools require the class files of the project's home and remote
 109   
      * interfaces to be available in the classpath, this also avoids having to
 110   
      * start ant with the class path of the project it is building.
 111   
      *
 112   
      * @exception BuildException if someting goes wrong with the build
 113   
      */
 114  0
     public void execute() throws BuildException {
 115  0
         if (descriptorDirectory == null ||
 116   
             !descriptorDirectory.isDirectory()) {
 117  0
             throw new BuildException("descriptors directory " + descriptorDirectory.getPath() +
 118   
                                      " is not valid");
 119   
         }
 120  0
         if (generatedFilesDirectory == null ||
 121   
             !generatedFilesDirectory.isDirectory()) {
 122  0
             throw new BuildException("dest directory " + generatedFilesDirectory.getPath() +
 123   
                                      " is not valid");
 124   
         }
 125   
 
 126  0
         if (sourceDirectory == null ||
 127   
             !sourceDirectory.isDirectory()) {
 128  0
             throw new BuildException("src directory " + sourceDirectory.getPath() +
 129   
                                      " is not valid");
 130   
         }
 131   
 
 132  0
         String systemClassPath = System.getProperty("java.class.path");
 133  0
         String execClassPath = getProject().translatePath(systemClassPath + ":" + classpath +
 134   
                                                          ":" + generatedFilesDirectory);
 135   
         // get all the files in the descriptor directory
 136  0
         DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory);
 137   
 
 138  0
         String[] files = ds.getIncludedFiles();
 139   
 
 140  0
         Java helperTask = (Java) getProject().createTask("java");
 141  0
         helperTask.setTaskName(getTaskName());
 142  0
         helperTask.setFork(true);
 143  0
         helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper");
 144  0
         String args = "";
 145  0
         args += " " + descriptorDirectory;
 146  0
         args += " " + generatedFilesDirectory;
 147  0
         args += " " + sourceDirectory;
 148  0
         args += " " + generatedManifestFile;
 149  0
         args += " " + keepgenerated;
 150   
 
 151  0
         for (int i = 0; i < files.length; ++i) {
 152  0
             args += " " + files[i];
 153   
         }
 154   
 
 155  0
         Commandline.Argument arguments = helperTask.createArg();
 156  0
         arguments.setLine(args);
 157  0
         helperTask.setClasspath(new Path(getProject(), execClassPath));
 158  0
         if (helperTask.executeJava() != 0) {
 159  0
             throw new BuildException("Execution of ejbc helper failed");
 160   
         }
 161   
     }
 162   
 
 163  0
     public boolean getKeepgenerated() {
 164  0
         return keepgenerated;
 165   
     }
 166   
 
 167   
     /**
 168   
      * Set the directory from where the serialized deployment descriptors are
 169   
      * to be read.
 170   
      *
 171   
      * @param dirName the name of the directory containing the serialised deployment descriptors.
 172   
      */
 173  0
     public void setDescriptors(String dirName) {
 174  0
         descriptorDirectory = new File(dirName);
 175   
     }
 176   
 
 177   
     /**
 178   
      * Set the directory into which the support classes, RMI stubs, etc are to be written.
 179   
      *
 180   
      * @param dirName the name of the directory into which code is generated
 181   
      */
 182  0
     public void setDest(String dirName) {
 183  0
         generatedFilesDirectory = new File(dirName);
 184   
     }
 185   
 
 186   
     /**
 187   
      * If true, ejbc will keep the
 188   
      * intermediate Java files used to build the class files.
 189   
      * This can be useful when debugging.
 190   
      */
 191  0
     public void setKeepgenerated(String newKeepgenerated) {
 192  0
         keepgenerated = Boolean.valueOf(newKeepgenerated.trim()).booleanValue();
 193   
 
 194   
     }
 195   
 
 196   
     /**
 197   
      * Set the name of the generated manifest file.
 198   
      *
 199   
      * For each EJB that is processed an entry is created in this file. This can then be used
 200   
      * to create a jar file for dploying the beans.
 201   
      *
 202   
      * @param manifestFilename the name of the manifest file to be generated.
 203   
      */
 204  0
     public void setManifest(String manifestFilename) {
 205  0
         generatedManifestFile = new File(manifestFilename);
 206   
     }
 207   
 
 208   
     /**
 209   
      * Set the classpath to be used for this compilation.
 210   
      */
 211  0
     public void setClasspath(String s) {
 212  0
         this.classpath = getProject().translatePath(s);
 213   
     }
 214   
 
 215   
     /**
 216   
      * Set the directory containing the source code for the home interface, remote interface
 217   
      * and public key class definitions.
 218   
      *
 219   
      * @param dirName the directory containg the source tree for the EJB's interface classes.
 220   
      */
 221  0
     public void setSrc(String dirName) {
 222  0
         sourceDirectory = new File(dirName);
 223   
     }
 224   
 }
 225