Coverage report

  %line %branch
nl.toolforge.karma.core.manifest.util.BaseModuleLayoutTemplate
94% 
98% 

 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.manifest.util;
 20  
 
 21  
 import nl.toolforge.karma.core.KarmaRuntimeException;
 22  
 import nl.toolforge.karma.core.manifest.SourceModule;
 23  
 import org.apache.commons.logging.Log;
 24  
 import org.apache.commons.logging.LogFactory;
 25  
 
 26  
 import java.io.BufferedReader;
 27  
 import java.io.File;
 28  
 import java.io.FileOutputStream;
 29  
 import java.io.IOException;
 30  
 import java.io.InputStreamReader;
 31  
 import java.io.Reader;
 32  
 
 33  
 /**
 34  
  * @author D.A. Smedes
 35  
  * @version $Id: BaseModuleLayoutTemplate.java,v 1.3 2004/11/02 23:57:06 asmedes Exp $
 36  
  */
 37  40
 public abstract class BaseModuleLayoutTemplate implements ModuleLayoutTemplate {
 38  
 
 39  85
   protected static Log logger = LogFactory.getLog(BaseModuleLayoutTemplate.class);
 40  
 
 41  35
   public abstract FileTemplate[] getFileElements();
 42  
 
 43  
   public abstract String[] getDirectoryElements();
 44  
 
 45  
   public final void createLayout(File baseDir) throws IOException {
 46  
 
 47  32
     FileTemplate[] fileTemplates = getFileElements();
 48  32
     String[] templateFiles = new String[fileTemplates.length];
 49  44
 
 50  148
     for (int i = 0; i < fileTemplates.length; i++) {
 51  
 
 52  215
       FileTemplate fileTemplate = fileTemplates[i];
 53  72
       logger.debug("Write template '" + fileTemplate.getSource() + "' to '" + fileTemplate.getTarget() + "'.");
 54  171
       Reader input = new BufferedReader(class="keyword">new InputStreamReader(SourceModule.class.getResourceAsStream(fileTemplate.getSource().toString().replace('\\','/'))));
 55  99
 
 56  171
       File outputFile = new File(baseDir + File.separator + fileTemplate.getTarget());
 57  72
       outputFile.getParentFile().mkdirs();
 58  171
       outputFile.createNewFile();
 59  99
 
 60  171
       FileOutputStream output = new FileOutputStream(outputFile);
 61  
 
 62  12307
       while (input.ready()) {
 63  12136
         output.write(input.read());
 64  16786
       }
 65  16759
       templateFiles[i] = fileTemplate.getTarget().getPath();
 66  72
       logger.debug("Wrote template.");
 67  99
     }
 68  99
 
 69  
     // Create directories.
 70  
     //
 71  32
     String[] dirs = getDirectoryElements();
 72  
 
 73  180
     for (int i=0; i < dirs.length; i++) {
 74  
 
 75  291
       File dirToAdd = new File(baseDir, dirs[i]);
 76  
 
 77  143
       // Try to create the dirs
 78  104
       if (!dirToAdd.mkdirs() && !dirToAdd.exists()) {
 79  
         // Failed to create the dirs and they do not exist yet.
 80  143
         //
 81  0
         throw new KarmaRuntimeException("Error while creating module layout.");
 82  
       }
 83  
     }
 84  32
   }
 85  
 }

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