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; |
20 |
|
|
21 |
|
import nl.toolforge.karma.core.boot.LocationStore; |
22 |
|
import nl.toolforge.karma.core.boot.ManifestStore; |
23 |
|
import nl.toolforge.karma.core.boot.WorkingContext; |
24 |
|
import nl.toolforge.karma.core.bundle.BundleCache; |
25 |
|
import nl.toolforge.karma.core.cmd.event.CommandResponseListener; |
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.location.LocationException; |
30 |
|
import nl.toolforge.karma.core.manifest.Manifest; |
31 |
|
import nl.toolforge.karma.core.manifest.ManifestException; |
32 |
|
import nl.toolforge.karma.core.vc.AuthenticationException; |
33 |
|
import nl.toolforge.karma.core.vc.VersionControlException; |
34 |
|
import org.apache.commons.cli.CommandLine; |
35 |
|
import org.apache.commons.logging.Log; |
36 |
|
import org.apache.commons.logging.LogFactory; |
37 |
|
|
38 |
|
import java.util.ResourceBundle; |
39 |
|
import java.util.prefs.BackingStoreException; |
40 |
|
import java.util.prefs.Preferences; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
public final class KarmaInitializationCommand implements Command { |
53 |
|
|
54 |
0 |
private static final Log logger = LogFactory.getLog(KarmaInitializationCommand.class); |
55 |
|
|
56 |
0 |
private CommandResponse commandResponse = new CommandResponse(); |
57 |
|
|
58 |
0 |
private CommandContext commandContext = null; |
59 |
0 |
private boolean updateStores = false; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
0 |
KarmaInitializationCommand(boolean updateStores) { |
65 |
0 |
this.updateStores = updateStores; |
66 |
0 |
} |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public void execute() throws CommandException { |
74 |
|
|
75 |
|
try { |
76 |
|
|
77 |
0 |
if (updateStores) { |
78 |
|
|
79 |
|
try { |
80 |
|
|
81 |
0 |
ManifestStore mStore = commandContext.getWorkingContext().getConfiguration().getManifestStore(); |
82 |
|
|
83 |
0 |
if (!mStore.getLocation().isAvailable()) { |
84 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage("Manifest store location unreachable!"))); |
85 |
|
} else { |
86 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage(("Updating manifests ...")))); |
87 |
0 |
mStore.update(); |
88 |
|
} |
89 |
|
|
90 |
0 |
LocationStore lStore = commandContext.getWorkingContext().getConfiguration().getLocationStore(); |
91 |
|
|
92 |
0 |
if (!lStore.getLocation().isAvailable()) { |
93 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage("Location store location unreachable!"))); |
94 |
|
} else { |
95 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage(("Updating locations ...")))); |
96 |
0 |
lStore.update(); |
97 |
|
} |
98 |
|
|
99 |
0 |
} catch (VersionControlException e) { |
100 |
0 |
logger.warn(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments())); |
101 |
0 |
commandResponse.addEvent(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments())); |
102 |
0 |
} catch (AuthenticationException e) { |
103 |
0 |
logger.warn(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments())); |
104 |
0 |
commandResponse.addEvent(new ErrorEvent(this, e.getErrorCode(), e.getMessageArguments())); |
105 |
0 |
} |
106 |
|
} |
107 |
|
|
108 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage(getFrontendMessages().getString("message.LOADING_MANIFEST_FROM_HISTORY")))); |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
0 |
Manifest currentManifest = commandContext.getWorkingContext().getManifestCollector().loadManifestFromHistory(); |
113 |
0 |
if (currentManclass="keyword">ifest != null) { |
114 |
0 |
SimpleMessage message = |
115 |
|
new SimpleMessage(getFrontendMessages().getString("message.MANIFEST_ACTIVATED"), new Object[]{currentManifest}); |
116 |
0 |
commandResponse.addEvent(new MessageEvent(this, message)); |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
0 |
commandContext.changeCurrentManifest(currentManifest); |
121 |
0 |
commandContext.register(); |
122 |
|
} else { |
123 |
0 |
commandResponse.addEvent(new MessageEvent(this, class="keyword">new SimpleMessage(getFrontendMessages().getString("message.NO_MANIFEST_IN_HISTORY")))); |
124 |
|
} |
125 |
|
|
126 |
|
try { |
127 |
0 |
Preferences.userRoot().put(WorkingContext.WORKING_CONTEXT_PREFERENCE, commandContext.getWorkingContext().getName()); |
128 |
0 |
Preferences.userRoot().flush(); |
129 |
0 |
} catch (BackingStoreException e) { |
130 |
|
|
131 |
0 |
} |
132 |
0 |
} catch (ManifestException e) { |
133 |
0 |
throw new CommandException(e, e.getErrorCode(), e.getMessageArguments()); |
134 |
0 |
} catch (LocationException e) { |
135 |
0 |
throw new CommandException(e, e.getErrorCode(), e.getMessageArguments()); |
136 |
0 |
} |
137 |
0 |
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
public String getName() { |
145 |
0 |
return "init"; |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
public String getAlias() { |
154 |
0 |
return "init"; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
public String getDescription() { |
163 |
0 |
return "This command initializes a command context."; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
public String getHelp() { |
173 |
0 |
return getDescription(); |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
0 |
public void cleanUp() { } |
180 |
|
|
181 |
|
public void setContext(CommandContext context) { |
182 |
0 |
this.commandContext = context; |
183 |
0 |
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
0 |
public void setCommandLine(CommandLine commandLine) {} |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
public CommandLine getCommandLine() { |
198 |
0 |
return null; |
199 |
|
} |
200 |
|
|
201 |
|
public final void registerCommandResponseListener(CommandResponseListener responseListener) { |
202 |
0 |
getCommandResponse().addCommandResponseListener(responseListener); |
203 |
0 |
} |
204 |
|
|
205 |
|
public final void deregisterCommandResponseListener(CommandResponseListener responseListener) { |
206 |
0 |
getCommandResponse().removeCommandReponseListener(responseListener); |
207 |
0 |
} |
208 |
|
|
209 |
|
public CommandResponse getCommandResponse() { |
210 |
0 |
return commandResponse; |
211 |
|
} |
212 |
|
|
213 |
|
private ResourceBundle getFrontendMessages() { |
214 |
0 |
return BundleCache.getInstance().getBundle(BundleCache.FRONTEND_MESSAGES_KEY); |
215 |
|
} |
216 |
|
} |