diff options
author | Michael Valenta | 2003-10-22 14:54:17 +0000 |
---|---|---|
committer | Michael Valenta | 2003-10-22 14:54:17 +0000 |
commit | 2eb76c226da3ac930122c29d1c16c7a3083697fe (patch) | |
tree | efb38d8e49e7df3c0f38cf2209c917dbd4cf8c30 /bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal | |
parent | a2286f98c4e2ef45800dfe7ba51a825ab564e2d5 (diff) | |
download | eclipse.platform.team-2eb76c226da3ac930122c29d1c16c7a3083697fe.tar.gz eclipse.platform.team-2eb76c226da3ac930122c29d1c16c7a3083697fe.tar.xz eclipse.platform.team-2eb76c226da3ac930122c29d1c16c7a3083697fe.zip |
41738: Comparing two remote versions can result in many connectionsRoot_SynchronizeViewPageBook20031011
Diffstat (limited to 'bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal')
16 files changed, 518 insertions, 26 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java index 48f244e15..8e66c0c7c 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java @@ -737,6 +737,10 @@ public class CVSProviderPlugin extends Plugin { Policy.DEBUG_CVS_PROTOCOL = value; } + public boolean isDebugProtocol() { + return Policy.DEBUG_CVS_PROTOCOL; + } + /* * Create the crash indicator file. This method returns true if the file * already existed, indicating that a crash occurred on the last invokation of 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 e8188540f..6bc313765 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 @@ -649,7 +649,11 @@ public class CVSTeamProvider extends RepositoryProvider { Session session = new Session(workspaceRoot.getRemoteLocation(), workspaceRoot.getLocalRoot(), true /* output to console */); session.open(Policy.subMonitorFor(progress,10), false /* read-only */); try { - new PrepareForReplaceVisitor().visitResources(getProject(), resources, "CVSTeamProvider.scrubbingResource", depth, Policy.subMonitorFor(progress, 20)); //$NON-NLS-1$ + ICVSResource[] cvsResources = new ICVSResource[resources.length]; + for (int i = 0; i < cvsResources.length; i++) { + cvsResources[i] = CVSWorkspaceRoot.getCVSResourceFor(resources[i]); + } + new PrepareForReplaceVisitor().visitResources(getProject(), cvsResources, "CVSTeamProvider.scrubbingResource", depth, Policy.subMonitorFor(progress, 20)); //$NON-NLS-1$ List options = new ArrayList(); options.add(Update.IGNORE_LOCAL_CHANGES); 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 f23cc3f59..afba8870a 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 @@ -45,6 +45,7 @@ public abstract class Command extends Request { public final static Checkout CHECKOUT = new CheckoutWithOverwrite(); public final static Commit COMMIT = new Commit(); public final static Diff DIFF = new Diff(); + public final static RDiff RDIFF = new RDiff(); public final static Editors EDITORS = new Editors(); public final static Import IMPORT = new Import(); public final static Log LOG = new Log(); diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java index 14d43e601..dc32ec188 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java @@ -27,6 +27,7 @@ public class Diff extends Command { public static final LocalOption UNIFIED_FORMAT = new LocalOption("-u"); //$NON-NLS-1$ public static final LocalOption CONTEXT_FORMAT = new LocalOption("-c"); //$NON-NLS-1$ public static final LocalOption INCLUDE_NEWFILES = new LocalOption("-N"); //$NON-NLS-1$ + public static final LocalOption BRIEF = new LocalOption("--brief"); //$NON-NLS-1$ protected Diff() { } protected String getRequestId() { diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RDiff.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RDiff.java new file mode 100644 index 000000000..de27da825 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RDiff.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.core.client; + +import org.eclipse.team.internal.ccvs.core.CVSTag; + +public class RDiff extends RemoteCommand { + + /*** Local options: specific to rdiff ***/ + public static final LocalOption SUMMARY = new LocalOption("-s", null); //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.client.Request#getRequestId() + */ + protected String getRequestId() { + return "rdiff"; //$NON-NLS-1$ + } + + /** + * Makes a -r or -D option for a tag. + * Valid for: checkout export history rdiff update + */ + public static LocalOption makeTagOption(CVSTag tag) { + if (tag == null) tag = CVSTag.DEFAULT; + int type = tag.getType(); + switch (type) { + case CVSTag.BRANCH: + case CVSTag.VERSION: + case CVSTag.HEAD: + return new LocalOption("-r", tag.getName()); //$NON-NLS-1$ + case CVSTag.DATE: + return new LocalOption("-D", tag.getName()); //$NON-NLS-1$ + default: + // Unknow tag type!!! + throw new IllegalArgumentException(); + } + } +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java index a83cca00b..0baca4b3a 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java @@ -98,8 +98,7 @@ public class RTag extends RemoteCommand { CVSTag sourceTag, CVSTag tag, ICVSRemoteResource[] arguments, IProgressMonitor monitor) throws CVSException { - ICVSResource[] resources = (ICVSResource[])Arrays.asList(arguments).toArray(new ICVSResource[arguments.length]); - String[] stringArguments = convertArgumentsForOpenSession(arguments); + String[] stringArguments = convertArgumentsForOpenSession(arguments, session); return execute(session, globalOptions, localOptions, sourceTag, tag, stringArguments, monitor); } diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoteCommand.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoteCommand.java index 3343962a7..bc99a257d 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoteCommand.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoteCommand.java @@ -15,7 +15,6 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource; import org.eclipse.team.internal.ccvs.core.ICVSResource; /** @@ -42,12 +41,20 @@ public abstract class RemoteCommand extends Command { // do nothing } - protected String[] convertArgumentsForOpenSession(ICVSRemoteResource[] arguments) throws CVSException { - // Convert arguments - List stringArguments = new ArrayList(arguments.length); - for (int i = 0; i < arguments.length; i++) { - stringArguments.add(arguments[i].getRepositoryRelativePath()); - } - return (String[]) stringArguments.toArray(new String[stringArguments.size()]); + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.client.Command#convertArgumentsForOpenSession(org.eclipse.team.internal.ccvs.core.ICVSResource[], org.eclipse.team.internal.ccvs.core.client.Session) + */ + protected String[] convertArgumentsForOpenSession( + ICVSResource[] arguments, + Session openSession) + throws CVSException { + + // Convert arguments + List stringArguments = new ArrayList(arguments.length); + for (int i = 0; i < arguments.length; i++) { + stringArguments.add(arguments[i].getRepositoryRelativePath()); + } + return (String[]) stringArguments.toArray(new String[stringArguments.size()]); } + } diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/CompareDiffListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/CompareDiffListener.java new file mode 100644 index 000000000..02e448576 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/CompareDiffListener.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.core.client.listeners; + +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; +import org.eclipse.team.internal.ccvs.core.CVSStatus; +import org.eclipse.team.internal.ccvs.core.ICVSFolder; +import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; + +/** + * This class interprets the output of "cvs diff --brief ..." in order to get the revisions + * of two compared versions of a project or folder. + */ +public class CompareDiffListener extends CommandOutputListener { + + private static ServerMessageLineMatcher LOCAL_FILE_MATCHER; + private static ServerMessageLineMatcher REMOTE_FILE_MATCHER; + private static ServerMessageLineMatcher REVISION_LINE_MATCHER; + + static { + try { + LOCAL_FILE_MATCHER = new ServerMessageLineMatcher( + "Index: (localFile:.*:localFile)", new String[] {"localFile"}); + REMOTE_FILE_MATCHER = new ServerMessageLineMatcher( + "RCS file: (remoteFile:.*:remoteFile),v", new String[] {"remoteFile"}); + REVISION_LINE_MATCHER = new ServerMessageLineMatcher( + "diff .* -r(leftRevision:.*:leftRevision) -r(rightRevision:.*:rightRevision)", new String[] {"leftRevision", "rightRevision"}); + } catch (CVSException e) { + // This is serious as the listener will not function properly + CVSProviderPlugin.log(e); + LOCAL_FILE_MATCHER = null; + REMOTE_FILE_MATCHER = null; + REVISION_LINE_MATCHER = null; + } + } + + private String localFilePath, remoteFilePath, leftRevision, rightRevision; + + private IFileDiffListener listener; + + public interface IFileDiffListener { + public void fileDiff( + String localFilePath, + String remoteFilePath, + String leftRevision, + String rightRevision); + } + + public CompareDiffListener(IFileDiffListener listener) { + this.listener = listener; + } + + public IStatus messageLine( + String line, + ICVSRepositoryLocation location, + ICVSFolder commandRoot, + IProgressMonitor monitor) { + // ignore any server messages + if (getServerMessage(line, location) != null) { + return OK; + } + Map map = LOCAL_FILE_MATCHER.processServerMessage(line); + if (map != null) { + localFilePath = (String)map.get("localFile"); + return OK; + } + map = REMOTE_FILE_MATCHER.processServerMessage(line); + if (map != null) { + remoteFilePath = (String)map.get("remoteFile"); + return OK; + } + map = REVISION_LINE_MATCHER.processServerMessage(line); + if (map != null) { + leftRevision = (String)map.get("leftRevision"); + rightRevision = (String)map.get("rightRevision"); + if (localFilePath == null || remoteFilePath == null) { + return new CVSStatus(IStatus.ERROR, "Unsupported message sequence received while comparing using CVS diff command"); + } + listener.fileDiff(localFilePath, remoteFilePath, leftRevision, rightRevision); + localFilePath = remoteFilePath = leftRevision = rightRevision = null; + return OK; + } + // Ignore all other lines + return OK; + } + + private IStatus handleUnknownDiffFormat(String line) { + return new CVSStatus(IStatus.ERROR, "Unknown message format received while comparing using CVS diff command: {0}" + line); + } + + public IStatus errorLine( + String line, + ICVSRepositoryLocation location, + ICVSFolder commandRoot, + IProgressMonitor monitor) { + // ignore server messages for now - this is used only with the diff + // request and the errors can be safely ignored. + if (getServerMessage(line, location) != null) { + return OK; + } + return super.errorLine(line, location, commandRoot, monitor); + } + +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IMessagePatterns.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IMessagePatterns.java new file mode 100644 index 000000000..e3207ec7c --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IMessagePatterns.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.core.client.listeners; + +import org.eclipse.team.internal.ccvs.core.util.Util; + +/** + * This class contains the default server message patterns + */ +public interface IMessagePatterns { + + public static final String SERVER_MESSAGE_PREFIX = "\\w* \\w*: "; //$NON-NLS-1$ + public static final String SERVER_ABORTED_MESSAGE_PREFIX = "\\w* [\\w* aborted]: "; //$NON-NLS-1$ + + // TODO: These patterns could be more specific but this would require non-capturing + // groups which currently throw off variable matching + public static final String TAG_PATTERN = "\\w*"; //$NON-NLS-1$ + public static final String REVISION_PATTERN = ".*"; //$NON-NLS-1$ + public static final String FILE_PATH_PATTERN = ".*"; //$NON-NLS-1$ + + // TODO: It would be better if the prefix was optional but this requires the use of a capturing group which throws the group count off + public static final String RDIFF_DIRECTORY = SERVER_MESSAGE_PREFIX + "Diffing " + Util.getVariablePattern(FILE_PATH_PATTERN, "remoteFolderPath"); //$NON-NLS-1$ //$NON-NLS-2$ + public static final String RDIFF_SUMMARY_FILE_DIFF = "File " + Util.getVariablePattern(FILE_PATH_PATTERN, "remoteFilePath") + " changed from revision " + Util.getVariablePattern(REVISION_PATTERN, "leftRevision") + " to " + Util.getVariablePattern(REVISION_PATTERN, "rightRevision"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ + public static final String RDIFF_SUMMARY_NEW_FILE = "File " + Util.getVariablePattern(FILE_PATH_PATTERN, "remoteFilePath") + " is new; " + TAG_PATTERN + " revision " + Util.getVariablePattern(REVISION_PATTERN, "rightRevision"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ + public static final String RDIFF_SUMMARY_DELETED_FILE = "File " + Util.getVariablePattern(FILE_PATH_PATTERN, "remoteFilePath") + " is removed; not included in release tag " + TAG_PATTERN; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + // This format was introduced in 1.11.7 + public static final String RDIFF_SUMMARY_DELETED_FILE2 = "File " + Util.getVariablePattern(FILE_PATH_PATTERN, "remoteFilePath") + " is removed; " + TAG_PATTERN + " revision " + Util.getVariablePattern(REVISION_PATTERN, "leftRevision"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/RDiffSummaryListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/RDiffSummaryListener.java new file mode 100644 index 000000000..29d2ec260 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/RDiffSummaryListener.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.core.client.listeners; + +import java.util.Map; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; +import org.eclipse.team.internal.ccvs.core.ICVSFolder; +import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; + +/** + * This class parses the messages recieved in response to an "cvs rdiff -s ..." command + */ +public class RDiffSummaryListener extends CommandOutputListener { + + private static final String RIGHT_REVISION_VARIABLE_NAME = "rightRevision"; //$NON-NLS-1$ + private static final String LEFT_REVISION_VARIABLE_NAME = "leftRevision"; //$NON-NLS-1$ + private static final String REMOTE_FILE_PATH_VARIABLE_NAME = "remoteFilePath"; //$NON-NLS-1$ + private static final String REMOTE_FOLDER_PATH_VARIABLE_NAME = "remoteFolderPath"; //$NON-NLS-1$ + + private IFileDiffListener listener; + private static ServerMessageLineMatcher DIRECTORY_MATCHER; + private static ServerMessageLineMatcher FILE_DIFF_MATCHER; + private static ServerMessageLineMatcher NEW_FILE_MATCHER; + private static ServerMessageLineMatcher DELETED_FILE_MATCHER; + private static ServerMessageLineMatcher DELETED_FILE_MATCHER2; + + static { + // TODO: temprary until proper lifecycle is defined + initializePatterns(); + } + public static void initializePatterns() { + try { + DIRECTORY_MATCHER = new ServerMessageLineMatcher( + IMessagePatterns.RDIFF_DIRECTORY, new String[] {REMOTE_FOLDER_PATH_VARIABLE_NAME}); + FILE_DIFF_MATCHER = new ServerMessageLineMatcher( + IMessagePatterns.RDIFF_SUMMARY_FILE_DIFF, new String[] {REMOTE_FILE_PATH_VARIABLE_NAME, LEFT_REVISION_VARIABLE_NAME, RIGHT_REVISION_VARIABLE_NAME}); + NEW_FILE_MATCHER = new ServerMessageLineMatcher( + IMessagePatterns.RDIFF_SUMMARY_NEW_FILE, new String[] {REMOTE_FILE_PATH_VARIABLE_NAME, RIGHT_REVISION_VARIABLE_NAME}); + DELETED_FILE_MATCHER = new ServerMessageLineMatcher( + IMessagePatterns.RDIFF_SUMMARY_DELETED_FILE, new String[] {REMOTE_FILE_PATH_VARIABLE_NAME}); + DELETED_FILE_MATCHER2 = new ServerMessageLineMatcher( + IMessagePatterns.RDIFF_SUMMARY_DELETED_FILE2, new String[] {REMOTE_FILE_PATH_VARIABLE_NAME, LEFT_REVISION_VARIABLE_NAME}); + } catch (CVSException e) { + // This is serious as the listener will not function properly + CVSProviderPlugin.log(e); + } + } + + public interface IFileDiffListener { + public void fileDiff( + String remoteFilePath, + String leftRevision, + String rightRevision); + public void newFile( + String remoteFilePath, + String rightRevision); + public void deletedFile( + String remoteFilePath, + String leftRevision); + public void directory(String remoteFolderPath); + } + + public RDiffSummaryListener(IFileDiffListener listener) { + this.listener = listener; + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener#messageLine(java.lang.String, org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, org.eclipse.team.internal.ccvs.core.ICVSFolder, org.eclipse.core.runtime.IProgressMonitor) + */ + public IStatus messageLine( + String line, + ICVSRepositoryLocation location, + ICVSFolder commandRoot, + IProgressMonitor monitor) { + + Map variables = FILE_DIFF_MATCHER.processServerMessage(line); + if (variables != null) { + listener.fileDiff( + (String)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME), + (String)variables.get(LEFT_REVISION_VARIABLE_NAME), + (String)variables.get(RIGHT_REVISION_VARIABLE_NAME)); + return OK; + } + + variables = NEW_FILE_MATCHER.processServerMessage(line); + if (variables != null) { + listener.newFile( + (String)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME), + (String)variables.get(RIGHT_REVISION_VARIABLE_NAME)); + return OK; + } + + variables = DELETED_FILE_MATCHER.processServerMessage(line); + if (variables != null) { + listener.deletedFile( + (String)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME), + null); + return OK; + } + + variables = DELETED_FILE_MATCHER2.processServerMessage(line); + if (variables != null) { + listener.deletedFile( + (String)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME), + (String)variables.get(LEFT_REVISION_VARIABLE_NAME)); + return OK; + } + + return super.messageLine(line, location, commandRoot, monitor); + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener#errorLine(java.lang.String, org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, org.eclipse.team.internal.ccvs.core.ICVSFolder, org.eclipse.core.runtime.IProgressMonitor) + */ + public IStatus errorLine( + String line, + ICVSRepositoryLocation location, + ICVSFolder commandRoot, + IProgressMonitor monitor) { + + Map variables = DIRECTORY_MATCHER.processServerMessage(line); + if (variables != null) { + listener.directory( + (String)variables.get(REMOTE_FOLDER_PATH_VARIABLE_NAME)); + return OK; + } + + return super.errorLine(line, location, commandRoot, monitor); + } + +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ServerMessageLineMatcher.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ServerMessageLineMatcher.java new file mode 100644 index 000000000..3e42ee1a6 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ServerMessageLineMatcher.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ccvs.core.client.listeners; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.util.Assert; +import org.eclipse.team.internal.ccvs.core.Policy; + +/** + * This class extracts matches server lines to expected patterns and extracts + * required information from the line. + */ +public class ServerMessageLineMatcher { + + protected static final Pattern VARIABLE_MATCHING_PATTERN = Pattern.compile("(\\((\\w*):.*:\\2\\))"); //$NON-NLS-1$ + + Pattern pattern; + String[] variables; + + public ServerMessageLineMatcher(String template, String[] expectedVariables) throws CVSException { + // Extract the variable names from the template + Matcher matcher = VARIABLE_MATCHING_PATTERN.matcher(template); + List variables = new ArrayList(); + while (matcher.find()) { + if (matcher.groupCount() != 2) { + throw new CVSException(Policy.bind("ServerMessageLineMatcher.5", template)); //$NON-NLS-1$ + } + variables.add(matcher.group(2)); + } + ensureMatches(template, variables, expectedVariables); + this.variables = (String[]) variables.toArray(new String[variables.size()]); + + // Modify the template so it can be used to match message lines from the server + // (i.e. remove the variable markup) + for (Iterator iter = variables.iterator(); iter.hasNext();) { + String element = (String) iter.next(); + template = template.replaceAll(element + ":", ""); //$NON-NLS-1$ //$NON-NLS-2$ + template = template.replaceAll(":" + element, ""); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // Ensure that the number of groups in the pattern match the number of variables + int count = 0; + int start = -1; + while ((start = template.indexOf('(', start + 1)) != -1) { + count++; + } + if (count != variables.size()) { + throw new CVSException(Policy.bind("ServerMessageLineMatcher.6", template)); //$NON-NLS-1$ + } + + // Create the pattern fir matching lines from the server + this.pattern = Pattern.compile(template); + } + + /* + * Throw an exception if the found variables do not match the expected variables + */ + private void ensureMatches(String template, List variables, String[] expectedVariables) throws CVSException { + for (int i = 0; i < expectedVariables.length; i++) { + String expected = expectedVariables[i]; + if (!variables.contains(expected)) { + throw new CVSException(Policy.bind("ServerMessageLineMatcher.7", expected, template)); //$NON-NLS-1$ + } + } + } + + public Map processServerMessage(String line) { + Matcher matcher = pattern.matcher(line); + if (!matcher.find()) return null; + Assert.isTrue(matcher.groupCount() == variables.length); + Map result = new HashMap(); + for (int i = 1; i <= matcher.groupCount(); i++) { + result.put(variables[i - 1], matcher.group(i)); + } + return result; + } + + public boolean matches(String line) { + Matcher matcher = pattern.matcher(line); + return (matcher.find()); + } + +} 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 3eb870416..aa23fa7fb 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 @@ -330,3 +330,6 @@ DeferredResourceChangeHandler.0=Reconciling CVS state changes DeferredResourceChangeHandler.1=Errors occured handling ignore file (.cvsignore) changes. Some resources may not be decorated properly. CVSWorkspaceRoot.11=The parent folder of managed file {0} does not have sync info associated with it. RemoveEntryHandler.2=Remove-entry received and ignored from CVS server for existing file {0}. +ServerMessageLineMatcher.5=Variable in template is not of the correct format: {0} +ServerMessageLineMatcher.6=There are additional groups above those defining variables in template: {0} +ServerMessageLineMatcher.7=Expected variable {0} in {1} but it is not present. diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FileContentCachingService.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FileContentCachingService.java index c2735c91d..e7b9146e4 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FileContentCachingService.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FileContentCachingService.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; import org.eclipse.team.internal.ccvs.core.CVSTag; import org.eclipse.team.internal.ccvs.core.ICVSFile; import org.eclipse.team.internal.ccvs.core.ICVSFolder; @@ -49,6 +50,18 @@ public class FileContentCachingService { } } + /** + * Fetch and cache the file contents for the specified files. + * @param root the root folder for the files being fetched + * @param filePaths the root relative file paths + * @param monitor + * @throws CVSException + */ + public static void fetchFileContents(RemoteFolderTree root, String[] filePaths, IProgressMonitor monitor) throws CVSException { + FileContentCachingService service = new FileContentCachingService((CVSRepositoryLocation)root.getRepository(), root, filePaths); + service.cacheFileContents(monitor); + } + public static RemoteFile buildRemoteTree(CVSRepositoryLocation repository, ICVSFile file, CVSTag tag, IProgressMonitor monitor) throws CVSException { monitor.beginTask(null, 100); try { @@ -86,6 +99,10 @@ public class FileContentCachingService { files, null, Policy.subMonitorFor(monitor, files.length * 100)); + if (!status.isOK()) { + // No big deal but log the problem anyway + CVSProviderPlugin.log (new CVSException(status)); + } } finally { session.close(); monitor.done(); diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java index 1556dccf4..8d04eb5dc 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java @@ -180,6 +180,13 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { /* package*/ void fetchContents(IProgressMonitor monitor) throws CVSException { monitor.beginTask(Policy.bind("RemoteFile.getContents"), 100);//$NON-NLS-1$ + if (getRevision().equals(ResourceSyncInfo.ADDED_REVISION)) { + // The revision of the remote file is not known so we need to use the tag to get the status of the file + CVSTag tag = getSyncInfo().getTag(); + if (tag == null) tag = CVSTag.DEFAULT; + RemoteFolderMemberFetcher fetcher = new RemoteFolderMemberFetcher((RemoteFolder)getParent(), tag); + fetcher.updateFileRevisions(new ICVSFile[] { this }, Policy.subMonitorFor(monitor, 10)); + } Session session = new Session(getRepository(), parent, false /* create backups */); session.open(Policy.subMonitorFor(monitor, 10), false /* read-only */); try { @@ -191,7 +198,7 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { Update.IGNORE_LOCAL_CHANGES }, new ICVSResource[] { this }, null, - Policy.subMonitorFor(monitor, 90)); + Policy.subMonitorFor(monitor, 80)); if (status.getCode() == CVSStatus.SERVER_ERROR) { throw new CVSServerException(status); } @@ -412,13 +419,15 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { * Return whether there are already contents cached for the given handle */ public boolean isContentsCached() { + if (getRevision().equals(ResourceSyncInfo.ADDED_REVISION)) return false; return getRemoteContentsCache().hasContents(getCacheRelativePath()); } /* * @see ICVSFile#setReadOnly(boolean) */ - public void setReadOnly(boolean readOnly) throws CVSException { + public void setReadOnly(boolean readOnly) { + // RemoteFiles are always read only } /* @@ -438,20 +447,21 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { /* * @see ICVSFile#setTimeStamp(Date) */ - public void setTimeStamp(Date date) throws CVSException { + public void setTimeStamp(Date date) { + // RemoteFiles are not muttable so do not support timestamp changes } /** * @see ICVSFile#moveTo(String) */ - public void copyTo(String mFile) throws CVSException { + public void copyTo(String mFile) { // Do nothing } /* * @see IRemoteResource#members(IProgressMonitor) */ - public IRemoteResource[] members(IProgressMonitor progress) throws TeamException { + public IRemoteResource[] members(IProgressMonitor progress) { return new IRemoteResource[0]; } @@ -505,14 +515,14 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { /** * @see org.eclipse.team.internal.ccvs.core.ICVSFile#checkout(int) */ - public void edit(int notifications, IProgressMonitor monitor) throws CVSException { + public void edit(int notifications, IProgressMonitor monitor) { // do nothing } /** * @see org.eclipse.team.internal.ccvs.core.ICVSFile#uncheckout() */ - public void unedit(IProgressMonitor monitor) throws CVSException { + public void unedit(IProgressMonitor monitor) { // do nothing } @@ -526,7 +536,7 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { /** * @see org.eclipse.team.internal.ccvs.core.ICVSFile#getPendingNotification() */ - public NotifyInfo getPendingNotification() throws CVSException { + public NotifyInfo getPendingNotification() { return null; } @@ -551,13 +561,13 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { /** * @see org.eclipse.team.internal.ccvs.core.ICVSFile#committed(org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo) */ - public void checkedIn(String info) throws CVSException { + public void checkedIn(String info) { // do nothing } /** * @see org.eclipse.team.internal.ccvs.core.ICVSFile#isEdited() */ - public boolean isEdited() throws CVSException { + public boolean isEdited() { return false; } /** @@ -588,7 +598,7 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile { /* (non-Javadoc) * @see org.eclipse.team.core.sync.IRemoteResource#getContentIdentifier() */ - public String getContentIdentifier() throws CVSException { + public String getContentIdentifier() { return getRevision(); } diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/PrepareForReplaceVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/PrepareForReplaceVisitor.java index 4fef8987f..8963c8d83 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/PrepareForReplaceVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/PrepareForReplaceVisitor.java @@ -91,7 +91,7 @@ public class PrepareForReplaceVisitor implements ICVSResourceVisitor { monitor.worked(1); } - public void visitResources(IProject project, final IResource[] resources, final String key, int depth, IProgressMonitor pm) throws CVSException { + public void visitResources(IProject project, final ICVSResource[] resources, final String key, int depth, IProgressMonitor pm) throws CVSException { this.depth = depth; CVSWorkspaceRoot.getCVSFolderFor(project).run(new ICVSRunnable() { public void run(IProgressMonitor pm) throws CVSException { @@ -99,10 +99,9 @@ public class PrepareForReplaceVisitor implements ICVSResourceVisitor { monitor.beginTask(null, 512); for (int i = 0; i < resources.length; i++) { if (key != null) { - monitor.subTask(Policy.bind(key, resources[i].getFullPath().toString())); //$NON-NLS-1$ + monitor.subTask(Policy.bind(key, resources[i].getIResource().getFullPath().toString())); //$NON-NLS-1$ } - IResource resource = resources[i]; - CVSWorkspaceRoot.getCVSResourceFor(resource).accept(PrepareForReplaceVisitor.this); + resources[i].accept(PrepareForReplaceVisitor.this); } monitor.done(); } diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java index 1b9977154..d5f3c7c08 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java @@ -540,4 +540,8 @@ public class Util { } return resource.getName(); } + + public static String getVariablePattern(String pattern, String variableName) { + return "(" + variableName + ":" + pattern + ":" + variableName + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } } |