Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2003-08-14 18:50:35 +0000
committerMichael Valenta2003-08-14 18:50:35 +0000
commitb959280f790f2a87455a10b65f693872a0ddf2fd (patch)
tree245c306e4b0c02b661251172da001ceb5401e9d0
parentf2b85cb1f058c4b0c740aaa1141cd23407b0fcdb (diff)
downloadeclipse.platform.team-b959280f790f2a87455a10b65f693872a0ddf2fd.tar.gz
eclipse.platform.team-b959280f790f2a87455a10b65f693872a0ddf2fd.tar.xz
eclipse.platform.team-b959280f790f2a87455a10b65f693872a0ddf2fd.zip
Removed use of Session.run()
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java298
1 files changed, 163 insertions, 135 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java
index da491c47e..4e6dcf3f1 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java
@@ -67,6 +67,64 @@ import org.eclipse.team.internal.ccvs.core.util.Util;
*/
public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, ICVSFolder {
+ private final class FolderMembersUpdateListener implements IUpdateMessageListener {
+ List newRemoteDirectories = new ArrayList();
+ List newRemoteFiles = new ArrayList();
+ boolean exists = true;
+ List exceptions = new ArrayList();
+ protected List getExceptions() {
+ return exceptions;
+ }
+ protected List getNewRemoteDirectories() {
+ return newRemoteDirectories;
+ }
+ protected List getNewRemoteFiles() {
+ return newRemoteFiles;
+ }
+
+ public void directoryInformation(ICVSFolder commandRoot, String stringPath, boolean newDirectory) {
+ try {
+ IPath path = getRelativePathFromRootRelativePath(commandRoot, new Path(stringPath));
+ if (newDirectory && path.segmentCount() == 1) {
+ newRemoteDirectories.add(path.lastSegment());
+ }
+ } catch (CVSException e) {
+ exceptions.add(e);
+ }
+ }
+ public void directoryDoesNotExist(ICVSFolder parent, String stringPath) {
+ try {
+ IPath path = getRelativePathFromRootRelativePath(parent, new Path(stringPath));
+ if (path.isEmpty()) {
+ // the remote folder doesn't exist
+ exists = false;
+ }
+ } catch (CVSException e) {
+ exceptions.add(e);
+ }
+ }
+ public void fileInformation(int type, ICVSFolder parent, String filename) {
+ try {
+ IPath filePath = new Path(filename);
+ filePath = getRelativePathFromRootRelativePath(parent, filePath);
+ if( filePath.segmentCount() == 1 ) {
+ String properFilename = filePath.lastSegment();
+ newRemoteFiles.add(properFilename);
+ }
+ } catch (CVSException e) {
+ exceptions.add(e);
+ }
+ }
+ public void fileDoesNotExist(ICVSFolder parent, String filename) {
+ }
+ public boolean foundChildren() {
+ return newRemoteDirectories.size() + newRemoteFiles.size() != 0;
+ }
+ public boolean parentFolderExists() {
+ return exists;
+ }
+ }
+
protected FolderSyncInfo folderInfo;
private ICVSRemoteResource[] children;
private ICVSRepositoryLocation repository;
@@ -117,22 +175,27 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC
};
// Perform a "cvs status..." with a listener
+ monitor = Policy.monitorFor(monitor);
+ monitor.beginTask(null, 100);
QuietOption quietness = CVSProviderPlugin.getPlugin().getQuietness();
try {
CVSProviderPlugin.getPlugin().setQuietness(Command.VERBOSE);
- Session.run(getRepository(), this, false, new ICVSRunnable() {
- public void run(IProgressMonitor monitor) throws CVSException {
- IStatus status = Command.STATUS.execute(
- Command.NO_GLOBAL_OPTIONS,
- Command.NO_LOCAL_OPTIONS,
- files,
- new StatusListener(listener),
- monitor);
- if (status.getCode() == CVSStatus.SERVER_ERROR) {
- throw new CVSServerException(status);
- }
+ Session session = new Session(getRepository(), this, false /* output to console */);
+ session.open(Policy.subMonitorFor(monitor, 10));
+ try {
+ IStatus status = Command.STATUS.execute(
+ session,
+ Command.NO_GLOBAL_OPTIONS,
+ Command.NO_LOCAL_OPTIONS,
+ files,
+ new StatusListener(listener),
+ Policy.subMonitorFor(monitor, 90));
+ if (status.getCode() == CVSStatus.SERVER_ERROR) {
+ throw new CVSServerException(status);
}
- }, monitor);
+ } finally {
+ session.close();
+ }
} finally {
CVSProviderPlugin.getPlugin().setQuietness(quietness);
}
@@ -282,139 +345,104 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC
children = null;
// Create the listener for remote files and folders
- final List newRemoteDirectories = new ArrayList();
- final List newRemoteFiles = new ArrayList();
- final boolean[] exists = new boolean[] {true};
- final List exceptions = new ArrayList();
- final IUpdateMessageListener listener = new IUpdateMessageListener() {
- public void directoryInformation(ICVSFolder commandRoot, String stringPath, boolean newDirectory) {
- try {
- IPath path = getRelativePathFromRootRelativePath(commandRoot, new Path(stringPath));
- if (newDirectory && path.segmentCount() == 1) {
- newRemoteDirectories.add(path.lastSegment());
- progress.subTask(path.lastSegment().toString());
- progress.worked(1);
- }
- } catch (CVSException e) {
- exceptions.add(e);
- }
- }
- public void directoryDoesNotExist(ICVSFolder parent, String stringPath) {
- try {
- IPath path = getRelativePathFromRootRelativePath(parent, new Path(stringPath));
- if (path.isEmpty()) {
- // the remote folder doesn't exist
- exists[0] = false;
- }
- } catch (CVSException e) {
- exceptions.add(e);
- }
+ FolderMembersUpdateListener listener = new FolderMembersUpdateListener();
+
+ // Perform an update to retrieve the child files and folders
+ IStatus status = performUpdate(tag, listener, Policy.subMonitorFor(progress, 50));
+
+ if (status.getCode() == CVSStatus.SERVER_ERROR) {
+ // Only throw the exception if no files or folders were found
+ if (!listener.foundChildren()) {
+ throw new CVSServerException(status);
+ } else {
+ CVSProviderPlugin.log(new CVSServerException(status));
}
- public void fileInformation(int type, ICVSFolder parent, String filename) {
- try {
- IPath filePath = new Path(filename);
- filePath = getRelativePathFromRootRelativePath(parent, filePath);
- if( filePath.segmentCount() == 1 ) {
- String properFilename = filePath.lastSegment();
- newRemoteFiles.add(properFilename);
- progress.subTask(properFilename);
- progress.worked(1);
- }
- } catch (CVSException e) {
- exceptions.add(e);
+
+ }
+ if (! listener.parentFolderExists()) {
+ throw new CVSException(new CVSStatus(CVSStatus.ERROR, CVSStatus.DOES_NOT_EXIST, Policy.bind("RemoteFolder.doesNotExist", getRepositoryRelativePath()))); //$NON-NLS-1$
+ }
+
+ // Report any internal exceptions that occured fetching the members
+ if ( ! listener.getExceptions().isEmpty()) {
+ if (listener.getExceptions().size() == 1) {
+ throw (CVSException)listener.getExceptions().get(0);
+ } else {
+ MultiStatus multi = new MultiStatus(CVSProviderPlugin.ID, 0, Policy.bind("RemoteFolder.errorFetchingMembers"), null); //$NON-NLS-1$
+ for (int i = 0; i < listener.getExceptions().size(); i++) {
+ multi.merge(((CVSException)listener.getExceptions().get(i)).getStatus());
}
+ throw new CVSException(multi);
}
- public void fileDoesNotExist(ICVSFolder parent, String filename) {
- }
- };
+ }
+
+ // Convert the file names to remote resources
+ Policy.checkCanceled(monitor);
+ List result = new ArrayList();
+ List remoteFiles = new ArrayList();
+ for (int i=0;i<listener.getNewRemoteFiles().size();i++) {
+ RemoteFile newFile = new RemoteFile(RemoteFolder.this, Update.STATE_NONE, (String)listener.getNewRemoteFiles().get(i), tag);
+ result.add(newFile);
+ remoteFiles.add(newFile);
+ }
+ // Convert the folder names to remote resources
+ for (int i=0;i<listener.getNewRemoteDirectories().size();i++)
+ result.add(new RemoteFolder(RemoteFolder.this, getRepository(), Util.appendPath(getRepositoryRelativePath(), (String)listener.getNewRemoteDirectories().get(i)), tag));
+ children = (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[0]);
+
+ // Get the revision numbers for the files
+ if (remoteFiles.size() > 0) {
+ updateFileRevisions((ICVSFile[])remoteFiles.toArray(new ICVSFile[remoteFiles.size()]),
+ Policy.subMonitorFor(progress, 50));
+ } else {
+ progress.worked(50);
+ }
+ } catch (CVSServerException e) {
+ if ( ! e.isNoTagException() && e.containsErrors())
+ throw e;
+ if (tag == null)
+ throw e;
+ // we now know that this is an exception caused by a cvs bug.
+ // if the folder has no files in it (just subfolders) cvs does not respond with the subfolders...
+ // workaround: retry the request with no tag to get the directory names (if any)
+ Policy.checkCanceled(progress);
+ children = getMembers(null, Policy.subMonitorFor(progress, 20));
+ // the returned children must be given the original tag
+ for (int i = 0; i < children.length; i++) {
+ ICVSRemoteResource remoteResource = children[i];
+ if(remoteResource.isContainer()) {
+ ((RemoteFolder)remoteResource).setTag(tag);
+ }
+ }
+ } finally {
+ progress.done();
+ }
+
+ // We need to remember the children that were fetched in order to support file
+ // operations that depend on the parent knowing about the child (i.e. RemoteFile#getContents)
+ return children;
+ }
+
+ private IStatus performUpdate(CVSTag tag, IUpdateMessageListener listener, IProgressMonitor progress) throws CVSException {
+ progress.beginTask(null, 100);
+ Session session = new Session(getRepository(), this, false /* output to console */);
+ session.open(Policy.subMonitorFor(progress, 10));
+ try {
// Build the local options
final List localOptions = new ArrayList();
localOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES);
if (tag != null) localOptions.add(Update.makeTagOption(tag));
- // Retrieve the children and any file revision numbers in a single connection
- try {
- Session.run(getRepository(), this, false, new ICVSRunnable() {
- public void run(IProgressMonitor monitor) throws CVSException {
- // Perform a "cvs -n update -d -r tagName folderName"
- monitor.beginTask(null, 100); //$NON-NLS-1$
- IStatus status = Command.UPDATE.execute(
- new GlobalOption[] { Command.DO_NOT_CHANGE },
- (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]),
- new ICVSResource[] { RemoteFolder.this },
- new UpdateListener(listener),
- Policy.subMonitorFor(monitor, 60));
- if (status.getCode() == CVSStatus.SERVER_ERROR) {
- // Only throw the exception if no files or folders were found
- if (newRemoteDirectories.size() + newRemoteFiles.size() == 0) {
- throw new CVSServerException(status);
- } else {
- CVSProviderPlugin.log(new CVSServerException(status));
- }
-
- }
- if (! exists[0]) {
- throw new CVSException(new CVSStatus(CVSStatus.ERROR, CVSStatus.DOES_NOT_EXIST, Policy.bind("RemoteFolder.doesNotExist", getRepositoryRelativePath()))); //$NON-NLS-1$
- }
- // Report any internal exceptions that occured fetching the members
- if ( ! exceptions.isEmpty()) {
- if (exceptions.size() == 1) {
- throw (CVSException)exceptions.get(0);
- } else {
- MultiStatus multi = new MultiStatus(CVSProviderPlugin.ID, 0, Policy.bind("RemoteFolder.errorFetchingMembers"), null); //$NON-NLS-1$
- for (int i = 0; i < exceptions.size(); i++) {
- multi.merge(((CVSException)exceptions.get(i)).getStatus());
- }
- throw new CVSException(multi);
- }
- }
- // Convert the file names to remote resources
- Policy.checkCanceled(monitor);
- List result = new ArrayList();
- List remoteFiles = new ArrayList();
- for (int i=0;i<newRemoteFiles.size();i++) {
- RemoteFile newFile = new RemoteFile(RemoteFolder.this, Update.STATE_NONE, (String)newRemoteFiles.get(i), tag);
- result.add(newFile);
- remoteFiles.add(newFile);
- }
- // Convert the folder names to remote resources
- for (int i=0;i<newRemoteDirectories.size();i++)
- result.add(new RemoteFolder(RemoteFolder.this, getRepository(), Util.appendPath(getRepositoryRelativePath(), (String)newRemoteDirectories.get(i)), tag));
- children = (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[0]);
- // Get the revision numbers for the files
- if (remoteFiles.size() > 0) {
- updateFileRevisions((ICVSFile[])remoteFiles.toArray(new ICVSFile[remoteFiles.size()]),
- Policy.subMonitorFor(monitor, 40));
- } else {
- monitor.worked(40);
- }
- }
- }, Policy.subMonitorFor(progress, 80));
- } catch (CVSServerException e) {
- if ( ! e.isNoTagException() && e.containsErrors())
- throw e;
- if (tag == null)
- throw e;
- // we now know that this is an exception caused by a cvs bug.
- // if the folder has no files in it (just subfolders) cvs does not respond with the subfolders...
- // workaround: retry the request with no tag to get the directory names (if any)
- Policy.checkCanceled(progress);
- children = getMembers(null, Policy.subMonitorFor(progress, 20));
- // the returned children must be given the original tag
- for (int i = 0; i < children.length; i++) {
- ICVSRemoteResource remoteResource = children[i];
- if(remoteResource.isContainer()) {
- ((RemoteFolder)remoteResource).setTag(tag);
- }
- }
- }
-
- // We need to remember the children that were fetched in order to support file
- // operations that depend on the parent knowing about the child (i.e. RemoteFile#getContents)
- return children;
+ return Command.UPDATE.execute(
+ session,
+ new GlobalOption[] { Command.DO_NOT_CHANGE },
+ (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]),
+ new ICVSResource[] { RemoteFolder.this },
+ new UpdateListener(listener),
+ Policy.subMonitorFor(progress, 90));
} finally {
- progress.done();
+ session.close();
}
}

Back to the top