Coverage report

  %line %branch
nl.toolforge.karma.core.module.ModuleDescriptor
96% 
100% 

 1  
 /*
 2  
 Karma core - Core of the Karma application
 3  
 Copyright (C) 2004  Toolforge <www.toolforge.nl>
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, write to the Free Software
 17  
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 */
 19  
 package nl.toolforge.karma.core.module;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 
 24  
 import java.io.BufferedWriter;
 25  
 import java.io.File;
 26  
 import java.io.FileWriter;
 27  
 import java.io.IOException;
 28  
 import java.io.Writer;
 29  
 
 30  
 /**
 31  
  * @author D.A. Smedes
 32  
  * @version $Id: ModuleDescriptor.java,v 1.5 2004/11/10 22:25:11 hippe Exp $
 33  
  */
 34  
 public class ModuleDescriptor {
 35  
 
 36  14
   protected static Log logger = LogFactory.getLog(ModuleDescriptor.class);
 37  
 
 38  28
   private Module.Type moduleType = null;
 39  
 
 40  44
   public ModuleDescriptor(Module module) {
 41  22
 
 42  60
     if (module == null) {
 43  44
       throw new IllegalArgumentException("Module type cannot be null.");
 44  32
     }
 45  44
 
 46  32
     // todo should be implemented by a method overridden by specific module types
 47  44
     //
 48  28
     if (module instanceof LibModule) {
 49  7
       this.moduleType = Module.LIBRARY_MODULE;
 50  21
     } else if (module instanceof SourceModule) {
 51  7
       this.moduleType = Module.JAVA_SOURCE_MODULE;
 52  46
     } else if (module instanceof JavaEnterpriseApplicationModule) {
 53  59
       this.moduleType = Module.JAVA_ENTERPRISE_APPLICATION;
 54  42
     } else if (module instanceof JavaWebApplicationModule) {
 55  48
       this.moduleType = Module.JAVA_WEB_APPLICATION;
 56  27
     } else if (module instanceof OtherModule) {
 57  30
       this.moduleType = Module.OTHER_MODULE;
 58  19
     }
 59  47
   }
 60  11
 
 61  0
   /**
 62  
    * Writes the <code>module-descriptor.xml</code> file to <code>dir</code>.
 63  32
    *
 64  44
    * @param dir An existing directory where the <code>module-descriptor.xml</code> file should be created.
 65  
    */
 66  
   public void createFile(File dir) throws IOException {
 67  
 
 68  28
     StringBuffer buffer = new StringBuffer();
 69  
 
 70  28
     buffer.append("<?xml version=\ŕ.0\"?>\n");
 71  
 
 72  60
     buffer.append("<module-descriptor version=\ŕ-0\">\n");
 73  72
     buffer.append("  <type>").append(moduleType.getType()).append("</type>\n");
 74  60
     buffer.append("  <layout-specification/> <!-- for future usage -->\n");
 75  72
     buffer.append("</module-descriptor>\n");
 76  32
 
 77  104
     Writer writer = new BufferedWriter(class="keyword">new FileWriter(class="keyword">new File(dir, "module-descriptor.xml")));
 78  104
     writer.write(buffer.toString());
 79  76
 
 80  72
     logger.debug("Creating `module-descriptor.xml` for type : " + moduleType.getType());
 81  32
 
 82  104
     writer.flush();
 83  72
   }
 84  32
 
 85  44
 }

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