Coverage report

  %line %branch
nl.toolforge.karma.core.vc.cvsimpl.Utils
36% 
97% 

 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.vc.cvsimpl;
 20  
 
 21  
 import nl.toolforge.karma.core.KarmaRuntimeException;
 22  
 import nl.toolforge.karma.core.Patch;
 23  
 import nl.toolforge.karma.core.Version;
 24  
 import nl.toolforge.karma.core.module.Module;
 25  
 import nl.toolforge.karma.core.vc.AuthenticationException;
 26  
 import nl.toolforge.karma.core.vc.DevelopmentLine;
 27  
 import nl.toolforge.karma.core.vc.ModuleStatus;
 28  
 import nl.toolforge.karma.core.vc.PatchLine;
 29  
 import nl.toolforge.karma.core.vc.Runner;
 30  
 import nl.toolforge.karma.core.vc.RunnerFactory;
 31  
 import nl.toolforge.karma.core.vc.SymbolicName;
 32  
 import nl.toolforge.karma.core.vc.VersionControlException;
 33  
 import nl.toolforge.karma.core.vc.model.MainLine;
 34  
 import org.apache.commons.logging.Log;
 35  
 import org.apache.commons.logging.LogFactory;
 36  
 
 37  0
 public final class Utils {
 38  
 
 39  28
   private static final Log logger = LogFactory.getLog(Utils.class);
 40  24
 
 41  52
   /**
 42  
    * <p>Creates a symbolic name for <code>module</code>, based on <code>version</code> and whether a module has an
 43  
    * associated <code>DevelopmentLine</code>.</p>
 44  
    *
 45  
    * <p>Right now, symbolic name stuff is supported for <code>SourceModule</code>s, so if this method is supplied with
 46  
    * another <code>module</code> type, the method returns an empty <code>CVSTag</code>.
 47  
    *
 48  
    * @param module The module at hand.
 49  
    * @param developmentLine The development line to which the version applies.
 50  
    * @param version The version (within the modules' development line. <code>version</code> may be <code>null</code> in
 51  
    *   which case it is ignored when creating a <code>SymbolicName</code>.
 52  
    *
 53  
    * @return A symbolic name (tag) as they are used in a CVS repository. An empty CVSTag is returned when another
 54  
    *  instance than a {@link nl.toolforge.karma.core.module.SourceModule} is passed as the <code>module</code> parameter.
 55  
    */
 56  
   public static SymbolicName createSymbolicName(Module module, DevelopmentLine developmentLine, Version version) {
 57  
 
 58  28
     if (version == null) {
 59  24
       new CVSTag("");
 60  52
       if (developmentLine != null) {
 61  0
         return new CVSTag(developmentLine.getName());
 62  0
       } else {
 63  0
         // We are using the TRUNK.
 64  
         //
 65  0
         new CVSTag("");
 66  
       }
 67  0
     } else {
 68  28
       if (developmentLine != null) {
 69  24
 
 70  59
         if (developmentLine instanceof PatchLine) {
 71  13
           if (!(version instanceof Patch)) {
 72  19
             throw new KarmaRuntimeException(
 73  13
                 "The provided developmentLine is a PatchLine instance. This implies " +
 74  0
                 "that the provided version should be a Patch instance.");
 75  
           }
 76  7
           return createSymbolicName((Patch)version);
 77  6
         } else {
 78  13
           return new CVSTag(developmentLine.getName() + "_" + version.getVersionNumber());
 79  
         }
 80  21
       } else if (version instanceof Patch) {
 81  18
 
 82  39
         // If the version argument is in fact a Patch instance, we have to create something like : PATCHLINE|p_0-0-0-
 83  
         //
 84  0
         return new CVSTag(PatchLine.NAME_PREFIX + PatchLine.PATCH_SEPARATOR + version.getVersionNumber());
 85  
 
 86  0
       } else {
 87  21
         return new CVSTag(MainLine.NAME_PREFIX + "_" + version.getVersionNumber());
 88  18
       }
 89  39
 
 90  
     }
 91  0
     return new CVSTag("");
 92  
   }
 93  0
 
 94  
   public static SymbolicName createSymbolicName(Module module,  Version version) {
 95  7
     return Utils.createSymbolicName(module, null, version);
 96  18
   }
 97  39
 
 98  
   public static SymbolicName createSymbolicName(Patch patch) {
 99  7
     return new CVSTag(PatchLine.NAME_PREFIX + PatchLine.PATCH_SEPARATOR + patch.getVersionNumber());
 100  6
   }
 101  13
 
 102  
   public static Version getLastVersion(Module module) throws VersionControlException {
 103  
 
 104  0
     logger.debug("Getting last version for module : " + module.getName());
 105  
 
 106  0
     Runner runner = null;
 107  
     try {
 108  0
       runner = RunnerFactory.getRunner(module.getLocation());
 109  0
     } catch (AuthenticationException e) {
 110  0
       throw new CVSException(e.getErrorCode(), e.getMessageArguments());
 111  0
     }
 112  0
 
 113  0
     ModuleStatus status = new CVSModuleStatus(module, ((CVSRunner) runner).log(module));
 114  0
     return status.getLastVersion();
 115  0
   }
 116  0
 
 117  
   public static Version getLocalVersion(Module module) throws VersionControlException {
 118  0
     logger.debug("Getting local version for module : " + module.getName());
 119  
 
 120  0
     ModuleStatus status = new CVSModuleStatus(module);
 121  0
     logger.debug("returning: " + status.getLocalVersion());
 122  0
     return status.getLocalVersion();
 123  0
   }
 124  0
 
 125  
   public static boolean existsInRepository(Module module) {
 126  
 
 127  0
     Runner runner = null;
 128  
     try {
 129  0
       runner = RunnerFactory.getRunner(module.getLocation());
 130  0
       return runner.existsInRepository(module);
 131  0
 
 132  0
     } catch (AuthenticationException e) {
 133  0
       return false;
 134  0
     } catch (VersionControlException c) {
 135  0
       return false;
 136  0
     }
 137  0
   }
 138  
 }

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