| 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.Version; |
| 22 |
|
import nl.toolforge.karma.core.cmd.CommandDescriptor; |
| 23 |
|
import nl.toolforge.karma.core.cmd.CommandException; |
| 24 |
|
import nl.toolforge.karma.core.cmd.CommandResponse; |
| 25 |
|
import nl.toolforge.karma.core.cmd.DefaultCommand; |
| 26 |
|
import nl.toolforge.karma.core.manifest.Manifest; |
| 27 |
|
import nl.toolforge.karma.core.manifest.ManifestException; |
| 28 |
|
import nl.toolforge.karma.core.module.Module; |
| 29 |
|
import nl.toolforge.karma.core.module.ModuleComparator; |
| 30 |
|
import nl.toolforge.karma.core.module.ModuleTypeException; |
| 31 |
|
import nl.toolforge.karma.core.vc.ModuleStatus; |
| 32 |
|
import nl.toolforge.karma.core.vc.VersionControlException; |
| 33 |
|
import nl.toolforge.karma.core.vc.cvsimpl.threads.CVSLogThread; |
| 34 |
|
import nl.toolforge.karma.core.vc.threads.ParallelRunner; |
| 35 |
|
import org.apache.commons.logging.Log; |
| 36 |
|
import org.apache.commons.logging.LogFactory; |
| 37 |
|
|
| 38 |
|
import java.util.ArrayList; |
| 39 |
|
import java.util.Collection; |
| 40 |
|
import java.util.Collections; |
| 41 |
|
import java.util.Iterator; |
| 42 |
|
import java.util.List; |
| 43 |
|
import java.util.Map; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
public class ViewManifest extends DefaultCommand { |
| 50 |
|
|
| 51 |
0 |
protected Log logger = LogFactory.getLog(ViewManifest.class); |
| 52 |
|
|
| 53 |
0 |
private List renderedList = null; |
| 54 |
0 |
private CommandResponse commandResponse = new CommandResponse(); |
| 55 |
|
|
| 56 |
|
public ViewManifest(CommandDescriptor descriptor) { |
| 57 |
0 |
super(descriptor); |
| 58 |
|
|
| 59 |
0 |
renderedList = new ArrayList(); |
| 60 |
0 |
} |
| 61 |
|
|
| 62 |
|
public void execute() throws CommandException { |
| 63 |
|
|
| 64 |
0 |
if (!getContext().isManclass="keyword">ifestLoaded()) { |
| 65 |
0 |
throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST); |
| 66 |
|
} |
| 67 |
0 |
Manifest manifest = getContext().getCurrentManifest(); |
| 68 |
|
|
| 69 |
0 |
List sourceModules = new ArrayList(); |
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
0 |
Collection c = manifest.getAllModules().values(); |
| 77 |
|
|
| 78 |
0 |
for (Iterator i = c.iterator(); i.hasNext();) { |
| 79 |
0 |
sourceModules.add(i.next()); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
0 |
Collections.sort(sourceModules, new ModuleComparator()); |
| 83 |
|
|
| 84 |
0 |
ParallelRunner runner = new ParallelRunner(manifest, CVSLogThread.class); |
| 85 |
0 |
runner.execute(0); |
| 86 |
|
|
| 87 |
0 |
Map statusOverview = runner.retrieveResults(); |
| 88 |
|
|
| 89 |
0 |
for (Iterator i = sourceModules.iterator(); i.hasNext();) { |
| 90 |
|
|
| 91 |
0 |
Module module = (Module) i.next(); |
| 92 |
|
|
| 93 |
0 |
ModuleStatus moduleStatus = (ModuleStatus) statusOverview.get(module); |
| 94 |
|
|
| 95 |
0 |
String[] moduleData = new String[8]; |
| 96 |
0 |
moduleData[0] = module.getName(); |
| 97 |
|
|
| 98 |
0 |
boolean existsInRepository = moduleStatus.existsInRepository(); |
| 99 |
|
|
| 100 |
|
try { |
| 101 |
|
|
| 102 |
0 |
if (!existsInRepository) { |
| 103 |
0 |
moduleData[1] = Module.UNKNOWN.getType(); |
| 104 |
|
} else { |
| 105 |
|
try { |
| 106 |
0 |
moduleData[1] = module.getType().getShortType(); |
| 107 |
0 |
} catch (ModuleTypeException e) { |
| 108 |
|
|
| 109 |
|
|
| 110 |
0 |
logger.warn(e); |
| 111 |
0 |
moduleData[1] = Module.UNKNOWN.getType(); |
| 112 |
0 |
} |
| 113 |
|
} |
| 114 |
|
|
| 115 |
0 |
if (!manclass="keyword">ifest.isLocal(module)) { |
| 116 |
0 |
moduleData[2] = "N/A"; |
| 117 |
|
} else { |
| 118 |
0 |
if (manclass="keyword">ifest.getState(module).equals(Module.WORKING)) { |
| 119 |
0 |
moduleData[2] = "HEAD"; |
| 120 |
|
} else { |
| 121 |
0 |
Version localVersion = moduleStatus.getLocalVersion(); |
| 122 |
0 |
moduleData[2] = (localVersion == null ? "" : localVersion.getVersionNumber()); |
| 123 |
|
} |
| 124 |
|
} |
| 125 |
|
|
| 126 |
0 |
if (existsInRepository) { |
| 127 |
0 |
Version remoteVersion = moduleStatus.getLastVersion(); |
| 128 |
0 |
moduleData[3] = (remoteVersion == null ? "" : "(" + remoteVersion.getVersionNumber() + ")"); |
| 129 |
|
} else { |
| 130 |
0 |
moduleData[3] = ""; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
0 |
} catch (VersionControlException v) { |
| 134 |
|
|
| 135 |
|
|
| 136 |
0 |
throw new CommandException(v.getErrorCode(), v.getMessageArguments()); |
| 137 |
0 |
} |
| 138 |
|
|
| 139 |
0 |
moduleData[4] = "(" + module.getVersionAsString() + ")"; |
| 140 |
0 |
if ( moduleData[4].equals("(N/A)") ) { |
| 141 |
0 |
moduleData[4] = ""; |
| 142 |
|
} |
| 143 |
0 |
moduleData[5] = (module.hasPatchLine() ? "available" : "not available"); |
| 144 |
|
|
| 145 |
0 |
if (existsInRepository) { |
| 146 |
0 |
moduleData[6] = manifest.getState(module).toString(); |
| 147 |
0 |
moduleData[7] = module.getLocation().getId(); |
| 148 |
|
} else { |
| 149 |
0 |
moduleData[6] = ""; |
| 150 |
0 |
if (moduleStatus.connectionFailure()) { |
| 151 |
0 |
moduleData[7] = module.getLocation().getId() + " : <Connection failed>"; |
| 152 |
0 |
} else if (moduleStatus.authenticationFailure()) { |
| 153 |
0 |
moduleData[7] = module.getLocation().getId() + "<Authentication failed>"; |
| 154 |
0 |
} else if (moduleStatus.internalError()) { |
| 155 |
0 |
moduleData[7] = module.getLocation().getId() + "<Internal Error>"; |
| 156 |
|
} else { |
| 157 |
0 |
moduleData[7] = module.getLocation().getId() + "<Not in repository>"; |
| 158 |
|
} |
| 159 |
|
} |
| 160 |
0 |
renderedList.add(moduleData); |
| 161 |
|
} |
| 162 |
0 |
} |
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
public CommandResponse getCommandResponse() { |
| 170 |
0 |
return this.commandResponse; |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
| 180 |
|
protected List getData() { |
| 181 |
0 |
return renderedList; |
| 182 |
|
} |
| 183 |
|
} |