1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.team.internal.ccvs.core.*; 19 import org.eclipse.team.internal.ccvs.core.client.listeners.*; 20 import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; 21 import org.eclipse.team.internal.ccvs.core.resources.RemoteModule; 22 23 public class Checkout extends Command { 24 25 public static final LocalOption DO_NOT_SHORTEN = new LocalOption("-N"); public static final LocalOption FETCH_MODULE_ALIASES = new LocalOption("-c"); public static LocalOption makeDirectoryNameOption(String moduleName) { 28 return new LocalOption("-d", moduleName); } 30 31 32 private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new UpdateListener(null); 33 34 35 public static LocalOption ALIAS = new LocalOption("-a"); public static LocalOption makeStatusOption(String status) { 37 return new LocalOption("-s", status); } 39 40 protected Checkout() { } 41 protected String getRequestId() { 42 return "co"; } 44 45 protected ICommandOutputListener getDefaultCommandOutputListener() { 46 return DEFAULT_OUTPUT_LISTENER; 47 } 48 49 protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, 50 String [] arguments) throws CVSException { 51 52 if (arguments.length < 1 && ! FETCH_MODULE_ALIASES.isElementOf(localOptions)) throw new IllegalArgumentException (); 54 55 Option dOption = findOption(localOptions, "-d"); if (dOption != null) { 58 return new ICVSResource[] {session.getLocalRoot().getFolder(dOption.argument)}; 60 } 61 String [] modules = session.getModuleExpansions(); 62 ICVSResource[] resources = new ICVSResource[modules.length]; 63 for (int i = 0; i < resources.length; i++) { 64 resources[i] = session.getLocalRoot().getFolder(modules[i]); 65 } 66 return resources; 67 } 68 69 76 protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, 77 LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) 78 throws CVSException { 79 80 Assert.isTrue(session.getLocalRoot().isFolder()); 82 83 List resourcesToSend = new ArrayList (resources.length); 85 for (int i = 0; i < resources.length; i++) { 86 ICVSResource resource = resources[i]; 87 if (resource.exists() && resource.isFolder() && ((ICVSFolder)resource).isCVSFolder()) { 88 resourcesToSend.add(resource); 89 } 90 } 91 if ( ! resourcesToSend.isEmpty()) { 92 resources = (ICVSResource[]) resourcesToSend.toArray(new ICVSResource[resourcesToSend.size()]); 93 new FileStructureVisitor(session, localOptions, true, true).visit(session, resources, monitor); 94 } else { 95 monitor.beginTask(null, 100); 96 monitor.done(); 97 } 98 return resources; 99 } 100 101 protected void sendLocalWorkingDirectory(Session session) throws CVSException { 102 session.sendConstructedRootDirectory(); 103 } 104 105 109 protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, 110 LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, 111 IStatus status) throws CVSException { 112 if (status.getCode() == CVSStatus.SERVER_ERROR) { 114 return status; 115 } 116 117 if (FETCH_MODULE_ALIASES.isElementOf(localOptions)) return status; 119 120 if (PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions) || 122 (findOption(localOptions, "-D") != null) || (findOption(localOptions, "-r") != null)) { 125 new PruneFolderVisitor().visit(session, resources); 127 } 128 129 return status; 130 } 131 132 135 protected IStatus doExecute(Session session, GlobalOption[] globalOptions, 136 LocalOption[] localOptions, String [] arguments, ICommandOutputListener listener, 137 IProgressMonitor monitor) throws CVSException { 138 monitor.beginTask(null, 100); 139 140 if ( ! FETCH_MODULE_ALIASES.isElementOf(localOptions)) { 141 IStatus status = Request.EXPAND_MODULES.execute(session, arguments, Policy.subMonitorFor(monitor, 10)); 144 if (status.getCode() == CVSStatus.SERVER_ERROR) 145 return status; 146 147 if (findOption(localOptions, "-d") == null) { if ( ! DO_NOT_SHORTEN.isElementOf(localOptions)) { 151 LocalOption[] newLocalOptions = new LocalOption[localOptions.length + 1]; 152 newLocalOptions[0] = DO_NOT_SHORTEN; 153 System.arraycopy(localOptions, 0, newLocalOptions, 1, localOptions.length); 154 localOptions = newLocalOptions; 155 } 156 } 157 } 158 159 return super.doExecute(session, globalOptions, localOptions, arguments, listener, Policy.subMonitorFor(monitor, 90)); 160 } 161 162 165 public RemoteModule[] getRemoteModules(Session session, CVSTag tag, IProgressMonitor monitor) 166 throws CVSException { 167 168 ModuleDefinitionsListener moduleDefinitionListener = new ModuleDefinitionsListener(); 169 170 IStatus status = super.execute(session, NO_GLOBAL_OPTIONS, new LocalOption[] {FETCH_MODULE_ALIASES}, NO_ARGUMENTS, 171 moduleDefinitionListener, monitor); 172 173 if (status.getCode() == CVSStatus.SERVER_ERROR) { 174 throw new CVSServerException(status); 175 } 176 177 return RemoteModule.createRemoteModules(moduleDefinitionListener.getModuleExpansions(), session.getCVSRepositoryLocation(), tag); 178 } 179 180 protected String getDisplayText() { 181 return "checkout"; } 183 } 184 | Popular Tags |