| 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.Patch; |
| 22 |
|
import nl.toolforge.karma.core.Version; |
| 23 |
|
import nl.toolforge.karma.core.cmd.CommandDescriptor; |
| 24 |
|
import nl.toolforge.karma.core.cmd.CommandException; |
| 25 |
|
import nl.toolforge.karma.core.cmd.CommandResponse; |
| 26 |
|
import nl.toolforge.karma.core.cmd.DefaultCommand; |
| 27 |
|
import nl.toolforge.karma.core.cmd.event.MessageEvent; |
| 28 |
|
import nl.toolforge.karma.core.cmd.event.SimpleMessage; |
| 29 |
|
import nl.toolforge.karma.core.manifest.Manifest; |
| 30 |
|
import nl.toolforge.karma.core.manifest.ManifestException; |
| 31 |
|
import nl.toolforge.karma.core.manifest.ReleaseManifest; |
| 32 |
|
import nl.toolforge.karma.core.module.Module; |
| 33 |
|
import nl.toolforge.karma.core.vc.AuthenticationException; |
| 34 |
|
import nl.toolforge.karma.core.vc.RunnerFactory; |
| 35 |
|
import nl.toolforge.karma.core.vc.VersionControlException; |
| 36 |
|
import nl.toolforge.karma.core.vc.cvsimpl.CVSRunner; |
| 37 |
|
import nl.toolforge.karma.core.vc.cvsimpl.Utils; |
| 38 |
|
|
| 39 |
|
import java.util.regex.PatternSyntaxException; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
public class UpdateModuleCommand extends DefaultCommand { |
| 57 |
|
|
| 58 |
0 |
protected CommandResponse response = new CommandResponse(); |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
public UpdateModuleCommand(CommandDescriptor descriptor) { |
| 67 |
0 |
super(descriptor); |
| 68 |
0 |
} |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
public void execute() throws CommandException { |
| 76 |
|
|
| 77 |
0 |
String moduleName = ""; |
| 78 |
0 |
Module module = null; |
| 79 |
0 |
Manifest manifest = null; |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
0 |
if (!getContext().isManclass="keyword">ifestLoaded()) { |
| 84 |
0 |
throw new CommandException(ManifestException.NO_ACTIVE_MANIFEST); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
0 |
moduleName = getCommandLine().getOptionValue("m"); |
| 88 |
|
try { |
| 89 |
0 |
manifest = getContext().getCurrentManifest(); |
| 90 |
0 |
module = manifest.getModule(moduleName); |
| 91 |
0 |
} catch (ManifestException e) { |
| 92 |
0 |
throw new CommandException(e.getErrorCode(),e.getMessageArguments()); |
| 93 |
0 |
} |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
0 |
Version version = null; |
| 98 |
|
|
| 99 |
0 |
if (!manclass="keyword">ifest.getState(module).equals(Module.WORKING)) { |
| 100 |
|
|
| 101 |
0 |
if (getCommandLine().getOptionValue("v") != null) { |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
try { |
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
0 |
String manualVersion = getCommandLine().getOptionValue("v"); |
| 109 |
0 |
if (manualVersion.matches(Patch.VERSION_PATTERN_STRING)) { |
| 110 |
0 |
version = new Patch(manualVersion); |
| 111 |
|
} else { |
| 112 |
0 |
version = new Version(manualVersion); |
| 113 |
|
} |
| 114 |
0 |
} catch (PatternSyntaxException pse) { |
| 115 |
0 |
throw new CommandException(CommandException.INVALID_ARGUMENT, |
| 116 |
|
new Object[]{getCommandLine().getOptionValue("v"), |
| 117 |
|
"Version has to be <number>-<number>[-<number>], e.g. '0-0'"}); |
| 118 |
0 |
} |
| 119 |
0 |
} else if (manclass="keyword">ifest.getState(module).equals(Module.STATIC)) { |
| 120 |
0 |
version = module.getVersion(); |
| 121 |
0 |
} else if (manclass="keyword">ifest.getState(module).equals(Module.DYNAMIC)) { |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
try { |
| 125 |
0 |
version = Utils.getLastVersion(module); |
| 126 |
0 |
} catch (VersionControlException e) { |
| 127 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
| 128 |
0 |
} |
| 129 |
|
} |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
try { |
| 133 |
0 |
if (version != null && !manclass="keyword">ifest.getState(module).equals(Module.WORKING) && version.equals(Utils.getLocalVersion(module))) { |
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
0 |
response.addEvent( |
| 140 |
|
new MessageEvent(this, class="keyword">new SimpleMessage("Module `" + module.getName() + "` is already up-to-date with version `" + version.toString() + "`."))); |
| 141 |
|
|
| 142 |
|
} else { |
| 143 |
|
|
| 144 |
0 |
CVSRunner runner = (CVSRunner) RunnerFactory.getRunner(module.getLocation()); |
| 145 |
0 |
runner.setCommandResponse(response); |
| 146 |
|
|
| 147 |
0 |
if (!Utils.existsInRepository(module)) { |
| 148 |
0 |
throw new CommandException(VersionControlException.MODULE_NOT_IN_REPOSITORY, class="keyword">new Object[]{module.getName(), module.getLocation().getId()}); |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
0 |
if (manclass="keyword">ifest.getState(module).equals(Module.WORKING) && manclass="keyword">ifest instanceof ReleaseManclass="keyword">ifest) { |
| 154 |
0 |
runner.checkout(module, module.getPatchLine(), null); |
| 155 |
|
} else { |
| 156 |
0 |
runner.checkout(module, version); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
0 |
SimpleMessage message = null; |
| 160 |
|
|
| 161 |
0 |
if (version == null) { |
| 162 |
|
|
| 163 |
|
|
| 164 |
0 |
message = new SimpleMessage("Module `" + module.getName() + "` updated."); |
| 165 |
|
} else { |
| 166 |
0 |
if (manclass="keyword">ifest instanceof ReleaseManclass="keyword">ifest) { |
| 167 |
0 |
manifest.setState(module, Module.STATIC); |
| 168 |
0 |
message = new SimpleMessage("Module `" + module.getName() + "` updated with version `" + version.toString() + "`; state set to STATIC."); |
| 169 |
|
} else { |
| 170 |
0 |
if (manclass="keyword">ifest.getState(module).equals(Module.STATIC)) { |
| 171 |
|
|
| 172 |
|
|
| 173 |
0 |
message = new SimpleMessage("Module `" + module.getName() + "` updated."); |
| 174 |
|
} else { |
| 175 |
0 |
manifest.setState(module, Module.DYNAMIC); |
| 176 |
0 |
message = new SimpleMessage("Module `" + module.getName() + "` updated with version `" + version.toString() + "`; state set to DYNAMIC."); |
| 177 |
|
} |
| 178 |
|
} |
| 179 |
|
} |
| 180 |
0 |
response.addEvent(new MessageEvent(this, message)); |
| 181 |
|
} |
| 182 |
0 |
} catch (VersionControlException e) { |
| 183 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
| 184 |
0 |
} catch (AuthenticationException e) { |
| 185 |
0 |
throw new CommandException(e.getErrorCode(), e.getMessageArguments()); |
| 186 |
0 |
} |
| 187 |
0 |
} |
| 188 |
|
|
| 189 |
|
public CommandResponse getCommandResponse() { |
| 190 |
0 |
return response; |
| 191 |
|
} |
| 192 |
|
} |