1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 14 import org.eclipse.core.resources.*; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.team.internal.ccvs.core.*; 18 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; 19 import org.eclipse.team.internal.ccvs.core.util.Util; 20 21 26 public abstract class ResponseHandler { 27 31 public abstract String getResponseID(); 32 33 57 public abstract void handle(Session session, String argument, 58 IProgressMonitor monitor) throws CVSException; 59 60 66 protected static ICVSFolder createFolder( 67 Session session, 68 String localDir, 69 String repositoryDir) throws CVSException { 70 71 ICVSFolder folder = session.getLocalRoot().getFolder(localDir); 72 if (!folder.exists() 73 && (!CVSProviderPlugin.getPlugin().getPruneEmptyDirectories() 74 || !folder.getParent().isCVSFolder())) { 75 folder.mkdir(); 80 } 81 if (! folder.isCVSFolder()) { 82 String repositoryRoot = session.getRepositoryRoot(); 83 String relativePath; 84 if (repositoryDir.startsWith(repositoryRoot)) { 85 relativePath = Util.getRelativePath(repositoryRoot, repositoryDir); 87 } else { 88 relativePath = repositoryDir; 90 } 91 IResource resource = folder.getIResource(); 92 if (resource != null) { 93 IProject project = resource.getProject(); 94 if (project != null && project.isAccessible() && !CVSTeamProvider.isSharedWithCVS(project)) { 95 CVSTeamProvider.markAsTempShare(project); 98 } 99 } 100 try{ 101 folder.setFolderSyncInfo(new FolderSyncInfo( 102 relativePath, 103 session.getCVSRepositoryLocation().getLocation(false), 104 null, false)); 105 } catch (CVSException ex){ 106 IStatus status = ex.getStatus(); 107 if (status != null){ 108 if (status.getCode() == IResourceStatus.INVALID_VALUE){ 109 } else { 112 throw ex; 113 } 114 } 115 } 116 } 117 return folder; 118 } 119 120 protected ICVSFolder getExistingFolder(Session session, String localDir) throws CVSException { 121 ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); 122 if (! mParent.exists()) { 123 IContainer container = (IContainer)mParent.getIResource(); 125 if (container != null) { 126 try { 127 recreatePhantomFolders(mParent); 129 } catch (CVSException e) { 130 if (!handleInvalidResourceName(session, mParent, e)) { 131 throw e; 132 } 133 } 134 } 135 } 136 return mParent; 137 } 138 139 143 private void recreatePhantomFolders(ICVSFolder folder) throws CVSException { 144 ICVSFolder parent = folder.getParent(); 145 if (!parent.exists()) { 146 recreatePhantomFolders(parent); 147 } 148 folder.mkdir(); 149 } 150 151 155 ResponseHandler getInstance() { 156 return this; 157 } 158 159 protected boolean handleInvalidResourceName(Session session, ICVSResource resource, CVSException e) { 160 int code = e.getStatus().getCode(); 161 if (code == IResourceStatus.INVALID_VALUE 162 || code == IResourceStatus.INVALID_RESOURCE_NAME 163 || code == IResourceStatus.RESOURCE_NOT_FOUND 164 || code == IResourceStatus.RESOURCE_EXISTS 165 || code == IResourceStatus.RESOURCE_WRONG_TYPE 166 || code == IResourceStatus.CASE_VARIANT_EXISTS 167 || code == IResourceStatus.PATH_OCCUPIED) { 168 169 try { 170 IResource local = resource.getIResource(); 171 String path; 172 if (local == null) { 173 path = resource.getRepositoryRelativePath(); 174 } else { 175 path = local.getFullPath().toString(); 176 } 177 IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.INVALID_LOCAL_RESOURCE_PATH, NLS.bind(CVSMessages.ResponseHandler_0, new String [] { path, e.getMessage() }), e, session.getLocalRoot()); 178 session.handleResponseError(status); 179 } catch (CVSException e1) { 180 CVSProviderPlugin.log(e1); 181 } 182 return true; 183 } 184 return false; 185 } 186 } 187 188 | Popular Tags |