| 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 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
public class BuildAllModules extends DefaultCommand { |
| 52 |
|
|
| 53 |
0 |
private CommandResponse commandResponse = new CommandResponse(); |
| 54 |
0 |
private List orderedCollection = null; |
| 55 |
0 |
private Manifest currentManifest = null; |
| 56 |
|
|
| 57 |
|
public BuildAllModules(CommandDescriptor descriptor) { |
| 58 |
0 |
super(descriptor); |
| 59 |
0 |
} |
| 60 |
|
|
| 61 |
|
public void execute() throws CommandException { |
| 62 |
|
|
| 63 |
0 |
currentManifest = getContext().getCurrentManifest(); |
| 64 |
|
|
| 65 |
|
try { |
| 66 |
0 |
orderedCollection = new ArrayList(); |
| 67 |
|
|
| 68 |
0 |
createBuildList(currentManifest.getAllModules().values()); |
| 69 |
|
|
| 70 |
0 |
} catch (KarmaBuildException e) { |
| 71 |
0 |
throw new CommandException(e, CommandException.BUILD_FAILED); |
| 72 |
0 |
} catch (ManifestException e) { |
| 73 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
| 74 |
0 |
} |
| 75 |
|
|
| 76 |
0 |
for (Iterator i = orderedCollection.iterator(); i.hasNext();) { |
| 77 |
|
|
| 78 |
0 |
Module module = (Module) i.next(); |
| 79 |
|
|
| 80 |
0 |
Command command = null; |
| 81 |
|
try { |
| 82 |
0 |
String commandLineString = PackageModule.COMMAND_NAME + " -m " + module.getName() + " -n"; |
| 83 |
|
|
| 84 |
0 |
command = CommandFactory.getInstance().getCommand(commandLineString); |
| 85 |
0 |
command.setContext(getContext()); |
| 86 |
0 |
command.registerCommandResponseListener(getResponseListener()); |
| 87 |
0 |
command.execute(); |
| 88 |
|
|
| 89 |
0 |
} catch (CommandException ce) { |
| 90 |
0 |
if (ce.getErrorCode().equals(CommandException.DEPENDENCY_DOES_NOT_EXIST) || |
| 91 |
|
ce.getErrorCode().equals(CommandException.BUILD_FAILED) ) { |
| 92 |
|
|
| 93 |
0 |
commandResponse.addEvent(new CommandFailedEvent(this, ce)); |
| 94 |
|
|
| 95 |
0 |
throw new CommandException(ce, CommandException.TEST_FAILED, class="keyword">new Object[]{module.getName()}); |
| 96 |
|
} else { |
| 97 |
|
|
| 98 |
0 |
commandResponse.addEvent(new CommandFailedEvent(this, ce)); |
| 99 |
|
|
| 100 |
0 |
commandResponse.addEvent(new ErrorEvent(CommandException.BUILD_WARNING)); |
| 101 |
|
} |
| 102 |
0 |
} catch (CommandLoadException e) { |
| 103 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
| 104 |
|
} finally { |
| 105 |
0 |
if ( command != null ) { |
| 106 |
0 |
command.deregisterCommandResponseListener(getResponseListener()); |
| 107 |
|
} |
| 108 |
0 |
} |
| 109 |
|
} |
| 110 |
0 |
} |
| 111 |
|
|
| 112 |
|
private void createBuildList(Collection collection) throws ManifestException, KarmaBuildException { |
| 113 |
|
|
| 114 |
0 |
for (Iterator i = collection.iterator(); i.hasNext();) { |
| 115 |
|
|
| 116 |
0 |
Module module = (Module) i.next(); |
| 117 |
|
|
| 118 |
0 |
Set deps = module.getDependencies(); |
| 119 |
0 |
if (deps.size() == 0) { |
| 120 |
0 |
orderedCollection.add(module); |
| 121 |
|
} else { |
| 122 |
0 |
Set mods = new HashSet(); |
| 123 |
0 |
for (Iterator j = deps.iterator(); j.hasNext();) { |
| 124 |
0 |
ModuleDependency dep = (ModuleDependency) j.next(); |
| 125 |
0 |
Module mod = null; |
| 126 |
0 |
if (dep.isModuleDependency()) { |
| 127 |
0 |
mod = currentManifest.getModule(dep.getModule()); |
| 128 |
0 |
if (!orderedCollection.contains(mod)) { |
| 129 |
0 |
mods.add(mod); |
| 130 |
|
} |
| 131 |
|
} |
| 132 |
|
} |
| 133 |
|
|
| 134 |
0 |
if (mods.size() == 0) { |
| 135 |
0 |
orderedCollection.add(module); |
| 136 |
|
} else { |
| 137 |
0 |
createBuildList(mods); |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
0 |
} |
| 142 |
|
|
| 143 |
|
public CommandResponse getCommandResponse() { |
| 144 |
0 |
return this.commandResponse; |
| 145 |
|
} |
| 146 |
|
} |