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.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.cmd.event.ErrorEvent; |
27 |
|
import nl.toolforge.karma.core.cmd.event.MessageEvent; |
28 |
|
import nl.toolforge.karma.core.cmd.event.SimpleMessage; |
29 |
|
import nl.toolforge.karma.core.manifest.DevelopmentManifest; |
30 |
|
import nl.toolforge.karma.core.manifest.Manifest; |
31 |
|
import nl.toolforge.karma.core.manifest.ManifestException; |
32 |
|
import nl.toolforge.karma.core.module.Module; |
33 |
|
import nl.toolforge.karma.core.vc.AuthenticationException; |
34 |
|
import nl.toolforge.karma.core.vc.ModuleStatus; |
35 |
|
import nl.toolforge.karma.core.vc.Runner; |
36 |
|
import nl.toolforge.karma.core.vc.RunnerFactory; |
37 |
|
import nl.toolforge.karma.core.vc.VersionControlException; |
38 |
|
import nl.toolforge.karma.core.vc.cvsimpl.AdminHandler; |
39 |
|
import nl.toolforge.karma.core.vc.cvsimpl.CVSModuleStatus; |
40 |
|
import nl.toolforge.karma.core.vc.cvsimpl.CVSRunner; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
public class PromoteCommand extends DefaultCommand { |
52 |
|
|
53 |
0 |
private Version newVersion = null; |
54 |
0 |
protected CommandResponse commandResponse = new CommandResponse(); |
55 |
|
|
56 |
|
public PromoteCommand(CommandDescriptor descriptor) { |
57 |
0 |
super(descriptor); |
58 |
0 |
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
public void execute() throws CommandException { |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
0 |
if (!getContext().isManclass="keyword">ifestLoaded()) { |
69 |
0 |
throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST); |
70 |
|
} |
71 |
|
|
72 |
|
try { |
73 |
|
|
74 |
0 |
String moduleName = getCommandLine().getOptionValue("m"); |
75 |
0 |
String comment = getCommandLine().getOptionValue("c"); |
76 |
|
|
77 |
0 |
Manifest manifest = getContext().getCurrentManifest(); |
78 |
0 |
Module module = manifest.getModule(moduleName); |
79 |
|
|
80 |
0 |
if (!manclass="keyword">ifest.getState(module).equals(Module.WORKING)) { |
81 |
0 |
throw new CommandException(CommandException.PROMOTE_ONLY_ALLOWED_ON_WORKING_MODULE, class="keyword">new Object[]{moduleName}); |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
0 |
AdminHandler handler = new AdminHandler(module); |
87 |
0 |
handler.administrate(); |
88 |
|
|
89 |
0 |
boolean force = getCommandLine().hasOption("f"); |
90 |
0 |
boolean proceed = true; |
91 |
|
|
92 |
0 |
if (handler.hasNewStuff()) { |
93 |
0 |
if (force) { |
94 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage("WARNING : Module " + moduleName + " has new, but uncommitted files."))); |
95 |
|
} else { |
96 |
0 |
commandResponse.addEvent(new ErrorEvent(this, CommandException.UNCOMMITTED_NEW_FILES, class="keyword">new Object[]{moduleName})); |
97 |
0 |
proceed = false; |
98 |
|
} |
99 |
|
} |
100 |
0 |
if (handler.hasChangedStuff()) { |
101 |
0 |
if (force) { |
102 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage("WARNING : Module " + moduleName + " has changed, but uncommitted files."))); |
103 |
|
} else { |
104 |
0 |
commandResponse.addEvent(new ErrorEvent(this, CommandException.UNCOMMITTED_CHANGED_FILES, class="keyword">new Object[]{moduleName})); |
105 |
0 |
proceed = false; |
106 |
|
} |
107 |
|
} |
108 |
0 |
if (handler.hasRemovedStuff()) { |
109 |
0 |
if (force) { |
110 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage("WARNING : Module " + moduleName + " has removed, but uncommitted files."))); |
111 |
|
} else { |
112 |
0 |
commandResponse.addEvent(new ErrorEvent(this, CommandException.UNCOMMITTED_REMOVED_FILES, class="keyword">new Object[]{moduleName})); |
113 |
0 |
proceed = false; |
114 |
|
} |
115 |
|
} |
116 |
|
|
117 |
0 |
if (proceed) { |
118 |
0 |
Runner runner = RunnerFactory.getRunner(module.getLocation()); |
119 |
|
|
120 |
0 |
ModuleStatus status = new CVSModuleStatus(module, ((CVSRunner) runner).log(module)); |
121 |
0 |
Version nextVersion = null; |
122 |
|
|
123 |
0 |
if (getCommandLine().hasOption("v")) { |
124 |
0 |
if (! (manclass="keyword">ifest instanceof DevelopmentManclass="keyword">ifest)) { |
125 |
0 |
throw new CommandException(CommandException.PROMOTE_WITH_INCREASE_MAJOR_VERSION_NOT_ALLOWED_ON_RELEASE_MANIFEST); |
126 |
|
} |
127 |
|
|
128 |
0 |
nextVersion = status.getNextMajorVersion(); |
129 |
|
} else { |
130 |
0 |
nextVersion = status.getNextVersion(); |
131 |
|
} |
132 |
|
|
133 |
0 |
newVersion = nextVersion; |
134 |
|
|
135 |
0 |
runner.promote(module, comment, newVersion); |
136 |
|
|
137 |
0 |
commandResponse.addEvent( |
138 |
|
new MessageEvent(this, |
139 |
|
new SimpleMessage( |
140 |
|
getFrontendMessages().getString("message.MODULE_PROMOTED"), |
141 |
|
new Object[]{getCommandLine().getOptionValue("m"), getNewVersion()} |
142 |
|
))); |
143 |
|
|
144 |
|
} else { |
145 |
0 |
commandResponse.addEvent( |
146 |
|
new MessageEvent(this, |
147 |
|
new SimpleMessage( |
148 |
|
getFrontendMessages().getString("message.PROMOTE_MODULE_FAILED"), |
149 |
|
new Object[]{module.getName(), moduleName} |
150 |
|
))); |
151 |
|
} |
152 |
|
|
153 |
0 |
} catch (ManifestException e) { |
154 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
155 |
0 |
} catch (VersionControlException e) { |
156 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
157 |
0 |
} catch (AuthenticationException e) { |
158 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
159 |
0 |
} |
160 |
0 |
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
public CommandResponse getCommandResponse() { |
168 |
0 |
return commandResponse; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
protected final Version getNewVersion() { |
177 |
0 |
return newVersion; |
178 |
|
} |
179 |
|
} |
180 |
|
|