diff options
Diffstat (limited to 'bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client')
75 files changed, 0 insertions, 8512 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractMessageCommand.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractMessageCommand.java deleted file mode 100644 index ae2b8d4d2..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractMessageCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSResource; - -/** - * Superclass for commands that do not change the structure on - * the local working copy (it can change the content of the files).<br> - * Most of the subclasses are asking the server for response in - * message format (log, status) - */ -abstract class AbstractMessageCommand extends Command { - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // Send all folders that are already managed to the server - new FileStructureVisitor(session, localOptions, false, false).visit(session, resources, monitor); - return resources; - } - -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractStructureVisitor.java deleted file mode 100644 index ec891993f..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractStructureVisitor.java +++ /dev/null @@ -1,300 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt McCutchen <hashproduct+eclipse@gmail.com> - Bug 178874 Test failure against CVS 1.11.22 - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.*; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; -import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag; -import org.eclipse.team.internal.ccvs.core.syncinfo.*; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * An ICVSResourceVisitor that is superclass to all ICVSResourceVisitor's used - * by Command and it's subclasses. - * Provides helper methods to send files and folders with modifications - * to the server. - * - * This class does not perform a beginTask of done on the provided monitor. - * It is used only to signal worl and subTask. - */ -abstract class AbstractStructureVisitor implements ICVSResourceVisitor { - - protected Session session; - private ICVSFolder lastFolderSent; - protected IProgressMonitor monitor; - protected boolean sendQuestionable; - protected boolean sendModifiedContents; - private boolean sendBinary; - - private boolean recurse = true; - - public AbstractStructureVisitor(Session session, LocalOption[] localOptions, boolean sendQuestionable, boolean sendModifiedContents) { - this(session, localOptions, sendQuestionable, sendModifiedContents, true); - } - - public AbstractStructureVisitor(Session session, LocalOption[] localOptions, boolean sendQuestionable, boolean sendModifiedContents, boolean sendBinary) { - this.session = session; - this.sendQuestionable = sendQuestionable; - this.sendModifiedContents = sendModifiedContents; - this.sendBinary = sendBinary; - if (Command.DO_NOT_RECURSE.isElementOf(localOptions)) - recurse = false; - } - - /** - * Helper method to indicate if a directory has already been sent to the server - */ - protected boolean isLastSent(ICVSFolder folder) { - return folder.equals(lastFolderSent); - } - - /** - * Helper method to record if a directory has already been sent to the server - */ - protected void recordLastSent(ICVSFolder folder) { - lastFolderSent = folder; - } - - /** - * Helper which indicates if a folder is an orphaned subtree. - * That is, a directory which contains a CVS subdirectory but is - * not managed by its parent. The root directory of the session - * is not considered orphaned even if it is not managed by its - * parent. - */ - protected boolean isOrphanedSubtree(ICVSFolder mFolder) throws CVSException { - return mFolder.isCVSFolder() && ! mFolder.isManaged() && ! mFolder.equals(session.getLocalRoot()) && mFolder.getParent().isCVSFolder(); - } - - /** - * Send the folder relative to the root to the server. Send all - * appropiate modifier like Sticky, Questionable, Static-directory. - * <br> - * Folders will only be sent once. - */ - protected void sendFolder(ICVSFolder mFolder) throws CVSException { - - Policy.checkCanceled(monitor); - - boolean exists = mFolder.exists(); - FolderSyncInfo info = mFolder.getFolderSyncInfo(); - boolean isCVSFolder = info != null; - - // We are only interested in folders that exist or are CVS folders - // A folder could be a non-existant CVS folder if it is a holder for outgoing file deletions - if ( ! exists && ! isCVSFolder) return; - - // Do not send the same folder twice - if (isLastSent(mFolder)) return; - - // Do not send virtual directories - if (isCVSFolder && info.isVirtualDirectory()) { - return; - } - - String localPath = mFolder.getRelativePath(session.getLocalRoot()); - - monitor.subTask(NLS.bind(CVSMessages.AbstractStructureVisitor_sendingFolder, new String[] { Util.toTruncatedPath(mFolder, session.getLocalRoot(), 3) })); - - // Deal with questionable directories - boolean isQuestionable = exists && (! isCVSFolder || isOrphanedSubtree(mFolder)); - if (isQuestionable) { - if (sendQuestionable) { - // We need to make sure the parent folder was sent - sendFolder(mFolder.getParent()); - session.sendQuestionable(mFolder); - } - return; - } - - // Send the directory to the server - String remotePath = mFolder.getRemoteLocation(session.getLocalRoot()); - if (remotePath == null) { - IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR, CVSMessages.AbstractStructureVisitor_noRemote, session.getLocalRoot()); - throw new CVSException(status); - } - session.sendDirectory(localPath, remotePath); - - // Send any directory properties to the server - if (info != null) { - - if (info.getIsStatic()) { - session.sendStaticDirectory(); - } - - CVSEntryLineTag tag = info.getTag(); - - if (tag != null && tag.getType() != CVSTag.HEAD) { - session.sendSticky(tag.toEntryLineFormat(false)); - } - } - - // Record that we sent this folder - recordLastSent(mFolder); - - monitor.worked(1); - } - - /** - * Send the information about the file to the server. - * - * If the file is modified, its contents are sent as well. - */ - protected void sendFile(ICVSFile mFile) throws CVSException { - - Policy.checkCanceled(monitor); - - // Send the parent folder if it hasn't been sent already - sendFolder(mFile.getParent()); - - // Send the file's entry line to the server - byte[] syncBytes = mFile.getSyncBytes(); - boolean isManaged = syncBytes != null; - - if (isManaged) { - sendPendingNotification(mFile); - } else { - // If the file is not managed, send a questionable to the server if the file exists locally - // A unmanaged, locally non-existant file results from the explicit use of the file name as a command argument - if (sendQuestionable) { - if (mFile.exists()) { - session.sendQuestionable(mFile); - } - return; - } - // else we are probably doing an import so send the file contents below - } - - // Determine if we need to send the contents. - // If the file is unmodified since a conflict, we need to not send the - // contents so that the server rejects the file (bug 178874). - boolean sendContents = mFile.exists() && mFile.isModified(monitor) - && !mFile.getSyncInfo().isNeedsMerge(mFile.getTimeStamp()); - if (ResourceSyncInfo.isDeletion(syncBytes)) { - sendEntryLineToServer(mFile, syncBytes); - } else if (sendContents) { - // Perform the send of modified contents in a sheduling rule to ensure that - // the contents are not modified while we are sending them - final IResource resource = mFile.getIResource(); - try { - if (resource != null) - Job.getJobManager().beginRule(resource, monitor); - - sendEntryLineToServer(mFile, syncBytes); - if (mFile.exists() && mFile.isModified(null)) { - boolean binary = ResourceSyncInfo.isBinary(syncBytes); - if (sendModifiedContents) { - session.sendModified(mFile, binary, sendBinary, monitor); - } else { - session.sendIsModified(mFile, binary, monitor); - } - } else { - session.sendUnchanged(mFile); - } - } finally { - if (resource != null) - Job.getJobManager().endRule(resource); - } - } else { - sendEntryLineToServer(mFile, syncBytes); - session.sendUnchanged(mFile); - } - - monitor.worked(1); - } - - private void sendEntryLineToServer(ICVSFile mFile, byte[] syncBytes) throws CVSException { - if (syncBytes != null) { - String syncBytesToServer = ResourceSyncInfo.getTimestampToServer(syncBytes, mFile.getTimeStamp()); - session.sendEntry(syncBytes, syncBytesToServer); - } - } - - protected void sendPendingNotification(ICVSFile mFile) throws CVSException { - NotifyInfo notify = mFile.getPendingNotification(); - if (notify != null) { - sendFolder(mFile.getParent()); - session.sendNotify(mFile.getParent(), notify); - } - } - - /** - * This method is used to visit a set of ICVSResources. Using it ensures - * that a common parent between the set of resources is only sent once - */ - public void visit(Session session, ICVSResource[] resources, IProgressMonitor monitor) throws CVSException { - - // Sort the resources to avoid sending the same directory multiple times - List resourceList = new ArrayList(resources.length); - resourceList.addAll(Arrays.asList(resources)); - final ICVSFolder localRoot = session.getLocalRoot(); - Collections.sort(resourceList, new Comparator() { - public int compare(Object object1, Object object2) { - ICVSResource resource1 = (ICVSResource)object1; - ICVSResource resource2 = (ICVSResource)object2; - try { - String path1 = resource1.getParent().getRelativePath(localRoot); - String path2 = resource2.getParent().getRelativePath(localRoot); - int pathCompare = path1.compareTo(path2); - if (pathCompare == 0) { - if (resource1.isFolder() == resource2.isFolder()) { - return resource1.getName().compareTo(resource2.getName()); - } else if (resource1.isFolder()) { - return 1; - } else { - return -1; - } - } else { - return pathCompare; - } - } catch (CVSException e) { - return resource1.getName().compareTo(resource2.getName()); - } - } - }); - - // Create a progress monitor suitable for the visit - int resourceHint = 64; - monitor.beginTask(null, resourceHint); - this.monitor = Policy.infiniteSubMonitorFor(monitor, resourceHint); - try { - // Visit all the resources - this.monitor.beginTask(null, resourceHint); - session.setSendFileTitleKey(getSendFileMessage()); - for (int i = 0; i < resourceList.size(); i++) { - ((ICVSResource)resourceList.get(i)).accept(this); - } - } finally { - monitor.done(); - } - } - - /** - * Return a send file message that contains one argument slot - * for the file name. - * @return a send file message that contains one argument slot - * for the file name - */ - protected String getSendFileMessage() { - return CVSMessages.AbstractStructureVisitor_sendingFile; - } - public boolean isRecurse() { - return recurse; - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Add.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Add.java deleted file mode 100644 index b8dfba8f1..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Add.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.MutableFolderSyncInfo; - -public class Add extends Command { - /*** Local options: specific to add ***/ - - protected Add() { } - protected String getRequestId() { - return "add"; //$NON-NLS-1$ - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // Check that all the arguments can give you an - // repo that you will need while traversing the - // file-structure - for (int i = 0; i < resources.length; i++) { - Assert.isNotNull(resources[i].getRemoteLocation(session.getLocalRoot())); - } - - // Get a vistor and use it on every resource we should - // work on - AddStructureVisitor visitor = new AddStructureVisitor(session, localOptions); - visitor.visit(session, resources, monitor); - return resources; - } - - /** - * If the add succeeded then folders have to be initialized with the - * sync info - */ - protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, - IStatus status) throws CVSException { - - if (status.getCode() == CVSStatus.SERVER_ERROR) { - return status; - } - - for (int i = 0; i < resources.length; i++) { - if (resources[i].isFolder()) { - ICVSFolder mFolder = (ICVSFolder) resources[i]; - FolderSyncInfo info = mFolder.getParent().getFolderSyncInfo(); - if (info == null) { - status = mergeStatus(status, new CVSStatus(IStatus.ERROR, NLS.bind(CVSMessages.Add_invalidParent, new String[] { mFolder.getRelativePath(session.getLocalRoot()) }))); - } else { - String repository = info.getRepository() + "/" + mFolder.getName(); //$NON-NLS-1$ - MutableFolderSyncInfo newInfo = info.cloneMutable(); - newInfo.setRepository(repository); - mFolder.setFolderSyncInfo(newInfo); - } - } - } - return status; - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#getDefaultCommandOutputListener() - */ - protected ICommandOutputListener getDefaultCommandOutputListener() { - return new CommandOutputListener() { - public IStatus errorLine(String line, - ICVSRepositoryLocation location, ICVSFolder commandRoot, - IProgressMonitor monitor) { - - String serverMessage = getServerMessage(line, location); - if (serverMessage != null) { - if (serverMessage.indexOf("cvs commit") != -1 && serverMessage.indexOf("add") != -1 && serverMessage.indexOf("permanently") != -1) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - return OK; - if (serverMessage.startsWith("scheduling file") && serverMessage.indexOf("for addition") != -1) //$NON-NLS-1$ //$NON-NLS-2$ - 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/AddStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AddStructureVisitor.java deleted file mode 100644 index 4ce700957..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AddStructureVisitor.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.Assert; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; - -/** - * This visitor is used by the Add command to ensure that the parent - * folder is sent along with the added resource. - */ -class AddStructureVisitor extends AbstractStructureVisitor { - - public AddStructureVisitor(Session session, LocalOption[] localOptions) { - super(session, localOptions, false, true); - } - - /** - * @see ICVSResourceVisitor#visitFile(IManagedFile) - */ - public void visitFile(ICVSFile mFile) throws CVSException { - - // Send the parent folder - sendFolder(mFile.getParent()); - - // Sends the Is-modified request if it is supported, otherwise - // the file contents are sent as binary. The server does not - // need the contents at this stage so this should not be a problem. - session.sendIsModified(mFile, true, monitor); - - } - - /** - * @see ICVSResourceVisitor#visitFolder(ICVSFolder) - */ - public void visitFolder(ICVSFolder mFolder) throws CVSException { - - Assert.isNotNull(mFolder); - - // Send the parent folder - sendFolder(mFolder.getParent()); - - // Send the directory - String localPath = mFolder.getRelativePath(session.getLocalRoot()); - String remotePath = mFolder.getRemoteLocation(session.getLocalRoot()); - session.sendDirectory(localPath, remotePath); - - // Record that we sent this folder - recordLastSent(mFolder); - } - -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Admin.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Admin.java deleted file mode 100644 index 58afba45a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Admin.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -public class Admin extends AbstractMessageCommand { - /*** Local options: specific to admin ***/ - - protected Admin() { } - protected String getRequestId() { - return "admin"; //$NON-NLS-1$ - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Annotate.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Annotate.java deleted file mode 100644 index 3c1a04a7a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Annotate.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -/** - * The CVS Annotate Command. - * Answers a resource with each line annotated with the revision the line - * was added/changed and the user making the change. - */ -public class Annotate extends AbstractMessageCommand { - - public static final Object FORCE_BINARY_ANNOTATE = new LocalOption("-F"); //$NON-NLS-1$ - - protected Annotate() { } - - protected String getRequestId() { - return "annotate"; //$NON-NLS-1$ - } - - // Local options specific to Annotate - revision (can be tag or revision) - public static LocalOption makeRevisionOption(String revision) { - return new LocalOption("-r" + revision, null); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ByteCountOutputStream.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ByteCountOutputStream.java deleted file mode 100644 index c1f89d81b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ByteCountOutputStream.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.io.*; - -class ByteCountOutputStream extends OutputStream { - - private long size = 0; - - public void write(int b) throws IOException { - size++; - } - public long getSize() { - return size; - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java deleted file mode 100644 index 32f73719a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.io.*; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; - -/** - * Stream which detects CRLF in text file contents recieved from the server - */ -public class CRLFDetectInputStream extends FilterInputStream { - - private boolean previousCR; - private String filename; - private boolean reported = false; - - protected CRLFDetectInputStream(InputStream in, ICVSStorage file) { - super(in); - try { - this.filename = getFileName(file); - } catch (CVSException e) { - this.filename = file.getName(); - } - } - - private String getFileName(ICVSStorage storage) throws CVSException { - String fileName; - if (storage instanceof ICVSFile) { - ICVSFile file = (ICVSFile)storage; - fileName = file.getRepositoryRelativePath(); - if (fileName == null) { - IResource resource = file.getIResource(); - if (resource == null) { - fileName = file.getName(); - } else { - // Use the resource path if there is one since the remote pat - fileName = file.getIResource().getFullPath().toString(); - } - } - } else { - fileName = storage.getName(); - } - return fileName; - } - - /** - * Wraps the underlying stream's method. - * Translates CR/LF sequences to LFs transparently. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred will be zero - * @throws IOException if an i/o error occurs - */ - public int read() throws IOException { - int next = in.read(); - if (next != -1) { - testForCRLF((byte)next); - } - return next; - } - - /** - * Wraps the underlying stream's method. - * Translates CR/LF sequences to LFs transparently. - * @throws InterruptedIOException if the operation was interrupted before all of the - * bytes specified have been skipped, bytesTransferred may be non-zero - * @throws IOException if an i/o error occurs - */ - public int read(byte[] buffer, int off, int len) throws IOException { - int count = super.read(buffer, off, len); - for (int i = off; i < count; i++) { - testForCRLF(buffer[i]); - } - return count; - } - - /** - * Test the byte to see if a CRLF sequence was read - */ - private void testForCRLF(byte next) { - if (reported) return; - if (previousCR && next == '\n') { - CVSProviderPlugin.log(IStatus.WARNING, NLS.bind(CVSMessages.CRLFDetectInputStream_0, new String[] { filename }), null); - reported = true; - } - previousCR = (next == '\r'); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckedInHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckedInHandler.java deleted file mode 100644 index 8f621315c..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckedInHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Handles a "Checked-in" response from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Checked-in ??? \n - * [...] - * </pre> - * Then - * </p> - */ -class CheckedInHandler extends ResponseHandler { - public String getResponseID() { - return "Checked-in"; //$NON-NLS-1$ - } - - public void handle(Session session, String localDir, IProgressMonitor monitor) throws CVSException { - // read additional data for the response - String repositoryFile = session.readLine(); - String entryLine = session.readLine(); - - // clear file update modifiers - session.setModTime(null); - - // Get the local file - String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$ - ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); - ICVSFile mFile = mParent.getFile(fileName); - - // Marked the local file as checked-in - monitor.subTask(NLS.bind(CVSMessages.CheckInHandler_checkedIn, new String[] { Util.toTruncatedPath((ICVSResource)mFile, session.getLocalRoot(), 3) })); - mFile.checkedIn(entryLine, session.getCurrentCommand() instanceof Commit); - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java deleted file mode 100644 index 4b00f40c7..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java +++ /dev/null @@ -1,183 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.*; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.listeners.*; -import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; -import org.eclipse.team.internal.ccvs.core.resources.RemoteModule; - -public class Checkout extends Command { - /*** Local options: specific to checkout ***/ - public static final LocalOption DO_NOT_SHORTEN = new LocalOption("-N"); //$NON-NLS-1$ - public static final LocalOption FETCH_MODULE_ALIASES = new LocalOption("-c"); //$NON-NLS-1$ - public static LocalOption makeDirectoryNameOption(String moduleName) { - return new LocalOption("-d", moduleName); //$NON-NLS-1$ - } - - /*** Default command output listener ***/ - private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new UpdateListener(null); - - /** Command options found in the CVSROOT/modules file */ - public static LocalOption ALIAS = new LocalOption("-a"); //$NON-NLS-1$ - public static LocalOption makeStatusOption(String status) { - return new LocalOption("-s", status); //$NON-NLS-1$ - } - - protected Checkout() { } - protected String getRequestId() { - return "co"; //$NON-NLS-1$ - } - - protected ICommandOutputListener getDefaultCommandOutputListener() { - return DEFAULT_OUTPUT_LISTENER; - } - - protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, - String[] arguments) throws CVSException { - - // We shouldn't have any arguments if we're fetching the module definitions - if (arguments.length < 1 && ! FETCH_MODULE_ALIASES.isElementOf(localOptions)) throw new IllegalArgumentException(); - - // We can determine the local directories using either the -d option or the module expansions - Option dOption = findOption(localOptions, "-d"); //$NON-NLS-1$ - if (dOption != null) { - // Should we append the expansions to the -d argument? - return new ICVSResource[] {session.getLocalRoot().getFolder(dOption.argument)}; - } - String[] modules = session.getModuleExpansions(); - ICVSResource[] resources = new ICVSResource[modules.length]; - for (int i = 0; i < resources.length; i++) { - resources[i] = session.getLocalRoot().getFolder(modules[i]); - } - return resources; - } - - /** - * Start the Checkout command: - * Send the module that is going to be checked-out to the server - * by reading the name of the resource given - * (This has to change to we give it the name of the modul and the - * Checkout creates everything for us) - */ - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // We need a folder to put the project(s) we checkout into - Assert.isTrue(session.getLocalRoot().isFolder()); - - // Send the information about the local workspace resources to the server - List resourcesToSend = new ArrayList(resources.length); - for (int i = 0; i < resources.length; i++) { - ICVSResource resource = resources[i]; - if (resource.exists() && resource.isFolder() && ((ICVSFolder)resource).isCVSFolder()) { - resourcesToSend.add(resource); - } - } - if ( ! resourcesToSend.isEmpty()) { - resources = (ICVSResource[]) resourcesToSend.toArray(new ICVSResource[resourcesToSend.size()]); - new FileStructureVisitor(session, localOptions, true, true).visit(session, resources, monitor); - } else { - monitor.beginTask(null, 100); - monitor.done(); - } - return resources; - } - - protected void sendLocalWorkingDirectory(Session session) throws CVSException { - session.sendConstructedRootDirectory(); - } - - /** - * On sucessful finish, prune empty directories if - * the -P option was specified (or is implied by -D or -r) - */ - protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, - IStatus status) throws CVSException { - // If we didn't succeed, don't do any post processing - if (status.getCode() == CVSStatus.SERVER_ERROR) { - return status; - } - - // If we are retrieving the modules file, ignore other options - if (FETCH_MODULE_ALIASES.isElementOf(localOptions)) return status; - - // If we are pruning (-P) or getting a sticky copy (-D or -r), then prune empty directories - if (PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions) || - (findOption(localOptions, "-D") != null) || //$NON-NLS-1$ - (findOption(localOptions, "-r") != null)) { //$NON-NLS-1$ - - // Prune empty directories - new PruneFolderVisitor().visit(session, resources); - } - - return status; - } - - /** - * Override execute to perform a expand-modules before the checkout - */ - protected IStatus doExecute(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, - IProgressMonitor monitor) throws CVSException { - monitor.beginTask(null, 100); - - if ( ! FETCH_MODULE_ALIASES.isElementOf(localOptions)) { - // Execute the expand-modules command. - // This will put the expansions in the session for later retrieval - IStatus status = Request.EXPAND_MODULES.execute(session, arguments, Policy.subMonitorFor(monitor, 10)); - if (status.getCode() == CVSStatus.SERVER_ERROR) - return status; - - // If -d is not included in the local options, then send -N (do not shorten directory paths) - // to the server (as is done by other cvs clients) - if (findOption(localOptions, "-d") == null) { //$NON-NLS-1$ - if ( ! DO_NOT_SHORTEN.isElementOf(localOptions)) { - LocalOption[] newLocalOptions = new LocalOption[localOptions.length + 1]; - newLocalOptions[0] = DO_NOT_SHORTEN; - System.arraycopy(localOptions, 0, newLocalOptions, 1, localOptions.length); - localOptions = newLocalOptions; - } - } - } - - return super.doExecute(session, globalOptions, localOptions, arguments, listener, Policy.subMonitorFor(monitor, 90)); - } - - /** - * Perform a checkout to get the module expansions defined in the CVSROOT/modules file - */ - public RemoteModule[] getRemoteModules(Session session, CVSTag tag, IProgressMonitor monitor) - throws CVSException { - - ModuleDefinitionsListener moduleDefinitionListener = new ModuleDefinitionsListener(); - - IStatus status = super.execute(session, NO_GLOBAL_OPTIONS, new LocalOption[] {FETCH_MODULE_ALIASES}, NO_ARGUMENTS, - moduleDefinitionListener, monitor); - - if (status.getCode() == CVSStatus.SERVER_ERROR) { - throw new CVSServerException(status); - } - - return RemoteModule.createRemoteModules(moduleDefinitionListener.getModuleExpansions(), session.getCVSRepositoryLocation(), tag); - } - - protected String getDisplayText() { - return "checkout"; //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckoutWithOverwrite.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckoutWithOverwrite.java deleted file mode 100644 index b5169ab3a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckoutWithOverwrite.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -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.client.listeners.ICommandOutputListener; - -/** - * This checkout will overwrite any resources even for created responses - */ -public class CheckoutWithOverwrite extends Checkout { - - /** - * This class overrides the "Created" handler but uses the "Updated" - * behavior which will overwrite existing files. - */ - public class CreatedResponseHandler extends UpdatedHandler { - public CreatedResponseHandler() { - super(UpdatedHandler.HANDLE_UPDATED); - } - public String getResponseID() { - return "Created"; //$NON-NLS-1$ - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#doExecute(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption[], org.eclipse.team.internal.ccvs.core.client.Command.LocalOption[], java.lang.String[], org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus doExecute( - Session session, - GlobalOption[] globalOptions, - LocalOption[] localOptions, - String[] arguments, - ICommandOutputListener listener, - IProgressMonitor monitor) - throws CVSException { - - ResponseHandler newCreated = new CreatedResponseHandler(); - ResponseHandler oldCreated = session.getResponseHandler(newCreated.getResponseID()); - session.registerResponseHandler(newCreated); - try { - return super.doExecute( - session, - globalOptions, - localOptions, - arguments, - listener, - monitor); - } finally { - session.registerResponseHandler(oldCreated); - } - } - -} 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 deleted file mode 100644 index 52c3a26b9..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java +++ /dev/null @@ -1,834 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt McCutchen <hashproduct+eclipse@gmail.com> - Bug 179174 CVS client sets timestamps back when replacing - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.*; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; - -/** - * Abstract base class for command requests. - * Provides a framework for implementing command execution. - */ -public abstract class Command extends Request { - /*** Command singleton instances ***/ - public final static Add ADD = new Add(); - public final static Admin ADMIN = new Admin(); - public final static Annotate ANNOTATE = new Annotate(); - 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(); - public final static Remove REMOVE = new Remove(); - public final static Status STATUS = new Status(); - public final static Tag TAG = new Tag(); - // The CUSTOM_TAG command has special handling for added and removed resources. - // This behavior supports branching with local changes in the workspace - public final static Tag CUSTOM_TAG = new Tag(true); - public final static RTag RTAG = new RTag(); - public final static Update UPDATE = new Update(); - public final static Update REPLACE = new Replace(); - public final static SyncUpdate SYNCUPDATE = new SyncUpdate(); - public final static Version VERSION = new Version(); - public final static NOOPCommand NOOP = new NOOPCommand(); - - // Empty argument array - public final static String[] NO_ARGUMENTS = new String[0]; - - /*** Global options ***/ - // Empty global option array - public static final GlobalOption[] NO_GLOBAL_OPTIONS = new GlobalOption[0]; - // Do not change file contents - public static final GlobalOption DO_NOT_CHANGE = new GlobalOption("-n"); //$NON-NLS-1$ - // Do not record this operation into CVS command history - public static final GlobalOption DO_NOT_LOG = new GlobalOption("-l"); //$NON-NLS-1$ - // Make new working files read-only - public static final GlobalOption MAKE_READ_ONLY = new GlobalOption("-r"); //$NON-NLS-1$ - // Trace command execution - public static final GlobalOption TRACE_EXECUTION = new GlobalOption("-t"); //$NON-NLS-1$ - - /*** Global options: quietness ***/ - // Don't be quiet (normal verbosity) - public static final QuietOption VERBOSE = new QuietOption(""); //$NON-NLS-1$ - // Be somewhat quiet (suppress informational messages) - public static final QuietOption PARTLY_QUIET = new QuietOption("-q"); //$NON-NLS-1$ - // Be really quiet (silent but for serious problems) - public static final QuietOption SILENT = new QuietOption("-Q"); //$NON-NLS-1$ - - /*** Local options: common to many commands ***/ - // Empty local option array - public static final LocalOption[] NO_LOCAL_OPTIONS = new LocalOption[0]; - // valid for: annotate checkout commit diff export log rdiff remove rtag status tag update - public static final LocalOption RECURSE = new LocalOption("-R"); //$NON-NLS-1$ - public static final LocalOption DO_NOT_RECURSE = new LocalOption("-l"); //$NON-NLS-1$ - // valid for: checkout export update - public static final LocalOption PRUNE_EMPTY_DIRECTORIES = new LocalOption("-P"); //$NON-NLS-1$ - // valid for: checkout export update - public static final LocalOption MESSAGE_OPTION = new LocalOption("-m"); //$NON-NLS-1$ - - /*** Local options: keyword substitution mode ***/ - // valid for: add admin checkout export import update - private static final Map ksubstOptionMap = new HashMap(); - public static final KSubstOption KSUBST_BINARY = new KSubstOption("-kb"); //$NON-NLS-1$ - public static final KSubstOption KSUBST_TEXT = new KSubstOption("-ko"); //$NON-NLS-1$ - public static final KSubstOption KSUBST_TEXT_EXPAND = new KSubstOption("-kkv"); //$NON-NLS-1$ - public static final KSubstOption KSUBST_TEXT_EXPAND_LOCKER = new KSubstOption("-kkvl"); //$NON-NLS-1$ - public static final KSubstOption KSUBST_TEXT_VALUES_ONLY = new KSubstOption("-kv"); //$NON-NLS-1$ - public static final KSubstOption KSUBST_TEXT_KEYWORDS_ONLY = new KSubstOption("-kk"); //$NON-NLS-1$ - - /*** Default command output listener ***/ - protected static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new CommandOutputListener(); - - /** - * Prevents client code from instantiating us. - */ - protected Command() { } - - /** - * Provides the default command output listener which is used to accumulate errors. - * - * Subclasses can override this method in order to properly interpret information - * received from the server. - */ - protected ICommandOutputListener getDefaultCommandOutputListener() { - return DEFAULT_OUTPUT_LISTENER; - } - - /** - * Sends the command's arguments to the server. - * [template method] - * <p> - * The default implementation sends all arguments. Subclasses may override - * this method to provide alternate behaviour. - * </p> - * - * @param session the CVS session - * @param arguments the arguments that were supplied by the caller of execute() - */ - protected void sendArguments(Session session, String[] arguments) throws CVSException { - for (int i = 0; i < arguments.length; ++i) { - session.sendArgument(arguments[i]); - } - } - - /** - * Describes the local resource state to the server prior to command execution. - * [template method] - * <p> - * Commands must override this method to inform the server about the state of - * local resources using the Entries, Modified, Unchanged, and Questionable - * requests as needed. - * </p> - * <p> - * This method should return the resources that are of interest to the - * <code>Command#commandFinished()</code> method. In most cases, it - * is the same resources that are provided but in some cases (e.g. Commit) - * the resources to be passed to the above method are different. - * </p> - * - * @param session the CVS session - * @param globalOptions the global options for the command - * @param localOptions the local options for the command - * @param resources the resource arguments for the command - * @param monitor the progress monitor - * @return ICVSResource[] - */ - protected abstract ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException; - - /** - * Cleans up after command execution. - * [template method] - * <p> - * The default implementation is a no-op. Subclasses may override this - * method to follow up command execution on the server with clean up - * operations on local resources. - * </p> - * - * @param session the CVS session - * @param globalOptions the global options for the command - * @param localOptions the local options for the command - * @param resources the resource arguments for the command - * @param monitor the progress monitor - * @param status the status accumulated so far. If the code == CVSStatus.SERVER_ERROR - * then the command failed - * @return status the status past in plus any additional status accumulated during the finish - */ - protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, - IStatus status) throws CVSException { - return status; - } - - /** - * Sends the local working directory path prior to command execution. - * [template method] - * <p> - * The default implementation sends the paths of local root directory - * (assuming it exists). Subclasses may override this method to provide - * alternate behaviour. - * </p> - * - * @param session the CVS session - */ - protected void sendLocalWorkingDirectory(Session session) throws CVSException { - ICVSFolder localRoot = session.getLocalRoot(); - if (localRoot.isCVSFolder()) { - session.sendLocalRootDirectory(); - } else { - session.sendConstructedRootDirectory(); - } - } - - /** - * Computes an array of ICVSResources corresponding to command arguments. - * [template method] - * <p> - * The default implementation assumes that all arguments supplied to the - * command represent resources in the local root that are to be manipulated. - * Subclasses must override this method if this assumption does not hold. - * </p> - * @param session the CVS session - * @param localOptions the command local options - * @param arguments the command arguments - * @return the resource arguments for the command - */ - protected ICVSResource[] computeWorkResources(Session session, - LocalOption[] localOptions, String[] arguments) throws CVSException { - ICVSFolder localRoot = session.getLocalRoot(); - - if (arguments.length == 0) { - // As a convenience, passing no arguments to the CVS command - // implies the command will operate on the local root folder. - return new ICVSResource[] { localRoot }; - } else { - // Assume all arguments represent resources that are descendants - // of the local root folder. - ICVSResource[] resources = new ICVSResource[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - ICVSResource resource = localRoot.getChild(arguments[i]); - // file does not exist, it could have been deleted. It doesn't matter - // which type we return since only the name of the resource is used - // and sent to the server. - if(resource==null) { - if(localRoot.getName().length()==0) { - // Return a folder because it is the safest choice when - // localRoot is a handle to the IWorkspaceRoot! - resource = localRoot.getFolder(arguments[i]); - } else { - resource = localRoot.getFile(arguments[i]); - } - } - resources[i] = resource; - } - return resources; - } - } - - /** - * Send an array of Resources. - * @param localOptions - * - * @see Command#sendFileStructure(ICVSResource,IProgressMonitor,boolean,boolean,boolean) - */ - protected void sendFileStructure(Session session, ICVSResource[] resources, - LocalOption[] localOptions, boolean emptyFolders, IProgressMonitor monitor) throws CVSException { - checkResourcesManaged(session, resources); - - new FileStructureVisitor(session, localOptions, emptyFolders, true).visit(session, resources, monitor); - } - - /** - * Checks that all work resources are managed. - * @param session TODO - * @param resources the resource arguments for the command - * - * @throws CVSException if some resources are not managed - */ - protected void checkResourcesManaged(Session session, ICVSResource[] resources) throws CVSException { - for (int i = 0; i < resources.length; ++i) { - ICVSFolder folder; - if (resources[i].isFolder()) { - folder = (ICVSFolder) resources[i]; - } - else { - folder = resources[i].getParent(); - } - if (!folder.isCVSFolder() && folder.exists()) { - IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR,NLS.bind(CVSMessages.Command_argumentNotManaged, new String[] { folder.getName() }),session.getLocalRoot()); - throw new CVSException(status); - } - } - } - - /** - * Executes a CVS command. - * <p> - * Dispatches the commands, retrieves the results, and determines whether or - * not an error occurred. A listener may be supplied to capture message text - * that would normally be written to the standard error and standard output - * streams of a command line CVS client. - * </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 arguments (usually filenames relative to localRoot), or NO_ARGUMENTS - * @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) - */ - public final IStatus execute(final Session session, final GlobalOption[] globalOptions, - final LocalOption[] localOptions, final String[] arguments, final ICommandOutputListener listener, - IProgressMonitor pm) throws CVSException { - final IStatus[] status = new IStatus[1]; - ICVSRunnable job = new ICVSRunnable() { - public void run(IProgressMonitor monitor) throws CVSException { - // update the global and local options - GlobalOption[] gOptions = filterGlobalOptions(session, globalOptions); - LocalOption[] lOptions = filterLocalOptions(session, gOptions, localOptions); - - // print the invocation string to the console - if (session.isOutputToConsole() || Policy.isDebugProtocol()) { - IPath commandRootPath; - IResource resource = session.getLocalRoot().getIResource(); - if (resource == null) { - commandRootPath = Path.EMPTY; - } else { - commandRootPath = resource.getFullPath(); - } - String line = constructCommandInvocationString(commandRootPath, gOptions, lOptions, arguments); - ConsoleListeners.getInstance().commandInvoked(session, line); - if (Policy.isDebugProtocol()) Policy.printProtocolLine("CMD> " + line); //$NON-NLS-1$ - } - - // run the command - try { - session.setCurrentCommand(Command.this); - status[0] = doExecute(session, gOptions, lOptions, arguments, listener, monitor); - notifyConsoleOnCompletion(session, status[0], null); - } catch (CVSException e) { - notifyConsoleOnCompletion(session, null, e); - throw e; - } catch (RuntimeException e) { - notifyConsoleOnCompletion(session, null, e); - throw e; - } - } - }; - if (isWorkspaceModification()) { - session.getLocalRoot().run(job, pm); - } else { - job.run(pm); - } - return status[0]; - } - - /** - * Return whether this command modifies the workspace. - * If <code>true</code> is returned, a scheduling rule on - * the session local root is obtained. Otherwise, no - * scheduling rule is obtained. By default, <code>true</code> - * is returned - * @return whether this command modifies the workspace - */ - protected boolean isWorkspaceModification() { - return true; - } - - private void notifyConsoleOnCompletion(Session session, IStatus status, Exception exception) { - ConsoleListeners.getInstance().commandCompleted(session, status, exception); - if (Policy.isDebugProtocol()) { - if (status != null) Policy.printProtocolLine("RESULT> " + status.toString()); //$NON-NLS-1$ - else Policy.printProtocolLine("RESULT> " + exception.toString()); //$NON-NLS-1$ - } - } - - protected IStatus doExecute(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, - IProgressMonitor monitor) throws CVSException { - ICVSResource[] resources = null; - /*** setup progress monitor ***/ - monitor = Policy.monitorFor(monitor); - monitor.beginTask(null, 100); - Policy.checkCanceled(monitor); - try { - /*** prepare for command ***/ - // clear stale command state from previous runs - session.setNoLocalChanges(DO_NOT_CHANGE.isElementOf(globalOptions)); - session.setModTime(null); - - /*** initiate command ***/ - // send global options - for (int i = 0; i < globalOptions.length; i++) { - globalOptions[i].send(session); - } - Policy.checkCanceled(monitor); - // send local options - for (int i = 0; i < localOptions.length; i++) { - localOptions[i].send(session); - } - Policy.checkCanceled(monitor); - // compute the work resources - resources = computeWorkResources(session, localOptions, arguments); - Policy.checkCanceled(monitor); - // send local working directory state contributes 48% of work - resources = sendLocalResourceState(session, globalOptions, localOptions, - resources, Policy.infiniteSubMonitorFor(monitor, 48)); - Policy.checkCanceled(monitor); - // escape file names, see bug 149683 - for(int i = 0; i < arguments.length; i++){ - if(arguments[i].startsWith("-")){ //$NON-NLS-1$ - arguments[i] = "./" + arguments[i]; //$NON-NLS-1$ - } - } - // send arguments - sendArguments(session, arguments); - // send local working directory path - sendLocalWorkingDirectory(session); - - // if no listener was provided, use the command's default in order to get error reporting - if (listener == null) listener = getDefaultCommandOutputListener(); - - /*** execute command and process responses ***/ - // Processing responses contributes 50% of work. - IStatus status = executeRequest(session, listener, Policy.subMonitorFor(monitor, 50)); - - // Finished adds last 2% of work. - status = commandFinished(session, globalOptions, localOptions, resources, Policy.subMonitorFor(monitor, 2), - status); - return status; - } finally { - monitor.done(); - } - } - - /** - * Constucts the CVS command invocation string corresponding to the arguments. - * - * @param globalOptions the global options - * @param localOption the local options - * @param arguments the arguments - * @return the command invocation string - */ - private String constructCommandInvocationString(IPath commandRootPath, GlobalOption[] globalOptions, - LocalOption[] localOptions, String[] arguments) { - StringBuffer commandLine = new StringBuffer("cvs"); //$NON-NLS-1$ - for (int i = 0; i < globalOptions.length; ++i) { - String option = globalOptions[i].toString(); - if (option.length() == 0) continue; - commandLine.append(' '); - commandLine.append(option); - } - commandLine.append(' '); - commandLine.append(getRequestId()); - for (int i = 0; i < localOptions.length; ++i) { - String option = localOptions[i].toString(); - if (option.length() == 0) continue; - commandLine.append(' '); - commandLine.append(option); - } - for (int i = 0; i < arguments.length; ++i) { - if (arguments[i].length() == 0) continue; - commandLine.append(" \""); //$NON-NLS-1$ - IPath completePath = commandRootPath; - if (!arguments[i].equals(Session.CURRENT_LOCAL_FOLDER)) { - completePath = completePath.append(arguments[i]); - } - commandLine.append(completePath.toString()); - commandLine.append('"'); - } - return commandLine.toString(); - } - - /** - * Superclass for all CVS command options - */ - protected static abstract class Option { - protected String option, argument; - protected Option(String option, String argument) { - this.option = option; - this.argument = argument; - } - /** - * Determines if this option is an element of an array of options - * @param array the array of options - * @return true iff the array contains this option - */ - public boolean isElementOf(Option[] array) { - return findOption(array, option) != null; - } - /** - * Returns the option part of the option - */ - String getOption() { - return option; - } - /** - * Compares two options for equality. - * @param other the other option - */ - public boolean equals(Object other) { - if (this == other) return true; - if (other instanceof Option) { - Option otherOption = (Option) other; - return option.equals(otherOption.option); - } - return false; - } - /** - * Sends the option to a CVS server - * @param session the CVS session - */ - public abstract void send(Session session) throws CVSException; - /* - * To make debugging a tad easier. - */ - public String toString() { - if (argument != null && argument.length() != 0) { - return option + " \"" + argument + '"'; //$NON-NLS-1$ - } else { - return option; - } - } - } - /** - * Option subtype for global options that are common to all commands. - */ - public static class GlobalOption extends Option { - protected GlobalOption(String option) { - super(option, null); - } - public void send(Session session) throws CVSException { - session.sendGlobalOption(option); - } - /** - * Add the given global option to the end of the provided list - * - * @param newOption - * @param options - * @return GlobalOption[] - */ - protected GlobalOption[] addToEnd(GlobalOption[] options) { - GlobalOption[] globalOptions = new GlobalOption[options.length + 1]; - System.arraycopy(options, 0, globalOptions, 0, options.length); - globalOptions[globalOptions.length - 1] = this; - return globalOptions; - } - } - /** - * Option subtype for global quietness options. - */ - public static final class QuietOption extends GlobalOption { - private QuietOption(String option) { - super(option); - } - public void send(Session session) throws CVSException { - if (option.length() != 0) super.send(session); - } - } - /** - * Option subtype for local options that vary from command to command. - */ - public static class LocalOption extends Option { - protected LocalOption(String option) { - super(option, null); - } - protected LocalOption(String option, String argument) { - super(option, argument); - } - public void send(Session session) throws CVSException { - session.sendArgument(option); - if (argument != null) session.sendArgument(argument); - } - public LocalOption[] addTo(LocalOption[] options) { - if (this.isElementOf(options)) { - return options; - } - LocalOption[] newOptions = new LocalOption[options.length + 1]; - System.arraycopy(options, 0, newOptions, 0, options.length); - newOptions[options.length] = this; - return newOptions; - } - public LocalOption[] removeFrom(LocalOption[] options) { - if (!this.isElementOf(options)) { - return options; - } - List result = new ArrayList(); - for (int i = 0; i < options.length; i++) { - Command.LocalOption option = options[i]; - if (!option.equals(this)) { - result.add(option); - } - } - return (LocalOption[]) result.toArray(new LocalOption[result.size()]); - } - } - /** - * Options subtype for keyword substitution options. - */ - public static class KSubstOption extends LocalOption { - private boolean isUnknownMode; - private KSubstOption(String option) { - this(option, false); - } - private KSubstOption(String option, boolean isUnknownMode) { - super(option); - this.isUnknownMode = isUnknownMode; - ksubstOptionMap.put(option, this); - } - /** - * Gets the KSubstOption instance for the specified mode. - * - * @param mode the mode, e.g. -kb - * @return an instance for that mode - */ - public static KSubstOption fromMode(String mode) { - if (mode.length() == 0) mode = "-kkv"; // use default //$NON-NLS-1$ - KSubstOption option = (KSubstOption) ksubstOptionMap.get(mode); - if (option == null) option = new KSubstOption(mode, true); - return option; - } - /** - * Gets the KSubstOption instance for the specified file. - * - * @param file the file to get the option for - * @return an instance for that mode - */ - public static KSubstOption fromFile(IFile file) { - if (CVSProviderPlugin.isText(file)) - return getDefaultTextMode(); - return KSUBST_BINARY; - } - /** - * Returns an array of all valid modes. - */ - public static KSubstOption[] getAllKSubstOptions() { - return (KSubstOption[]) ksubstOptionMap.values().toArray(new KSubstOption[ksubstOptionMap.size()]); - } - /** - * Returns the entry line mode string for this instance. Note that it might return blank strings - * for certain options. For UI, use {@link #toMode()} which will always return the a string - * containing the keyword substitution. - */ - public String toEntryLineMode() { - if (KSUBST_TEXT_EXPAND.equals(this)) return ""; //$NON-NLS-1$ - return getOption(); - } - - /** - * Returns the entry line mode string for this instance. - */ - public String toMode(){ - return getOption(); - } - - /** - * Returns true if the substitution mode requires no data translation - * during file transfer. - */ - public boolean isBinary() { - return KSUBST_BINARY.equals(this); - } - /** - * Returns a short localized text string describing this mode. - */ - public String getShortDisplayText() { - if (isUnknownMode) - return NLS.bind(CVSMessages.KSubstOption_unknown_short, new String[] { option }); - if (option.equals("-kb")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kb_short; - if (option.equals("-kkv")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kkv_short; - if (option.equals("-ko")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__ko_short; - if (option.equals("-kk")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kk_short; - if (option.equals("-kv")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kv_short; - if (option.equals("-kkvl")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kkvl_short; - return NLS.bind(CVSMessages.KSubstOption_unknown_short, new String[] { option }); - } - /** - * Returns a long localized text string describing this mode. - */ - public String getLongDisplayText() { - if (isUnknownMode) - return NLS.bind(CVSMessages.KSubstOption_unknown_long, new String[] { option }); - if (option.equals("-kb")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kb_long; - if (option.equals("-kkv")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kkv_long; - if (option.equals("-ko")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__ko_long; - if (option.equals("-kk")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kk_long; - if (option.equals("-kv")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kv_long; - if (option.equals("-kkvl")) //$NON-NLS-1$ - return CVSMessages.KSubstOption__kkvl_long; - return NLS.bind(CVSMessages.KSubstOption_unknown_long, new String[] { option }); - } - /** - * Return the text mode that will be used by default - */ - public static KSubstOption getDefaultTextMode() { - return CVSProviderPlugin.getPlugin().getDefaultTextKSubstOption(); - } - } - - /** - * Makes a -m log message option. - * Valid for: add commit import - */ - public static LocalOption makeArgumentOption(LocalOption option, String argument) { - if(argument == null) { - argument = ""; //$NON-NLS-1$ - } - return new LocalOption(option.getOption(), argument); - } - - /** - * Makes a -r or -D option for a tag. - * Valid for: checkout export history rdiff update - */ - public static LocalOption makeTagOption(CVSTag tag) { - int type = tag.getType(); - switch (type) { - case CVSTag.BRANCH: - case CVSTag.VERSION: - return new LocalOption("-r", tag.getName()); //$NON-NLS-1$ - case CVSTag.DATE: - return new LocalOption("-D", tag.getName()); //$NON-NLS-1$ - default: - // tag must not be HEAD - throw new IllegalArgumentException(CVSMessages.Command_invalidTag); - } - } - - /** - * Find a specific option in an array of options - * @param array the array of options - * @param option the option string to search for - * @return the first element matching the option string, or null if none - */ - public static Option findOption(Option[] array, String option) { - for (int i = 0; i < array.length; ++i) { - if (array[i].getOption().equals(option)) return array[i]; - } - return null; - } - - /** - * Collect all arguments of a specific option from an array of options - * @param array the array of options - * @param option the option string to search for - * @return an array of all arguments of belonging to matching options - */ - protected static String[] collectOptionArguments(Option[] array, String option) { - List /* of String */ list = new ArrayList(); - for (int i = 0; i < array.length; ++i) { - if (array[i].getOption().equals(option)) { - list.add(array[i].argument); - } - } - return (String[]) list.toArray(new String[list.size()]); - } - - /** - * Allows commands to filter the set of global options to be sent. - * This method invokes the method of the same name on the session - * itself in order to get any session wide or globally set options. - * Subclasses that override this method should call the superclass. - * - * @param session the session - * @param globalOptions the global options, read-only - * @return the filtered global options - */ - protected GlobalOption[] filterGlobalOptions(Session session, GlobalOption[] globalOptions) { - return session.filterGlobalOptions(globalOptions); - } - - /** - * Allows commands to filter the set of local options to be sent. - * Subclasses that override this method should call the superclass. - * - * @param session the session - * @param globalOptions the global options, read-only - * @param localOptions the local options, read-only - * @return the filtered local options - */ - protected LocalOption[] filterLocalOptions(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions) { - return localOptions; - } - - /** - * 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 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].getRelativePath(openSession.getLocalRoot())); - } - return (String[]) stringArguments.toArray(new String[stringArguments.size()]); - } - - /** - * Method mergeStatus. - * @param status - * @param cVSStatus - * @return IStatus - */ - protected IStatus mergeStatus(IStatus accumulatedStatus, IStatus newStatus) { - if (accumulatedStatus.isMultiStatus()) { - ((MultiStatus)accumulatedStatus).merge(newStatus); - return accumulatedStatus; - } - if (accumulatedStatus.isOK()) return newStatus; - if (newStatus.isOK()) return accumulatedStatus; - MultiStatus result = new MultiStatus(CVSProviderPlugin.ID, IStatus.INFO, - new IStatus[] {accumulatedStatus, newStatus}, - NLS.bind(CVSMessages.Command_warnings, new String[] { getDisplayText() }), null); - return result; - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CommandOutputListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CommandOutputListener.java deleted file mode 100644 index 8eed8512b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CommandOutputListener.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -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.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; - -public class CommandOutputListener implements ICommandOutputListener { - - /* - * Failure string that is returned from the server when pserver is used and the root directory - * is not readable. The problem can be fixed by making the directory readable or by using -f in - * the pserver configuration file. We will ignore the error since it does not affect the command. - */ - public static final String ROOT_CVSIGNORE_READ_FAILURE = "cvs server: cannot open /root/.cvsignore: Permission denied"; //$NON-NLS-1$ - - public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - return OK; - } - public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - String protocolError = getProtocolError(line, location); - if (protocolError != null) { - return new CVSStatus(IStatus.ERROR, CVSStatus.PROTOCOL_ERROR, protocolError, commandRoot); - } - if (line.equals(ROOT_CVSIGNORE_READ_FAILURE) || getServerMessage(ROOT_CVSIGNORE_READ_FAILURE, location).equals(getServerMessage(line, location))) { - // Don't report this as an error since it does not affect the command - return new CVSStatus(IStatus.WARNING, CVSStatus.ERROR_LINE, line, commandRoot); - } - return new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE, line, commandRoot); - } - - /** - * Return the portion of the line that describes the error if the error line - * is a protocol error or null if the line is not a protocol error. - * - * @param line the error line received from the server - * @param location the repository location - * @return String the potocol error or null - */ - protected String getProtocolError(String line, ICVSRepositoryLocation location) { - if (line.startsWith("Protocol error:")) { //$NON-NLS-1$ - return line; - } - return null; - } - - public String getServerMessage(String line, ICVSRepositoryLocation location) { - return ((CVSRepositoryLocation)location).getServerMessageWithoutPrefix(line, SERVER_PREFIX); - } - - public String getServerAbortedMessage(String line, ICVSRepositoryLocation location) { - return ((CVSRepositoryLocation)location).getServerMessageWithoutPrefix(line, SERVER_ABORTED_PREFIX); - } - - public String getServerRTagMessage(String line, ICVSRepositoryLocation location) { - return ((CVSRepositoryLocation)location).getServerMessageWithoutPrefix(line, RTAG_PREFIX); - } -} 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 deleted file mode 100644 index 6ad5c676b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import java.util.Collection; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.Status; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; - -public class Commit extends Command { - /*** Local options: specific to commit ***/ - // Forces a file to be committed even if it has not been modified; implies -l. - // NOTE: This option is not fully supported -- a file will not be sent - // unless it is dirty. The primary use is to resend a file that may - // or may not be changed (e.g. could depend on CR/LF translations, etc...) - // and force the server to create a new revision and reply Checked-in. - public static final LocalOption FORCE = new LocalOption("-f"); //$NON-NLS-1$ - - protected Commit() { } - protected String getRequestId() { - return "ci"; //$NON-NLS-1$ - } - - /** - * Send all files under the workingFolder as changed files to - * the server. - */ - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // Get the folders we want to work on - checkResourcesManaged(session, resources); - - // Send all changed files to the server - ModifiedFileSender visitor = new ModifiedFileSender(session, localOptions); - visitor.visit(session, resources, monitor); - - // Send the changed files as arguments (because this is what other cvs clients do) - ICVSFile[] changedFiles = visitor.getModifiedFiles(); - for (int i = 0; i < changedFiles.length; i++) { - // escape file names, see bug 149683 - String fileName = changedFiles[i].getRelativePath(session.getLocalRoot()); - if(fileName.startsWith("-")){ //$NON-NLS-1$ - fileName = "./" + fileName; //$NON-NLS-1$ - } - session.sendArgument(fileName); - } - return changedFiles; - } - - /** - * On successful finish, prune empty directories if the -P or -D option was specified. - */ - protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, - IStatus status) throws CVSException { - // If we didn't succeed, don't do any post processing - if (status.getCode() == CVSStatus.SERVER_ERROR) { - return status; - } - - // If pruning is enable, prune empty directories after a commit - if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) { - new PruneFolderVisitor().visit(session, resources); - } - - // Reset the timestamps of any committed files that are still dirty. - // Only do so if there were no E messages from the server - if (status.isOK()) { - for (int i = 0; i < resources.length; i++) { - ICVSResource resource = resources[i]; - if (!resource.isFolder()) { - ICVSFile cvsFile = (ICVSFile)resources[i]; - if (cvsFile.exists() && cvsFile.isModified(null)) { - status = mergeStatus(status, clearModifiedState(cvsFile)); - } - } - } - } - return status; - } - - protected IStatus clearModifiedState(ICVSFile cvsFile) throws CVSException { - byte[] info = cvsFile.getSyncBytes(); - IResource resource = cvsFile.getIResource(); - String filePath; - if (resource == null) { - filePath = cvsFile.getRepositoryRelativePath(); - } else { - filePath = resource.getFullPath().toString(); - } - if (info == null) { - // There should be sync info. Log the problem - return new Status(IStatus.WARNING, CVSProviderPlugin.ID, 0, NLS.bind(CVSMessages.Commit_syncInfoMissing, new String[] { filePath }), null); - } - cvsFile.checkedIn(null, true /* commit in progress */); - return new Status(IStatus.INFO, CVSProviderPlugin.ID, 0, NLS.bind(CVSMessages.Commit_timestampReset, new String[] { filePath }), null); //; - } - - /** - * We do not want to send the arguments here, because we send - * them in sendRequestsToServer (special handling). - */ - protected void sendArguments(Session session, String[] arguments) throws CVSException { - } - - public final IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, - ICVSResource[] arguments, Collection filesToCommitAsText, - ICommandOutputListener listener, IProgressMonitor pm) throws CVSException { - - session.setTextTransferOverride(filesToCommitAsText); - try { - return super.execute(session, globalOptions, localOptions, arguments, listener, pm); - } finally { - session.setTextTransferOverride(null); - } - } - - protected String getDisplayText() { - return "commit"; //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ConsoleListeners.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ConsoleListeners.java deleted file mode 100644 index f5ec56c79..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ConsoleListeners.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener; - -/** - * Class which forwards CVS console output to 1 or more - * registered console listeners. - */ -public class ConsoleListeners implements IConsoleListener { - - private static ConsoleListeners instance = new ConsoleListeners(); - private Set listeners = new HashSet(); - - /** - * Return the console listeners - * @return the console listeners - */ - public static ConsoleListeners getInstance() { - return instance; - } - - public void addListener(IConsoleListener listener) { - synchronized(listeners) { - listeners.add(listener); - } - } - - public void removeListener(IConsoleListener listener) { - synchronized(listeners) { - listeners.remove(listener); - } - } - - private IConsoleListener[] getListeners() { - synchronized(listeners) { - return (IConsoleListener[]) listeners.toArray(new IConsoleListener[listeners.size()]); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener#commandInvoked(java.lang.String) - */ - public void commandInvoked(final Session session, final String line) { - if (listeners.isEmpty()) return; - IConsoleListener[] listeners = getListeners(); - for (int i = 0; i < listeners.length; i++) { - final IConsoleListener listener = listeners[i]; - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - // Exception logged by Platform - } - public void run() throws Exception { - listener.commandInvoked(session, line); - } - }); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener#messageLineReceived(java.lang.String) - */ - public void messageLineReceived(final Session session, final String line, final IStatus status) { - if (listeners.isEmpty()) return; - IConsoleListener[] listeners = getListeners(); - for (int i = 0; i < listeners.length; i++) { - final IConsoleListener listener = listeners[i]; - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - // Exception logged by Platform - } - public void run() throws Exception { - listener.messageLineReceived(session, line, status); - } - }); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener#errorLineReceived(java.lang.String) - */ - public void errorLineReceived(final Session session, final String line, final IStatus status) { - if (listeners.isEmpty()) return; - IConsoleListener[] listeners = getListeners(); - for (int i = 0; i < listeners.length; i++) { - final IConsoleListener listener = listeners[i]; - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - // Exception logged by Platform - } - public void run() throws Exception { - listener.errorLineReceived(session, line, status); - } - }); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.listeners.IConsoleListener#commandCompleted(org.eclipse.core.runtime.IStatus, java.lang.Exception) - */ - public void commandCompleted(final Session session, final IStatus status, final Exception exception) { - if (listeners.isEmpty()) return; - IConsoleListener[] listeners = getListeners(); - for (int i = 0; i < listeners.length; i++) { - final IConsoleListener listener = listeners[i]; - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - // Exception logged by Platform - } - public void run() throws Exception { - listener.commandCompleted(session, status, exception); - } - }); - } - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CopyHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CopyHandler.java deleted file mode 100644 index d2a25d5c1..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CopyHandler.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.*; - -/** - * Handles a "Copy-file" response from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Copy-file myproject/ \n - * /u/cvsroot/myproject/oldfile.txt \n - * newfile.txt - * [...] - * </pre> - * Then we copy (or optionally rename) the local file "oldfile.txt" in - * folder "myproject" to "newfile.txt". This response is used to create - * a backup copy of an existing file before merging in new changes. - * </p> - */ -class CopyHandler extends ResponseHandler { - public String getResponseID() { - return "Copy-file"; //$NON-NLS-1$ - } - - public void handle(Session session, String localDir, - IProgressMonitor monitor) throws CVSException { - // read additional data for the response - String repositoryFile = session.readLine(); - String newFile = session.readLine(); - if (session.isNoLocalChanges() || ! session.isCreateBackups()) return; - - // Get the local file - String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$ - ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); - ICVSFile mFile = mParent.getFile(fileName); - - Assert.isTrue(mParent.exists()); - Assert.isTrue(mFile.exists() && mFile.isManaged()); - - // rename the file - mFile.copyTo(newFile); - } -} - 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 deleted file mode 100644 index 07ef7f070..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSResource; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; - -/** - * Runs the CVS diff command. - */ -public class Diff extends Command { - /*** Local options: specific to diff ***/ - 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() { - return "diff"; //$NON-NLS-1$ - } - - /** - * Overwritten to throw the CVSDiffException if the server returns an error, because it just does - * so when there is a difference between the checked files. - */ - protected IStatus doExecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, - String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor) throws CVSException { - try { - IStatus status = super.doExecute(session, globalOptions, localOptions, arguments, listener, monitor); - if (status.getCode() == CVSStatus.SERVER_ERROR) { - if (status.isMultiStatus()) { - IStatus[] children = status.getChildren(); - for (int i = 0; i < children.length; i++) { - IStatus child = children[i]; - if (child.getMessage().indexOf("[diff aborted]") != -1) { //$NON-NLS-1$ - throw new CVSServerException(status); - } - } - } - } - return status; - } catch (CVSServerException e) { - if (e.containsErrors()) throw e; - return e.getStatus(); - } - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - checkResourcesManaged(session, resources); - DiffStructureVisitor visitor = new DiffStructureVisitor(session, localOptions); - visitor.visit(session, resources, monitor); - return resources; - } - - protected String getServerErrorMessage() { - return CVSMessages.Diff_serverError; - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/DiffStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/DiffStructureVisitor.java deleted file mode 100644 index 4c3d45c3b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/DiffStructureVisitor.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; - -/** - * The diff command needs to send a file structure to the server that differs somewhat from the canonical - * format sent by other commands. Instead of sending new files as questionables this class sends - * new files as modified and fakes them being added. The contents are sent to the server and are - * included in the returned diff report. - */ -class DiffStructureVisitor extends FileStructureVisitor { - - public DiffStructureVisitor(Session session, LocalOption[] localOptions) { - super(session, localOptions, true, true); - } - - /** - * Send unmanaged files as modified with a default entry line. - */ - protected void sendFile(ICVSFile mFile) throws CVSException { - byte[] info = mFile.getSyncBytes(); - if (info==null) { - return; - } - - // Send the parent folder if it hasn't been sent already - sendFolder(mFile.getParent()); - Policy.checkCanceled(monitor); - session.sendEntry(info, null); - - if (!mFile.exists()) { - return; - } - - if (mFile.isModified(null)) { - session.sendModified(mFile, ResourceSyncInfo.isBinary(info), monitor); - } else { - session.sendUnchanged(mFile); - } - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Editors.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Editors.java deleted file mode 100644 index 4175282e9..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Editors.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * CSC - Intial implementation - * IBM Corporation - ongoing maintenance - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -/** - * - * The editors command - * - * @author <a href="mailto:kohlwes@gmx.net">Gregor Kohlwes</a> - */ -public class Editors extends AbstractMessageCommand { - - /** - * @see org.eclipse.team.internal.ccvs.core.client.Request#getRequestId() - */ - protected String getRequestId() { - return "editors"; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#isWorkspaceModification() - */ - protected boolean isWorkspaceModification() { - return false; - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ExpandModules.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ExpandModules.java deleted file mode 100644 index dd7297c7c..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ExpandModules.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.CVSException; - -public class ExpandModules extends Request { - protected ExpandModules() { } - protected String getRequestId() { - return "expand-modules"; //$NON-NLS-1$ - } - - public IStatus execute(Session session, String[] modules, IProgressMonitor monitor) throws CVSException { - // Reset the module expansions before the responses arrive - session.resetModuleExpansion(); - for (int i = 0; i < modules.length; ++i) { - session.sendArgument(modules[i]); - } - return executeRequest(session, Command.DEFAULT_OUTPUT_LISTENER, monitor); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/FileStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/FileStructureVisitor.java deleted file mode 100644 index 298c3384e..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/FileStructureVisitor.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSFile; -import org.eclipse.team.internal.ccvs.core.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.ICVSResource; -import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; - -/** - * Visitor to send the local file structure to the CVS Server. - * - * Files are sent as Unchanged or Modified. - * Folders are sent if they contain files unless sendEmptyFolders is true - * in which case all folders are sent. - * - * @param sendEmptyFolders sends the folder-entrie even if there is no file - to send in it - */ - -class FileStructureVisitor extends AbstractStructureVisitor { - - private boolean sendEmptyFolders; - - public FileStructureVisitor(Session session, LocalOption[] localOptions, boolean sendEmptyFolders, boolean sendModifiedContents) { - this(session, localOptions, sendEmptyFolders, sendModifiedContents, true); - } - - public FileStructureVisitor(Session session, LocalOption[] localOptions, boolean sendEmptyFolders, boolean sendModifiedContents, boolean sendBinary) { - super(session, localOptions, true, sendModifiedContents, sendBinary); - this.sendEmptyFolders = sendEmptyFolders; - } - - /** - * @see ICVSResourceVisitor#visitFile(IManagedFile) - */ - public void visitFile(ICVSFile mFile) throws CVSException { - sendFile(mFile); - } - - /** - * @see ICVSResourceVisitor#visitFolder(ICVSFolder) - */ - public void visitFolder(ICVSFolder mFolder) throws CVSException { - - if (sendEmptyFolders) { - // If we want to send empty folder, that just send it when - // we come to it - sendFolder(mFolder); - } - - boolean exists = mFolder.exists(); - boolean isCVSFolder = mFolder.isCVSFolder(); - - // We are only interested in CVS folders - // A folder could be a non-existant CVS folder if it is a holder for outgoing file deletions - if ( ! isCVSFolder) return; - - if (exists && isOrphanedSubtree(mFolder)) { - return; - } - - // Send files, then the questionable folders, then the managed folders - ICVSResource[] children = mFolder.members(ICVSFolder.ALL_UNIGNORED_MEMBERS); - sendFiles(children); - sendQuestionableFolders(children); - if (isRecurse()) { - sendManagedFolders(children); - } - } - - /** - * Method sendManagedFolders. - * @param children - */ - private void sendManagedFolders(ICVSResource[] children) throws CVSException { - for (int i = 0; i < children.length; i++) { - ICVSResource resource = children[i]; - if (resource.isFolder() && resource.isManaged()) { - resource.accept(this); - } - } - } - - /** - * Method sendQuestionableFolders. - * @param children - */ - private void sendQuestionableFolders(ICVSResource[] children) throws CVSException { - for (int i = 0; i < children.length; i++) { - ICVSResource resource = children[i]; - if (resource.isFolder() && ! resource.isManaged()) { - resource.accept(this); - } - } - } - - /** - * Method sendFiles. - * @param children - */ - private void sendFiles(ICVSResource[] children) throws CVSException { - for (int i = 0; i < children.length; i++) { - ICVSResource resource = children[i]; - if (!resource.isFolder()) { - resource.accept(this); - } - } - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Import.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Import.java deleted file mode 100644 index 8ff4cac82..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Import.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -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.ICVSResource; -import org.eclipse.team.internal.ccvs.core.ICVSResourceVisitor; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; - - -public class Import extends Command { - protected Import() { } - protected String getRequestId() { - return "import"; //$NON-NLS-1$ - } - - protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, - String[] arguments) throws CVSException { - if (arguments.length < 3) throw new IllegalArgumentException(); - return new ICVSResource[0]; - } - - protected IStatus doExecute(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, - IProgressMonitor monitor) throws CVSException { - - // If the branch option is not provided, a default value of 1.1.1 is used. - // This is done to maintain reference client compatibility - if (findOption(localOptions, "-b") == null) { //$NON-NLS-1$ - LocalOption[] newLocalOptions = new LocalOption[localOptions.length + 1]; - newLocalOptions[0] = new LocalOption("-b", "1.1.1"); //$NON-NLS-1$ //$NON-NLS-2$ - System.arraycopy(localOptions, 0, newLocalOptions, 1, localOptions.length); - localOptions = newLocalOptions; - } - return super.doExecute(session, globalOptions, localOptions, arguments, listener, monitor); - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - ICVSResourceVisitor visitor = new ImportStructureVisitor(session, - collectOptionArguments(localOptions, "-W"), monitor); //$NON-NLS-1$ - session.getLocalRoot().accept(visitor); - return resources; - } - - protected void sendLocalWorkingDirectory(Session session) throws CVSException { - session.sendConstructedRootDirectory(); - } - -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ImportStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ImportStructureVisitor.java deleted file mode 100644 index d218a4e82..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ImportStructureVisitor.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.core.Team; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption; -import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher; - -/** - * The ImportStructureVisitor sends the content of the folder it is - * used on to the server. It constructs the locations of the resources - * because the resources do not yet have a remote-location.<br> - * It can also ignore certain files and decides wether to send - * a file in binary or text mode due to a specification that is passed - * as a "wrapper" argument. - */ -class ImportStructureVisitor implements ICVSResourceVisitor { - - private static final String KEYWORD_OPTION = "-k"; //$NON-NLS-1$ - private static final String QUOTE = "'"; //$NON-NLS-1$ - - protected Session session; - protected IProgressMonitor monitor; - - private FileNameMatcher ignoreMatcher; - private FileNameMatcher wrapMatcher; - - /** - * Constructor for ImportStructureVisitor. - * @param requestSender - * @param mRoot - * @param monitor - */ - public ImportStructureVisitor(Session session, - String[] wrappers, IProgressMonitor monitor) { - - this.session = session; - this.monitor = Policy.infiniteSubMonitorFor(monitor, 512); - wrapMatcher = initWrapMatcher(wrappers); - } - - - /** - * Inits the wrapMatcher, that is responsible to find out - * whether a file is to be send as a binary (on an import) - * or not. - * - * Takes wrappers of this format: - * *.class -k 'o' - * - * and inits the FileNameMatcher to give - * -ko back if you call it with match("somename.class") - * - * ignores all wrappers, that do not contain -k - */ - private FileNameMatcher initWrapMatcher(String[] wrappers) { - - FileNameMatcher wrapMatcher; - - if (wrappers == null) { - return null; - } - - wrapMatcher = new FileNameMatcher(); - - for (int i = 0; i < wrappers.length; i++) { - - if (wrappers[i].indexOf(KEYWORD_OPTION) == -1) { - continue; - } - - StringTokenizer st = new StringTokenizer(wrappers[i]); - String pattern = st.nextToken(); - String option = st.nextToken(); - // get rid of the quotes - StringTokenizer quoteSt = - new StringTokenizer(st.nextToken(),QUOTE); - option += quoteSt.nextToken(); - - wrapMatcher.register(pattern,option); - } - - return wrapMatcher; - } - - /** - * @see ICVSResourceVisitor#visitFile(IManagedFile) - */ - public void visitFile(ICVSFile mFile) throws CVSException { - if (ignoreMatcher != null && ignoreMatcher.match(mFile.getName())) { - return; - } - - boolean binary = Team.getFileContentManager().getType((IFile)mFile.getIResource()) == Team.BINARY; - if (wrapMatcher != null) { - String mode = wrapMatcher.getMatch(mFile.getName()); - if (mode != null) binary = KSubstOption.fromMode(mode).isBinary(); - } - session.sendModified(mFile, binary, monitor); - } - - /** - * @see ICVSResourceVisitor#visitFolder(ICVSFolder) - */ - public void visitFolder(ICVSFolder mFolder) throws CVSException { - - if (ignoreMatcher != null && ignoreMatcher.match(mFolder.getName())) { - return; - } - - String localPath = mFolder.getRelativePath(session.getLocalRoot()); - monitor.subTask(NLS.bind(CVSMessages.AbstractStructureVisitor_sendingFolder, new String[] { localPath })); - - session.sendConstructedDirectory(localPath); - mFolder.acceptChildren(this); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Log.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Log.java deleted file mode 100644 index 69e6befda..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Log.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSResource; - -public class Log extends AbstractMessageCommand { - /*** Local options: specific to log ***/ - - public static LocalOption makeRevisionOption(String revision) { - return new LocalOption("-r" + revision, null); //$NON-NLS-1$ - } - public static final LocalOption RCS_FILE_NAMES_ONLY = new LocalOption("-R"); //$NON-NLS-1$ - - public static final LocalOption NO_TAGS = new LocalOption("-N"); //$NON-NLS-1$ - - protected Log() { } - protected String getRequestId() { - return "log"; //$NON-NLS-1$ - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // Send all folders that are already managed to the server - boolean sendEmptyFolders = Command.findOption(localOptions, RCS_FILE_NAMES_ONLY.getOption()) != null; - new FileStructureVisitor(session, localOptions, sendEmptyFolders, false /* send modified contents */).visit(session, resources, monitor); - return resources; - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java deleted file mode 100644 index 7bc1bc22b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; - -public class MTHandler extends ResponseHandler { - - private String nextLine; - private boolean isLineAvailable; - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#getInstance() - */ - ResponseHandler getInstance() { - return new MTHandler(); - } - - /** - * @see ResponseHandler#getResponseID() - */ - public String getResponseID() { - return "MT"; //$NON-NLS-1$ - } - - /** - * @see ResponseHandler#handle(Session, String, IProgressMonitor) - */ - public void handle(Session session, String argument, IProgressMonitor monitor) - throws CVSException { - - // If there was a line available from before, clear it - if (isLineAvailable()) { - startNextLine(); - } - - if (argument.charAt(0) == '+') { - // Reset any previously accumulated text - startNextLine(); - } else if (argument.charAt(0) == '-') { - // Mark the line as available in case there was no trailing newline - if (nextLine != null) { - isLineAvailable = true; - } - } else { - // Extract the tag and text from the line - String tag; - String text; - int spaceIndex = argument.indexOf(' '); - if (spaceIndex == -1) { - tag = argument; - text = null; - } else { - tag = argument.substring(0, spaceIndex); - text = argument.substring(spaceIndex + 1); - } - - // Accumulate the line and indicate if its available for use - if (tag.equals("newline")) { //$NON-NLS-1$ - isLineAvailable = true; - } else if (text != null) { - // Reset the previous line if required - if (isLineAvailable()) { - startNextLine(); - } - // Accumulate the line - if (nextLine == null) { - nextLine = text; - } else { - // The text from the sevrver contains spaces when appropriate so just append - nextLine = nextLine + text; - } - } - } - } - - /** - * Check if there is a line available. If there is, it should be fetched with - * getLine() immediatly before the next MT response is processed. - */ - public boolean isLineAvailable() { - return isLineAvailable; - } - - /** - * Get the available line. This purges the line from the handler - */ - public String getLine() { - return nextLine; - } - - private void startNextLine() { - isLineAvailable = false; - nextLine = null; - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModTimeHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModTimeHandler.java deleted file mode 100644 index 8a9f75cbf..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModTimeHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import java.text.ParseException; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.util.CVSDateFormatter; - -/** - * Handles a "Mod-time" response from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Mod-time 18 Oct 2001 20:21:13 -0330\n - * [...] - * </pre> - * Then we parse and remember the date for use in subsequent - * file transfer responses such as Updated. - * </p> - */ -class ModTimeHandler extends ResponseHandler { - public String getResponseID() { - return "Mod-time"; //$NON-NLS-1$ - } - - public void handle(Session session, String timeStamp, - IProgressMonitor monitor) throws CVSException { - try { - session.setModTime(CVSDateFormatter.serverStampToDate(timeStamp)); - } catch (ParseException e) { - IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR,NLS.bind(CVSMessages.ModTimeHandler_invalidFormat, new String[] { timeStamp }), e, session.getLocalRoot()); - throw new CVSException(status); - } - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModifiedFileSender.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModifiedFileSender.java deleted file mode 100644 index 25d552516..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModifiedFileSender.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSFile; -import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; - -/** - * Visit the CVS file structure, only sending files if they are modified. - */ -class ModifiedFileSender extends FileStructureVisitor { - - private final Set modifiedFiles; - - public ModifiedFileSender(Session session, LocalOption[] localOptions) { - super(session, localOptions, false, true); - modifiedFiles = new HashSet(); - } - - /** - * Override sendFile to only send modified files - */ - protected void sendFile(ICVSFile mFile) throws CVSException { - // Only send the file if its modified - if (mFile.isManaged() && mFile.isModified(null)) { - super.sendFile(mFile); - modifiedFiles.add(mFile); - } - } - - protected String getSendFileMessage() { - return null; - } - - /** - * Return all the files that have been send to the server - */ - public ICVSFile[] getModifiedFiles() { - return (ICVSFile[]) modifiedFiles.toArray(new ICVSFile[modifiedFiles.size()]); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModuleExpansionHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModuleExpansionHandler.java deleted file mode 100644 index f9ac3170b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModuleExpansionHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; - -public class ModuleExpansionHandler extends ResponseHandler { - - /* - * @see ResponseHandler#getResponseID() - */ - public String getResponseID() { - return "Module-expansion";//$NON-NLS-1$ - } - - /* - * @see ResponseHandler#handle(Session, String, IProgressMonitor) - */ - public void handle(Session session, String expansion, IProgressMonitor monitor) - throws CVSException { - - session.addModuleExpansion(expansion); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NOOPCommand.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NOOPCommand.java deleted file mode 100644 index 331e7609c..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NOOPCommand.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSResource; - -/** - * Noop command that sends edit notifications to the server. - */ -public class NOOPCommand extends Command { - - /** - * @see org.eclipse.team.internal.ccvs.core.client.Command#sendLocalResourceState(Session, GlobalOption[], LocalOption[], ICVSResource[], IProgressMonitor) - */ - protected ICVSResource[] sendLocalResourceState( - Session session, - GlobalOption[] globalOptions, - LocalOption[] localOptions, - ICVSResource[] resources, - IProgressMonitor monitor) - throws CVSException { - - // The noop visitor will send any pending notifications - new NOOPVisitor(session, localOptions).visit(session, resources, monitor); - return resources; - } - - /** - * @see org.eclipse.team.internal.ccvs.core.client.Request#getRequestId() - */ - protected String getRequestId() { - return "noop"; //$NON-NLS-1$ - } - - /** - * @see org.eclipse.team.internal.ccvs.core.client.Command#sendArguments(Session, String[]) - */ - protected void sendArguments(Session session, String[] arguments)throws CVSException { - // don't send any arguments - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#isWorkspaceModification() - */ - protected boolean isWorkspaceModification() { - return false; - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NOOPVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NOOPVisitor.java deleted file mode 100644 index c2c5a8c0a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NOOPVisitor.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSFile; -import org.eclipse.team.internal.ccvs.core.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; - -/** - * Send the contents of the CVS/Notify files to the server - */ -public class NOOPVisitor extends AbstractStructureVisitor { - - public NOOPVisitor(Session session, LocalOption[] localOptions) { - // Only send non-empty folders - super(session, localOptions, false, false); - } - - /** - * @see org.eclipse.team.internal.ccvs.core.ICVSResourceVisitor#visitFile(ICVSFile) - */ - public void visitFile(ICVSFile file) throws CVSException { - sendPendingNotification(file); - } - - /** - * @see org.eclipse.team.internal.ccvs.core.ICVSResourceVisitor#visitFolder(ICVSFolder) - */ - public void visitFolder(ICVSFolder folder) throws CVSException { - if (isRecurse() && folder.isCVSFolder()) { - folder.acceptChildren(this); - } - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NewEntryHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NewEntryHandler.java deleted file mode 100644 index 123b8303e..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NewEntryHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.syncinfo.MutableResourceSyncInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; - -public class NewEntryHandler extends ResponseHandler { - - /* - * @see ResponseHandler#getResponseID() - */ - public String getResponseID() { - return "New-entry"; //$NON-NLS-1$ - } - - /* - * @see ResponseHandler#handle(Session, String, IProgressMonitor) - */ - public void handle(Session session, String localDir, IProgressMonitor monitor) - throws CVSException { - - // read additional data for the response - String repositoryFile = session.readLine(); - String entryLine = session.readLine(); - - // Clear the recorded mod-time - session.setModTime(null); - - // Get the local file - String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$ - ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); - ICVSFile mFile = mParent.getFile(fileName); - - ResourceSyncInfo fileInfo = mFile.getSyncInfo(); - MutableResourceSyncInfo newInfo = fileInfo.cloneMutable(); - newInfo.setEntryLine(entryLine); - // Set the tag to the previous tag if the new tag is the base tag (see bug 106876) - CVSTag newTag = newInfo.getTag(); - if(newTag != null && newTag.isBaseTag()) { - newInfo.setTag(fileInfo.getTag()); - } - mFile.setSyncInfo(newInfo, ICVSFile.UNKNOWN); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NotifiedHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NotifiedHandler.java deleted file mode 100644 index 86f424602..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/NotifiedHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSFile; -import org.eclipse.team.internal.ccvs.core.ICVSFolder; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class NotifiedHandler extends ResponseHandler { - - /** - * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#getResponseID() - */ - public String getResponseID() { - return "Notified"; //$NON-NLS-1$ - } - - /** - * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#handle(Session, String, IProgressMonitor) - */ - public void handle( - Session session, - String localDir, - IProgressMonitor monitor) - throws CVSException { - - // read additional data for the response - // (which is the full repository path of the file) - String repositoryFilePath = session.readLine(); - - // clear the notify info for the file - ICVSFolder folder = session.getLocalRoot().getFolder(localDir); - ICVSFile file = folder.getFile(new Path(null, repositoryFilePath).lastSegment()); - file.notificationCompleted(); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/PruneFolderVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/PruneFolderVisitor.java deleted file mode 100644 index 14dde597b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/PruneFolderVisitor.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSFile; -import org.eclipse.team.internal.ccvs.core.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.ICVSResource; -import org.eclipse.team.internal.ccvs.core.ICVSResourceVisitor; - -/** - * Goes recursivly through the folders checks if they are empyty - * and deletes them. Of course it is starting at the leaves of the - * recusion (the folders that do not have subfolders). - */ -public class PruneFolderVisitor implements ICVSResourceVisitor { - - private ICVSFolder localRoot; - - public PruneFolderVisitor() { - } - - /** - * This method is used to visit a set of ICVSResources. - */ - public void visit(Session s, ICVSResource[] resources) throws CVSException { - visit(s.getLocalRoot(), resources); - } - - /** - * This method is used to visit a set of ICVSResources. - */ - public void visit(ICVSFolder root, ICVSResource[] resources) throws CVSException { - localRoot = root; - - // Visit the resources - Set prunableParents = new HashSet(); - for (int i = 0; i < resources.length; i++) { - ICVSResource cvsResource = resources[i]; - // prune the resource and it's children when appropriate - cvsResource.accept(this); - // if the resource doesn't exists, attempt to prune it's parent - if (!cvsResource.exists()) - prunableParents.add(cvsResource.getParent()); - } - for (Iterator iter = prunableParents.iterator(); iter.hasNext();) { - ICVSFolder cvsFolder = (ICVSFolder)iter.next(); - pruneFolderAndParentsIfAppropriate(cvsFolder); - } - } - /** - * @see ICVSResourceVisitor#visitFile(IManagedFile) - */ - public void visitFile(ICVSFile file) throws CVSException { - // nothing to do here - } - - /** - * @see ICVSResourceVisitor#visitFolder(ICVSFolder) - */ - public void visitFolder(ICVSFolder folder) throws CVSException { - // First prune any empty children - folder.acceptChildren(this); - // Then prune the folder if it is empty - pruneFolderIfAppropriate(folder); - } - - private void pruneFolderIfAppropriate(ICVSFolder folder) throws CVSException { - // Only prune managed folders that are not the root of the operation - if (folder.exists() && folder.isManaged() - && ! folder.equals(getLocalRoot()) - && folder.members(ICVSFolder.ALL_EXISTING_MEMBERS).length == 0) { - - // Delete the folder but keep a phantom for local folders - folder.delete(); - } - } - - private ICVSFolder getLocalRoot() { - return localRoot; - } - - /** - * Attempt to prune the given folder. If the folder is pruned, attempt to prune it's parent. - */ - private void pruneFolderAndParentsIfAppropriate(ICVSFolder folder) throws CVSException { - pruneFolderIfAppropriate(folder); - if (!folder.exists()) { - ICVSFolder parent = folder.getParent(); - pruneFolderAndParentsIfAppropriate(parent); - } - } -} 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 deleted file mode 100644 index b1f5f1ebb..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RDiff.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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/RLog.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RLog.java deleted file mode 100644 index 12b9220cd..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RLog.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.Date; - -import org.eclipse.team.internal.ccvs.core.CVSTag; - -/** - * The "cvs rlog..." command - */ -public class RLog extends RemoteCommand { - - /*** Local options: specific to rlog ***/ - public static final LocalOption NO_TAGS = new LocalOption("-N"); //$NON-NLS-1$ - public static final LocalOption ONLY_INCLUDE_CHANGES = new LocalOption("-S"); //$NON-NLS-1$ - public static final LocalOption REVISIONS_ON_DEFAULT_BRANCH = new LocalOption("-b"); //$NON-NLS-1$ - public static final LocalOption LOCAL_DIRECTORY_ONLY = new LocalOption("-l"); //$NON-NLS-1$ - /** - * Makes a -r option for rlog. Here are the currently supported options: - * - * tag1 tag2 result - * ==== ==== ================================= - * date date date<date (all revisions between date and later) - * tag tag tag:tag (all revisions between tag and tag, must be on same branch) - * branch date >date (all revisions of date or later) - * branch tag tag: (all revisions from tag to the end of branchs tip) - * - * Valid for: rlog - */ - public static LocalOption makeTagOption(CVSTag tag1, CVSTag tag2) { - int type1 = tag1.getType(); - int type2 = tag2.getType(); - - if(type1 == type2) { - switch (type1) { - case CVSTag.HEAD: - case CVSTag.BRANCH: - // A range of branches - all revisions on all the branches in that range. - case CVSTag.VERSION: - // Revisions from tag1 to tag2 (they must be on the same branch). - return new LocalOption("-r" + tag1.getName() + ":" + tag2.getName(), null); //$NON-NLS-1$ //$NON-NLS-2$ - case CVSTag.DATE: - // Selects revisions created between DATE1 and DATE2. If DATE1 is after DATE2, use > instead; otherwise, no log messages are retrieved. - Date date1 = tag1.asDate(); - Date date2 = tag2.asDate(); - String operator = "<"; //$NON-NLS-1$ - if(date1.compareTo(date2) > 0) { - operator = ">"; //$NON-NLS-1$ - } - return new LocalOption("-d", tag1.getName() + operator + tag2.getName()); //$NON-NLS-1$ - default: - // Unknow tag type!!! - throw new IllegalArgumentException(); - } - } - - if((type1 == CVSTag.BRANCH || type1 == CVSTag.HEAD) && type2 == CVSTag.DATE) { - return new LocalOption("-d", ">" + tag2.getName()); //$NON-NLS-1$ //$NON-NLS-2$ - } - - if((type1 == CVSTag.BRANCH || type1 == CVSTag.HEAD) && type2 == CVSTag.VERSION) { - return new LocalOption("-r" + tag2.getName() + ":", null); //$NON-NLS-1$ //$NON-NLS-2$ - } - - // defaults - switch (type1) { - case CVSTag.HEAD: - case CVSTag.BRANCH: - // All revisions on this branch - case CVSTag.VERSION: - // revisions in this tag - return new LocalOption("-r" + tag1.getName(), null); //$NON-NLS-1$ - case CVSTag.DATE: - // Revisions at this date tag - return new LocalOption("-d", tag1.getName()); //$NON-NLS-1$ - default: - // Unknow tag type!!! - throw new IllegalArgumentException(); - } - } - - /*** - * Experimental - Used for obtaining the latest revisions on HEAD or the specified branch. - * @param tag1 - * @return the option to use - * - * Valid for rlog - */ - public static LocalOption getCurrentTag(CVSTag tag1) { - - int type = tag1.getType(); - - switch (type){ - case CVSTag.HEAD: - return new LocalOption("-r"); //$NON-NLS-1$ - - case CVSTag.BRANCH: - return new LocalOption("-r" + tag1.getName() + "."); //$NON-NLS-1$ //$NON-NLS-2$ - - case CVSTag.VERSION: - return new LocalOption("-r" + tag1.getName()); //$NON-NLS-1$ - - case CVSTag.DATE: - return new LocalOption("-d", tag1.asDate().toString()); //$NON-NLS-1$ - default: - // Unknow tag type!!! - throw new IllegalArgumentException(); - } - - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Request#getRequestId() - */ - protected String getRequestId() { - return "rlog"; //$NON-NLS-1$ - } -} 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 deleted file mode 100644 index 99ff4de83..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RTag.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.CVSStatus; -import org.eclipse.team.internal.ccvs.core.CVSTag; -import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource; -import org.eclipse.team.internal.ccvs.core.ICVSResource; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.client.listeners.TagListener; - -public class RTag extends RemoteCommand { - /*** Local options: specific to tag ***/ - public static final LocalOption CREATE_BRANCH = Tag.CREATE_BRANCH; - public static final LocalOption CLEAR_FROM_REMOVED = new LocalOption("-a", null); //$NON-NLS-1$ - public static final LocalOption FORCE_REASSIGNMENT = new LocalOption("-F", null); //$NON-NLS-1$ - public static final LocalOption FORCE_BRANCH_REASSIGNMENT = new LocalOption("-B", null); //$NON-NLS-1$ - - /*** Default command output listener ***/ - private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new TagListener(); - - /** - * Makes a -r or -D option for a tag. - * Valid for: checkout export history rdiff update - */ - public static LocalOption makeTagOption(CVSTag tag) { - 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(); - } - } - - protected String getRequestId() { - return "rtag"; //$NON-NLS-1$ - } - - protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, - String[] arguments) throws CVSException { - if (arguments.length < 2) throw new IllegalArgumentException(); - return super.computeWorkResources(session, localOptions, arguments); - } - - public IStatus execute(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, CVSTag sourceTag, CVSTag tag, String[] arguments, - IProgressMonitor monitor) throws CVSException { - - if(tag.getType() != CVSTag.VERSION && tag.getType() != CVSTag.BRANCH) { - throw new CVSException(new CVSStatus(IStatus.ERROR, CVSMessages.Tag_notVersionOrBranchError)); - } - - // Add the source tag to the local options - List modifiedLocalOptions = new ArrayList(localOptions.length + 1); - if (sourceTag==null) sourceTag = CVSTag.DEFAULT; - modifiedLocalOptions.addAll(Arrays.asList(localOptions)); - modifiedLocalOptions.add(makeTagOption(sourceTag)); - - // Add the CREATE_BRANCH option for a branch tag - if (tag.getType() == CVSTag.BRANCH) { - if ( ! CREATE_BRANCH.isElementOf(localOptions)) { - modifiedLocalOptions.add(CREATE_BRANCH); - } - } - - // Add the tag name to the start of the arguments - String[] newArguments = new String[arguments.length + 1]; - newArguments[0] = tag.getName(); - System.arraycopy(arguments, 0, newArguments, 1, arguments.length); - - return execute(session, globalOptions, - (LocalOption[]) modifiedLocalOptions.toArray(new LocalOption[modifiedLocalOptions.size()]), - newArguments, null, monitor); - } - - public IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, - CVSTag sourceTag, CVSTag tag, ICVSRemoteResource[] arguments, IProgressMonitor monitor) - throws CVSException { - - String[] stringArguments = convertArgumentsForOpenSession(arguments, session); - - return execute(session, globalOptions, localOptions, sourceTag, tag, stringArguments, monitor); - } - - protected ICommandOutputListener getDefaultCommandOutputListener() { - return DEFAULT_OUTPUT_LISTENER; - } -} 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 deleted file mode 100644 index fbecc624b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoteCommand.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSResource; - -/** - * This class acts as a super class for those CVS commands that do not send up the local file structure - */ -public abstract class RemoteCommand extends Command { - - protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, - String[] arguments) throws CVSException { - return new ICVSResource[0]; - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // do nothing - monitor.beginTask(null, 100); - monitor.done(); - return resources; - } - - protected void sendLocalWorkingDirectory(Session session) throws CVSException { - // do nothing - } - - /* (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++) { - ICVSResource resource = arguments[i]; - String remotePath; - if (isDefinedModule(resource)) { - remotePath = resource.getName(); - } else { - remotePath = resource.getRepositoryRelativePath(); - - } - stringArguments.add(remotePath); - } - return (String[]) stringArguments.toArray(new String[stringArguments.size()]); - } - - private boolean isDefinedModule(ICVSResource resource) { - return resource instanceof ICVSRemoteFolder && ((ICVSRemoteFolder)resource).isDefinedModule(); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Remove.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Remove.java deleted file mode 100644 index a275fdf72..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Remove.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSResource; - -public class Remove extends Command { - /*** Local options: specific to remove ***/ - - protected Remove() { } - protected String getRequestId() { - return "remove"; //$NON-NLS-1$ - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // Send all modified files to the server - // XXX Does the command line client send all modified files? - new ModifiedFileSender(session, localOptions).visit(session, resources, monitor); - return resources; - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoveEntryHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoveEntryHandler.java deleted file mode 100644 index 274a3d45e..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoveEntryHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; - -/** - * Handles a "Remove-entry" response from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Remove-entry ??? \n - * [...] - * </pre> - * Then - * </p> - */ - -/** - * It removes the file from both the entries of the parent-folder. - * This happen, when the folder has allready been removed locally - * what happens on a checkin that includes a removed file. - */ -class RemoveEntryHandler extends ResponseHandler { - public String getResponseID() { - return "Remove-entry"; //$NON-NLS-1$ - } - - public void handle(Session session, String localDir, - IProgressMonitor monitor) throws CVSException { - // read additional data for the response - String repositoryFile = session.readLine(); - - // Get the local file - String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$ - ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); - ICVSFile mFile = mParent.getFile(fileName); - if (mFile.exists()) { - IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR, NLS.bind(CVSMessages.RemoveEntryHandler_2, new String[] { mFile.getRepositoryRelativePath() }),session.getLocalRoot()); - CVSProviderPlugin.log(status); - } else { - mFile.unmanage(null); - } - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemovedHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemovedHandler.java deleted file mode 100644 index 237eb0976..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemovedHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; - -/** - * Handles a "Removed" response from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Removed ??? \n - * [...] - * </pre> - * Then - * </p> - */ - -/** - * It removes the file from both the entries of the parent-folder - * and from the local filesystem. - */ -class RemovedHandler extends ResponseHandler { - public String getResponseID() { - return "Removed"; //$NON-NLS-1$ - } - - public void handle(Session session, String localDir, IProgressMonitor monitor) throws CVSException { - - // read additional data for the response - String repositoryFile = session.readLine(); - - // Get the local file - String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$ - ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); - ICVSFile mFile = mParent.getFile(fileName); - - if ( ! mFile.isManaged()) { - IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR,NLS.bind(CVSMessages.RemovedHandler_invalid, new String[] { new Path(null, localDir).append(fileName).toString() }),session.getLocalRoot()); - throw new CVSException(status); - } - - // delete then unmanage the file - try { - if (mFile.isReadOnly()) mFile.setReadOnly(false); - mFile.delete(); - mFile.unmanage(null); - } catch (CVSException e) { - IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.RESPONSE_HANDLING_FAILURE, NLS.bind(CVSMessages.RemovedHandler_0, new String[] { getPath(mFile) }), e, session.getLocalRoot()); - session.handleResponseError(status); - } - } - - private String getPath(ICVSFile file) { - IResource resource = file.getIResource(); - if (resource != null) { - return resource.getFullPath().toString(); - } - try { - return file.getRepositoryRelativePath(); - } catch (CVSException e1) { - return file.getName(); - } - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Replace.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Replace.java deleted file mode 100644 index 04f039f20..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Replace.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Matt McCutchen <hashproduct+eclipse@gmail.com> - Bug 179174 CVS client sets timestamps back when replacing - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.Date; -import java.util.Set; - -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.ICVSFile; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; - -/** - * A specialized update that will ignore unmanaged local content like - * CheckoutWithOverwrite and avoid setting back the timestamps of files - * recreated after being deleted by PrepareForReplaceVisitor. - */ -public class Replace extends Update { - - private Set/*<ICVSFile>*/ prepDeletedFiles = null; - - public Replace() {} - public Replace(Set/*<ICVSFile>*/ prepDeletedFiles) { - this.prepDeletedFiles = prepDeletedFiles; - } - - /** - * This class overrides the "Created" handler but uses the "Updated" - * behavior which will overwrite existing files. - */ - public class CreatedResponseHandler extends UpdatedHandler { - public CreatedResponseHandler() { - super(UpdatedHandler.HANDLE_UPDATED); - } - public String getResponseID() { - return "Created"; //$NON-NLS-1$ - } - protected void receiveTargetFile(Session session, ICVSFile file, String entryLine, Date modTime, - boolean binary, boolean readOnly, boolean executable, IProgressMonitor monitor) throws CVSException { - // Discard any timestamp for files being recreated after being - // deleted by PrepareForReplaceVisitor. - if (prepDeletedFiles != null && prepDeletedFiles.contains(file)) - modTime = null; - super.receiveTargetFile(session, file, entryLine, modTime, binary, readOnly, executable, monitor); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#doExecute(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption[], org.eclipse.team.internal.ccvs.core.client.Command.LocalOption[], java.lang.String[], org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus doExecute( - Session session, - GlobalOption[] globalOptions, - LocalOption[] localOptions, - String[] arguments, - ICommandOutputListener listener, - IProgressMonitor monitor) - throws CVSException { - - ResponseHandler newCreated = new CreatedResponseHandler(); - ResponseHandler oldCreated = session.getResponseHandler(newCreated.getResponseID()); - session.registerResponseHandler(newCreated); - try { - return super.doExecute( - session, - globalOptions, - localOptions, - arguments, - listener, - monitor); - } finally { - session.registerResponseHandler(oldCreated); - } - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java deleted file mode 100644 index 9278f4b71..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; - -/** - * Abstract base class for requests that are to be sent to the server. - */ -public abstract class Request { - public static final ExpandModules EXPAND_MODULES = new ExpandModules(); - public static final ValidRequests VALID_REQUESTS = new ValidRequests(); - - /*** Response handler map ***/ - private static final Map responseHandlers = new HashMap(); - - private static void initializeHandlerCache() { - synchronized(responseHandlers) { - registerResponseHandler(new CheckedInHandler()); - registerResponseHandler(new CopyHandler()); - registerResponseHandler(new ModTimeHandler()); - registerResponseHandler(new NewEntryHandler()); - registerResponseHandler(new RemovedHandler()); - registerResponseHandler(new RemoveEntryHandler()); - registerResponseHandler(new StaticHandler(true)); - registerResponseHandler(new StaticHandler(false)); - registerResponseHandler(new StickyHandler(true)); - registerResponseHandler(new StickyHandler(false)); - registerResponseHandler(new UpdatedHandler(UpdatedHandler.HANDLE_UPDATED)); - registerResponseHandler(new UpdatedHandler(UpdatedHandler.HANDLE_UPDATE_EXISTING)); - registerResponseHandler(new UpdatedHandler(UpdatedHandler.HANDLE_CREATED)); - registerResponseHandler(new UpdatedHandler(UpdatedHandler.HANDLE_MERGED)); - registerResponseHandler(new ValidRequestsHandler()); - registerResponseHandler(new ModuleExpansionHandler()); - registerResponseHandler(new MTHandler()); - registerResponseHandler(new NotifiedHandler()); - registerResponseHandler(new TemplateHandler()); - } - } - private static void registerResponseHandler(ResponseHandler handler) { - synchronized(responseHandlers) { - responseHandlers.put(handler.getResponseID(), handler); - } - } - - /** - * This method is invoked by Session to get a mutable copy of the - * global list of acceptable response handlers. - * - * @return a map of reponse handlers - */ - protected static Map getReponseHandlerMap() { - synchronized(responseHandlers) { - if (responseHandlers.isEmpty()) { - initializeHandlerCache(); - } - Map copy = new HashMap(); - for (Iterator iter = responseHandlers.values().iterator(); iter.hasNext();) { - ResponseHandler handler = (ResponseHandler) iter.next(); - copy.put(handler.getResponseID(), handler.getInstance()); - - } - return copy; - } - } - /** - * Prevents client code from instantiating us. - */ - protected Request() { } - - /** - * Returns the string used to invoke this request on the server. - * [template method] - * - * @return the request identifier string - */ - protected abstract String getRequestId(); - - /** - * Executes a request and processes the responses. - * - * @param session the open CVS session - * @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 - */ - protected IStatus executeRequest(Session session, ICommandOutputListener listener, - IProgressMonitor monitor) throws CVSException { - // send request - session.sendRequest(getRequestId()); - - // This number can be tweaked if the monitor is judged to move too - // quickly or too slowly. After some experimentation this is a good - // number for both large projects (it doesn't move so quickly as to - // give a false sense of speed) and smaller projects (it actually does - // move some rather than remaining still and then jumping to 100). - final int TOTAL_WORK = 300; - monitor.beginTask(CVSMessages.Command_receivingResponses, TOTAL_WORK); - monitor.subTask(CVSMessages.Command_receivingResponses); - int halfWay = TOTAL_WORK / 2; - int currentIncrement = 4; - int nextProgress = currentIncrement; - int worked = 0; - - // If the session is connected to a CVSNT server (1.11.1.1), we'll need to do some special handling for - // some errors. Unfortunately, CVSNT 1.11.1.1 will drop the connection after so some functionality is - // still effected - boolean isCVSNT = session.isCVSNT(); - - session.clearErrors(); - for (;;) { - // update monitor work amount - if (--nextProgress <= 0) { - monitor.worked(1); - worked++; - if (worked >= halfWay) { - // we have passed the current halfway point, so double the - // increment and reset the halfway point. - currentIncrement *= 2; - halfWay += (TOTAL_WORK - halfWay) / 2; - } - // reset the progress counter to another full increment - nextProgress = currentIncrement; - } - Policy.checkCanceled(monitor); - - // retrieve a response line - String response = session.readLine(); - int spacePos = response.indexOf(' '); - String argument; - if (spacePos != -1) { - argument = response.substring(spacePos + 1); - response = response.substring(0, spacePos); - } else argument = ""; //$NON-NLS-1$ - - // handle completion responses - if (response.equals("ok")) { //$NON-NLS-1$ - break; - } else if (response.equals("error") || (isCVSNT && response.equals(""))) { //$NON-NLS-1$ //$NON-NLS-2$ - argument = argument.trim(); - boolean serious = false; - if (argument.length() == 0) { - argument = getServerErrorMessage(); - } else { - argument = NLS.bind(CVSMessages.Command_seriousServerError, new String[] { argument }); - if (!session.hasErrors()) { - session.addError(new CVSStatus(IStatus.ERROR, CVSStatus.SERVER_ERROR, argument,session.getLocalRoot())); - } - serious = true; - } - - if (!session.hasErrors()) { - session.addError(new CVSStatus(IStatus.ERROR, CVSStatus.SERVER_ERROR, CVSMessages.Command_noMoreInfoAvailable,session.getLocalRoot())); - } - IStatus status = new MultiStatus(CVSProviderPlugin.ID, CVSStatus.SERVER_ERROR, - session.getErrors(), - argument, null); - if (serious) { - throw new CVSServerException(status); - } else { - // look for particularly bad errors in the accumulated statii - IStatus[] errors = session.getErrors(); - for (int i = 0; i < errors.length; i++) { - IStatus s = errors[i]; - if (s.getCode() == CVSStatus.PROTOCOL_ERROR) { - throw new CVSServerException(status); - } - } - } - return status; - // handle message responses - } else if (response.equals("MT")) { //$NON-NLS-1$ - // Handle the MT response - MTHandler handler = (MTHandler) session.getResponseHandler(response); - if (handler != null) { - handler.handle(session, argument, monitor); - } else { - throw new CVSException(new org.eclipse.core.runtime.Status(IStatus.ERROR, - CVSProviderPlugin.ID, TeamException.IO_FAILED, - NLS.bind(CVSMessages.Command_unsupportedResponse, new String[] { response, argument }), null)); - } - // If a line is available, pass it on to the message listener - // and console as if it were an M response - if (handler.isLineAvailable()) { - String line = handler.getLine(); - IStatus status = listener.messageLine(line, session.getCVSRepositoryLocation(), session.getLocalRoot(), monitor); - session.addError(status); // The session ignores OK status - ConsoleListeners.getInstance().messageLineReceived(session, line, status); - - } - } else if (response.equals("M")) { //$NON-NLS-1$ - IStatus status = listener.messageLine(argument, session.getCVSRepositoryLocation(), session.getLocalRoot(), monitor); - session.addError(status); // The session ignores OK status - ConsoleListeners.getInstance().messageLineReceived(session, argument, status); - } else if (response.equals("E")) { //$NON-NLS-1$ - IStatus status = listener.errorLine(argument, session.getCVSRepositoryLocation(), session.getLocalRoot(), monitor); - session.addError(status); // The session ignores OK status - ConsoleListeners.getInstance().errorLineReceived(session, argument, status); - // handle other responses - } else { - ResponseHandler handler = session.getResponseHandler(response); - if (handler != null) { - handler.handle(session, argument, monitor); - } else { - throw new CVSException(new org.eclipse.core.runtime.Status(IStatus.ERROR, - CVSProviderPlugin.ID, TeamException.IO_FAILED, - NLS.bind(CVSMessages.Command_unsupportedResponse, new String[] { response, argument }), null)); - } - } - } - if (!session.hasErrors()) { - return ICommandOutputListener.OK; - } else { - return new MultiStatus(CVSProviderPlugin.ID, IStatus.INFO, - session.getErrors(), - NLS.bind(CVSMessages.Command_warnings, new String[] { getDisplayText() }), null); // - } - } - - /* - * Provide the message that is used for the status that is generated when the server - * reports as error. - */ - protected String getServerErrorMessage() { - return NLS.bind(CVSMessages.Command_serverError, new String[] { getDisplayText() }); // - } - protected String getDisplayText() { - return getRequestId(); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java deleted file mode 100644 index 176d29036..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java +++ /dev/null @@ -1,187 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Handles server responses that arise as a result of issuing a request - * (usually a command) to a CVS server. The processing of each such - * response is deferred to subclasses. - */ -public abstract class ResponseHandler { - /** - * Returns the text string of the server response handled by this object. - * @return the id - */ - public abstract String getResponseID(); - - /** - * Handles a server response. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Clear-sticky myDirectory \n - * /u/cvsroot/myDirectory \n - * [...] - * </pre> - * Then the <code>handle</code> method of the <code>ResponseHandler</code> - * for <em>Clear-sticky</em> will be invoked with <code>argument</code> - * set to <em>"myDirectory"</em>. It must then read the remaining - * response data from the connection (<em>"/u/cvsroot/myDirectory"</em> - * including the newline) and take any necessary action. - * </p><p> - * Note: The type and quantity of additional data that must be read - * from the connection varies on a per-response basis. - * </p> - * @param session the Session used for CVS communication - * @param argument the argument supplied with the response - * @param monitor the progress monitor for the current CVS command - */ - public abstract void handle(Session session, String argument, - IProgressMonitor monitor) throws CVSException; - - /** - * Creates a new CVS folder. - * @param localDir the local path of the folder relative to root - * @param repositoryDir the remote path of the folder relative to the repository - * @return the new folder - */ - protected static ICVSFolder createFolder( - Session session, - String localDir, - String repositoryDir) throws CVSException { - - ICVSFolder folder = session.getLocalRoot().getFolder(localDir); - if (!folder.exists() - && (!CVSProviderPlugin.getPlugin().getPruneEmptyDirectories() - || !folder.getParent().isCVSFolder())) { - // Only create the folder if pruning is disabled or the - // folder's parent is not a CVS folder (which occurs on checkout). - // When pruning is enabled, the folder will be lazily created - // when it contains a file (see getExistingFolder) - folder.mkdir(); - } - if (! folder.isCVSFolder()) { - String repositoryRoot = session.getRepositoryRoot(); - String relativePath; - if (repositoryDir.startsWith(repositoryRoot)) { - // The repositoryDir is an absolute path - relativePath = Util.getRelativePath(repositoryRoot, repositoryDir); - } else { - // The repositoryDir is already a relative path - relativePath = repositoryDir; - } - IResource resource = folder.getIResource(); - if (resource != null) { - IProject project = resource.getProject(); - if (project != null && project.isAccessible() && !CVSTeamProvider.isSharedWithCVS(project)) { - // The project isn't shared but we are about to perform an operation on it. - // we need to flag the project as shared so that the sync info management works - CVSTeamProvider.markAsTempShare(project); - } - } - try{ - folder.setFolderSyncInfo(new FolderSyncInfo( - relativePath, - session.getCVSRepositoryLocation().getLocation(false), - null, false)); - } catch (CVSException ex){ - IStatus status = ex.getStatus(); - if (status != null){ - if (status.getCode() == IResourceStatus.INVALID_VALUE){ - //if it's an invalid value, just ignore the exception (see Bug# 152053), - //else throw it again - } else { - throw ex; - } - } - } - } - return folder; - } - - protected ICVSFolder getExistingFolder(Session session, String localDir) throws CVSException { - ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); - if (! mParent.exists()) { - // First, check if the parent is a phantom - IContainer container = (IContainer)mParent.getIResource(); - if (container != null) { - try { - // Create all the parents as need - recreatePhantomFolders(mParent); - } catch (CVSException e) { - if (!handleInvalidResourceName(session, mParent, e)) { - throw e; - } - } - } - } - return mParent; - } - - /** - * Method recreatePhantomFolders. - * @param mParent - */ - private void recreatePhantomFolders(ICVSFolder folder) throws CVSException { - ICVSFolder parent = folder.getParent(); - if (!parent.exists()) { - recreatePhantomFolders(parent); - } - folder.mkdir(); - } - - /** - * Return as instance that can be used by an open session. Subclasses that contain - * session related state must override this message to return a copy of themselves. - */ - /* package */ ResponseHandler getInstance() { - return this; - } - - protected boolean handleInvalidResourceName(Session session, ICVSResource resource, CVSException e) { - int code = e.getStatus().getCode(); - if (code == IResourceStatus.INVALID_VALUE - || code == IResourceStatus.INVALID_RESOURCE_NAME - || code == IResourceStatus.RESOURCE_NOT_FOUND - || code == IResourceStatus.RESOURCE_EXISTS - || code == IResourceStatus.RESOURCE_WRONG_TYPE - || code == IResourceStatus.CASE_VARIANT_EXISTS - || code == IResourceStatus.PATH_OCCUPIED) { - - try { - IResource local = resource.getIResource(); - String path; - if (local == null) { - path = resource.getRepositoryRelativePath(); - } else { - path = local.getFullPath().toString(); - } - IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.INVALID_LOCAL_RESOURCE_PATH, NLS.bind(CVSMessages.ResponseHandler_0, new String[] { path, e.getMessage() }), e, session.getLocalRoot()); - session.handleResponseError(status); - } catch (CVSException e1) { - CVSProviderPlugin.log(e1); - } - return true; - } - return false; - } -} - 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 deleted file mode 100644 index 96996950f..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java +++ /dev/null @@ -1,1038 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Red Hat Incorporated - is/setExecutable() code - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.io.*; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption; -import org.eclipse.team.internal.ccvs.core.client.Command.QuietOption; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.syncinfo.NotifyInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; -import org.eclipse.team.internal.ccvs.core.util.Util; -import org.eclipse.team.internal.core.streams.*; - -/** - * Maintains CVS communication state for the lifetime of a connection - * to a remote repository. This class covers the initialization, use, - * and eventual shutdown of a dialogue between a CVS client and a - * remote server. This dialogue may be monitored through the use of - * a console. - * - * Initially the Session is in a CLOSED state during which communication - * with the server cannot take place. Once OPENED, any number of commands - * may be issued serially to the server, one at a time. When finished, the - * Session MUST be CLOSED once again to prevent eventual local and/or - * remote resource exhaustion. The session can either be discarded, or - * re-opened for use with the same server though no state is persisted from - * previous connections except for console attributes. - * - * CVSExceptions are thrown only as a result of unrecoverable errors. Once - * this happens, commands must no longer be issued to the server. If the - * Session is in the OPEN state, it is still the responsibility of the - * caller to CLOSE it before moving on. - */ -public class Session { - public static final String CURRENT_LOCAL_FOLDER = "."; //$NON-NLS-1$ - public static final String CURRENT_REMOTE_FOLDER = ""; //$NON-NLS-1$ - public static final String SERVER_SEPARATOR = "/"; //$NON-NLS-1$ - - // default file transfer buffer size (in bytes) - private static final int TRANSFER_BUFFER_SIZE = 8192; - // update progress bar in increments of this size (in bytes) - // no incremental progress shown for files smaller than this size - private static final int TRANSFER_PROGRESS_INCREMENT = 32768; - - public static final boolean IS_CRLF_PLATFORM = Arrays.equals( - System.getProperty("line.separator").getBytes(), new byte[] { '\r', '\n' }); //$NON-NLS-1$ - - private CVSRepositoryLocation location; - private ICVSFolder localRoot; - private boolean outputToConsole; - private Connection connection = null; - private String validRequests = null; - private Date modTime = null; - private boolean noLocalChanges = false; - private boolean createBackups = true; - private int compressionLevel = 0; - private List expansions; - private Collection /* of ICVSFile */ textTransferOverrideSet = null; - - // state need to indicate whether - private boolean ignoringLocalChanges = false; - - // The resource bundle key that provides the file sending message - private String sendFileTitleMessage; - private Map responseHandlers; - - // List of errors accumulated while the command is executing - private List errors = new ArrayList(); - - private Command currentCommand; - - /** - * Creates a new CVS session, initially in the CLOSED state. - * By default, command output is directed to the console. - * - * @param location the CVS repository location used for this session - * @param localRoot represents the current working directory of the client - */ - public Session(ICVSRepositoryLocation location, ICVSFolder localRoot) { - this(location, localRoot, true); - } - - /** - * Creates a new CVS session, initially in the CLOSED state. - * - * @param location the CVS repository location used for this session - * @param localRoot represents the current working directory of the client - * @param outputToConsole if true, command output is directed to the console - */ - public Session(ICVSRepositoryLocation location, ICVSFolder localRoot, boolean outputToConsole) { - this.location = (CVSRepositoryLocation) location; - this.localRoot = localRoot; - this.outputToConsole = outputToConsole; - } - - /* - * Add a module expansion receivered from the server. - * This is only used by the ModuleExpansionsHandler - */ - protected void addModuleExpansion(String expansion) { - expansions.add(expansion); - } - - /* - * Add a module expansion receivered from the server. - * This is only used by the ExpandModules command - */ - protected void resetModuleExpansion() { - if (expansions == null) - expansions = new ArrayList(); - else - expansions.clear(); - } - - /** - * Opens, authenticates and initializes a connection to the server specified - * for the remote location. - * - * @param monitor the progress monitor - * @throws IllegalStateException if the Session is not in the CLOSED state - */ - public void open(IProgressMonitor monitor) throws CVSException { - open(monitor, true /* write access*/); - } - - public void open(IProgressMonitor monitor, boolean writeAccess) throws CVSException { - if (connection != null) throw new IllegalStateException(); - monitor = Policy.monitorFor(monitor); - monitor.beginTask(null, 100); - boolean opened = false; - - try { - connection = getLocationForConnection(writeAccess).openConnection(Policy.subMonitorFor(monitor, 50)); - - // If we're connected to a CVSNT server or we don't know the platform, - // accept MT. Otherwise don't. - boolean useMT = ! (location.getServerPlatform() == CVSRepositoryLocation.CVS_SERVER); - if ( ! useMT) { - removeResponseHandler("MT"); //$NON-NLS-1$ - } - - // tell the server the names of the responses we can handle - connection.writeLine("Valid-responses " + makeResponseList()); //$NON-NLS-1$ - // Flush in order to recieve the valid requests - connection.flush(); - - // ask for the set of valid requests - IStatus status = Request.VALID_REQUESTS.execute(this, Policy.subMonitorFor(monitor, 40)); - if (!status.isOK()) { - throw new CVSException(status); - } - - // set the root directory on the server for this connection - connection.writeLine("Root " + getRepositoryRoot()); //$NON-NLS-1$ - - // enable compression - compressionLevel = CVSProviderPlugin.getPlugin().getCompressionLevel(); - if (compressionLevel != 0 && isValidRequest("gzip-file-contents")) { //$NON-NLS-1$ - // Enable the use of CVS 1.8 per-file compression mechanism. - // The newer Gzip-stream request seems to be problematic due to Java's - // GZIPInputStream tendency to block on read() rather than to return a - // partially filled buffer. The latter option would be better since it - // can make more effective use of the code dictionary, if it can be made - // to work... - connection.writeLine("gzip-file-contents " + Integer.toString(compressionLevel)); //$NON-NLS-1$ - } else { - compressionLevel = 0; - } - - // get the server platform if it is unknown - if (CVSProviderPlugin.getPlugin().isDetermineVersionEnabled() && location.getServerPlatform() == CVSRepositoryLocation.UNDETERMINED_PLATFORM) { - Command.VERSION.execute(this, location, Policy.subMonitorFor(monitor, 10)); - } - opened = true; - } finally { - if (connection != null && ! opened) { - close(); - } - monitor.done(); - } - } - - /* - * Return the location to be used for this connection - */ - private CVSRepositoryLocation getLocationForConnection(boolean writeAccess) { - return location; - } - - /** - * Closes a connection to the server. - * - * @throws IllegalStateException if the Session is not in the OPEN state - */ - public void close() { - if (connection != null) { - connection.close(); - connection = null; - validRequests = null; - } - } - - /** - * Determines if the server supports the specified request. - * - * @param request the request string to verify - * @return true iff the request is supported - */ - public boolean isValidRequest(String request) { - return (validRequests == null) || - (validRequests.indexOf(" " + request + " ") != -1); //$NON-NLS-1$ //$NON-NLS-2$ - } - - public boolean isCVSNT() { - if (location.getServerPlatform() == CVSRepositoryLocation.UNDETERMINED_PLATFORM) { - return location.getRootDirectory().indexOf(':') == 1; - } else { - return location.getServerPlatform() == CVSRepositoryLocation.CVSNT_SERVER; - } - } - - /** - * Returns the local root folder for this session. - * <p> - * Generally speaking, specifies the "current working directory" at - * the time of invocation of an equivalent CVS command-line client. - * </p> - * - * @return the local root folder - */ - public ICVSFolder getLocalRoot() { - return localRoot; - } - - /** - * Return the list of module expansions communicated from the server. - * - * The modules expansions are typically a directory path of length 1 - * but can be of greater length on occasion. - */ - public String[] getModuleExpansions() { - if (expansions == null) return new String[0]; - return (String[]) expansions.toArray(new String[expansions.size()]); - } - - /** - * Returns the repository root folder for this session. - * <p> - * Specifies the unqualified path to the CVS repository root folder - * on the server. - * </p> - * - * @return the repository root folder - */ - public String getRepositoryRoot() { - return location.getRootDirectory(); - } - - /** - * Returns an object representing the CVS repository location for this session. - * - * @return the CVS repository location - */ - public ICVSRepositoryLocation getCVSRepositoryLocation() { - return location; - } - - /** - * Receives a line of text minus the newline from the server. - * - * @return the line of text - */ - public String readLine() throws CVSException { - return connection.readLine(); - } - - /** - * Sends a line of text followed by a newline to the server. - * - * @param line the line of text - */ - public void writeLine(String line) throws CVSException { - connection.writeLine(line); - } - - /** - * Sends an argument to the server. - * <p>e.g. sendArgument("Hello\nWorld\n Hello World") sends: - * <pre> - * Argument Hello \n - * Argumentx World \n - * Argumentx Hello World \n - * </pre></p> - * - * @param arg the argument to send - */ - public void sendArgument(String arg) throws CVSException { - connection.write("Argument "); //$NON-NLS-1$ - int oldPos = 0; - for (;;) { - int pos = arg.indexOf('\n', oldPos); - if (pos == -1) break; - connection.writeLine(stripTrainingCR(arg.substring(oldPos, pos))); - connection.write("Argumentx "); //$NON-NLS-1$ - oldPos = pos + 1; - } - connection.writeLine(stripTrainingCR(arg.substring(oldPos))); - } - - /* - * Remove any trailing CR from the string - */ - private String stripTrainingCR(String string) { - if (string.endsWith("\r")) { //$NON-NLS-1$ - return string.substring(0, string.length() - 1); - } - return string; - } - - /** - * Sends a request to the server and flushes any output buffers. - * - * @param requestId the string associated with the request to be executed - */ - public void sendRequest(String requestId) throws CVSException { - connection.writeLine(requestId); - connection.flush(); - } - - /** - * Sends an Is-modified request to the server without the file contents. - * <p>e.g. if a file called "local_file" was modified, sends: - * <pre> - * Is-modified local_file \n - * </pre></p><p> - * This request is an optimized form of the Modified request and may not - * be supported by all servers. Hence, if it is not supported, a Modified - * request is sent instead along with the file's contents. According to - * the CVS protocol specification, this request is only safe for use with - * some forms of: admin, annotate, diff, editors, log, watch-add, watch-off, - * watch-on, watch-remove, and watchers.<br> - * It may be possible to use this for: add, export, remove and status.<br> - * Do not use with co, ci, history, init, import, release, rdiff, rtag, or update. - * </p><p> - * Note: The most recent Directory request must have specified the file's - * parent folder. - * </p> - * - * @param file the file that was modified - * @see #sendModified - */ - public void sendIsModified(ICVSFile file, boolean isBinary, IProgressMonitor monitor) - throws CVSException { - if (isValidRequest("Is-modified")) { //$NON-NLS-1$ - connection.writeLine("Is-modified " + file.getName()); //$NON-NLS-1$ - } else { - sendModified(file, isBinary, monitor); - } - } - - /** - * Sends a Static-directory request to the server. - * <p> - * Indicates that the directory specified in the most recent Directory request - * is static. No new files will be checked out into this directory unless - * explicitly requested. - * </p> - */ - public void sendStaticDirectory() throws CVSException { - connection.writeLine("Static-directory"); //$NON-NLS-1$ - } - - /** - * Sends a Directory request to the server with a constructed path. - * <p> - * It may be necessary at times to guess the remote path of a directory since - * it does not exist yet. In this case we construct a remote path based on the - * local path by prepending the local path with the repository root. This may - * not work in the presence of modules, so only use it for creating new projects. - * </p><p> - * Note: A CVS repository root can end with a trailing slash. The CVS server - * expects that the repository root sent contain this extra slash. Including - * the foward slash in addition to the absolute remote path makes for a string - * containing two consecutive slashes (e.g. /home/cvs/repo//projecta/a.txt). - * This is valid in the CVS protocol. - * </p> - */ - public void sendConstructedDirectory(String localDir) throws CVSException { - String path = Util.appendPath(getRepositoryRoot(), localDir); - sendDirectory(localDir, path); - } - - /** - * Sends a Directory request to the server. - * <p>e.g. sendDirectory("local_dir", "remote_dir") sends: - * <pre> - * Directory local_dir - * repository_root/remote_dir - * </pre></p> - * - * @param localDir the path of the local directory relative to localRoot - * @param remoteDir the path of the remote directory relative to repositoryRoot - */ - public void sendDirectory(String localDir, String remoteDir) throws CVSException { - if (localDir.length() == 0) localDir = CURRENT_LOCAL_FOLDER; - connection.writeLine("Directory " + localDir); //$NON-NLS-1$ - connection.writeLine(remoteDir); - } - - /** - * Sends a Directory request for the localRoot. - */ - public void sendLocalRootDirectory() throws CVSException { - sendDirectory(CURRENT_LOCAL_FOLDER, localRoot.getRemoteLocation(localRoot)); - } - - /** - * Sends a Directory request for the localRoot with a constructed path. - * <p> - * Use this when creating a new project that does not exist in the repository. - * </p> - * @see #sendConstructedDirectory - */ - public void sendConstructedRootDirectory() throws CVSException { - sendConstructedDirectory(""); //$NON-NLS-1$ - } - - /** - * Sends an Entry request to the server. - * <p> - * Indicates that a file is managed (but it may not exist locally). Sends - * the file's entry line to the server to indicate the version that was - * previously checked out. - * </p><p> - * Note: The most recent Directory request must have specified the file's - * parent folder. - * </p> - * - * @param entryLine the formatted entry line of the managed file. - */ - public void sendEntry(byte[] syncBytes, String serverTimestamp) throws CVSException { - connection.write("Entry "); //$NON-NLS-1$ - if (serverTimestamp == null) { - serverTimestamp = ""; //$NON-NLS-1$ - } - int start = Util.getOffsetOfDelimeter(syncBytes, (byte)'/', 0, 3); - if (start == -1) { - // something is wrong with the entry line so just send it as is - // and let the server report the error. - connection.writeLine(new String(syncBytes)); - return; - } - int end = Util.getOffsetOfDelimeter(syncBytes, (byte)'/', start + 1, 1); - if (end == -1) { - // something is wrong with the entry line so just send it as is - // and let the server report the error. - connection.writeLine(new String(syncBytes)); - return; - } - connection.write(new String(syncBytes, 0, start + 1)); - connection.write(serverTimestamp); - connection.writeLine(new String(syncBytes, end, syncBytes.length - end)); - } - - /** - * Sends a global options to the server. - * <p>e.g. sendGlobalOption("-n") sends: - * <pre> - * Global_option -n \n - * </pre></p> - * - * @param option the global option to send - */ - public void sendGlobalOption(String option) throws CVSException { - connection.writeLine("Global_option " + option); //$NON-NLS-1$ - } - - /** - * Sends an Unchanged request to the server. - * <p>e.g. if a file called "local_file" was not modified, sends: - * <pre> - * Unchanged local_file \n - * </pre></p><p> - * Note: The most recent Directory request must have specified the file's - * parent folder. - * </p> - * - * @param file the file that was not modified - */ - public void sendUnchanged(ICVSFile file) throws CVSException { - connection.writeLine("Unchanged " + file.getName()); //$NON-NLS-1$ - } - - /** - * Sends the Notify request to the server - */ - public void sendNotify(ICVSFolder parent, NotifyInfo info) - throws CVSException { - - String filename = info.getName(); - connection.writeLine("Notify " + filename); //$NON-NLS-1$ - connection.writeLine(info.getServerLine(parent)); - } - - /** - * Sends a Questionable request to the server. - * <p> - * Indicates that a file exists locally but is unmanaged. Asks the server - * whether or not the file should be ignored in subsequent CVS operations. - * The reply to the request occurs in the form of special M-type message - * responses prefixed with '?' when the next command is executed. - * </p><p> - * Note: The most recent Directory request must have specified the file's - * parent folder. - * </p> - * - * @param resource the local file or folder - */ - public void sendQuestionable(ICVSResource resource) throws CVSException { - connection.writeLine("Questionable " + resource.getName()); //$NON-NLS-1$ - } - - /** - * Sends a Sticky tag request to the server. - * <p> - * Indicates that the directory specified in the most recent Directory request - * has a sticky tag or date, and sends the tag's contents. - * </p> - * - * @param tag the sticky tag associated with the directory - */ - public void sendSticky(String tag) throws CVSException { - connection.writeLine("Sticky " + tag); //$NON-NLS-1$ - } - - /** - * Sends a Modified request to the server along with the file contents. - * <p>e.g. if a file called "local_file" was modified, sends: - * <pre> - * Modified local_file \n - * file_permissions \n - * file_size \n - * [... file_contents ...] - * </pre></p><p> - * Under some circumstances, Is-modified may be used in place of this request.<br> - * Do not use with history, init, import, rdiff, release, rtag, or update. - * </p><p> - * Note: The most recent Directory request must have specified the file's - * parent folder. - * </p> - * - * @param file the file that was modified - * @param isBinary if true the file is sent without translating line delimiters - * @param monitor the progress monitor - * @see #sendIsModified - */ - public void sendModified(ICVSFile file, boolean isBinary, IProgressMonitor monitor) - throws CVSException { - sendModified(file, isBinary, true, monitor); - } - - public void sendModified(ICVSFile file, boolean isBinary, boolean sendBinary, IProgressMonitor monitor) - throws CVSException { - - String filename = file.getName(); - connection.writeLine("Modified " + filename); //$NON-NLS-1$ - // send the default permissions for now - if (file.isExecutable()) { - connection.writeLine(ResourceSyncInfo.getDefaultExecutablePermissions()); - } else { - connection.writeLine(ResourceSyncInfo.getDefaultPermissions()); - } - sendFile(file, isBinary, sendBinary, monitor); - } - - /** - * Sends a file to the remote CVS server, possibly translating line delimiters. - * <p> - * Line termination sequences are automatically converted to linefeeds only - * (required by the CVS specification) when sending non-binary files. This - * may alter the actual size and contents of the file that is sent. - * </p><p> - * Note: Non-binary files must be small enough to fit in available memory. - * </p> - * @param file the file to be sent - * @param isBinary is true if the file should be sent without translation - * @param monitor the progress monitor - */ - public void sendFile(ICVSStorage file, boolean isBinary, boolean sendBinary, IProgressMonitor monitor) throws CVSException { - // check overrides - if (textTransferOverrideSet != null && - textTransferOverrideSet.contains(file)) isBinary = false; - - // update progress monitor - final String title = NLS.bind(getSendFileTitleMessage(), (new Object[]{ Util.toTruncatedPath(file, localRoot, 3) })); - monitor.subTask(NLS.bind(CVSMessages.Session_transferNoSize, new String[] { title })); - try { - InputStream in = null; - long length; - try { - if (isBinary && !sendBinary) { - byte[] bytes = "hello".getBytes(); //$NON-NLS-1$ - sendUncompressedBytes(new ByteArrayInputStream(bytes), bytes.length); - return; - } - - if (compressionLevel == 0) { - in = file.getContents(); - if (!isBinary && IS_CRLF_PLATFORM){ - // uncompressed text - byte[] buffer = new byte[TRANSFER_BUFFER_SIZE]; - in = new CRLFtoLFInputStream(in); - ByteCountOutputStream counter = new ByteCountOutputStream(); - try { - for (int count; (count = in.read(buffer)) != -1;) counter.write(buffer, 0, count); - } finally { - counter.close(); - } - in.close(); - length = counter.getSize(); - in = new CRLFtoLFInputStream(file.getContents()); - } else { - // uncompressed binary - length = file.getSize(); - } - in = new ProgressMonitorInputStream(in, length, TRANSFER_PROGRESS_INCREMENT, monitor) { - protected void updateMonitor(long bytesRead, long bytesTotal, IProgressMonitor monitor) { - if (bytesRead == 0) return; - Assert.isTrue(bytesRead <= bytesTotal); - monitor.subTask(NLS.bind(CVSMessages.Session_transfer, (new Object[] { title, Long.toString(bytesRead >> 10), Long.toString(bytesTotal >> 10) }))); - } - }; - sendUncompressedBytes(in, length); - } else { - monitor.subTask(NLS.bind(CVSMessages.Session_calculatingCompressedSize, new String[] { Util.toTruncatedPath(file, localRoot, 3) })); - in = file.getContents(); - byte[] buffer = new byte[TRANSFER_BUFFER_SIZE]; - ByteCountOutputStream counter = new ByteCountOutputStream(); - OutputStream zout = new GZIPOutputStream(counter); - if (!isBinary && IS_CRLF_PLATFORM) in = new CRLFtoLFInputStream(in); - try { - for (int count; (count = in.read(buffer)) != -1;) zout.write(buffer, 0, count); - } finally { - zout.close(); - } - in.close(); - in = file.getContents(); - in = new ProgressMonitorInputStream(in, file.getSize(), TRANSFER_PROGRESS_INCREMENT, monitor) { - protected void updateMonitor(long bytesRead, long bytesTotal, IProgressMonitor monitor) { - if (bytesRead == 0) return; - Assert.isTrue(bytesRead <= bytesTotal); - monitor.subTask(NLS.bind(CVSMessages.Session_transfer, (new Object[] { title, Long.toString(bytesRead >> 10), Long.toString(bytesTotal >> 10) }))); - } - }; - if (!isBinary && IS_CRLF_PLATFORM) in = new CRLFtoLFInputStream(in); - sendCompressedBytes(in, counter.getSize()); - } - } finally { - if (in != null) in.close(); - } - } catch (IOException e) { - throw CVSException.wrapException(e); - } - } - - /* - * Send the contents of the input stream to CVS. - * Length must equal the number of bytes that will be transferred - * across the wire, that is, the compressed file size. - */ - private void sendCompressedBytes(InputStream in, long length) throws IOException, CVSException { - String sizeLine = "z" + Long.toString(length); //$NON-NLS-1$ - writeLine(sizeLine); - OutputStream out = connection.getOutputStream(); - GZIPOutputStream zo = new GZIPOutputStream(out); - byte[] buffer = new byte[TRANSFER_BUFFER_SIZE]; - for (int count; - (count = in.read(buffer)) != -1;) - zo.write(buffer, 0, count); - zo.finish(); - } - - /* - * Send the contents of the input stream to CVS. - * Length must equal the number of bytes that will be transferred - * across the wire. - */ - private void sendUncompressedBytes(InputStream in, long length) throws IOException, CVSException { - OutputStream out = connection.getOutputStream(); - String sizeLine = Long.toString(length); - writeLine(sizeLine); - byte[] buffer = new byte[TRANSFER_BUFFER_SIZE]; - for (int count; (count = in.read(buffer)) != -1;) out.write(buffer, 0, count); - } - - - - - /** - * Receives a file from the remote CVS server, possibly translating line delimiters. - * <p> - * Line termination sequences are automatically converted to platform format - * only when receiving non-binary files. This may alter the actual size and - * contents of the file that is received. - * </p><p> - * Translation is performed on-the-fly, so the file need not fit in available memory. - * </p> - * @param file the file to be received - * @param isBinary is true if the file should be received without translation - * @param responseType one of the ICVSFile updated types (UPDATED, CREATED, MERGED, UPDATE_EXISTING) - * indicating what repsonse type provided the file contents - * @param monitor the progress monitor - */ - public void receiveFile(ICVSStorage file, boolean isBinary, int responseType, IProgressMonitor monitor) - throws CVSException { - // check overrides - if (textTransferOverrideSet != null && - textTransferOverrideSet.contains(file)) isBinary = false; - - // update progress monitor - final String title = NLS.bind(CVSMessages.Session_receiving, (new Object[]{ Util.toTruncatedPath(file, localRoot, 3) })); - monitor.subTask(NLS.bind(CVSMessages.Session_transferNoSize, new String[] { title })); - // get the file size from the server - long size; - boolean compressed = false; - String sizeLine = null; - try { - sizeLine = readLine(); - if (sizeLine.charAt(0) == 'z') { - compressed = true; - sizeLine = sizeLine.substring(1); - } - size = Long.parseLong(sizeLine, 10); - } catch (NumberFormatException e) { - // In some cases, the server will give us an error line here - if (sizeLine != null && sizeLine.startsWith("E")) { //$NON-NLS-1$ - handleErrorLine(sizeLine.substring(1).trim(), org.eclipse.core.runtime.Status.OK_STATUS); - return; - } else { - IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR,CVSMessages.Session_badInt, e, localRoot); - throw new CVSException(status); - } - } - // create an input stream that spans the next 'size' bytes from the connection - InputStream in = new SizeConstrainedInputStream(connection.getInputStream(), size, true /*discardOnClose*/); - // setup progress monitoring - in = new ProgressMonitorInputStream(in, size, TRANSFER_PROGRESS_INCREMENT, monitor) { - protected void updateMonitor(long bytesRead, long bytesTotal, IProgressMonitor monitor) { - if (bytesRead == 0) return; - monitor.subTask(NLS.bind(CVSMessages.Session_transfer, (new Object[] { title, Long.toString(bytesRead >> 10), Long.toString(bytesTotal >> 10) }))); - } - }; - // if compression enabled, decompress on the fly - if (compressed) { - try { - in = new GZIPInputStream(in); - } catch (IOException e) { - throw CVSException.wrapException(e); - } - } - // if not binary, translate line delimiters on the fly - if (! isBinary) { - // switch from LF to CRLF if appropriate - if (IS_CRLF_PLATFORM && CVSProviderPlugin.getPlugin().isUsePlatformLineend()) { - // auto-correct for CRLF line-ends that come from the server - in = new CRLFtoLFInputStream(in); - // convert LF to CRLF - in = new LFtoCRLFInputStream(in); - } else { - // be nice and warn about text files that contain CRLF - in = new CRLFDetectInputStream(in, file); - } - } - // write the file locally - file.setContents(in, responseType, true, new NullProgressMonitor()); - } - - /** - * Stores the value of the last Mod-time response encountered. - * Valid only for the duration of a single CVS command. - */ - void setModTime(Date modTime) { - this.modTime = modTime; - } - - /** - * Returns the stored value of the last Mod-time response, - * or null if there was none while processing the current command. - */ - Date getModTime() { - return modTime; - } - - /** - * Stores true if the -n global option was specified for the current command. - * Valid only for the duration of a single CVS command. - */ - void setNoLocalChanges(boolean noLocalChanges) { - this.noLocalChanges = noLocalChanges; - } - - /** - * Returns true if the -n global option was specified for the current command, - * false otherwise. - */ - boolean isNoLocalChanges() { - return noLocalChanges; - } - - /** - * Callback hook for the ValidRequestsHandler to specify the set of valid - * requests for this session. - */ - void setValidRequests(String validRequests) { - this.validRequests = " " + validRequests + " "; //$NON-NLS-1$ //$NON-NLS-2$ - } - - public boolean isOutputToConsole() { - return outputToConsole; - } - - /** - * Stores a flag as to whether .# files will be created. (Default is true) - * @param createBackups if true, creates .# files at the server's request - */ - void setCreateBackups(boolean createBackups) { - this.createBackups = createBackups; - } - - /** - * Returns a flag as to whether .# files will be created. - */ - boolean isCreateBackups() { - return createBackups; - } - - /** - * Gets the sendFileTitleKey. - * @return Returns a String - */ - String getSendFileTitleMessage() { - if (sendFileTitleMessage == null) - return CVSMessages.Session_sending; - return sendFileTitleMessage; - } - - /** - * Sets the sendFileTitleKey. - * @param sendFileTitleKey The sendFileTitleKey to set - */ - public void setSendFileTitleKey(String sendFileTitleMessage) { - this.sendFileTitleMessage = sendFileTitleMessage; - } - - /** - * Remembers a set of files that must be transferred as 'text' - * regardless of what the isBinary parameter to sendFile() is. - * - * @param textTransferOverrideSet the set of ICVSFiles to override, or null if none - */ - public void setTextTransferOverride(Collection textTransferOverrideSet) { - this.textTransferOverrideSet = textTransferOverrideSet; - } - - /** - * Filter the provided global options using parameters set on this session - * or globally. The session may add global options that correspond to user - * preferences or remove those that contradict requirements for this - * particular session. - * - * @param globalOptions the global options, read-only - * @return the filtered global options - */ - protected GlobalOption[] filterGlobalOptions(GlobalOption[] globalOptions) { - if (! Command.DO_NOT_CHANGE.isElementOf(globalOptions)) { - // Get the user preference for verbosity - QuietOption quietOption = CVSProviderPlugin.getPlugin().getQuietness(); - if (quietOption != null) { - globalOptions = quietOption.addToEnd(globalOptions); - } - // Get the user preference for read-only - if (isWatchEditEnabled()) { - if (!Command.MAKE_READ_ONLY.isElementOf(globalOptions)) { - globalOptions = Command.MAKE_READ_ONLY.addToEnd(globalOptions); - } - } - } - return globalOptions; - } - - private boolean isWatchEditEnabled() { - // First, look at the global preference - if (CVSProviderPlugin.getPlugin().getPluginPreferences().getBoolean(CVSProviderPlugin.READ_ONLY)) { - return true; - } - // If there is a provider, use the providers setting for watch/edit - try { - IResource resource = getLocalRoot().getIResource(); - if (resource != null && resource.getType() != IResource.ROOT) { - RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId()); - if (provider != null) { - return ((CVSTeamProvider) provider).isWatchEditEnabled(); - } - } - } catch (CVSException e) { - CVSProviderPlugin.log(e); - } - return false; - } - - /** - * Method setIgnoringLocalChanges. - * @param b - */ - protected void setIgnoringLocalChanges(boolean b) { - ignoringLocalChanges = b; - } - /** - * Returns the ignoringLocalChanges. - * @return boolean - */ - protected boolean isIgnoringLocalChanges() { - return ignoringLocalChanges; - } - - /* - * Get the response handler map to be used for this session. The map is created by making a copy of the global - * reponse handler map. - */ - protected Map getReponseHandlers() { - if (responseHandlers == null) { - responseHandlers = Request.getReponseHandlerMap(); - } - return responseHandlers; - } - - /* - * Makes a list of all valid responses; for initializing a session. - * @return a space-delimited list of all valid response strings - */ - private String makeResponseList() { - StringBuffer result = new StringBuffer("ok error M E"); //$NON-NLS-1$ - Iterator elements = getReponseHandlers().keySet().iterator(); - while (elements.hasNext()) { - result.append(' '); - result.append((String) elements.next()); - } - - return result.toString(); - } - public void registerResponseHandler(ResponseHandler handler) { - getReponseHandlers().put(handler.getResponseID(), handler); - } - - public void removeResponseHandler(String responseID) { - getReponseHandlers().remove(responseID); - } - - public ResponseHandler getResponseHandler(String responseID) { - return (ResponseHandler)getReponseHandlers().get(responseID); - } - - /** - * Accumulate the added errors so they can be included in the status returned - * when the command execution is finished. OK status are ignored. - * @param status the status to be accumulated - */ - public void addError(IStatus status) { - if (!status.isOK()) - errors.add(status); - } - - public boolean hasErrors() { - return !errors.isEmpty(); - } - - public IStatus[] getErrors() { - return (IStatus[]) errors.toArray(new IStatus[errors.size()]); - } - - public void clearErrors() { - errors.clear(); - } - - public void setCurrentCommand(Command c) { - currentCommand = c; - } - - public Command getCurrentCommand() { - return currentCommand; - } - - /** - * Report the given error line to any listeners - * @param line the error line - * @param status the status that indicates any problems encountered parsing the line - */ - public void handleErrorLine(String line, IStatus status) { - ConsoleListeners.getInstance().errorLineReceived(this, line, status); - } - - /** - * An error has occurred while processing responses from the - * server. Place this error is the status that will be returned - * from the command and show the error in the console - * @param status the status that descibes the error - */ - public void handleResponseError(IStatus status) { - addError(status); - handleErrorLine(NLS.bind(CVSMessages.Session_0, new String[] { status.getMessage() }), status); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StaticHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StaticHandler.java deleted file mode 100644 index 7464d716d..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StaticHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.MutableFolderSyncInfo; - -/** - * Handles any "Set-static-directory" and "Clear-static-directory" responses - * from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Set-static-directory myproject/ \n - * /u/cvsroot/myproject/ \n - * [...] - * </pre> - * Then we set or clear the static flag of the folder "myproject", - * automatically creating it if it does not exist locally, - * </p> - */ -class StaticHandler extends ResponseHandler { - private final boolean setStaticDirectory; - - public StaticHandler(boolean setStaticDirectory) { - this.setStaticDirectory = setStaticDirectory; - } - - public String getResponseID() { - if (setStaticDirectory) { - return "Set-static-directory"; //$NON-NLS-1$ - } else { - return "Clear-static-directory"; //$NON-NLS-1$ - } - } - - public void handle(Session session, String localDir, - IProgressMonitor monitor) throws CVSException { - // read additional data for the response - String repositoryDir = session.readLine(); - - // create the directory then set or clear the static flag - Assert.isTrue(repositoryDir.endsWith("/")); //$NON-NLS-1$ - repositoryDir = repositoryDir.substring(0, repositoryDir.length() - 1); - try { - ICVSFolder folder = createFolder(session, localDir, repositoryDir); - FolderSyncInfo syncInfo = folder.getFolderSyncInfo(); - // Added to ignore sync info for workspace root - if (syncInfo == null) return; - MutableFolderSyncInfo newInfo = syncInfo.cloneMutable(); - newInfo.setStatic(setStaticDirectory); - // only set the sync info if it has changed - if (!syncInfo.equals(newInfo)) - folder.setFolderSyncInfo(newInfo); - } catch (CVSException e) { - if (!handleInvalidResourceName(session, session.getLocalRoot().getFolder(localDir), e)) { - throw e; - } - } - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Status.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Status.java deleted file mode 100644 index 146ad41d0..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Status.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -public class Status extends AbstractMessageCommand { - /*** Local options: specific to status ***/ - - protected Status() { } - protected String getRequestId() { - return "status"; //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StickyHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StickyHandler.java deleted file mode 100644 index 080b5ce50..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StickyHandler.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag; -import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.MutableFolderSyncInfo; - -/** - * Handles any "Set-sticky" and "Clear-stick" responses from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Set-sticky myproject/ \n - * /u/cvsroot/myproject/ \n - * Tsometag \n - * [...] - * </pre> - * Then we set or clear the sticky tag property of the folder "myproject", - * automatically creating it if it does not exist locally, - * </p> - */ -class StickyHandler extends ResponseHandler { - private final boolean setSticky; - - public StickyHandler(boolean setSticky) { - this.setSticky = setSticky; - } - - public String getResponseID() { - if (setSticky) { - return "Set-sticky"; //$NON-NLS-1$ - } else { - return "Clear-sticky"; //$NON-NLS-1$ - } - } - - public void handle(Session session, String localDir, - IProgressMonitor monitor) throws CVSException { - // read additional data for the response - String repositoryDir = session.readLine(); - String tag = null; - if (setSticky) { - tag = session.readLine(); - if (tag != null && tag.length() == 0) tag = null; - } - - // create the directory then set or clear the sticky tag - Assert.isTrue(repositoryDir.endsWith("/")); //$NON-NLS-1$ - repositoryDir = repositoryDir.substring(0, repositoryDir.length() - 1); - try { - ICVSFolder folder = createFolder(session, localDir, repositoryDir); - FolderSyncInfo syncInfo = folder.getFolderSyncInfo(); - // Added to ignore sync info for workspace root - if (syncInfo == null) return; - MutableFolderSyncInfo newInfo = syncInfo.cloneMutable(); - newInfo.setTag(tag != null ? new CVSEntryLineTag(tag) : null); - /* if we are reverting to BASE we do not change anything here - * see bug 106876 */ - if(tag != null && tag.equals("TBASE")) //$NON-NLS-1$ - newInfo.setTag(syncInfo.getTag()); - // only set the sync info if it has changed - if (!syncInfo.equals(newInfo)) - folder.setFolderSyncInfo(newInfo); - } catch (CVSException e) { - if (!handleInvalidResourceName(session, session.getLocalRoot().getFolder(localDir), e)) { - throw e; - } - } - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/SyncUpdate.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/SyncUpdate.java deleted file mode 100644 index 62e15e50a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/SyncUpdate.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.ICVSResource; - -public class SyncUpdate extends Update { - - public SyncUpdate() { }; - - /* - * @see Command#sendFileStructure(ICVSResource,IProgressMonitor,boolean,boolean,boolean) - */ - protected void sendFileStructure(Session session, ICVSResource[] resources, - LocalOption[] localOptions, boolean emptyFolders, IProgressMonitor monitor) throws CVSException { - - checkResourcesManaged(session, resources); - new FileStructureVisitor(session, localOptions, emptyFolders, true, false).visit(session, resources, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#isWorkspaceModification() - */ - protected boolean isWorkspaceModification() { - // The sync-update will not modify the workspace - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#filterGlobalOptions(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption[]) - */ - protected GlobalOption[] filterGlobalOptions(Session session, GlobalOption[] globalOptions) { - // Ensure that the DO_NOT_CHANGE (-n) global option is present - if (! Command.DO_NOT_CHANGE.isElementOf(globalOptions)) { - globalOptions = Command.DO_NOT_CHANGE.addToEnd(globalOptions); - } - return super.filterGlobalOptions(session, globalOptions); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Tag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Tag.java deleted file mode 100644 index 3cb2e9978..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Tag.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.CVSStatus; -import org.eclipse.team.internal.ccvs.core.CVSTag; -import org.eclipse.team.internal.ccvs.core.ICVSResource; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.client.listeners.TagListener; - -public class Tag extends Command { - /*** Local options: specific to tag ***/ - public static final LocalOption CREATE_BRANCH = new LocalOption("-b", null); //$NON-NLS-1$ - public static final LocalOption FORCE_REASSIGNMENT = new LocalOption("-F", null); //$NON-NLS-1$ - - /*** Default command output listener ***/ - private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new TagListener(); - - // handle added and removed resources in a special way - private boolean customBehaviorEnabled; - - protected Tag(boolean customBehaviorEnabled) { - this.customBehaviorEnabled = customBehaviorEnabled; - } - - protected Tag() { - this(false); - } - - protected String getRequestId() { - return "tag"; //$NON-NLS-1$ - } - - protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, - String[] arguments) throws CVSException { - - if (arguments.length < 1) throw new IllegalArgumentException(); - String[] allButFirst = new String[arguments.length - 1]; - System.arraycopy(arguments, 1, allButFirst, 0, arguments.length - 1); - return super.computeWorkResources(session, localOptions, allButFirst); - } - - public IStatus execute(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, CVSTag tag, String[] arguments, ICommandOutputListener listener, - IProgressMonitor monitor) throws CVSException { - - if(tag.getType() != CVSTag.VERSION && tag.getType() != CVSTag.BRANCH) { - throw new CVSException(new CVSStatus(IStatus.ERROR, CVSMessages.Tag_notVersionOrBranchError)); - } - - // Add the CREATE_BRANCH option for a branch tag - if (tag.getType() == CVSTag.BRANCH) { - if ( ! CREATE_BRANCH.isElementOf(localOptions)) { - LocalOption[] newLocalOptions = new LocalOption[localOptions.length + 1]; - System.arraycopy(localOptions, 0, newLocalOptions, 0, localOptions.length); - newLocalOptions[newLocalOptions.length - 1] = CREATE_BRANCH; - localOptions = newLocalOptions; - } - } - - // Add the tag name to the start of the arguments - String[] newArguments = new String[arguments.length + 1]; - newArguments[0] = tag.getName(); - System.arraycopy(arguments, 0, newArguments, 1, arguments.length); - - return execute(session, globalOptions, localOptions, newArguments, listener, monitor); - } - - public IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, - CVSTag tag, ICVSResource[] arguments, ICommandOutputListener listener, IProgressMonitor monitor) - throws CVSException { - - String[] stringArguments = convertArgumentsForOpenSession(arguments, session); - - return execute(session, globalOptions, localOptions, tag, stringArguments, listener, monitor); - } - - protected ICommandOutputListener getDefaultCommandOutputListener() { - return DEFAULT_OUTPUT_LISTENER; - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // Send all folders that are already managed to the server - if (customBehaviorEnabled) { - new TagFileSender(session, localOptions).visit(session, resources, monitor); - } else { - new FileStructureVisitor(session, localOptions, false, false).visit(session, resources, monitor); - } - return resources; - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TagFileSender.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TagFileSender.java deleted file mode 100644 index a15df388f..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TagFileSender.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; - -/** - * Special visitor which handles added and removed files in a special way. - * Added resources are skipped. Deleted resources are sent as if they were not deleted. - */ -class TagFileSender extends FileStructureVisitor { - - public TagFileSender(Session session, LocalOption[] localOptions) { - super(session, localOptions, false, false); - } - - /** - * Override sendFile to provide custom handling of added and deleted resources. - * Added resources are skipped. Deleted resources are sent as if they were not deleted. - */ - protected void sendFile(ICVSFile mFile) throws CVSException { - Policy.checkCanceled(monitor); - byte[] syncBytes = mFile.getSyncBytes(); - if (syncBytes != null) { - // Send the parent folder if it hasn't been sent already - sendFolder(mFile.getParent()); - // Send the file if appropriate - if (ResourceSyncInfo.isDeletion(syncBytes)) { - // makes this resource sync undeleted - syncBytes = ResourceSyncInfo.convertFromDeletion(syncBytes); - } - if (!ResourceSyncInfo.isAddition(syncBytes)) { - session.sendEntry(syncBytes, ResourceSyncInfo.getTimestampToServer(syncBytes, mFile.getTimeStamp())); - session.sendIsModified(mFile, ResourceSyncInfo.isBinary(syncBytes), monitor); - } - } - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TemplateHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TemplateHandler.java deleted file mode 100644 index 1f64df408..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TemplateHandler.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.io.*; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; -import org.eclipse.team.internal.ccvs.core.util.SyncFileWriter; - -/** - * @author Administrator - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ -public class TemplateHandler extends ResponseHandler { - - /** - * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#getResponseID() - */ - public String getResponseID() { - return "Template"; //$NON-NLS-1$ - } - - /** - * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#handle(org.eclipse.team.internal.ccvs.core.client.Session, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) - */ - public void handle(Session session, String localDir, IProgressMonitor monitor) throws CVSException { - session.readLine(); /* read the remote dir which is not needed */ - // Only read the template file if the container exists. - // This is OK as we only use the template from the project folder which must exist - ICVSFolder localFolder = session.getLocalRoot().getFolder(localDir); - IContainer container = (IContainer)localFolder.getIResource(); - ICVSStorage templateFile = null; - if (container != null && container.exists()) { - try { - templateFile = CVSWorkspaceRoot.getCVSFileFor(SyncFileWriter.getTemplateFile(container)); - } catch (CVSException e) { - // Log the inability to create the template file - CVSProviderPlugin.log(new CVSStatus(IStatus.ERROR, CVSStatus.ERROR, "Could not write template file in " + container.getFullPath() + ": " + e.getMessage(), e, session.getLocalRoot())); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - if (container == null || templateFile == null) { - // Create a dummy storage handle to recieve the contents from the server - templateFile = new ICVSStorage() { - public String getName() { - return "Template"; //$NON-NLS-1$ - } - public void setContents( - InputStream stream, - int responseType, - boolean keepLocalHistory, - IProgressMonitor monitor) - throws CVSException { - - try { - // Transfer the contents - OutputStream out = new ByteArrayOutputStream(); - try { - byte[] buffer = new byte[1024]; - int read; - while ((read = stream.read(buffer)) >= 0) { - Policy.checkCanceled(monitor); - out.write(buffer, 0, read); - } - } finally { - out.close(); - } - } catch (IOException e) { - throw CVSException.wrapException(e); - } finally { - try { - stream.close(); - } catch (IOException e1) { - // Ignore close errors - } - } - } - public long getSize() { - return 0; - } - public InputStream getContents() throws CVSException { - return new ByteArrayInputStream(new byte[0]); - } - }; - } - try { - session.receiveFile(templateFile, false, UpdatedHandler.HANDLE_UPDATED, monitor); - } catch (CVSException e) { - if (!(templateFile instanceof ICVSFile && handleInvalidResourceName(session, (ICVSFile)templateFile, e))) { - throw e; - } - } - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Update.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Update.java deleted file mode 100644 index c12730723..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Update.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.client.listeners.UpdateListener; - -public class Update extends Command { - /*** Local options: specific to update ***/ - public static final LocalOption CLEAR_STICKY = new LocalOption("-A"); //$NON-NLS-1$ - public static final LocalOption IGNORE_LOCAL_CHANGES = new LocalOption("-C"); //$NON-NLS-1$ - public static final LocalOption RETRIEVE_ABSENT_DIRECTORIES = new LocalOption("-d"); //$NON-NLS-1$ - public static final LocalOption JOIN = new LocalOption("-j"); //$NON-NLS-1$ - - /*** Default command output listener ***/ - private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new UpdateListener(null); - - /*** File information status returned from update ***/ - public static final int STATE_NONE = 0; // no state information available - public static final int STATE_ADDED_LOCAL = 1; // new file locally that was added but not comitted to server yet - public static final int STATE_UNKOWN = 2; // new file locally but not added to server - public static final int STATE_REMOTE_CHANGES = 3; // remote changes to an unmodified local file - public static final int STATE_DELETED = 4; // removed locally but still exists on the server - public static final int STATE_MODIFIED = 5; // modified locally - public static final int STATE_CONFLICT = 6; // modified locally and on the server but cannot be auto-merged - public static final int STATE_MERGEABLE_CONFLICT = 7; // modified locally and on the server but can be auto-merged - - /** - * Makes a -r or -D or -A option for a tag. - * Valid for: checkout export history rdiff update - */ - public static LocalOption makeTagOption(CVSTag tag) { - int type = tag.getType(); - switch (type) { - case CVSTag.HEAD: - return CLEAR_STICKY; - default: - return Command.makeTagOption(tag); - } - } - - protected Update() { } - protected String getRequestId() { - return "update"; //$NON-NLS-1$ - } - - protected ICommandOutputListener getDefaultCommandOutputListener() { - return DEFAULT_OUTPUT_LISTENER; - } - - protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) - throws CVSException { - - // Send all folders that are already managed to the server - // even folders that are empty - sendFileStructure(session, resources, localOptions, true, monitor); - return resources; - } - - /** - * On successful finish, prune empty directories if the -P or -D option was specified. - */ - protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, - LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, - IStatus status) throws CVSException { - // If we didn't succeed, don't do any post processing - if (status.getCode() == CVSStatus.SERVER_ERROR) { - return status; - } - - // If we are pruning (-P), then prune empty directories - // Note, the CVS spec says that Date (-D) and version (-r) updates - // should automatically prune but this is a problem for remote CVS handles - // which fetch a level at a time - if (PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions)) { - // Delete empty directories - new PruneFolderVisitor().visit(session, resources); - - } - return status; - } - - protected LocalOption[] filterLocalOptions(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions) { - List newOptions = new ArrayList(Arrays.asList(localOptions)); - - if (shouldRetrieveAbsentDirectories(session) && ! RETRIEVE_ABSENT_DIRECTORIES.isElementOf(localOptions)) { - newOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES); - } - - // Prune empty directories if pruning is enabled and the command in not being run in non-update mode - if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories() && ! PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions)) { - if (! DO_NOT_CHANGE.isElementOf(globalOptions)) { - newOptions.add(Command.PRUNE_EMPTY_DIRECTORIES); - } - } - localOptions = (LocalOption[]) newOptions.toArray(new LocalOption[newOptions.size()]); - return super.filterLocalOptions(session, globalOptions, localOptions); - } - - /** - * Return whether the update command should retrieve absent directories. - * @param session the session - * @return whether the update command should retrieve absent directories - */ - protected boolean shouldRetrieveAbsentDirectories(Session session) { - // Look for absent directories if enabled and the option is not already included - IResource resource = null; - RepositoryProvider provider = null; - // If there is a provider, use the providers setting - try { - resource = session.getLocalRoot().getIResource(); - if (resource != null) { - provider = RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId()); - if (provider != null) { - if (((CVSTeamProvider)provider).getFetchAbsentDirectories()) { - return true; - } - } - } - } catch (CVSException e) { - CVSProviderPlugin.log(e); - } - // If there is no provider, use the global setting - if (provider == null) { - if (CVSProviderPlugin.getPlugin().getFetchAbsentDirectories()) { - return true; - } - } - return false; - } - - /** - * We allow unmanaged resources as long as there parents are managed. - * - * @see Command#checkResourcesManaged(Session, ICVSResource[]) - */ - protected void checkResourcesManaged(Session session, ICVSResource[] resources) throws CVSException { - for (int i = 0; i < resources.length; ++i) { - ICVSFolder folder; - if (resources[i].isFolder()) { - if (((ICVSFolder)resources[i]).isCVSFolder()) { - folder = (ICVSFolder)resources[i]; - } else { - folder = resources[i].getParent(); - } - } - else { - folder = resources[i].getParent(); - } - if (folder==null || (!folder.isCVSFolder() && folder.exists())) { - if (folder == null) - folder = (ICVSFolder)resources[i]; - IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR,NLS.bind(CVSMessages.Command_argumentNotManaged, new String[] { folder.getName() }),session.getLocalRoot()); - throw new CVSException(status); - } - } - } - - /** - * @see org.eclipse.team.internal.ccvs.core.client.Command#doExecute(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption, org.eclipse.team.internal.ccvs.core.client.Command.LocalOption, java.lang.String, org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus doExecute( - Session session, - GlobalOption[] globalOptions, - LocalOption[] localOptions, - String[] arguments, - ICommandOutputListener listener, - IProgressMonitor monitor) - throws CVSException { - - session.setIgnoringLocalChanges(IGNORE_LOCAL_CHANGES.isElementOf(localOptions)); - try { - return super.doExecute( - session, - globalOptions, - localOptions, - arguments, - listener, - monitor); - } finally { - session.setIgnoringLocalChanges(false); - } - - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java deleted file mode 100644 index 8c7f4d734..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Red Hat Incorporated - is/setExecutable() code - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.listeners.*; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; - -/** - * This custom update command will only update files that - * are either incoming changes (Update-existing) or auto-mergable - * (Merged with no "+=" in entry line). - */ -public class UpdateMergableOnly extends Update { - - private static final String LOCAL_FILE_PATH_VARIABLE_NAME = "localFilePath"; //$NON-NLS-1$ - private static ServerMessageLineMatcher MERGE_UPDATE_CONFLICTING_ADDITION_MATCHER; - static { - // TODO: temprary until proper lifecycle is defined - initializePatterns(); - } - public static void initializePatterns() { - try { - MERGE_UPDATE_CONFLICTING_ADDITION_MATCHER = new ServerMessageLineMatcher( - IMessagePatterns.MERGE_UPDATE_CONFLICTING_ADDITION, new String[] {LOCAL_FILE_PATH_VARIABLE_NAME}); - } catch (CVSException e) { - // This is serious as the listener will not function properly - CVSProviderPlugin.log(e); - } - } - - List skippedFiles = new ArrayList(); - - public class MergableOnlyUpdatedHandler extends UpdatedHandler { - - public MergableOnlyUpdatedHandler() { - // handle "Merged" responses - super(UpdatedHandler.HANDLE_MERGED); - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.UpdatedHandler#getTargetFile(org.eclipse.team.internal.ccvs.core.ICVSFolder, java.lang.String, byte[]) - */ - protected ICVSFile getTargetFile(ICVSFolder mParent, String fileName, byte[] entryBytes) throws CVSException { - String adjustedFileName = fileName; - if (ResourceSyncInfo.isMergedWithConflicts(entryBytes)) { - // for merged-with-conflict, return a temp file - adjustedFileName = ".##" + adjustedFileName + " " + ResourceSyncInfo.getRevision(entryBytes); //$NON-NLS-1$ //$NON-NLS-2$ - skippedFiles.add(((IContainer)mParent.getIResource()).getFile(new Path(null, fileName))); - } - return super.getTargetFile(mParent, adjustedFileName, entryBytes); - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.UpdatedHandler#receiveTargetFile(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.ICVSFile, java.lang.String, java.util.Date, boolean, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void receiveTargetFile( - Session session, - ICVSFile mFile, - String entryLine, - Date modTime, - boolean binary, - boolean readOnly, - boolean executable, - IProgressMonitor monitor) - throws CVSException { - - if (ResourceSyncInfo.isMergedWithConflicts(entryLine.getBytes())) { - // For merged-with-conflict, just recieve the file contents. - // Use the Updated handler type so that the file will be created or - // updated. - session.receiveFile(mFile, binary, UpdatedHandler.HANDLE_UPDATED, monitor); - // Now delete the file since it is not used - mFile.delete(); - } else { - super.receiveTargetFile(session, mFile, entryLine, modTime, binary, readOnly, executable, monitor); - } - } - } - - /** - * Override the general update listener to handle the following - * message: - * cvs server: file folder/file.ext exists, but has been added in revision TAG_NAME - * This is required because MergeSubscriber adjusts the base when an update - * occurs and we can end up in a situation where the update faile with the - * above message (see buh 58654). - */ - public class MergeUpdateListener extends UpdateListener { - public MergeUpdateListener(IUpdateMessageListener updateMessageListener) { - super(updateMessageListener); - } - public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - Map variables = MERGE_UPDATE_CONFLICTING_ADDITION_MATCHER.processServerMessage(line); - if (variables != null) { - String filePath = (String)variables.get(LOCAL_FILE_PATH_VARIABLE_NAME); - try { - ICVSResource cvsResource = commandRoot.getChild(filePath); - IResource resource = cvsResource.getIResource(); - if (resource != null && resource.getType() == IResource.FILE) { - skippedFiles.add(resource); - return OK; - } - } catch (CVSException e) { - CVSProviderPlugin.log(e); - // Fall through to let the superclass process the error line - } - } - return super.errorLine(line, location, commandRoot, monitor); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#doExecute(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption[], org.eclipse.team.internal.ccvs.core.client.Command.LocalOption[], java.lang.String[], org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IStatus doExecute( - Session session, - GlobalOption[] globalOptions, - LocalOption[] localOptions, - String[] arguments, - ICommandOutputListener listener, - IProgressMonitor monitor) - throws CVSException { - - MergableOnlyUpdatedHandler newHandler = new MergableOnlyUpdatedHandler(); - ResponseHandler oldHandler = session.getResponseHandler(newHandler.getResponseID()); - skippedFiles.clear(); - try { - session.registerResponseHandler(newHandler); - // Don't create backup files since merges won't be overridden - session.setCreateBackups(false); - return super.doExecute( - session, - globalOptions, - localOptions, - arguments, - new MergeUpdateListener(null), - monitor); - } finally { - session.registerResponseHandler(oldHandler); - session.setCreateBackups(true); - } - } - - public IFile[] getSkippedFiles() { - return (IFile[]) skippedFiles.toArray(new IFile[skippedFiles.size()]); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdatedHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdatedHandler.java deleted file mode 100644 index dd6e43bed..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdatedHandler.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Red Hat Incorporated - is/setExecutable() code - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import java.util.Date; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.syncinfo.MutableResourceSyncInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; - -/** - * Handles any "Updated" and "Merged" responses - * from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Updated ???\n - * [...] - * </pre> - * Then - * </p> - */ - -/** - * Does get information about the file that is updated - * and the file-content itself and puts it on the fileSystem. - * - * The difference beetween the "Updated" and the "Merged" is, that - * an "Merged" file is not going to be up-to-date after the operation. - * - * Requiers a exisiting parent-folder. - */ -public class UpdatedHandler extends ResponseHandler { - - private int handlerType; - - public static final int HANDLE_UPDATED = ICVSFile.UPDATED; - public static final int HANDLE_MERGED = ICVSFile.MERGED; - public static final int HANDLE_UPDATE_EXISTING = ICVSFile.UPDATE_EXISTING; - public static final int HANDLE_CREATED = ICVSFile.CREATED; - - private static final String READ_ONLY_FLAG = "u=rw"; //$NON-NLS-1$ - private static final String EXECUTE_FLAG = "x"; //$NON-NLS-1$ - - public UpdatedHandler(int handlerType) { - this.handlerType = handlerType; - } - - public String getResponseID() { - switch (handlerType) { - case HANDLE_UPDATED: return "Updated"; //$NON-NLS-1$ - case HANDLE_MERGED: return "Merged"; //$NON-NLS-1$ - case HANDLE_UPDATE_EXISTING: return "Update-existing"; //$NON-NLS-1$ - case HANDLE_CREATED: return "Created"; //$NON-NLS-1$ - } - return null; - } - - public void handle(Session session, String localDir, IProgressMonitor monitor) throws CVSException { - // read additional data for the response - String repositoryFile = session.readLine(); - String entryLine = session.readLine(); - byte[] entryBytes = entryLine.getBytes(); - String permissionsLine = session.readLine(); - - // clear file update modifiers - Date modTime = session.getModTime(); - session.setModTime(null); - - // Get the local file - String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$ - ICVSFolder mParent = getExistingFolder(session, localDir); - ICVSFile mFile = getTargetFile(mParent, fileName, entryBytes); - - boolean binary = ResourceSyncInfo.isBinary(entryBytes); - boolean readOnly = permissionsLine.indexOf(READ_ONLY_FLAG) == -1; - boolean executable = permissionsLine.indexOf(EXECUTE_FLAG) != -1; - - try { - // The file may have been set as read-only by a previous checkout/update - if (mFile.isReadOnly()) mFile.setReadOnly(false); - } catch (CVSException e) { - // Just log and keep going - CVSProviderPlugin.log(e); - } - - try { - receiveTargetFile(session, mFile, entryLine, modTime, binary, readOnly, executable, monitor); - } catch (CVSException e) { - // An error occurred while recieving the file. - // If it is due to an invalid file name, - // accumulate the error and continue. - // Otherwise, exit - if (!handleInvalidResourceName(session, mFile, e)) { - throw e; - } - } - } - - protected ICVSFile getTargetFile(ICVSFolder mParent, String fileName, byte[] entryBytes) throws CVSException { - return mParent.getFile(fileName); - } - - protected void receiveTargetFile(Session session, ICVSFile mFile, String entryLine, Date modTime, boolean binary, boolean readOnly, boolean executable, IProgressMonitor monitor) throws CVSException { - - // receive the file contents from the server - session.receiveFile(mFile, binary, handlerType, monitor); - - // Set the timestamp in the file and get it again so that we use the *real* timestamp - // in the sync info. The os may not actually set the time we provided :) - mFile.setTimeStamp(modTime); - modTime = mFile.getTimeStamp(); - ResourceSyncInfo info = new ResourceSyncInfo(entryLine, null); - MutableResourceSyncInfo newInfoWithTimestamp = info.cloneMutable(); - newInfoWithTimestamp.setTimeStamp(modTime); - - //see bug 106876 - CVSTag tag = newInfoWithTimestamp.getTag(); - if(tag != null && CVSTag.BASE.getName().equals(tag.getName())){ - newInfoWithTimestamp.setTag(mFile.getSyncInfo().getTag()); - } - - int modificationState = ICVSFile.UNKNOWN; - if(handlerType==HANDLE_MERGED) { - newInfoWithTimestamp.setMerged(); - } else if (!session.isIgnoringLocalChanges() - && !info.isAdded() /* could be an added entry during a merge in which case it is dirty */ - && (handlerType==HANDLE_UPDATE_EXISTING || handlerType==HANDLE_CREATED)) { - // both these cases result in an unmodified file. - // reporting is handled by the FileModificationManager - modificationState = ICVSFile.CLEAN; - CVSProviderPlugin.getPlugin().getFileModificationManager().updated(mFile); - } - mFile.setSyncInfo(newInfoWithTimestamp, modificationState); - try { - if (readOnly) mFile.setReadOnly(true); - if (executable) mFile.setExecutable(true); - } catch (CVSException e) { - // Just log and keep going - CVSProviderPlugin.log(e); - } - } - - public int getHandlerType() { - return handlerType; - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequests.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequests.java deleted file mode 100644 index cdb088eb0..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequests.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.CVSException; - -class ValidRequests extends Request { - - protected ValidRequests() { } - - protected String getRequestId() { - return "valid-requests"; //$NON-NLS-1$ - } - - public IStatus execute(Session session, IProgressMonitor monitor) throws CVSException { - return executeRequest(session, Command.DEFAULT_OUTPUT_LISTENER, monitor); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequestsHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequestsHandler.java deleted file mode 100644 index d2c60a837..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequestsHandler.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.client.Session; - -/** - * Handles a "Valid-requests" response from the CVS server. - * <p> - * Suppose as a result of performing a command the CVS server responds - * as follows:<br> - * <pre> - * [...] - * Valid-requests ci co update Root Directory Valid-responses Argument ...\n - * [...] - * </pre> - * Then we remember the set of valid requests for this session in - * preparation for isValidRequests queries. - * </p> - */ -class ValidRequestsHandler extends ResponseHandler { - public String getResponseID() { - return "Valid-requests"; //$NON-NLS-1$ - } - - public void handle(Session session, String validRequests, - IProgressMonitor monitor) throws CVSException { - // remember the set of valid requests for this session - session.setValidRequests(validRequests); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Version.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Version.java deleted file mode 100644 index 5fdee7d52..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Version.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -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.listeners.ICommandOutputListener; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; - -/** - * Here are some of the output formats we know about: - * - * Concurrent Versions System (CVS) 1.11.1p1 (client/server) - * Concurrent Versions System (CVS) NT 1.11.1.1 (Build 27) - * Concurrent Versions System (CVSNT) 1.11.1.3 (Build 57a) (client/server) - */ -public class Version extends RemoteCommand { - - private static final String CVS_NT_PREFIX_1 = "Concurrent Versions System (CVS) NT "; //$NON-NLS-1$ - private static final String CVS_NT_PREFIX_2 = "Concurrent Versions System (CVSNT) "; //$NON-NLS-1$ - private static final String CVS_PREFIX = "Concurrent Versions System (CVS) "; //$NON-NLS-1$ - /** - * @see Request#getRequestId() - */ - protected String getRequestId() { - return "version"; //$NON-NLS-1$ - } - - public IStatus execute(Session session, final ICVSRepositoryLocation location, IProgressMonitor monitor) throws CVSException { - - // The server may not support the version request - if ( ! session.isValidRequest(getRequestId())) { - IStatus status = new CVSStatus(IStatus.WARNING, CVSStatus.SERVER_IS_UNKNOWN, NLS.bind(CVSMessages.Version_versionNotValidRequest, new String[] { location.getHost() }), session.getLocalRoot()); - ((CVSRepositoryLocation)location).setServerPlaform(CVSRepositoryLocation.UNKNOWN_SERVER); - CVSProviderPlugin.log(status); - return status; - } - - ICommandOutputListener listener = new ICommandOutputListener() { - public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - String knownPrefix = null; - boolean isCVSNT = false; - if (line.startsWith(CVS_NT_PREFIX_1)) { - isCVSNT = true; - knownPrefix = CVS_NT_PREFIX_1; - } else if (line.startsWith(CVS_NT_PREFIX_2)) { - isCVSNT = true; - knownPrefix = CVS_NT_PREFIX_2; - } else if (line.startsWith(CVS_PREFIX)) { - knownPrefix = CVS_PREFIX; - } - IStatus status = OK; - int serverType = CVSRepositoryLocation.CVS_SERVER; - if (knownPrefix != null) { - String versionNumber = line.substring(knownPrefix.length(), line.indexOf(' ', knownPrefix.length() + 1)); - if (versionNumber.startsWith("1.10") || versionNumber.equals("1.11") || versionNumber.equals("1.11.1")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - serverType = CVSRepositoryLocation.UNSUPPORTED_SERVER; - status = new CVSStatus(IStatus.WARNING, CVSStatus.UNSUPPORTED_SERVER_VERSION, NLS.bind(CVSMessages.Version_unsupportedVersion, new String[] { location.getHost(), versionNumber }),location); - } else if (isCVSNT) { - serverType = CVSRepositoryLocation.CVSNT_SERVER; - } - } else { - serverType = CVSRepositoryLocation.UNKNOWN_SERVER; - status = new CVSStatus(IStatus.INFO, CVSStatus.SERVER_IS_UNKNOWN, NLS.bind(CVSMessages.Version_unknownVersionFormat, new String[] { location.getHost(), line }), location); - } - ((CVSRepositoryLocation)location).setServerPlaform(serverType); - return status; - } - public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - return new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE, line, commandRoot); - } - }; - - return execute(session, NO_GLOBAL_OPTIONS, NO_LOCAL_OPTIONS, new String[] {}, listener, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.client.Command#isWorkspaceModification() - */ - protected boolean isWorkspaceModification() { - return false; - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/AdminKSubstListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/AdminKSubstListener.java deleted file mode 100644 index 78341bb1e..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/AdminKSubstListener.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - - -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; -import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption; -import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; -import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Used with 'admin -ksubst' to capture lines of text that are issued - * as confirmation that the remote keyword substitution mode has been - * changed. When encountered, updates the local ResourceSyncInfo for - * the file in question to reflect - * - * e.g. - * RCS file: path/filename,v - * done - * - * We don't expect to see anything special on stderr if the command succeeds. - */ -public class AdminKSubstListener extends CommandOutputListener { - private KSubstOption ksubstMode; - - public AdminKSubstListener(KSubstOption ksubstMode) { - this.ksubstMode = ksubstMode; - } - - public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, - IProgressMonitor monitor) { - if (line.startsWith("RCS file:")) { //$NON-NLS-1$ - String rcsFile = line.substring(10).trim(); - if (! rcsFile.endsWith(",v")) { //$NON-NLS-1$ - return new CVSStatus(IStatus.ERROR, - NLS.bind(CVSMessages.AdminKSubstListener_expectedRCSFile, new String[] { rcsFile })); - } - IPath rcsFilePath = new Path(null, Util.removeAtticSegment(rcsFile.substring(0, rcsFile.length() - 2))); - try { - ICVSFile file = findLocalFileFor(commandRoot, rcsFilePath); - //ResourceSyncInfo info = file.getSyncInfo(); - byte[] syncBytes = file.getSyncBytes(); - if (syncBytes != null) { - // only update sync info if we have it locally - file.setSyncBytes(ResourceSyncInfo.setKeywordMode(syncBytes, ksubstMode), ICVSFile.UNKNOWN); - } - } catch (CVSException e) { - return e.getStatus(); - } - } - return OK; - } - - private ICVSFile findLocalFileFor(ICVSFolder commandRoot, IPath rcsFilePath) throws CVSException { - - // First, look for the local file by following the remote path - FolderSyncInfo info = commandRoot.getFolderSyncInfo(); - String remoteRootLocation = info.getRemoteLocation(); - if (remoteRootLocation == null) { - throw new CVSException(new CVSStatus(IStatus.ERROR, - CVSMessages.AdminKSubstListener_commandRootNotManaged)); - } - IPath remoteRootPath = new Path(null, remoteRootLocation); - if (remoteRootPath.isPrefixOf(rcsFilePath)) { - IPath relativeFilePath = rcsFilePath.removeFirstSegments(remoteRootPath.segmentCount()); - ICVSFile file = commandRoot.getFile(relativeFilePath.toString()); - if (file.isManaged() && isMatchingPath(file, rcsFilePath)) { - return file; - } - } - - // We couldn't find the file that way which means we're working in a defined module. - // Scan all folders looking for a match - ICVSFolder parent = findFolder(commandRoot, rcsFilePath.removeLastSegments(1)); - if (parent != null) { - ICVSFile file = parent.getFile(rcsFilePath.lastSegment()); - if (file.isManaged()) { - return file; - } - } - - // No file was found so return null; - throw new CVSException(new CVSStatus(IStatus.ERROR, - NLS.bind(CVSMessages.AdminKSubstListener_expectedChildOfCommandRoot, new String[] { rcsFilePath.toString(), remoteRootPath.toString() }))); - } - - private ICVSFolder findFolder(ICVSFolder commandRoot, IPath path) throws CVSException { - final String remotePath = path.toString(); - final ICVSFolder[] result = new ICVSFolder[] { null }; - commandRoot.accept(new ICVSResourceVisitor() { - public void visitFile(ICVSFile file) throws CVSException { - // Nothing to do for files - } - public void visitFolder(ICVSFolder folder) throws CVSException { - FolderSyncInfo info = folder.getFolderSyncInfo(); - if (info != null && info.getRemoteLocation().equals(remotePath)) { - // We found the folder we're looking for - result[0] = folder; - } - if (result[0] == null) { - folder.acceptChildren(this); - } - } - }); - return result[0]; - } - - private boolean isMatchingPath(ICVSFile file, IPath rcsFilePath) throws CVSException { - FolderSyncInfo info = file.getParent().getFolderSyncInfo(); - return info != null - && info.getRemoteLocation().equals(rcsFilePath.removeLastSegments(1).toString()); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/AnnotateListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/AnnotateListener.java deleted file mode 100644 index d7576883b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/AnnotateListener.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; - -public class AnnotateListener extends CommandOutputListener { - -/** - * Handle output from the CVS Annotate command. - */ - ByteArrayOutputStream aStream = new ByteArrayOutputStream(); - List blocks = new ArrayList(); - int lineNumber; - - public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - String error = null; - CVSAnnotateBlock aBlock = new CVSAnnotateBlock(line, lineNumber++); - if (!aBlock.isValid()) { - error = line; - } - - /** - * Make sure all lines have a line terminator. - */ - try { - aStream.write(line.substring(aBlock.getSourceOffset()).getBytes()); - if (!(line.endsWith("\r") || line.endsWith("\r\n"))) { //$NON-NLS-1$ //$NON-NLS-2$ - aStream.write(System.getProperty("line.separator").getBytes()); //$NON-NLS-1$ - } - } catch (IOException e) { - } - add(aBlock); - if (error != null) - return new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE_PARSE_FAILURE, error, commandRoot); - return OK; - } - - public InputStream getContents() { - return new ByteArrayInputStream(aStream.toByteArray()); - } - - public List getCvsAnnotateBlocks() { - return blocks; - } - /** - * Add an annotate block to the receiver merging this block with the - * previous block if it is part of the same change. - * @param aBlock - */ - private void add(CVSAnnotateBlock aBlock) { - - int size = blocks.size(); - if (size == 0) { - blocks.add(aBlock); - } else { - CVSAnnotateBlock lastBlock = (CVSAnnotateBlock) blocks.get(size - 1); - if (lastBlock.getRevision().equals(aBlock.getRevision())) { - lastBlock.setEndLine(aBlock.getStartLine()); - } else { - blocks.add(aBlock); - } - } - } - - /* (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) { - if(line.startsWith(CVSMessages.AnnotateListener_3)) { - String error = CVSMessages.AnnotateListener_4; - return new CVSStatus(IStatus.ERROR, CVSStatus.SERVER_ERROR, error, commandRoot); - } - return super.errorLine(line, location, commandRoot, monitor); - } - - /** - * Set the contents of the listener to the provided contents. - * This is done if the contents fetched by the annotate command - * has a charater set that may have been mangled by the transfer - * @param remoteContents the actual contens of the file - */ - public void setContents(InputStream remoteContents) { - try { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - byte[] buffer = new byte[1024]; - int n = remoteContents.read(buffer); - while (n != -1) { - stream.write(buffer, 0, n); - n = remoteContents.read(buffer); - } - aStream = stream; - } catch (IOException e) { - // Log and continue - CVSProviderPlugin.log(CVSException.wrapException(e)); - } - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/DiffListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/DiffListener.java deleted file mode 100644 index 7de08ec0d..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/DiffListener.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - - -import java.io.PrintStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -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; -import org.eclipse.team.internal.ccvs.core.client.Session; - -public class DiffListener extends CommandOutputListener { - PrintStream patchStream; - boolean wroteToStream; - - //Error Messages returned by CVS - static final String ERR_NOSUCHDIRECTORY = "cvs [diff aborted]: no such directory"; //$NON-NLS-1$ - - public DiffListener(PrintStream patchStream) { - this.patchStream = patchStream; - wroteToStream=false; - } - - public IStatus messageLine( - String line, - ICVSRepositoryLocation location, - ICVSFolder commandRoot, - IProgressMonitor monitor) { - - // Special handling to avoid getting duplicate CRs when generating a patch on windows. - // If the remote file has CR/LF in it, then the line will have a CR at the end. - // We need to remove it so we don't end up with two CRs (since the printStream will also add one). - // On *nix, we want to include the CR since it will not be added by the printStream (see bug 92162). - if (Session.IS_CRLF_PLATFORM && line.length() > 0 && line.charAt(line.length() - 1) == '\r') { - line = line.substring(0, line.length() - 1); - } - patchStream.println(line); - wroteToStream=true; - - return OK; - } - - 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; - } - - //Check to see if this is a no such directory message - if (line.indexOf(ERR_NOSUCHDIRECTORY) != -1){ - return OK; - } - return super.errorLine(line, location, commandRoot, monitor); - } - - public boolean wroteToStream() { - return wroteToStream; - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/EditorsListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/EditorsListener.java deleted file mode 100644 index db5438fd3..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/EditorsListener.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * CSC - Intial implementation - * IBM Corporation - ongoing maintenance - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - -import java.util.LinkedList; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.EditorsInfo; -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; - - -/** - * - * - * Listener for the Editors command - * - * @author <a href="mailto:kohlwes@gmx.net">Gregor Kohlwes</a> - * - */ -public class EditorsListener extends CommandOutputListener { - /** - * List to store the EditorsInfos - */ - private List infos = new LinkedList(); - - /** - * Name of the current file - */ - private String fileName; - - /** - * Constructor EditorsListener. - */ - public EditorsListener() { - } - - /** - * @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) { - - // If there is a file with multiple editors - // then cvs will write the filename only - // in the first line and the following - // line will start with a Tab - if (line.startsWith("\t")) { //$NON-NLS-1$ - line = fileName + line; - } - EditorsInfo info = new EditorsInfo(); - StringTokenizer tokenizer = new StringTokenizer(line,"\t"); //$NON-NLS-1$ - int i = 0; - while(tokenizer.hasMoreTokens()) { - String token = tokenizer.nextToken(); - switch (i) { - case 0: - info.setFileName(token); - fileName = token; - break; - case 1: - info.setUserName(token); - break; - case 2: - info.setDateString(token); - break; - case 3: - info.setComputerName(token); - break; - default : - break; - } - i++; - } - - infos.add(info); - return OK; - - } - /** - * Method getEditorsInfos. - * @return IEditorsInfo[] - */ - public EditorsInfo[] getEditorsInfos() { - return (EditorsInfo[]) infos.toArray(new EditorsInfo[infos.size()]); - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ICommandOutputListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ICommandOutputListener.java deleted file mode 100644 index 051591325..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ICommandOutputListener.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.CVSStatus; -import org.eclipse.team.internal.ccvs.core.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; - -/** - * Instances of this interface can be passed to the <code>Command#execute</code> methods - * and will receive notification when M or E messages are received from the server. - */ -public interface ICommandOutputListener { - - /*** Status to be returned when no error or warning occured ***/ - public static final IStatus OK = new CVSStatus(IStatus.OK, CVSMessages.ok); - - public static final String SERVER_PREFIX = "server: "; //$NON-NLS-1$ - public static final String SERVER_ABORTED_PREFIX = "[server aborted]: "; //$NON-NLS-1$ - public static final String RTAG_PREFIX = "rtag: "; //$NON-NLS-1$ - - /** - * Invoked when a message line is received from the server. - * <p> - * Any status other than ICommandOutputListener.OK will be accumulated - * by the command and returned. The severity of the status matches those of - * IStatus and must indicate whether this is a warning, error, or informational - * text.while the code should be one of the codes provided by CVSStatus. - * The status code must not be CVSStatus.SERVER_ERROR. - * </p> - * - * @param line the line of message text sent by the server - * @param commandRoot the root directory of the command - * @param monitor the progress monitor - * @return a status indicating success or failure based on the text - */ - public IStatus messageLine(String line, - ICVSRepositoryLocation location, - ICVSFolder commandRoot, - IProgressMonitor monitor); - - /** - * Invoked when an error line is received from the server. - * <p> - * Any status other than ICommandOutputListener.OK will be accumulated - * by the command and returned. The severity of the status matches those of - * IStatus and must indicate whether this is a warning, error, or informational - * text.while the code should be one of the codes provided by CVSStatus. - * The status code must not be CVSStatus.SERVER_ERROR. - * </p> - * - * @param line the line of error text sent by the server - * @param commandRoot the root directory of the command - * @param monitor the progress monitor - * @return a status indicating success or failure based on the text - */ - public IStatus errorLine(String line, - ICVSRepositoryLocation location, - ICVSFolder commandRoot, - IProgressMonitor monitor); -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IConsoleListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IConsoleListener.java deleted file mode 100644 index a625735f3..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IConsoleListener.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.client.Session; - -public interface IConsoleListener { - /** - * Called when a command is invoked. - * @param session the session that the command is being executed over - * @param line the command invocation string - */ - public void commandInvoked(Session session, String line); - - /** - * Called when a line of message text has been received. - * @param session the session that the command is being executed over - * @param line the line of text - * @param status the status returned from the command message parser - */ - public void messageLineReceived(Session session, String line, IStatus status); - - /** - * Called when a line of error text has been received. - * @param session the session that the command is being executed over - * @param line the line of text - * @param status the status returned from the command message parser - */ - public void errorLineReceived(Session session, String line, IStatus status); - - /** - * Called when a command has been completed. - * @param session the session that the command is being executed over - * @param status the status code, or null if not applicable - * @param exception an exception, or null if not applicable - */ - public void commandCompleted(Session session, IStatus status, Exception exception); -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ILogEntryListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ILogEntryListener.java deleted file mode 100644 index 91a4c7bc3..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ILogEntryListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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.ILogEntry; - -/** - * Interface for receiving log entries from the <code>LogListener</code> - */ -public interface ILogEntryListener { - - /** - * A log entry was received for the current file - * @param entry the received log entry. - */ - void handleLogEntryReceived(ILogEntry entry); - -} 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 deleted file mode 100644 index 9d3a690df..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IMessagePatterns.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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$ - - public static final String MERGE_UPDATE_CONFLICTING_ADDITION = SERVER_MESSAGE_PREFIX + "file " + Util.getVariablePattern(FILE_PATH_PATTERN, "localFilePath") + " exists, but has been added in revision " + TAG_PATTERN; //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IStatusListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IStatusListener.java deleted file mode 100644 index 3e0093a37..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IStatusListener.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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.ICVSFolder; - -public interface IStatusListener { - - public static final String FOLDER_REVISION = ""; //$NON-NLS-1$ - - /** - * Provides access to the revision of a file through the use of the Status command. - * - * @param commandRoot the root directory of the command - * @param path the absolute remote path of the resource including the repository root directory - * @param remoteRevision the remote revision of the file - */ - public void fileStatus(ICVSFolder commandRoot, String path, String remoteRevision); -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IUpdateMessageListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IUpdateMessageListener.java deleted file mode 100644 index 009e8b42a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/IUpdateMessageListener.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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.ICVSFolder; - -/** - * This listener is used by RemoteFolder to listener for E and M messages - * from the CVS server in order to determine the files and folders contained in a parent folder. - */ -public interface IUpdateMessageListener { - /** - * Notification that a directory (which may or may not have been reported by - * directoryInformation()) does not exist. - * - * @param commandRoot the root directory of the command - * @param path the path of the directory relative to the commandRoot - */ - public void directoryDoesNotExist(ICVSFolder commandRoot, String path); - /** - * Notification of information about a directory. - * - * @param commandRoot the root directory of the command - * @param path the path of the directory relative to the commandRoot - * @param newDirectory true if the directory does not exist locally (i.e. in the commandRoot hierarchy) - */ - public void directoryInformation(ICVSFolder commandRoot, String path, boolean newDirectory); - /** - * Notification of information about a file - * - * @param type the type of update for the file (see Update for type constants) - * @param commandRoot the root directory of the command - * @param filename the path of the file relative to the commandRoot - */ - public void fileInformation(int type, ICVSFolder parent, String filename); - /** - * Notification that a file does not exists remotely - * - * @param commandRoot the root directory of the command - * @param filename the path of the file relative to the commandRoot - */ - public void fileDoesNotExist(ICVSFolder parent, String filename); -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/LogEntry.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/LogEntry.java deleted file mode 100644 index af2937a40..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/LogEntry.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - - -import java.util.Date; - -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; - -public class LogEntry extends PlatformObject implements ILogEntry { - - private RemoteFile file; - private String author; - private Date date; - private String comment; - private String state; - private CVSTag[] tags; - private String[] revisions; - - /* - * Flatten the text in the multi-line comment - */ - public static String flattenText(String string) { - StringBuffer buffer = new StringBuffer(string.length() + 20); - boolean skipAdjacentLineSeparator = true; - for (int i = 0; i < string.length(); i++) { - char c = string.charAt(i); - if (c == '\r' || c == '\n') { - if (!skipAdjacentLineSeparator) - buffer.append(CVSMessages.LogEntry_0); - skipAdjacentLineSeparator = true; - } else { - buffer.append(c); - skipAdjacentLineSeparator = false; - } - } - return buffer.toString(); - } - - public LogEntry(RemoteFile file, String revision, String author, Date date, String comment, String state, CVSTag[] tags) { - this.file = file.toRevision(revision); - this.author = author; - this.date = date; - this.comment = comment; - this.state = state; - this.tags = tags; - } - - public LogEntry(RemoteFile file, String revision, String author, Date date, String comment, String state, CVSTag[] tags, String[] revisions) { - this(file,revision,author,date,comment,state,tags); - this.revisions=revisions; - } - - /** - * @see ILogEntry#getRevision() - */ - public String getRevision() { - return file.getRevision(); - } - - /** - * @see ILogEntry#getAuthor() - */ - public String getAuthor() { - return author; - } - - /** - * @see ILogEntry#getDate() - */ - public Date getDate() { - return date; - } - - /** - * @see ILogEntry#getComment() - */ - public String getComment() { - return comment; - } - - /** - * @see ILogEntry#getState() - */ - public String getState() { - return state; - } - - /** - * @see ILogEntry#getTags() - */ - public CVSTag[] getTags() { - CVSTag[] result = new CVSTag[tags.length]; - System.arraycopy(tags, 0, result, 0, tags.length); - return result; - } - - /** - * @see ILogEntry#getRemoteFile() - */ - public ICVSRemoteFile getRemoteFile() { - return file; - } - - /** - * @see ILogEntry#isDeletion() - */ - public boolean isDeletion() { - return getState().equals("dead"); //$NON-NLS-1$ - } - - /** - * In the case where files on a branch haven't been modified since their initial branch point, - * they keep the revision number of their predecessor. In this case no revision info will be displayed - * while doing a log, so all branch revision numbers are recorded. This allows the user to pick which revision - * they are interested in. - * @return an array of branch revision strings or an empty array if no branch revisions were recorded - */ - public String[] getBranchRevisions(){ - - if (revisions != null) - return revisions; - - return new String[0]; - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/LogListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/LogListener.java deleted file mode 100644 index aab7efce6..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/LogListener.java +++ /dev/null @@ -1,330 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Brock Janiczak <brockj@tpg.com.au> - Bug 179977 CVS log command doesn't scale well with lots of tags and versions - * Brock Janiczak <brockj@tpg.com.au> - Bug 194396 Reduce retained memory usage of LogEntry objects - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - -import java.text.*; -import java.util.*; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Log listener that parses the log entries returned from the - * server but delegates the handling of the entries to a subclass. - */ -public class LogListener extends CommandOutputListener { - - /* - * A new format for log dates was introduced in 1.12.9 - */ - private static final String LOG_TIMESTAMP_FORMAT_OLD= "yyyy/MM/dd HH:mm:ss zzz";//$NON-NLS-1$ - private static final String LOG_TIMESTAMP_FORMAT= "yyyy-MM-dd HH:mm:ss zzz";//$NON-NLS-1$ - private static final Locale LOG_TIMESTAMP_LOCALE= Locale.US; - private final DateFormat LOG_DATE_FORMATTER_OLD = new SimpleDateFormat(LOG_TIMESTAMP_FORMAT_OLD, LOG_TIMESTAMP_LOCALE); - private final DateFormat LOG_DATE_FORMATTER = new SimpleDateFormat(LOG_TIMESTAMP_FORMAT, LOG_TIMESTAMP_LOCALE); - - // Server message prefix used for error detection - private static final String NOTHING_KNOWN_ABOUT = "nothing known about "; //$NON-NLS-1$ - - // States of log accumulation. - private final int DONE = 4; - private final int COMMENT = 3; - private final int REVISION = 2; - private final int SYMBOLIC_NAMES = 1; - private final int BEGIN = 0; - - //Tag used for accumulating all of a branch's revision info - public final static String BRANCH_REVISION = "branchRevision"; //$NON-NLS-1$ - - private static final CVSTag[] NO_TAGS = new CVSTag[0]; - private static final String[] NO_VERSIONS = new String[0]; - - // Instance variables for accumulating Log information - private RemoteFile currentFile; - private int state = BEGIN; - private StringBuffer comment; - private String fileState; - private String revision; - private String author; - private Date creationDate; - private List versions = new ArrayList(); - private Map internedStrings = new HashMap(); - private final ILogEntryListener listener; - - /** - * Create a log listener for receiving entries for one or more files. - */ - public LogListener(ILogEntryListener listener) { - this.listener = listener; - } - - public LogListener(RemoteFile file, ILogEntryListener listener) { - this(listener); - this.currentFile = file; - } - - private String getRelativeFilePath(ICVSRepositoryLocation location, String fileName) { - if (fileName.endsWith(",v")) { //$NON-NLS-1$ - fileName = fileName.substring(0, fileName.length() - 2); - } - fileName = Util.removeAtticSegment(fileName); - String rootDirectory = location.getRootDirectory(); - if (fileName.startsWith(rootDirectory)) { - try { - fileName = Util.getRelativePath(rootDirectory, fileName); - } catch (CVSException e) { - CVSProviderPlugin.log(e); - return null; - } - } - return fileName; - } - - public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - String serverMessage = getServerMessage(line, location); - if (serverMessage != null) { - // look for the following condition - // E cvs server: nothing known about fileName - if (serverMessage.startsWith(NOTHING_KNOWN_ABOUT)) { - return new CVSStatus(IStatus.ERROR, CVSStatus.DOES_NOT_EXIST, line, commandRoot); - } - } - return OK; - } - - public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - // Fields we will find in the log for a file - // keys = String (tag name), values = String (tag revision number) */ - switch (state) { - case BEGIN: - if (line.startsWith("RCS file: ")) { //$NON-NLS-1$ - // We are starting to recieve the log for a file - String fileName = getRelativeFilePath(location, line.substring(10).trim()); - if (fileName == null) { - currentFile = null; - handleInvalidFileName(location, fileName); - } else { - if (currentFile == null || !currentFile.getRepositoryRelativePath().equals(fileName)) { - // We are starting another file - beginFile(location, fileName); - } - } - } else if (line.startsWith("symbolic names:")) { //$NON-NLS-1$ - state = SYMBOLIC_NAMES; - } else if (line.startsWith("revision ")) { //$NON-NLS-1$ - revision = internAndCopyString(line.substring(9)); - state = REVISION; - } else if (line.startsWith("total revisions:")){ //$NON-NLS-1$ - //if there are no current revision selected and this is a branch then we are in the - //case where there have been no changes made on the branch since the initial branching - //and we need to get the revision that the branch was made from - int indexOfSelectedRevisions = line.lastIndexOf("selected revisions: "); //$NON-NLS-1$ - //20 for length of "selected revisions: " - String selectedRevisions = line.substring(indexOfSelectedRevisions + 20).trim(); - if (selectedRevisions.equals("0")){ //$NON-NLS-1$ - //ok put into comment state to await ======= and add info to log - state = COMMENT; - revision = BRANCH_REVISION; - comment = new StringBuffer(); - } - } - break; - case SYMBOLIC_NAMES: - if (line.startsWith("keyword substitution:")) { //$NON-NLS-1$ - state = BEGIN; - } else { - int firstColon = line.indexOf(':'); - String tagName = internAndCopyString(line.substring(1, firstColon)); - String tagRevision = internAndCopyString(line.substring(firstColon + 2)); - versions.add(new VersionInfo(tagRevision, tagName)); - } - break; - case REVISION: - // date: 2000/06/19 04:56:21; author: somebody; state: Exp; lines: +114 -45 - // get the creation date - int endOfDateIndex = line.indexOf(';', 6); - creationDate = convertFromLogTime(line.substring(6, endOfDateIndex) + " GMT"); //$NON-NLS-1$ - - // get the author name - int endOfAuthorIndex = line.indexOf(';', endOfDateIndex + 1); - author = internAndCopyString(line.substring(endOfDateIndex + 11, endOfAuthorIndex)); - - // get the file state (because this revision might be "dead") - fileState = internAndCopyString(line.substring(endOfAuthorIndex + 10, line.indexOf(';', endOfAuthorIndex + 1))); - comment = new StringBuffer(); - state = COMMENT; - break; - case COMMENT: - // skip next line (info about branches) if it exists, if not then it is a comment line. - if (line.startsWith("branches:")) break; //$NON-NLS-1$ - if (line.equals("=============================================================================") //$NON-NLS-1$ - || line.equals("----------------------------")) { //$NON-NLS-1$ - state = DONE; - break; - } - //check for null if we are in the waiting to finish case (brought on by branches) - if (comment == null) - break; - - if (comment.length() != 0) comment.append('\n'); - comment.append(line); - break; - } - if (state == DONE) { - // we are only interested in tag names for this revision, remove all others. - List thisRevisionTags = versions.isEmpty() ? Collections.EMPTY_LIST : new ArrayList(3); - //a parallel lists for revision tags (used only for branches with no commits on them) - List revisionVersions = versions.isEmpty() ? Collections.EMPTY_LIST : new ArrayList(3); - for (Iterator i = versions.iterator(); i.hasNext();) { - VersionInfo version = (VersionInfo) i.next(); - String tagName = version.getTagName(); - String tagRevision = version.getTagRevision(); - - if (tagRevision.equals(revision) || - revision.equals(BRANCH_REVISION)) { - int type = version.isBranch() ? CVSTag.BRANCH : CVSTag.VERSION; - thisRevisionTags.add(new CVSTag(tagName, type)); - if (revision.equals(BRANCH_REVISION)){ - //also record the tag revision - revisionVersions.add(tagRevision); - } - } - } - - if (currentFile != null) { - LogEntry entry = new LogEntry(currentFile, revision, author, creationDate, - internString(comment.toString()), fileState, !thisRevisionTags.isEmpty() ? (CVSTag[]) thisRevisionTags.toArray(new CVSTag[thisRevisionTags.size()]) : NO_TAGS, !revisionVersions.isEmpty() ? (String[]) revisionVersions.toArray(new String[revisionVersions.size()]) : NO_VERSIONS); - addEntry(entry); - } - state = BEGIN; - } - return OK; - } - - protected void beginFile(ICVSRepositoryLocation location, String fileName) { - currentFile = RemoteFile.create(fileName, location); - versions.clear(); - } - - protected void addEntry(LogEntry entry) { - listener.handleLogEntryReceived(entry); - } - - protected void handleInvalidFileName(ICVSRepositoryLocation location, String badFilePath) { - CVSProviderPlugin.log(IStatus.WARNING, "Invalid file path '" + badFilePath + "' received from " + location.toString(), null); //$NON-NLS-1$ //$NON-NLS-2$ - } - - /** - * Converts a time stamp as sent from a cvs server for a "log" command into a - * <code>Date</code>. - */ - private Date convertFromLogTime(String modTime) { - DateFormat format = LOG_DATE_FORMATTER; - // Compatibility for older cvs version (pre 1.12.9) - if (modTime.length() > 4 && modTime.charAt(4) == '/') - format = LOG_DATE_FORMATTER_OLD; - - try { - return format.parse(modTime); - } catch (ParseException e) { - // fallback is to return null - return null; - } - } - - private String internAndCopyString(String string) { - String internedString = (String) internedStrings.get(string); - if (internedString == null) { - internedString = new String(string); - internedStrings.put(internedString, internedString); - } - return internedString; - } - - private String internString(String string) { - String internedString = (String) internedStrings.get(string); - if (internedString == null) { - internedString = string; - internedStrings.put(internedString, internedString); - } - return internedString; - } - - private static class VersionInfo { - private final String version; - private final boolean isBranch; - private String tagRevision; - private final String tagName; - - public VersionInfo(String version, String tagName) { - this.version = version; - this.tagName = tagName; - this.isBranch = isBranchTag(version); - tagRevision = version; - if (isBranch) { - int lastDot = version.lastIndexOf('.'); - if (lastDot == -1) { - CVSProviderPlugin.log(IStatus.ERROR, - NLS.bind(CVSMessages.LogListener_invalidRevisionFormat, new String[] { tagName, version }), null); - } else { - if (version.charAt(lastDot - 1) == '0' && version.charAt(lastDot - 2) == '.') { - lastDot = lastDot - 2; - } - tagRevision = version.substring(0, lastDot); - } - } - } - - public String getVersion() { - return this.version; - } - - public String getTagName() { - return this.tagName; - } - - public String getTagRevision() { - return this.tagRevision; - } - - public boolean isBranch() { - return isBranch; - } - - /** branch tags have odd number of segments or have - * an even number with a zero as the second last segment - * e.g: 1.1.1, 1.26.0.2 are branch revision numbers */ - private boolean isBranchTag(String tagName) { - // First check if we have an odd number of segments (i.e. even number of dots) - int numberOfDots = 0; - int lastDot = 0; - for (int i = 0; i < tagName.length(); i++) { - if (tagName.charAt(i) == '.') { - numberOfDots++; - lastDot = i; - } - } - if ((numberOfDots % 2) == 0) return true; - if (numberOfDots == 1) return false; - - // If not, check if the second lat segment is a zero - if (tagName.charAt(lastDot - 1) == '0' && tagName.charAt(lastDot - 2) == '.') return true; - return false; - } - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleDefinitionsListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleDefinitionsListener.java deleted file mode 100644 index 99da58e17..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ModuleDefinitionsListener.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -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 pares the output of the "cvs checkout -c" command which returns the list of modules - * defined in the CVSROOT/modules file. - */ -public class ModuleDefinitionsListener extends CommandOutputListener { - - // the last line read from the context (used to accumulate multi-line definitions) - private String lastLine = ""; //$NON-NLS-1$ - - private Map moduleMap; - - public ModuleDefinitionsListener() { - reset(); - } - - /* - * @see ICommandOutputListener#messageLine(String, ICVSFolder, IProgressMonitor) - */ - public IStatus messageLine( - String line, - ICVSRepositoryLocation location, - ICVSFolder commandRoot, - IProgressMonitor monitor) { - - // Lines that start with a space indicate a multi line entry - if( line.charAt(0) == ' ' ) { - lastLine += line; - line = lastLine; - } - else - lastLine = line; - - // Use the module name as the key so that multi-line modules will be recorded properly - int firstSpace = line.indexOf(" "); //$NON-NLS-1$ - if (firstSpace > -1) { - String module = line.substring(0, firstSpace); - moduleMap.put(module, line); - } - return OK; - } - - public String[] getModuleExpansions() { - return (String[])moduleMap.values().toArray(new String[moduleMap.size()]); - } - - public void reset() { - this.moduleMap = new HashMap(); - } -} 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 deleted file mode 100644 index ff704aacc..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/RDiffSummaryListener.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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 deleted file mode 100644 index 7be00a490..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/ServerMessageLineMatcher.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; - -/** - * 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) { - IStatus status = new CVSStatus(IStatus.ERROR,NLS.bind(CVSMessages.ServerMessageLineMatcher_5, new String[] { template })); - throw new CVSException(status); - } - 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()) { - IStatus status = new CVSStatus(IStatus.ERROR,NLS.bind(CVSMessages.ServerMessageLineMatcher_6, new String[] { template })); - throw new CVSException(status); - } - - // 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)) { - IStatus status = new CVSStatus(IStatus.ERROR,NLS.bind(CVSMessages.ServerMessageLineMatcher_7, new String[] { expected, template })); - throw new CVSException(status); - } - } - } - - 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; - } - -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/StatusListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/StatusListener.java deleted file mode 100644 index e172f03a5..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/StatusListener.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.*; -import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; -import org.eclipse.team.internal.ccvs.core.util.Util; - -public class StatusListener extends CommandOutputListener { - private static boolean isFolder = false; - private IStatusListener statusListener; - - public StatusListener(IStatusListener statusListener) { - this.statusListener = statusListener; - } - - public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, - IProgressMonitor monitor) { - - // We're only concerned about file revisions. - if (line.startsWith(" Repository revision:")) { //$NON-NLS-1$ - if (!line.startsWith(" Repository revision: No revision control file")) { //$NON-NLS-1$ - int separatingTabIndex = line.indexOf('\t', 24); - String remoteRevision = line.substring(24, separatingTabIndex); - - // This is the full location on the server (e.g. /home/cvs/repo/project/file.txt) - String fileLocation = line.substring(separatingTabIndex + 1, line.length() - 2); - - // Inform the listener about the file revision - statusListener.fileStatus(commandRoot, removeAtticSegment(fileLocation), remoteRevision); - } - } - return OK; - } - - public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { - String serverMessage = getServerMessage(line, location); - if (serverMessage != null) { - if (serverMessage.startsWith("conflict:")) {//$NON-NLS-1$ - // We get this because we made up an entry line to send to the server - // Therefore, we make this a warning!!! - return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot); - } - if (serverMessage.startsWith("Examining")) {//$NON-NLS-1$ - isFolder = true; - return OK; - } - } - if (isFolder) { - // This used to do something but it was obviously wrong and there was no indication - // why it was needed. Therefore, I have removed the code to see if anything is effected - isFolder = false; - } - return super.errorLine(line, location, commandRoot, monitor); - } - - /** - * If the status returns that the file is in the Attic, then remove the - * Attic segment. This is because files added to a branch that are not in - * the main trunk (HEAD) are added to the Attic but cvs does magic on - * updateto put them in the correct location. - * (e.g. /project/Attic/file.txt -> /project/file.txt) - */ - private String removeAtticSegment(String path) { - return Util.removeAtticSegment(path); - } -} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/TagListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/TagListener.java deleted file mode 100644 index a2e041c98..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/TagListener.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ccvs.core.client.listeners; - - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -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; - -public class TagListener extends CommandOutputListener { - - /* - * @see ICommandOutputListener#messageLine(String, ICVSFolder, IProgressMonitor) - */ - public IStatus messageLine( - String line, - ICVSRepositoryLocation location, - ICVSFolder commandRoot, - IProgressMonitor monitor) { - - // Received a warning in the form: - // W folder/file : v1 already exists on version 1.2 : NOT MOVING tag to version 1.3 - // Indicate this as an error since no tagging was done - if(line.length() >= 2 && line.charAt(0) == 'W' && line.charAt(1) == ' ') { - return new CVSStatus(IStatus.ERROR, CVSStatus.TAG_ALREADY_EXISTS, line.substring(2), commandRoot); - } - - return OK; - } - - /* - * @see ICommandOutputListener#errorLine(String, ICVSFolder, IProgressMonitor) - */ - public IStatus errorLine( - String line, - ICVSRepositoryLocation location, - ICVSFolder commandRoot, - IProgressMonitor monitor) { - - // Ignore the lines: Tagging folder1/folder2 - String serverMessage = getServerMessage(line, location); - if ((serverMessage != null) && serverMessage.startsWith("Tagging")) { //$NON-NLS-1$ - return OK; - } - String rtagMessage = getServerRTagMessage(line, location); - if(rtagMessage != null && rtagMessage.startsWith("Tagging") ) { //$NON-NLS-1$ - 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/UpdateListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/UpdateListener.java deleted file mode 100644 index 20ec349b3..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/listeners/UpdateListener.java +++ /dev/null @@ -1,294 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-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.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.internal.ccvs.core.*; -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.ICVSFile; -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; -import org.eclipse.team.internal.ccvs.core.client.Update; -import org.eclipse.team.internal.ccvs.core.util.Util; - -public class UpdateListener extends CommandOutputListener { - - // Pattern matchers - private static ServerMessageLineMatcher MERGED_BINARY_FILE_LINE_1; - private static ServerMessageLineMatcher MERGED_BINARY_FILE_LINE_2; - - // Pattern Variables - private static final String REVISION_VARIABLE_NAME = "revision"; //$NON-NLS-1$ - private static final String LOCAL_FILE_PATH_VARIABLE_NAME = "localFilePath"; //$NON-NLS-1$ - private static final String BACKUP_FILE_VARIABLE_NAME = "backupFile"; //$NON-NLS-1$ - - static { - try { - String line1 = "revision " //$NON-NLS-1$ - + Util.getVariablePattern(IMessagePatterns.REVISION_PATTERN, REVISION_VARIABLE_NAME) - + " from repository is now in " //$NON-NLS-1$ - + Util.getVariablePattern(IMessagePatterns.FILE_PATH_PATTERN, LOCAL_FILE_PATH_VARIABLE_NAME); - MERGED_BINARY_FILE_LINE_1 = new ServerMessageLineMatcher( - line1, - new String[] {REVISION_VARIABLE_NAME, LOCAL_FILE_PATH_VARIABLE_NAME}); - String line2 = "file from working directory is now in " //$NON-NLS-1$ - + Util.getVariablePattern(IMessagePatterns.REVISION_PATTERN, BACKUP_FILE_VARIABLE_NAME); - MERGED_BINARY_FILE_LINE_2 = new ServerMessageLineMatcher( - line2, - new String[] {BACKUP_FILE_VARIABLE_NAME}); - - } catch (CVSException e) { - // Shouldn't happen - CVSProviderPlugin.log(e); - } - } - - IUpdateMessageListener updateMessageListener; - boolean merging = false; - boolean mergingBinary = false; - String mergedBinaryFileRevision, mergedBinaryFilePath; - - public UpdateListener(IUpdateMessageListener updateMessageListener) { - this.updateMessageListener = updateMessageListener; - } - - public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, - IProgressMonitor monitor) { - mergingBinary = false; - if (updateMessageListener == null) return OK; - if(line.startsWith("Merging differences")) { //$NON-NLS-1$ - merging = true; - } else if(line.indexOf(' ')==1) { - // We have a message that indicates the type of update. The possible messages are - // defined by the prefix constants MLP_*. - String path = line.substring(2); - char changeType = line.charAt(0); - - // calculate change type - int type = 0; - switch(changeType) { - case 'A': type = Update.STATE_ADDED_LOCAL; break; // new file locally that was added but not comitted to server yet - case '?': type = Update.STATE_UNKOWN; break; // new file locally but not added to server - case 'U': type = Update.STATE_REMOTE_CHANGES; break; // remote changes to an unmodified local file - case 'R': type = Update.STATE_DELETED; break; // removed locally but still exists on the server - case 'M': type = Update.STATE_MODIFIED; break; // modified locally - case 'C': type = Update.STATE_CONFLICT; break; // modified locally and on the server but cannot be auto-merged - case 'D': type = Update.STATE_DELETED; break; // deleted locally but still exists on server - default: type = Update.STATE_NONE; - } - - if (merging) { - // If we are merging the modified prefix is used both to show merges and - // local changes. We have to detect this case and use a more specific change - // type. - if (type == Update.STATE_MODIFIED) - type = Update.STATE_MERGEABLE_CONFLICT; - merging = false; - } - updateMessageListener.fileInformation(type, commandRoot, path); - } - return OK; - } - - /** - * This handler is used by the RemoteResource hierarchy to retrieve E messages - * from the CVS server in order to determine the folders contained in a parent folder. - * - * WARNING: This class parses the message output to determine the state of files in the - * repository. Unfortunately, these messages seem to be customizable on a server by server basis. - * - * Here's a list of responses we expect in various situations: - * - * Directory exists remotely: - * cvs server: Updating folder1/folder2 - * Directory doesn't exist remotely: - * cvs server: skipping directory folder1/folder2 - * New (or unknown) remote directory - * cvs server: New Directory folder1/folder2 - * File removed remotely - * cvs server: folder1/file.ext is no longer in the repository - * cvs server: warning: folder1/file.ext is not (any longer) pertinent - * Locally added file was added remotely as well - * cvs server: conflict: folder/file.ext created independently by second party - * File removed locally and modified remotely - * cvs server: conflict: removed file.txt was modified by second party - * File modified locally but removed remotely - * cvs server: conflict: file.txt is modified but no longer in the repository - * Ignored Messages - * cvs server: cannot open directory ... - * cvs server: nothing known about ... - * Tag error that really means there are no files in a directory - * cvs [server aborted]: no such tag - * Merge contained conflicts - * rcsmerge: warning: conflicts during merge - * Binary file conflict - * cvs server: nonmergeable file needs merge - * cvs server: revision 1.4 from repository is now in a1/a2/test - * cvs server: file from working directory is now in .#test.1.3 - */ - public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, - IProgressMonitor monitor) { - - try { - // Reset flag globally here because we have to many exit points - boolean wasMergingBinary = mergingBinary; - mergingBinary = false; - String serverMessage = getServerMessage(line, location); - if (serverMessage != null) { - // Strip the prefix from the line - String message = serverMessage; - if (message.startsWith("Updating")) { //$NON-NLS-1$ - if (updateMessageListener != null) { - String path = message.substring(9); - updateMessageListener.directoryInformation(commandRoot, path, false); - } - return OK; - } else if (message.startsWith("skipping directory")) { //$NON-NLS-1$ - if (updateMessageListener != null) { - String path = message.substring(18).trim(); - updateMessageListener.directoryDoesNotExist(commandRoot, path); - } - return OK; - } else if (message.startsWith("New directory")) { //$NON-NLS-1$ - if (updateMessageListener != null) { - String path = message.substring(15, message.lastIndexOf('\'')); - updateMessageListener.directoryInformation(commandRoot, path, true); - } - return OK; - } else if (message.endsWith("is no longer in the repository")) { //$NON-NLS-1$ - if (updateMessageListener != null) { - String filename = message.substring(0, message.length() - 31); - filename = stripQuotes(filename); - updateMessageListener.fileDoesNotExist(commandRoot, filename); - } - return OK; - } else if (message.startsWith("conflict:")) { //$NON-NLS-1$ - /* - * We can get the following conflict warnings - * cvs server: conflict: folder/file.ext created independently by second party - * cvs server: conflict: removed file.txt was modified by second party - * cvs server: conflict: file.txt is modified but no longer in the repository - * If we get the above line, we have conflicting additions or deletions and we can expect a server error. - * We still get "C foler/file.ext" so we don't need to do anything else (except in the remotely deleted case) - */ - if (updateMessageListener != null) { - if (message.endsWith("is modified but no longer in the repository")) { //$NON-NLS-1$ - // The "C foler/file.ext" will come after this so if whould be ignored! - String filename = message.substring(10, message.length() - 44); - filename = stripQuotes(filename); - updateMessageListener.fileDoesNotExist(commandRoot, filename); - } - } - return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot); - } else if (message.startsWith("warning:")) { //$NON-NLS-1$ - /* - * We can get the following conflict warnings - * cvs server: warning: folder1/file.ext is not (any longer) pertinent - * If we get the above line, we have local changes to a remotely deleted file. - */ - if (updateMessageListener != null) { - if (message.endsWith("is not (any longer) pertinent")) { //$NON-NLS-1$ - String filename = message.substring(9, message.length() - 30); - updateMessageListener.fileDoesNotExist(commandRoot, filename); - } - } - return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot); - } else if (message.startsWith("conflicts")) { //$NON-NLS-1$ - // This line is info only. The server doesn't report an error. - return new CVSStatus(IStatus.INFO, CVSStatus.CONFLICT, line, commandRoot); - } else if (message.startsWith("nonmergeable file needs merge")) { //$NON-NLS-1$ - mergingBinary = true; - mergedBinaryFileRevision = null; - mergedBinaryFilePath = null; - return OK; - } else if (wasMergingBinary) { - Map variables = MERGED_BINARY_FILE_LINE_1.processServerMessage(message); - if (variables != null) { - mergedBinaryFileRevision = (String)variables.get(REVISION_VARIABLE_NAME); - mergedBinaryFilePath = (String)variables.get(LOCAL_FILE_PATH_VARIABLE_NAME); - mergingBinary = true; - return OK; - } - variables = MERGED_BINARY_FILE_LINE_2.processServerMessage(message); - if (variables != null) { - String backupFile = (String)variables.get(BACKUP_FILE_VARIABLE_NAME); - try { - if (mergedBinaryFileRevision != null && mergedBinaryFilePath != null) { - ICVSFile file = commandRoot.getFile(mergedBinaryFilePath); - IResource resource = file.getIResource(); - if (resource != null) { - return new CVSStatus(IStatus.ERROR, CVSStatus.UNMEGERED_BINARY_CONFLICT, - NLS.bind(CVSMessages.UpdateListener_0, (new Object[] { - resource.getFullPath().toString(), - mergedBinaryFileRevision, - resource.getFullPath().removeLastSegments(1).append(backupFile).toString()})), commandRoot); - } - } - } catch (CVSException e1) { - CVSProviderPlugin.log(e1); - } - return OK; - } - } - - // Fallthrough case for "cvs server" messages - if (!message.startsWith("cannot open directory") //$NON-NLS-1$ - && !message.startsWith("nothing known about")) { //$NON-NLS-1$ - return super.errorLine(line, location, commandRoot, monitor); - } - } else { - String serverAbortedMessage = getServerAbortedMessage(line, location); - if (serverAbortedMessage != null) { - // Strip the prefix from the line - String message = serverAbortedMessage; - if (message.startsWith("no such tag")) { //$NON-NLS-1$ - // This is reported from CVS when a tag is used on the update there are no files in the directory - // To get the folders, the update request should be re-issued for HEAD - return new CVSStatus(IStatus.WARNING, CVSStatus.NO_SUCH_TAG, line, commandRoot); - } else if (message.startsWith("Numeric join") && message.endsWith("may not contain a date specifier")) { //$NON-NLS-1$ //$NON-NLS-2$ - // This error indicates a join failed because a date tag was used - return super.errorLine(line, location, commandRoot, monitor); - } else { - return super.errorLine(line, location, commandRoot, monitor); - } - } else if (line.equals("rcsmerge: warning: conflicts during merge")) { //$NON-NLS-1$ - // There were conflicts in the merge - return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot); - } - } - } catch (StringIndexOutOfBoundsException e) { - // Something went wrong in the parsing of the message. - // Return a status indicating the problem - if (CVSProviderPlugin.getPlugin().isDebugging()) { - System.out.println("Error parsing E line: " + line); //$NON-NLS-1$ - } - return new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE_PARSE_FAILURE, line, commandRoot); - } - return super.errorLine(line, location, commandRoot, monitor); - } - - private String stripQuotes(String filename) { - // CVS version 12 fix - filenames are returned inside quotes - // Fixes bug 49056 - if (filename.startsWith("`") && filename.endsWith("'")) //$NON-NLS-1$ //$NON-NLS-2$ - filename = filename.substring(1,filename.length()-1); - return filename; - } - -} |