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.KarmaRuntimeException; |
22 |
|
import nl.toolforge.karma.core.cmd.Command; |
23 |
|
import nl.toolforge.karma.core.cmd.CommandDescriptor; |
24 |
|
import nl.toolforge.karma.core.cmd.CommandException; |
25 |
|
import nl.toolforge.karma.core.cmd.CommandFactory; |
26 |
|
import nl.toolforge.karma.core.cmd.CommandLoadException; |
27 |
|
import nl.toolforge.karma.core.cmd.CommandResponse; |
28 |
|
import nl.toolforge.karma.core.cmd.DefaultCommand; |
29 |
|
import nl.toolforge.karma.core.cmd.event.ErrorEvent; |
30 |
|
import nl.toolforge.karma.core.cmd.threads.ParallelCommandWrapper; |
31 |
|
import nl.toolforge.karma.core.manifest.ManifestException; |
32 |
|
import nl.toolforge.karma.core.module.Module; |
33 |
|
|
34 |
|
import java.util.Collection; |
35 |
|
import java.util.Iterator; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
public class DocAllModules extends DefaultCommand { |
44 |
|
|
45 |
0 |
private CommandResponse commandResponse = new CommandResponse(); |
46 |
|
|
47 |
|
public DocAllModules(CommandDescriptor descriptor) { |
48 |
0 |
super(descriptor); |
49 |
0 |
} |
50 |
|
|
51 |
|
public void execute() throws CommandException { |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
0 |
if (!getContext().isManclass="keyword">ifestLoaded()) { |
56 |
0 |
throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST); |
57 |
|
} |
58 |
|
|
59 |
0 |
Collection modules = getContext().getCurrentManifest().getAllModules().values(); |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
0 |
ParallelCommandWrapper[] threads = new ParallelCommandWrapper[modules.size()]; |
64 |
|
|
65 |
0 |
int j = 0; |
66 |
0 |
for (Iterator i = modules.iterator(); i.hasNext();) { |
67 |
0 |
Module module = (Module) i.next(); |
68 |
|
|
69 |
0 |
String commandLineString = "dm -m " + module.getName(); |
70 |
0 |
Command clone = null; |
71 |
|
try { |
72 |
0 |
clone = CommandFactory.getInstance().getCommand(commandLineString); |
73 |
0 |
} catch (CommandLoadException e) { |
74 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
75 |
0 |
} |
76 |
0 |
clone.setContext(getContext()); |
77 |
|
|
78 |
0 |
threads[j] = new ParallelCommandWrapper(clone, getResponseListener()); |
79 |
0 |
threads[j].start(); |
80 |
0 |
j++; |
81 |
|
} |
82 |
|
|
83 |
0 |
int totalThreads = threads.length; |
84 |
|
|
85 |
0 |
for (int i = 0; i < totalThreads; i++) { |
86 |
|
|
87 |
|
try { |
88 |
0 |
threads[i].join(); |
89 |
|
|
90 |
0 |
if (threads[i].getException() != null) { |
91 |
0 |
getCommandResponse().addEvent( |
92 |
|
new ErrorEvent(this, threads[i].getException().getErrorCode(), threads[i].getException().getMessageArguments())); |
93 |
|
} |
94 |
0 |
} catch (InterruptedException e) { |
95 |
0 |
throw new KarmaRuntimeException(e.getMessage()); |
96 |
0 |
} |
97 |
|
} |
98 |
0 |
} |
99 |
|
|
100 |
|
public CommandResponse getCommandResponse() { |
101 |
0 |
return commandResponse; |
102 |
|
} |
103 |
|
|
104 |
|
} |