Coverage report

  %line %branch
net.sf.infrared.tools.ant.EarType
0% 
0% 

 1  
 /*
 2  
  * Copyright 2005 Tavant Technologies and Contributors
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License")
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  *
 17  
  *
 18  
  * Original Author:  binil.thomas (Tavant Technologies)
 19  
  * Contributor(s):   -;
 20  
  *
 21  
  */
 22  
 package net.sf.infrared.tools.ant;
 23  
 
 24  
 import java.io.File;
 25  
 import java.util.ArrayList;
 26  
 import java.util.HashSet;
 27  
 import java.util.Iterator;
 28  
 import java.util.List;
 29  
 import java.util.Set;
 30  
 
 31  
 import org.apache.commons.io.FileUtils;
 32  
 import org.apache.tools.ant.BuildException;
 33  
 import org.apache.tools.ant.Project;
 34  
 
 35  
 /**
 36  
  *
 37  
  * @author binil.thomas
 38  
  */
 39  
 public class EarType extends ApplicationType {          
 40  0
     public static String APP_INF_CLASSES = "APP-INF" + File.separator + "classes";
 41  
 	
 42  0
     public static String APP_INF_LIB = "APP-INF" + File.separator + "lib";
 43  
 	
 44  0
     private Set modules = new HashSet();
 45  
     
 46  0
     private List jarsToInstrument = new ArrayList();
 47  
     
 48  0
     private List classesToInstrument = new ArrayList();
 49  
     
 50  0
     private List packagesToInstrument = new ArrayList();
 51  
     
 52  
     public EarType(Project project) {
 53  0
         super(project);        
 54  0
     }
 55  
         
 56  
     public void addConfiguredModule(ModuleType module) {
 57  0
         modules.add(module);        
 58  0
     }
 59  
             
 60  
     public File[] getJarsToInstrument() {                
 61  0
         return (File[]) jarsToInstrument.toArray(new File[jarsToInstrument.size()]);
 62  
     }
 63  
     
 64  
     public File[] getClassesToInstrument() {
 65  0
         return (File[]) classesToInstrument.toArray(new File[classesToInstrument.size()]);
 66  
     }
 67  
     
 68  
     public String[] getPackagesToInstrument() {
 69  0
         return (String[]) packagesToInstrument.toArray(new String[packagesToInstrument.size()]);
 70  
     }
 71  
     
 72  
     public void setup() {    
 73  0
         verifyInputs();
 74  0
         backupSrcToWorkDir(); 
 75  0
         getLogger().verbose("[EAR:"+ getSrc().getName() + "] Backed up " + getSrc().getAbsolutePath() + 
 76  
                 " to " + getBackupDir().getAbsolutePath());
 77  0
         for (Iterator it = modules.iterator(); it.hasNext(); ) {
 78  0
             ModuleType module = (ModuleType) it.next();    
 79  0
             module.setLogger(getLogger());
 80  0
             module.setup(this.getBackupDir());
 81  
         }      
 82  0
         findJarsAndClassesToInstrument();
 83  0
     }
 84  
        
 85  
     public void cleanup() {     
 86  0
         for (Iterator it = modules.iterator(); it.hasNext(); ) {
 87  0
             ModuleType module = (ModuleType) it.next();            
 88  0
             module.cleanup();
 89  
         }
 90  0
         copyBackupToDest();
 91  0
         getLogger().verbose("[EAR:"+ getSrc().getName() + "] Copied backup " + 
 92  
                 getBackupDir().getAbsolutePath() + " to destination " + getDest().getAbsolutePath());
 93  0
     }
 94  
     
 95  
     public void appendToManifestClassPath(String cp) {
 96  0
         if ((cp == null) || (cp.trim().length() == 0)) {
 97  0
             return;
 98  
         }
 99  0
         for (Iterator it = modules.iterator(); it.hasNext(); ) {
 100  0
             ModuleType module = (ModuleType) it.next();      
 101  0
             module.appendToManifestClassPath(cp);
 102  
         }
 103  0
         getLogger().verbose("[EAR:"+ getSrc().getName() + "] Added " + cp + " to MANIFEST classpath");
 104  0
     }
 105  
     
 106  
     public File[] getApplicationClassPath() {
 107  0
         Set appClassPath = new HashSet();
 108  
         
 109  0
         for (Iterator it = modules.iterator(); it.hasNext(); ) {
 110  0
             ModuleType module = (ModuleType) it.next();            
 111  0
             appClassPath.addAll(module.getApplicationClasspath());
 112  
         }
 113  
         
 114  
         // we need to add APP-INF/lib and APP-INF/classes for weblogic's sake
 115  
         // @TODO do this only if server is Weblogic?
 116  0
         File app_inf_classes = new File(getBackupDir(), APP_INF_CLASSES);
 117  0
         File app_inf_lib = new File(getBackupDir(), APP_INF_LIB);
 118  0
         if(app_inf_lib.exists()){
 119  0
         	appClassPath.addAll(FileUtils.listFiles(app_inf_lib, new String[] {"jar", "zip"}, false));	
 120  
         }
 121  0
         if(app_inf_classes.exists()){
 122  0
         	appClassPath.add(app_inf_classes);
 123  
         }
 124  
                
 125  
         
 126  
         // @TODO we need to consider the ClassPath entries in the manifest of the module
 127  0
         getLogger().verbose("[EAR:"+ getSrc().getName() + "] Application ClassPath is " + appClassPath);
 128  0
         return (File[]) appClassPath.toArray(new File[appClassPath.size()]);
 129  
     }
 130  
     
 131  
     void verifyInputs() {
 132  0
         if (getSrc() == null) {
 133  0
             throw new BuildException("'src' attribute is not specified");
 134  
         }
 135  0
         if (getDest() == null) {
 136  0
             throw new BuildException("'dest' attribute is not specified");
 137  
         }
 138  0
         if (getDest().exists()) {
 139  0
             throw new BuildException(getDest().getAbsolutePath() + " exists already");
 140  
         }
 141  0
         getLogger().verbose("[EAR:"+ getSrc().getName() + "] Verified all inputs");
 142  0
     }
 143  
     
 144  
     void findJarsAndClassesToInstrument() {
 145  0
         for (Iterator it = modules.iterator(); it.hasNext(); ) {
 146  0
             ModuleType module = (ModuleType) it.next();            
 147  0
             jarsToInstrument.addAll(module.getJarsToInstrument());
 148  0
             classesToInstrument.addAll(module.getClassesToInstrument());
 149  0
             packagesToInstrument.addAll(module.getPackagesToInstrument());
 150  
         }
 151  0
         getLogger().verbose("[EAR:"+ getSrc().getName() + "] Collected all jars and classes to instrument: " +
 152  
                 "\n\tJars     = " + jarsToInstrument + 
 153  
                 "\n\tClasses  = " + classesToInstrument + 
 154  
                 "\n\tPackages = " + packagesToInstrument);
 155  0
     }
 156  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.