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.cmd.Command;
22 import nl.toolforge.karma.core.cmd.CommandDescriptor;
23 import nl.toolforge.karma.core.cmd.CommandException;
24 import nl.toolforge.karma.core.cmd.CommandFactory;
25 import nl.toolforge.karma.core.cmd.CommandLoadException;
26 import nl.toolforge.karma.core.cmd.CommandResponse;
27 import nl.toolforge.karma.core.cmd.DefaultCommand;
28 import nl.toolforge.karma.core.cmd.event.CommandFailedEvent;
29 import nl.toolforge.karma.core.cmd.event.ErrorEvent;
30 import nl.toolforge.karma.core.cmd.util.KarmaBuildException;
31 import nl.toolforge.karma.core.manifest.Manifest;
32 import nl.toolforge.karma.core.manifest.ManifestException;
33 import nl.toolforge.karma.core.module.Module;
34 import nl.toolforge.karma.core.scm.ModuleDependency;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.HashSet;
39 import java.util.Iterator;
40 import java.util.List;
41 import java.util.Set;
42
43 /***
44 * Builds all modules in a manifest.
45 *
46 * @author D.A. Smedes
47 * @version $Id: BuildAllModules.java,v 1.11 2004/11/10 23:53:08 asmedes Exp $
48 *
49 * @deprecated Not in use, but the current code remains. Not to be used.
50 */
51 public class BuildAllModules extends DefaultCommand {
52
53 private CommandResponse commandResponse = new CommandResponse();
54 private List orderedCollection = null;
55 private Manifest currentManifest = null;
56
57 public BuildAllModules(CommandDescriptor descriptor) {
58 super(descriptor);
59 }
60
61 public void execute() throws CommandException {
62
63 currentManifest = getContext().getCurrentManifest();
64
65 try {
66 orderedCollection = new ArrayList();
67
68 createBuildList(currentManifest.getAllModules().values());
69
70 } catch (KarmaBuildException e) {
71 throw new CommandException(e, CommandException.BUILD_FAILED);
72 } catch (ManifestException e) {
73 throw new CommandException(e.getErrorCode(), e.getMessageArguments());
74 }
75
76 for (Iterator i = orderedCollection.iterator(); i.hasNext();) {
77
78 Module module = (Module) i.next();
79
80 Command command = null;
81 try {
82 String commandLineString = PackageModule.COMMAND_NAME + " -m " + module.getName() + " -n";
83
84 command = CommandFactory.getInstance().getCommand(commandLineString);
85 command.setContext(getContext());
86 command.registerCommandResponseListener(getResponseListener());
87 command.execute();
88
89 } catch (CommandException ce) {
90 if (ce.getErrorCode().equals(CommandException.DEPENDENCY_DOES_NOT_EXIST) ||
91 ce.getErrorCode().equals(CommandException.BUILD_FAILED) ) {
92
93 commandResponse.addEvent(new CommandFailedEvent(this, ce));
94
95 throw new CommandException(ce, CommandException.TEST_FAILED, new Object[]{module.getName()});
96 } else {
97
98 commandResponse.addEvent(new CommandFailedEvent(this, ce));
99
100 commandResponse.addEvent(new ErrorEvent(CommandException.BUILD_WARNING));
101 }
102 } catch (CommandLoadException e) {
103 throw new CommandException(e.getErrorCode(), e.getMessageArguments());
104 } finally {
105 if ( command != null ) {
106 command.deregisterCommandResponseListener(getResponseListener());
107 }
108 }
109 }
110 }
111
112 private void createBuildList(Collection collection) throws ManifestException, KarmaBuildException {
113
114 for (Iterator i = collection.iterator(); i.hasNext();) {
115
116 Module module = (Module) i.next();
117
118 Set deps = module.getDependencies();
119 if (deps.size() == 0) {
120 orderedCollection.add(module);
121 } else {
122 Set mods = new HashSet();
123 for (Iterator j = deps.iterator(); j.hasNext();) {
124 ModuleDependency dep = (ModuleDependency) j.next();
125 Module mod = null;
126 if (dep.isModuleDependency()) {
127 mod = currentManifest.getModule(dep.getModule());
128 if (!orderedCollection.contains(mod)) {
129 mods.add(mod);
130 }
131 }
132 }
133
134 if (mods.size() == 0) {
135 orderedCollection.add(module);
136 } else {
137 createBuildList(mods);
138 }
139 }
140 }
141 }
142
143 public CommandResponse getCommandResponse() {
144 return this.commandResponse;
145 }
146 }