diff options
5 files changed, 126 insertions, 82 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java index 58f14e924..a50093edc 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java @@ -297,37 +297,43 @@ public class CVSTeamProvider extends RepositoryProvider { progress.beginTask(null, files.size() * 10 + (folders.isEmpty() ? 0 : 10)); try { if (!folders.isEmpty()) { - Session.run(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true, new ICVSRunnable() { - public void run(IProgressMonitor monitor) throws CVSException { - IStatus status = Command.ADD.execute( - Command.NO_GLOBAL_OPTIONS, - Command.NO_LOCAL_OPTIONS, - (ICVSResource[])folders.toArray(new ICVSResource[folders.size()]), - null, - monitor); - if (status.getCode() == CVSStatus.SERVER_ERROR) { - throw new CVSServerException(status); - } + Session session = new Session(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true); + session.open(Policy.subMonitorFor(progress, 2)); + try { + IStatus status = Command.ADD.execute( + session, + Command.NO_GLOBAL_OPTIONS, + Command.NO_LOCAL_OPTIONS, + (ICVSResource[])folders.toArray(new ICVSResource[folders.size()]), + null, + Policy.subMonitorFor(progress, 8)); + if (status.getCode() == CVSStatus.SERVER_ERROR) { + throw new CVSServerException(status); } - }, Policy.subMonitorFor(progress, 10)); + } finally { + session.close(); + } } for (Iterator it = files.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); final KSubstOption ksubst = (KSubstOption) entry.getKey(); final Set set = (Set) entry.getValue(); - Session.run(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true, new ICVSRunnable() { - public void run(IProgressMonitor monitor) throws CVSException { - IStatus status = Command.ADD.execute( - Command.NO_GLOBAL_OPTIONS, - new LocalOption[] { ksubst }, - (ICVSResource[])set.toArray(new ICVSResource[set.size()]), - null, - monitor); - if (status.getCode() == CVSStatus.SERVER_ERROR) { - throw new CVSServerException(status); - } + Session session = new Session(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true); + session.open(Policy.subMonitorFor(progress, 2)); + try { + IStatus status = Command.ADD.execute( + session, + Command.NO_GLOBAL_OPTIONS, + new LocalOption[] { ksubst }, + (ICVSResource[])set.toArray(new ICVSResource[set.size()]), + null, + Policy.subMonitorFor(progress, 8)); + if (status.getCode() == CVSStatus.SERVER_ERROR) { + throw new CVSServerException(status); } - }, Policy.subMonitorFor(progress, 10)); + } finally { + session.close(); + } } } finally { progress.done(); @@ -439,14 +445,14 @@ public class CVSTeamProvider extends RepositoryProvider { // Remove the files remotely IStatus status; Session s = new Session(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot()); - s.open(progress); + s.open(Policy.subMonitorFor(progress, 10)); try { status = Command.REMOVE.execute(s, Command.NO_GLOBAL_OPTIONS, Command.NO_LOCAL_OPTIONS, (String[])files.toArray(new String[files.size()]), null, - Policy.subMonitorFor(progress, 70)); + Policy.subMonitorFor(progress, 60)); } finally { s.close(); } @@ -526,9 +532,7 @@ public class CVSTeamProvider extends RepositoryProvider { * @param format * @throws CVSException */ - private void newFileDiff(final ICVSResource resource, final PrintStream stream, final boolean doNotRecurse, final int format) throws CVSException { - resource.accept(new ICVSResourceVisitor() { public void visitFile(ICVSFile file) throws CVSException { if (!(file.isIgnored() || file.isManaged())) { @@ -549,10 +553,10 @@ public class CVSTeamProvider extends RepositoryProvider { private void addFileToDiff(ICVSFile file, PrintStream stream, int format) throws CVSException { - String nullFilePrefix = ""; - String newFilePrefix = ""; - String positionInfo = ""; - String linePrefix = ""; + String nullFilePrefix = ""; //$NON-NLS-1$ + String newFilePrefix = ""; //$NON-NLS-1$ + String positionInfo = ""; //$NON-NLS-1$ + String linePrefix = ""; //$NON-NLS-1$ String pathString = file.getIResource().getProjectRelativePath().toString(); @@ -568,14 +572,14 @@ public class CVSTeamProvider extends RepositoryProvider { case UNIFIED_FORMAT : nullFilePrefix = "--- "; //$NON-NLS-1$ newFilePrefix = "+++ "; //$NON-NLS-1$ - positionInfo = "@@ -0,0 +1," + lines + " @@" ; //$NON-NLS-1$ + positionInfo = "@@ -0,0 +1," + lines + " @@" ; //$NON-NLS-1$ //$NON-NLS-2$ linePrefix = "+"; //$NON-NLS-1$ break; case CONTEXT_FORMAT : nullFilePrefix = "*** "; //$NON-NLS-1$ newFilePrefix = "--- "; //$NON-NLS-1$ - positionInfo = "--- 1," + lines + " ----"; //$NON-NLS-1$ + positionInfo = "--- 1," + lines + " ----"; //$NON-NLS-1$ //$NON-NLS-2$ linePrefix = "+ "; //$NON-NLS-1$ break; @@ -613,7 +617,7 @@ public class CVSTeamProvider extends RepositoryProvider { } } } catch (IOException e) { - throw new CVSException(Policy.bind("java.io.IOException", pathString)); + throw CVSException.wrapException(file.getIResource(), Policy.bind("CVSTeamProvider.errorAddingFileToDiff", pathString), e); //$NON-NLS-1$ } finally { try { fileReader.close(); @@ -1103,10 +1107,11 @@ public class CVSTeamProvider extends RepositoryProvider { /*** commit then admin the resources ***/ // compute the total work to be performed - int totalWork = filesToCommit.size(); + int totalWork = filesToCommit.size() + 1; for (Iterator it = filesToAdmin.values().iterator(); it.hasNext();) { List list = (List) it.next(); totalWork += list.size(); + totalWork += 1; // Add 1 for each connection that needs to be made } if (totalWork != 0) { monitor.beginTask(Policy.bind("CVSTeamProvider.settingKSubst"), totalWork); //$NON-NLS-1$ @@ -1115,21 +1120,25 @@ public class CVSTeamProvider extends RepositoryProvider { // NOTE: The files are committed as text with conversions even if the // resource sync info still says "binary". if (filesToCommit.size() != 0) { - Session.run(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true /* output to console */, - new ICVSRunnable( ) { - public void run(IProgressMonitor monitor) throws CVSException { - String keywordChangeComment = comment; - if (keywordChangeComment == null || keywordChangeComment.length() == 0) - keywordChangeComment = Policy.bind("CVSTeamProvider.changingKeywordComment"); //$NON-NLS-1$ - result[0] = Command.COMMIT.execute( - Command.NO_GLOBAL_OPTIONS, - new LocalOption[] { Commit.DO_NOT_RECURSE, Commit.FORCE, - Commit.makeArgumentOption(Command.MESSAGE_OPTION, keywordChangeComment) }, - (ICVSResource[]) filesToCommit.toArray(new ICVSResource[filesToCommit.size()]), - filesToCommitAsText, - null, Policy.subMonitorFor(monitor, filesToCommit.size())); - } - }, Policy.subMonitorFor(monitor, filesToCommit.size())); + Session session = new Session(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true /* output to console */); + session.open(Policy.subMonitorFor(monitor, 1)); + try { + String keywordChangeComment = comment; + if (keywordChangeComment == null || keywordChangeComment.length() == 0) + keywordChangeComment = Policy.bind("CVSTeamProvider.changingKeywordComment"); //$NON-NLS-1$ + result[0] = Command.COMMIT.execute( + session, + Command.NO_GLOBAL_OPTIONS, + new LocalOption[] { Commit.DO_NOT_RECURSE, Commit.FORCE, + Commit.makeArgumentOption(Command.MESSAGE_OPTION, keywordChangeComment) }, + (ICVSResource[]) filesToCommit.toArray(new ICVSResource[filesToCommit.size()]), + filesToCommitAsText, + null, + Policy.subMonitorFor(monitor, filesToCommit.size())); + } finally { + session.close(); + } + // if errors were encountered, abort if (! result[0].isOK()) return; } @@ -1145,16 +1154,19 @@ public class CVSTeamProvider extends RepositoryProvider { final KSubstOption toKSubst = (KSubstOption) entry.getKey(); final List list = (List) entry.getValue(); // do it - Session.run(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true /* output to console */, - new ICVSRunnable( ) { - public void run(IProgressMonitor monitor) throws CVSException { - result[0] = Command.ADMIN.execute(Command.NO_GLOBAL_OPTIONS, - new LocalOption[] { toKSubst }, - (ICVSResource[]) list.toArray(new ICVSResource[list.size()]), - new AdminKSubstListener(toKSubst), - Policy.subMonitorFor(monitor, list.size())); - } - }, Policy.subMonitorFor(monitor, list.size())); + Session session = new Session(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true /* output to console */); + session.open(Policy.subMonitorFor(monitor, 1)); + try { + result[0] = Command.ADMIN.execute( + session, + Command.NO_GLOBAL_OPTIONS, + new LocalOption[] { toKSubst }, + (ICVSResource[]) list.toArray(new ICVSResource[list.size()]), + new AdminKSubstListener(toKSubst), + Policy.subMonitorFor(monitor, list.size())); + } finally { + session.close(); + } // if errors were encountered, abort if (! result[0].isOK()) return; } @@ -1318,10 +1330,9 @@ public class CVSTeamProvider extends RepositoryProvider { * This method captures the common behavior between the edit and unedit methods. */ private void notifyEditUnedit(final IResource[] resources, final boolean recurse, final boolean notifyServer, final ICVSResourceVisitor editUneditVisitor, IProgressMonitor monitor) throws CVSException { - final IProgressMonitor progress = Policy.monitorFor(monitor); final CVSException[] exception = new CVSException[] { null }; IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() { - public void run(IProgressMonitor pm) throws CoreException { + public void run(IProgressMonitor monitor) throws CoreException { final ICVSResource[] cvsResources = getCVSArguments(resources); // mark the files locally as being checked out @@ -1336,27 +1347,33 @@ public class CVSTeamProvider extends RepositoryProvider { // send the noop command to the server in order to deliver the notifications if (notifyServer) { - final boolean[] connected = new boolean[] { false }; + monitor.beginTask(null, 100); + Session session = new Session(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true); try { - Session.run(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true, new ICVSRunnable() { - public void run(IProgressMonitor monitor) throws CVSException { - connected[0] = true; - Command.NOOP.execute(Command.NO_GLOBAL_OPTIONS, Command.NO_LOCAL_OPTIONS, - cvsResources, null, monitor); - } - }, progress); + session.open(Policy.subMonitorFor(monitor, 10)); + } catch (CVSException e1) { + // If the connection cannot be opened, just exit normally. + // The notifications will be sent when a connection can be made + return; + } + try { + Command.NOOP.execute( + session, + Command.NO_GLOBAL_OPTIONS, + Command.NO_LOCAL_OPTIONS, + cvsResources, + null, + Policy.subMonitorFor(monitor, 90)); } catch (CVSException e) { - // Only report the exception if we were able to connect. - // If we couldn't connect, the notification will be sent the next time we do. - if (connected[0]) exception[0] = e; + exception[0] = e; } finally { - progress.done(); + monitor.done(); } } } }; try { - ResourcesPlugin.getWorkspace().run(workspaceRunnable, monitor); + ResourcesPlugin.getWorkspace().run(workspaceRunnable, Policy.monitorFor(monitor)); } catch (CoreException e) { if (exception[0] == null) { throw CVSException.wrapException(e); diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java index 0b7541c74..6f0c3012e 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java @@ -630,7 +630,7 @@ public abstract class Command extends Request { */ public static LocalOption makeArgumentOption(LocalOption option, String argument) { if(argument == null) { - argument = ""; + argument = ""; //$NON-NLS-1$ } return new LocalOption(option.getOption(), argument); //$NON-NLS-1$ } @@ -724,6 +724,8 @@ public abstract class Command extends Request { * @param monitor the progress monitor * @return a status code indicating success or failure of the operation * @throws CVSException if a fatal error occurs (e.g. connection timeout) + * + * @deprecated */ public final IStatus execute(GlobalOption[] globalOptions, LocalOption[] localOptions, ICVSResource[] arguments, ICommandOutputListener listener, IProgressMonitor pm) throws CVSException { @@ -733,6 +735,29 @@ public abstract class Command extends Request { return execute(openSession, globalOptions, localOptions, stringArguments, listener, pm); } + /** + * Execute a CVS command on an array of ICVSResource. This method simply converts + * the ICVSResource to String paths relative to the local root of the session and + * invokes <code>execute(Session, GlobalOption[], LocalOption[], String[], ICommandOutputListener, IProgressMonitor)</code>. + * </p> + * @param session the open CVS session + * @param globalOptions the array of global options, or NO_GLOBAL_OPTIONS + * @param localOptions the array of local options, or NO_LOCAL_OPTIONS + * @param arguments the array of ICVSResource to be operated on + * @param listener the command output listener, or null to discard all messages + * @param monitor the progress monitor + * @return a status code indicating success or failure of the operation + * @throws CVSException if a fatal error occurs (e.g. connection timeout) + * + * @see Command#execute(Session, GlobalOption[], LocalOption[], String[], ICommandOutputListener, IProgressMonitor) + */ + public final IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, ICVSResource[] arguments, + ICommandOutputListener listener, IProgressMonitor pm) throws CVSException { + + String[] stringArguments = convertArgumentsForOpenSession(arguments, session); + return execute(session, globalOptions, localOptions, stringArguments, listener, pm); + } + protected Session getOpenSession(ICVSResource[] arguments) throws CVSException { // We assume that all the passed resources have the same root Session openSession; diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java index 463a91e7e..9bff4204f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java @@ -109,16 +109,15 @@ public class Commit extends Command { protected void sendArguments(Session session, String[] arguments) throws CVSException { } - public final IStatus execute(GlobalOption[] globalOptions, LocalOption[] localOptions, + public final IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, ICVSResource[] arguments, Collection filesToCommitAsText, ICommandOutputListener listener, IProgressMonitor pm) throws CVSException { - Session openSession = getOpenSession(arguments); - openSession.setTextTransferOverride(filesToCommitAsText); + session.setTextTransferOverride(filesToCommitAsText); try { - return super.execute(globalOptions, localOptions, arguments, listener, pm); + return super.execute(session, globalOptions, localOptions, arguments, listener, pm); } finally { - openSession.setTextTransferOverride(null); + session.setTextTransferOverride(null); } } } diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java index a5d3bb2c8..0f3971671 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java @@ -146,6 +146,8 @@ public class Session { * A session will be opened for the provided root. If the root is null, no session is opened. * However, sessions will be open for nested calls to run and these sessions will not be closed * until the outer most run finishes. + * + * @deprecated */ public static void run(final ICVSRepositoryLocation location, final ICVSFolder root, final boolean outputToConsole, final ICVSRunnable runnable, final IProgressMonitor monitor) throws CVSException { diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties index ec9d9cc4d..d14eae708 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties @@ -104,6 +104,7 @@ CVSTeamProvider.overlappingRemoteFolder=Cannot create linked resource ''{0}'' be CVSTeamProvider.overlappingFileDeletion=Cannot create linked resource ''{0}'' because a deletion for the file of that name has not been committed. CVSTeamProvider.errorGettingWatchEdit=Could not get "watch/edit" property for project ''{0}''. CVSTeamProvider.errorSettingWatchEdit=Could not set "watch/edit" property for project ''{0}''. +CVSTeamProvider.errorAddingFileToDiff=An I/O error occurred adding file ''{0}'' to the patch output. ProjectDescriptionManager.unableToSetDescription=An error occurred setting the project description ProjectDescriptionManager.unableToReadDescription=An error occurred reading the project description |