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 * Generates API documentation for all modules.
39 *
40 * @author W.H. Schraal
41 * @author D.A. Schraal
42 */
43 public class DocAllModules extends DefaultCommand {
44
45 private CommandResponse commandResponse = new CommandResponse();
46
47 public DocAllModules(CommandDescriptor descriptor) {
48 super(descriptor);
49 }
50
51 public void execute() throws CommandException {
52
53
54
55 if (!getContext().isManifestLoaded()) {
56 throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST);
57 }
58
59 Collection modules = getContext().getCurrentManifest().getAllModules().values();
60
61
62
63 ParallelCommandWrapper[] threads = new ParallelCommandWrapper[modules.size()];
64
65 int j = 0;
66 for (Iterator i = modules.iterator(); i.hasNext();) {
67 Module module = (Module) i.next();
68
69 String commandLineString = "dm -m " + module.getName();
70 Command clone = null;
71 try {
72 clone = CommandFactory.getInstance().getCommand(commandLineString);
73 } catch (CommandLoadException e) {
74 throw new CommandException(e.getErrorCode(), e.getMessageArguments());
75 }
76 clone.setContext(getContext());
77
78 threads[j] = new ParallelCommandWrapper(clone, getResponseListener());
79 threads[j].start();
80 j++;
81 }
82
83 int totalThreads = threads.length;
84
85 for (int i = 0; i < totalThreads; i++) {
86
87 try {
88 threads[i].join();
89
90 if (threads[i].getException() != null) {
91 getCommandResponse().addEvent(
92 new ErrorEvent(this, threads[i].getException().getErrorCode(), threads[i].getException().getMessageArguments()));
93 }
94 } catch (InterruptedException e) {
95 throw new KarmaRuntimeException(e.getMessage());
96 }
97 }
98 }
99
100 public CommandResponse getCommandResponse() {
101 return commandResponse;
102 }
103
104 }