1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
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 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
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 |
|
|
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 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
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 |
|
|
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 |
|
} |