1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import org.eclipse.core.resources.*; 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.swt.widgets.Shell; 17 import org.eclipse.team.core.RepositoryProvider; 18 import org.eclipse.team.core.TeamException; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.client.Command; 21 import org.eclipse.team.internal.ccvs.core.client.Session; 22 import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; 23 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 24 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderTree; 25 import org.eclipse.team.internal.ccvs.ui.*; 26 import org.eclipse.team.internal.ccvs.ui.Policy; 27 28 31 public class ShareProjectOperation extends CVSOperation { 32 33 private ICVSRepositoryLocation location; 34 private IProject project; 35 private String moduleName; 36 private Shell shell; 37 38 public ShareProjectOperation(Shell shell, ICVSRepositoryLocation location, IProject project, String moduleName) { 39 super(null); 40 this.shell = shell; 41 this.moduleName = moduleName; 42 this.project = project; 43 this.location = location; 44 } 45 46 49 protected void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 50 try { 51 monitor.beginTask(getTaskName(), 100); 52 final ICVSRemoteFolder remote = createRemoteFolder(Policy.subMonitorFor(monitor, 50)); 54 final TeamException[] exception = new TeamException[] {null}; 56 ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { 57 public void run(IProgressMonitor monitor) throws CoreException { 58 try { 59 mapProjectToRemoteFolder(remote, monitor); 60 } catch (TeamException e) { 61 exception[0] = e; 62 } 63 } 64 }, ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(project), 0, Policy.subMonitorFor(monitor, 100)); 65 if (exception[0] != null) 66 throw exception[0]; 67 } catch (CoreException e) { 68 throw CVSException.wrapException(e); 69 } finally { 70 monitor.done(); 71 } 72 } 73 74 82 protected ICVSRemoteFolder createRemoteFolder(IProgressMonitor monitor) throws CVSException { 83 String projectName = project.getName(); 84 if (moduleName == null) 85 moduleName = projectName; 86 87 RemoteFolderTree root = new RemoteFolderTree(null, location, Path.EMPTY.toString(), null); 88 Path path = new Path(null, moduleName); 89 90 try { 91 monitor.beginTask(getTaskName(), 100 * path.segmentCount()); 92 return ensureTreeExists(root, path, monitor); 93 } catch (TeamException e) { 94 throw CVSException.wrapException(e); 95 } finally { 96 monitor.done(); 97 } 98 } 99 100 109 protected void mapProjectToRemoteFolder(final ICVSRemoteFolder remote, IProgressMonitor monitor) throws TeamException { 110 monitor.beginTask(null, IProgressMonitor.UNKNOWN); 111 purgeAnyCVSFolders(Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN)); 112 monitor.subTask(NLS.bind(CVSUIMessages.ShareProjectOperation_3, new String [] { project.getName(), remote.getRepositoryRelativePath() })); 114 ICVSFolder folder = (ICVSFolder)CVSWorkspaceRoot.getCVSResourceFor(project); 115 folder.setFolderSyncInfo(remote.getFolderSyncInfo()); 116 RepositoryProvider.map(project, CVSProviderPlugin.getTypeId()); 118 monitor.done(); 119 } 120 121 124 private RemoteFolderTree createChild(RemoteFolderTree parent, String name, IProgressMonitor monitor) throws CVSException, TeamException { 125 RemoteFolderTree child = new RemoteFolderTree(parent, name, location, new Path(null, parent.getRepositoryRelativePath()).append(name).toString(), null); 126 parent.setChildren(new ICVSRemoteResource[] { child }); 127 if (child.exists(Policy.subMonitorFor(monitor, 50))) { 128 return (RemoteFolderTree)parent.getFolder(name); 130 } else { 131 createFolder(child, Policy.subMonitorFor(monitor, 50)); 133 return child; 134 } 135 } 136 137 140 private ICVSRemoteFolder ensureTreeExists(RemoteFolderTree folder, IPath path, IProgressMonitor monitor) throws TeamException { 141 if (path.isEmpty()) return folder; 142 String name = path.segment(0); 143 RemoteFolderTree child = createChild(folder, name, monitor); 144 return ensureTreeExists(child, path.removeFirstSegments(1), monitor); 145 } 146 147 private void createFolder(RemoteFolderTree folder, IProgressMonitor monitor) throws TeamException { 148 Session s = new Session(location, folder.getParent()); 149 s.open(monitor, true ); 150 try { 151 IStatus status = Command.ADD.execute(s, 152 Command.NO_GLOBAL_OPTIONS, 153 Command.NO_LOCAL_OPTIONS, 154 new String [] { folder.getName() }, 155 null, 156 monitor); 157 if (status.getCode() == CVSStatus.SERVER_ERROR || ! status.isOK()) { 159 throw new CVSServerException(status); 160 } 161 } finally { 162 s.close(); 163 } 164 } 165 166 169 protected String getTaskName() { 170 return NLS.bind(CVSUIMessages.ShareProjectOperation_0, new String [] { project.getName(), moduleName }); 171 } 172 173 176 public IProject getProject() { 177 return project; 178 } 179 180 183 public Shell getShell() { 184 return shell; 185 } 186 187 192 private void purgeAnyCVSFolders(final IProgressMonitor monitor) { 193 try { 194 monitor.beginTask(null, IProgressMonitor.UNKNOWN); 195 ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor(project); 196 folder.accept(new ICVSResourceVisitor() { 197 public void visitFile(ICVSFile file) throws CVSException { 198 } 200 public void visitFolder(ICVSFolder folder) throws CVSException { 201 monitor.subTask(NLS.bind(CVSUIMessages.ShareProjectOperation_2, new String [] { folder.getIResource().getFullPath().toString() } )); 202 if (folder.isCVSFolder()) { 203 folder.unmanage(null); 205 } 206 } 207 }, true ); 208 } catch (CVSException e) { 209 CVSUIPlugin.log(e); 211 } finally { 212 monitor.done(); 213 } 214 } 215 } 216 | Popular Tags |