1 12 package org.eclipse.team.internal.ccvs.ui.operations; 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.lang.reflect.InvocationTargetException ; 17 18 import org.eclipse.core.resources.*; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.team.core.TeamException; 22 import org.eclipse.team.internal.ccvs.core.*; 23 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; 24 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 25 import org.eclipse.team.internal.ccvs.ui.Policy; 26 import org.eclipse.ui.IWorkbenchPart; 27 28 47 public class ProjectMetaFileOperation extends CVSOperation { 48 49 private ICVSRemoteFolder[] remoteFolders; 50 private boolean metaFileExists; 51 private boolean retrieveContent; 52 53 57 public static ICVSRemoteFolder[] updateFoldersWithProjectName(IWorkbenchPart part, ICVSRemoteFolder[] folders) 58 throws InvocationTargetException , InterruptedException { 59 ProjectMetaFileOperation op = new ProjectMetaFileOperation(part, folders, true ); 60 op.run(); 61 return op.getUpdatedFolders(); 62 } 63 64 public ProjectMetaFileOperation(IWorkbenchPart part, ICVSRemoteFolder[] remoteFolders, boolean retrieveContent) { 65 super(part); 66 this.remoteFolders = remoteFolders; 67 this.retrieveContent = retrieveContent; 68 } 69 70 75 private void checkForMetafileAndUpdateFoldersWithRemoteProjectName(ICVSRemoteFolder[] folders, IProgressMonitor monitor) throws CVSException { 76 metaFileExists = false; 77 monitor.beginTask(null, folders.length*100); 78 for (int i = 0; i < folders.length; i++) { 79 ICVSRemoteFolder folder = (ICVSRemoteFolder) folders[i].forTag(folders[i].getTag()); 83 84 try { 85 folder.members(Policy.subMonitorFor(monitor, 50)); 86 } catch (TeamException e) { 87 throw CVSException.wrapException(e); 88 } 89 InputStream in = null; 93 try { 94 ICVSRemoteFile remote = (ICVSRemoteFile) folder.getFile(".project"); metaFileExists = true; 97 if (retrieveContent && folder instanceof RemoteFolder) { 99 RemoteFolder rf = (RemoteFolder) folder; 100 101 in = remote.getContents(Policy.subMonitorFor(monitor, 50)); 103 if (in == null || monitor.isCanceled()) { 104 break; 105 } 106 IWorkspace workspace = ResourcesPlugin.getWorkspace(); 107 IProjectDescription projectDesc = workspace.loadProjectDescription(in); 108 109 RemoteProjectFolder rpf = new RemoteProjectFolder(rf, projectDesc.getName()); 112 folders[i] = rpf; 114 } 115 } catch (TeamException e) { 116 } catch (CoreException e) { 119 } finally { 123 try { 124 if (in != null) { 125 in.close(); 126 } 127 } catch (IOException e) { 128 } 130 } 131 } 132 monitor.done(); 133 } 134 135 136 139 public void execute(IProgressMonitor monitor) throws CVSException, InterruptedException { 140 checkForMetafileAndUpdateFoldersWithRemoteProjectName(remoteFolders, monitor); 141 } 142 143 148 public boolean metaFileExists() { 149 return metaFileExists; 150 } 151 152 158 public ICVSRemoteFolder[] getUpdatedFolders() { 159 return remoteFolders; 160 } 161 162 165 protected String getTaskName() { 166 return CVSUIMessages.ProjectMetaFile_taskName; 167 } 168 169 172 public boolean canRunAsJob() { 173 return false; 175 } 176 } 177 | Popular Tags |