Coverage report

  %line %branch
nl.toolforge.karma.core.cmd.impl.CreateModuleCommand
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.CommandDescriptor;
 22  
 import nl.toolforge.karma.core.cmd.CommandException;
 23  
 import nl.toolforge.karma.core.cmd.CommandResponse;
 24  
 import nl.toolforge.karma.core.cmd.DefaultCommand;
 25  
 import nl.toolforge.karma.core.cmd.event.MessageEvent;
 26  
 import nl.toolforge.karma.core.cmd.event.SimpleMessage;
 27  
 import nl.toolforge.karma.core.location.LocationException;
 28  
 import nl.toolforge.karma.core.module.Module;
 29  
 import nl.toolforge.karma.core.module.ModuleDigester;
 30  
 import nl.toolforge.karma.core.module.ModuleFactory;
 31  
 import nl.toolforge.karma.core.vc.AuthenticationException;
 32  
 import nl.toolforge.karma.core.vc.AuthenticatorKey;
 33  
 import nl.toolforge.karma.core.vc.Authenticators;
 34  
 import nl.toolforge.karma.core.vc.VersionControlException;
 35  
 import org.apache.commons.cli.CommandLine;
 36  
 import org.apache.commons.logging.Log;
 37  
 import org.apache.commons.logging.LogFactory;
 38  
 
 39  
 import java.util.regex.PatternSyntaxException;
 40  
 
 41  
 /**
 42  
  * Creates a module in a repository. Modules are created using a layout template (instances of
 43  
  * <code>ModuleLayoutTemplate</code>).
 44  
  *
 45  
  * @author D.A. Smedes
 46  
  * @version $Id: CreateModuleCommand.java,v 1.49 2004/11/10 23:53:08 asmedes Exp $
 47  
  */
 48  
 public class CreateModuleCommand extends DefaultCommand {
 49  
 
 50  0
   private static Log logger = LogFactory.getLog(CreateModuleCommand.class);
 51  
 
 52  0
   private CommandResponse commandResponse = new CommandResponse();
 53  
 
 54  
   public CreateModuleCommand(CommandDescriptor descriptor) {
 55  0
     super(descriptor);
 56  0
   }
 57  
 
 58  
   /**
 59  
    * Physical creation of a module in a version control system.
 60  
    */
 61  
   public void execute() throws CommandException {
 62  
 
 63  0
     CommandLine commandLine = getCommandLine();
 64  
 
 65  0
     String locationAlias = commandLine.getOptionValue("l");
 66  0
     String moduleName = commandLine.getOptionValue("m");
 67  0
     String comment = commandLine.getOptionValue("c");
 68  
 
 69  
     // Part 1 of the transaction is the creation of a Module instance.
 70  
     //
 71  
 
 72  
     // todo this bit sucks. Since renamed to ModuleDigester, it doesn't make sense anymore.
 73  0
     ModuleDigester digester = null;
 74  
     try {
 75  0
       digester = new ModuleDigester(moduleName, locationAlias);
 76  0
     } catch (PatternSyntaxException e) {
 77  0
       throw new CommandException(CommandException.INVALID_ARGUMENT, class="keyword">new Object[]{moduleName, e.getMessage()});
 78  0
     }
 79  
 
 80  0
     Module.Type moduleType = new Module.Type();
 81  
     try {
 82  0
       moduleType.setType(commandLine.getOptionValue("t"));
 83  0
     } catch (IllegalArgumentException e1) {
 84  0
       throw new CommandException(CommandException.INVALID_ARGUMENT);
 85  0
     }
 86  
 
 87  0
     Module module = null;
 88  
     try {
 89  0
       ModuleFactory factory = new ModuleFactory(getWorkingContext());
 90  0
       module = factory.create(digester, moduleType);
 91  0
     } catch (LocationException e) {
 92  0
       throw new CommandException(e.getErrorCode(), e.getMessageArguments());
 93  0
     }
 94  
 
 95  0
     SimpleMessage message = new SimpleMessage(getFrontendMessages().getString("message.CREATE_MODULE_STARTED"), new Object[]{moduleName, locationAlias});
 96  0
     commandResponse.addEvent(new MessageEvent(this, message));
 97  
 
 98  
     try {
 99  
 
 100  0
       AuthenticatorKey key = new AuthenticatorKey(getWorkingContext().getName(), module.getLocation().getId());
 101  0
       module.createRemote(Authenticators.getAuthenticator(key), comment);
 102  
 
 103  
       // Ensure that only this message is passed back to the client
 104  
       //
 105  0
       message = new SimpleMessage(getFrontendMessages().getString("message.CREATE_MODULE_SUCCESSFULL"), new Object[]{moduleName, locationAlias});
 106  0
       commandResponse.addEvent(new MessageEvent(this, message));
 107  
 
 108  0
     } catch (VersionControlException e) {
 109  0
       logger.error(e);
 110  0
       throw new CommandException(e.getErrorCode(), e.getMessageArguments());
 111  0
     } catch (AuthenticationException e) {
 112  0
       logger.error(e);
 113  0
       throw new CommandException(e.getErrorCode(), e.getMessageArguments());
 114  0
     }
 115  0
   }
 116  
 
 117  
   public CommandResponse getCommandResponse() {
 118  0
     return this.commandResponse;
 119  
   }
 120  
 }

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