View Javadoc

1   /*
2   Karma core - Core of the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      // A manifest must be present for this command
54      //
55      if (!getContext().isManifestLoaded()) {
56        throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST);
57      }
58  
59      Collection modules = getContext().getCurrentManifest().getAllModules().values();
60  
61      // Initialize an array of threads.
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 }