Coverage report

  %line %branch
nl.toolforge.karma.core.cmd.impl.BuildAllModules
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.cmd.Command;
 22  
 import nl.toolforge.karma.core.cmd.CommandDescriptor;
 23  
 import nl.toolforge.karma.core.cmd.CommandException;
 24  
 import nl.toolforge.karma.core.cmd.CommandFactory;
 25  
 import nl.toolforge.karma.core.cmd.CommandLoadException;
 26  
 import nl.toolforge.karma.core.cmd.CommandResponse;
 27  
 import nl.toolforge.karma.core.cmd.DefaultCommand;
 28  
 import nl.toolforge.karma.core.cmd.event.CommandFailedEvent;
 29  
 import nl.toolforge.karma.core.cmd.event.ErrorEvent;
 30  
 import nl.toolforge.karma.core.cmd.util.KarmaBuildException;
 31  
 import nl.toolforge.karma.core.manifest.Manifest;
 32  
 import nl.toolforge.karma.core.manifest.ManifestException;
 33  
 import nl.toolforge.karma.core.module.Module;
 34  
 import nl.toolforge.karma.core.scm.ModuleDependency;
 35  
 
 36  
 import java.util.ArrayList;
 37  
 import java.util.Collection;
 38  
 import java.util.HashSet;
 39  
 import java.util.Iterator;
 40  
 import java.util.List;
 41  
 import java.util.Set;
 42  
 
 43  
 /**
 44  
  * Builds all modules in a manifest.
 45  
  *
 46  
  * @author D.A. Smedes
 47  
  * @version $Id: BuildAllModules.java,v 1.11 2004/11/10 23:53:08 asmedes Exp $
 48  
  *
 49  
  * @deprecated Not in use, but the current code remains. Not to be used.
 50  
  */
 51  
 public class BuildAllModules extends DefaultCommand {
 52  
 
 53  0
   private CommandResponse commandResponse = new CommandResponse();
 54  0
   private List orderedCollection = null;
 55  0
   private Manifest currentManifest = null;
 56  
 
 57  
   public BuildAllModules(CommandDescriptor descriptor) {
 58  0
     super(descriptor);
 59  0
   }
 60  
 
 61  
   public void execute() throws CommandException {
 62  
 
 63  0
     currentManifest = getContext().getCurrentManifest();
 64  
 
 65  
     try {
 66  0
       orderedCollection = new ArrayList();
 67  
 
 68  0
       createBuildList(currentManifest.getAllModules().values());
 69  
 
 70  0
     } catch (KarmaBuildException e) {
 71  0
       throw new CommandException(e, CommandException.BUILD_FAILED);
 72  0
     } catch (ManifestException e) {
 73  0
       throw new CommandException(e.getErrorCode(), e.getMessageArguments());
 74  0
     }
 75  
 
 76  0
     for (Iterator i = orderedCollection.iterator(); i.hasNext();) {
 77  
 
 78  0
       Module module = (Module) i.next();
 79  
 
 80  0
       Command command = null;
 81  
       try {
 82  0
         String commandLineString = PackageModule.COMMAND_NAME + " -m " + module.getName() + " -n";
 83  
 
 84  0
         command = CommandFactory.getInstance().getCommand(commandLineString);
 85  0
         command.setContext(getContext());
 86  0
         command.registerCommandResponseListener(getResponseListener());
 87  0
         command.execute();
 88  
 
 89  0
       } catch (CommandException ce) {
 90  0
         if (ce.getErrorCode().equals(CommandException.DEPENDENCY_DOES_NOT_EXIST) ||
 91  
             ce.getErrorCode().equals(CommandException.BUILD_FAILED) ) {
 92  
 
 93  0
           commandResponse.addEvent(new CommandFailedEvent(this, ce));
 94  
 //          commandResponse.addEvent(new ErrorMessage(ce.getErrorCode(), ce.getMessageArguments()));
 95  0
           throw new CommandException(ce, CommandException.TEST_FAILED, class="keyword">new Object[]{module.getName()});
 96  
         } else {
 97  
 //          Message message = new ErrorMessage(ce.getErrorCode(), ce.getMessageArguments());
 98  0
           commandResponse.addEvent(new CommandFailedEvent(this, ce));
 99  
 
 100  0
           commandResponse.addEvent(new ErrorEvent(CommandException.BUILD_WARNING));
 101  
         }
 102  0
       } catch (CommandLoadException e) {
 103  0
         throw new CommandException(e.getErrorCode(), e.getMessageArguments());
 104  
       } finally {
 105  0
         if ( command != null ) {
 106  0
           command.deregisterCommandResponseListener(getResponseListener());
 107  
         }
 108  0
       }
 109  
     }
 110  0
   }
 111  
 
 112  
   private void createBuildList(Collection collection) throws ManifestException, KarmaBuildException {
 113  
 
 114  0
     for (Iterator i = collection.iterator(); i.hasNext();) {
 115  
 
 116  0
       Module module = (Module) i.next();
 117  
 
 118  0
       Set deps = module.getDependencies();
 119  0
       if (deps.size() == 0) {
 120  0
         orderedCollection.add(module);
 121  
       } else {
 122  0
         Set mods = new HashSet();
 123  0
         for (Iterator j = deps.iterator(); j.hasNext();) {
 124  0
           ModuleDependency dep = (ModuleDependency) j.next();
 125  0
           Module mod = null;
 126  0
           if (dep.isModuleDependency()) {
 127  0
             mod = currentManifest.getModule(dep.getModule());
 128  0
             if (!orderedCollection.contains(mod)) {
 129  0
               mods.add(mod);
 130  
             }
 131  
           }
 132  
         }
 133  
 
 134  0
         if (mods.size() == 0) {
 135  0
           orderedCollection.add(module);
 136  
         } else {
 137  0
           createBuildList(mods);
 138  
         }
 139  
       }
 140  
     }
 141  0
   }
 142  
 
 143  
   public CommandResponse getCommandResponse() {
 144  0
     return this.commandResponse;
 145  
   }
 146  
 }

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