Coverage report

  %line %branch
nl.toolforge.karma.core.cmd.impl.ViewManifest
0% 
0% 

 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.cmd.impl;
 20  
 
 21  
 import nl.toolforge.karma.core.Version;
 22  
 import nl.toolforge.karma.core.cmd.CommandDescriptor;
 23  
 import nl.toolforge.karma.core.cmd.CommandException;
 24  
 import nl.toolforge.karma.core.cmd.CommandResponse;
 25  
 import nl.toolforge.karma.core.cmd.DefaultCommand;
 26  
 import nl.toolforge.karma.core.manifest.Manifest;
 27  
 import nl.toolforge.karma.core.manifest.ManifestException;
 28  
 import nl.toolforge.karma.core.module.Module;
 29  
 import nl.toolforge.karma.core.module.ModuleComparator;
 30  
 import nl.toolforge.karma.core.module.ModuleTypeException;
 31  
 import nl.toolforge.karma.core.vc.ModuleStatus;
 32  
 import nl.toolforge.karma.core.vc.VersionControlException;
 33  
 import nl.toolforge.karma.core.vc.cvsimpl.threads.CVSLogThread;
 34  
 import nl.toolforge.karma.core.vc.threads.ParallelRunner;
 35  
 import org.apache.commons.logging.Log;
 36  
 import org.apache.commons.logging.LogFactory;
 37  
 
 38  
 import java.util.ArrayList;
 39  
 import java.util.Collection;
 40  
 import java.util.Collections;
 41  
 import java.util.Iterator;
 42  
 import java.util.List;
 43  
 import java.util.Map;
 44  
 
 45  
 /**
 46  
  * This command gets the active manifest and presents it in the UI. UI implementations are responsible for the rendering
 47  
  * part.
 48  
  */
 49  
 public class ViewManifest extends DefaultCommand {
 50  
 
 51  0
   protected Log logger = LogFactory.getLog(ViewManifest.class);
 52  
 
 53  0
   private List renderedList = null;
 54  0
   private CommandResponse commandResponse = new CommandResponse();
 55  
 
 56  
   public ViewManifest(CommandDescriptor descriptor) {
 57  0
     super(descriptor);
 58  
 
 59  0
     renderedList = new ArrayList();
 60  0
   }
 61  
 
 62  
   public void execute() throws CommandException {
 63  
 
 64  0
     if (!getContext().isManclass="keyword">ifestLoaded()) {
 65  0
       throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST);
 66  
     }
 67  0
     Manifest manifest = getContext().getCurrentManifest();
 68  
 
 69  0
     List sourceModules = new ArrayList();
 70  
 
 71  
     // Transform and sort
 72  
     //
 73  
 
 74  
     // todo hmm kan dit niet simpeler ?
 75  
     //
 76  0
     Collection c = manifest.getAllModules().values();
 77  
 
 78  0
     for (Iterator i = c.iterator(); i.hasNext();) {
 79  0
       sourceModules.add(i.next());
 80  
     }
 81  
 
 82  0
     Collections.sort(sourceModules, new ModuleComparator());
 83  
 
 84  0
     ParallelRunner runner = new ParallelRunner(manifest, CVSLogThread.class);
 85  0
     runner.execute(0); // Blocks ...
 86  
 
 87  0
     Map statusOverview = runner.retrieveResults();
 88  
 
 89  0
     for (Iterator i = sourceModules.iterator(); i.hasNext();) {
 90  
 
 91  0
       Module module = (Module) i.next();
 92  
 
 93  0
       ModuleStatus moduleStatus = (ModuleStatus) statusOverview.get(module);
 94  
 
 95  0
       String[] moduleData = new String[8];
 96  0
       moduleData[0] = module.getName();
 97  
 
 98  0
       boolean existsInRepository = moduleStatus.existsInRepository();
 99  
 
 100  
       try {
 101  
 
 102  0
         if (!existsInRepository) {
 103  0
           moduleData[1] = Module.UNKNOWN.getType();
 104  
         } else {
 105  
           try {
 106  0
             moduleData[1] = module.getType().getShortType();
 107  0
           } catch (ModuleTypeException e) {
 108  
             //this exception occurs when a module has not yet been checked out.
 109  
             //therefore, only a warning.
 110  0
             logger.warn(e);
 111  0
             moduleData[1] = Module.UNKNOWN.getType();
 112  0
           }
 113  
         }
 114  
 
 115  0
         if (!manclass="keyword">ifest.isLocal(module)) {
 116  0
           moduleData[2] = "N/A";
 117  
         } else {
 118  0
           if (manclass="keyword">ifest.getState(module).equals(Module.WORKING)) {
 119  0
             moduleData[2] = "HEAD";
 120  
           } else {
 121  0
             Version localVersion = moduleStatus.getLocalVersion();
 122  0
             moduleData[2] = (localVersion == null ? "" : localVersion.getVersionNumber());
 123  
           }
 124  
         }
 125  
 
 126  0
         if (existsInRepository) {
 127  0
           Version remoteVersion = moduleStatus.getLastVersion();
 128  0
           moduleData[3] = (remoteVersion == null ? "" : "(" + remoteVersion.getVersionNumber() + ")");
 129  
         } else {
 130  0
           moduleData[3] = "";
 131  
         }
 132  
 
 133  0
       } catch (VersionControlException v) {
 134  
         // Version for the module is non-existing in the repository.
 135  
         //
 136  0
         throw new CommandException(v.getErrorCode(), v.getMessageArguments());
 137  0
       }
 138  
 
 139  0
       moduleData[4] = "(" + module.getVersionAsString() + ")";
 140  0
       if ( moduleData[4].equals("(N/A)") ) {
 141  0
         moduleData[4] = "";
 142  
       }
 143  0
       moduleData[5] = (module.hasPatchLine() ? "available" : "not available");
 144  
 
 145  0
       if (existsInRepository) {
 146  0
         moduleData[6] = manifest.getState(module).toString();
 147  0
         moduleData[7] = module.getLocation().getId();
 148  
       } else {
 149  0
         moduleData[6] = "";
 150  0
         if (moduleStatus.connectionFailure()) {
 151  0
           moduleData[7] = module.getLocation().getId() + " : <Connection failed>";
 152  0
         } else if (moduleStatus.authenticationFailure()) {
 153  0
           moduleData[7] = module.getLocation().getId() + "<Authentication failed>";
 154  0
         } else if (moduleStatus.internalError()) {
 155  0
           moduleData[7] = module.getLocation().getId() + "<Internal Error>";
 156  
         } else {
 157  0
           moduleData[7] = module.getLocation().getId() + "<Not in repository>";
 158  
         }
 159  
       }
 160  0
       renderedList.add(moduleData);
 161  
     }
 162  0
   }
 163  
 
 164  
   /**
 165  
    * Gets the commands' response object.
 166  
    *
 167  
    * @return The commands' response object.
 168  
    */
 169  
   public CommandResponse getCommandResponse() {
 170  0
     return this.commandResponse;
 171  
   }
 172  
 
 173  
   /**
 174  
    * <p>Returns the contents of the manifest in a two-dimensional <code>String[]</code> data-structure, for easy
 175  
    * reference. The contents of this structure can be queried through <code>renderedList.get(i)</code>. This call
 176  
    * retrieves a <code>String[]</code> with the most important data items for each module.
 177  
    *
 178  
    * @return A <code>List</code> containing <code>String[]</code> instances.
 179  
    */
 180  
   protected List getData() {
 181  0
     return renderedList;
 182  
   }
 183  
 }

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