1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.osgi.util.NLS; 22 import org.eclipse.team.core.RepositoryProvider; 23 import org.eclipse.team.internal.ccvs.core.*; 24 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; 25 import org.eclipse.team.internal.ccvs.core.client.listeners.UpdateListener; 26 27 public class Update extends Command { 28 29 public static final LocalOption CLEAR_STICKY = new LocalOption("-A"); public static final LocalOption IGNORE_LOCAL_CHANGES = new LocalOption("-C"); public static final LocalOption RETRIEVE_ABSENT_DIRECTORIES = new LocalOption("-d"); public static final LocalOption JOIN = new LocalOption("-j"); 34 35 private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new UpdateListener(null); 36 37 38 public static final int STATE_NONE = 0; public static final int STATE_ADDED_LOCAL = 1; public static final int STATE_UNKOWN = 2; public static final int STATE_REMOTE_CHANGES = 3; public static final int STATE_DELETED = 4; public static final int STATE_MODIFIED = 5; public static final int STATE_CONFLICT = 6; public static final int STATE_MERGEABLE_CONFLICT = 7; 47 51 public static LocalOption makeTagOption(CVSTag tag) { 52 int type = tag.getType(); 53 switch (type) { 54 case CVSTag.HEAD: 55 return CLEAR_STICKY; 56 default: 57 return Command.makeTagOption(tag); 58 } 59 } 60 61 protected Update() { } 62 protected String getRequestId() { 63 return "update"; } 65 66 protected ICommandOutputListener getDefaultCommandOutputListener() { 67 return DEFAULT_OUTPUT_LISTENER; 68 } 69 70 protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, 71 LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) 72 throws CVSException { 73 74 sendFileStructure(session, resources, localOptions, true, monitor); 77 return resources; 78 } 79 80 83 protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, 84 LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, 85 IStatus status) throws CVSException { 86 if (status.getCode() == CVSStatus.SERVER_ERROR) { 88 return status; 89 } 90 91 if (PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions)) { 96 new PruneFolderVisitor().visit(session, resources); 98 99 } 100 return status; 101 } 102 103 protected LocalOption[] filterLocalOptions(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions) { 104 List newOptions = new ArrayList (Arrays.asList(localOptions)); 105 106 if (shouldRetrieveAbsentDirectories(session) && ! RETRIEVE_ABSENT_DIRECTORIES.isElementOf(localOptions)) { 107 newOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES); 108 } 109 110 if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories() && ! PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions)) { 112 if (! DO_NOT_CHANGE.isElementOf(globalOptions)) { 113 newOptions.add(Command.PRUNE_EMPTY_DIRECTORIES); 114 } 115 } 116 localOptions = (LocalOption[]) newOptions.toArray(new LocalOption[newOptions.size()]); 117 return super.filterLocalOptions(session, globalOptions, localOptions); 118 } 119 120 125 protected boolean shouldRetrieveAbsentDirectories(Session session) { 126 IResource resource = null; 128 RepositoryProvider provider = null; 129 try { 131 resource = session.getLocalRoot().getIResource(); 132 if (resource != null) { 133 provider = RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId()); 134 if (provider != null) { 135 if (((CVSTeamProvider)provider).getFetchAbsentDirectories()) { 136 return true; 137 } 138 } 139 } 140 } catch (CVSException e) { 141 CVSProviderPlugin.log(e); 142 } 143 if (provider == null) { 145 if (CVSProviderPlugin.getPlugin().getFetchAbsentDirectories()) { 146 return true; 147 } 148 } 149 return false; 150 } 151 152 157 protected void checkResourcesManaged(Session session, ICVSResource[] resources) throws CVSException { 158 for (int i = 0; i < resources.length; ++i) { 159 ICVSFolder folder; 160 if (resources[i].isFolder()) { 161 if (((ICVSFolder)resources[i]).isCVSFolder()) { 162 folder = (ICVSFolder)resources[i]; 163 } else { 164 folder = resources[i].getParent(); 165 } 166 } 167 else { 168 folder = resources[i].getParent(); 169 } 170 if (folder==null || (!folder.isCVSFolder() && folder.exists())) { 171 if (folder == null) 172 folder = (ICVSFolder)resources[i]; 173 IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR,NLS.bind(CVSMessages.Command_argumentNotManaged, new String [] { folder.getName() }),session.getLocalRoot()); 174 throw new CVSException(status); 175 } 176 } 177 } 178 179 182 protected IStatus doExecute( 183 Session session, 184 GlobalOption[] globalOptions, 185 LocalOption[] localOptions, 186 String [] arguments, 187 ICommandOutputListener listener, 188 IProgressMonitor monitor) 189 throws CVSException { 190 191 session.setIgnoringLocalChanges(IGNORE_LOCAL_CHANGES.isElementOf(localOptions)); 192 try { 193 return super.doExecute( 194 session, 195 globalOptions, 196 localOptions, 197 arguments, 198 listener, 199 monitor); 200 } finally { 201 session.setIgnoringLocalChanges(false); 202 } 203 204 } 205 206 } 207 | Popular Tags |