1 /******************************************************************************* 2 * Copyright (c) 2000, 2007 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.team.internal.ccvs.core.client; 15 16 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.CVSException; 21 import org.eclipse.team.internal.ccvs.core.ICVSResource; 22 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; 23 import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; 24 25 /** 26 * Runs the CVS diff command. 27 */ 28 public class Diff extends Command { 29 /*** Local options: specific to diff ***/ 30 public static final LocalOption UNIFIED_FORMAT = new LocalOption("-u"); //$NON-NLS-1$ 31 public static final LocalOption CONTEXT_FORMAT = new LocalOption("-c"); //$NON-NLS-1$ 32 public static final LocalOption INCLUDE_NEWFILES = new LocalOption("-N"); //$NON-NLS-1$ 33 public static final LocalOption BRIEF = new LocalOption("--brief"); //$NON-NLS-1$ 34 Diff()35 protected Diff() { } getRequestId()36 protected String getRequestId() { 37 return "diff"; //$NON-NLS-1$ 38 } 39 40 /** 41 * Overwritten to throw the CVSDiffException if the server returns an error, because it just does 42 * so when there is a difference between the checked files. 43 */ doExecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor)44 protected IStatus doExecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, 45 String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor) throws CVSException { 46 try { 47 IStatus status = super.doExecute(session, globalOptions, localOptions, arguments, listener, monitor); 48 if (status.getCode() == CVSStatus.SERVER_ERROR) { 49 if (status.isMultiStatus()) { 50 IStatus[] children = status.getChildren(); 51 for (IStatus child : children) { 52 if (child.getMessage().contains("[diff aborted]")) { //$NON-NLS-1$ 53 throw new CVSServerException(status); 54 } 55 } 56 } 57 } 58 return status; 59 } catch (CVSServerException e) { 60 if (e.containsErrors()) throw e; 61 return e.getStatus(); 62 } 63 } 64 sendLocalResourceState(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor)65 protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions, 66 LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) 67 throws CVSException { 68 69 checkResourcesManaged(session, resources); 70 DiffStructureVisitor visitor = new DiffStructureVisitor(session, localOptions); 71 visitor.visit(session, resources, monitor); 72 return resources; 73 } 74 getServerErrorMessage()75 protected String getServerErrorMessage() { 76 return CVSMessages.Diff_serverError; 77 } 78 } 79