KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > client > Diff


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core.client;
12
13
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.team.internal.ccvs.core.*;
17 import org.eclipse.team.internal.ccvs.core.CVSException;
18 import org.eclipse.team.internal.ccvs.core.ICVSResource;
19 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
20 import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
21
22 /**
23  * Runs the CVS diff command.
24  */

25 public class Diff extends Command {
26     /*** Local options: specific to diff ***/
27     public static final LocalOption UNIFIED_FORMAT = new LocalOption("-u"); //$NON-NLS-1$
28
public static final LocalOption CONTEXT_FORMAT = new LocalOption("-c"); //$NON-NLS-1$
29
public static final LocalOption INCLUDE_NEWFILES = new LocalOption("-N"); //$NON-NLS-1$
30
public static final LocalOption BRIEF = new LocalOption("--brief"); //$NON-NLS-1$
31

32     protected Diff() { }
33     protected String JavaDoc getRequestId() {
34         return "diff"; //$NON-NLS-1$
35
}
36     
37     /**
38      * Overwritten to throw the CVSDiffException if the server returns an error, because it just does
39      * so when there is a difference between the checked files.
40      */

41     protected IStatus doExecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions,
42                                   String JavaDoc[] arguments, ICommandOutputListener listener, IProgressMonitor monitor) throws CVSException {
43         try {
44             IStatus status = super.doExecute(session, globalOptions, localOptions, arguments, listener, monitor);
45             if (status.getCode() == CVSStatus.SERVER_ERROR) {
46                 if (status.isMultiStatus()) {
47                     IStatus[] children = status.getChildren();
48                     for (int i = 0; i < children.length; i++) {
49                         IStatus child = children[i];
50                         if (child.getMessage().indexOf("[diff aborted]") != -1) { //$NON-NLS-1$
51
throw new CVSServerException(status);
52                         }
53                     }
54                 }
55             }
56             return status;
57         } catch (CVSServerException e) {
58             if (e.containsErrors()) throw e;
59             return e.getStatus();
60         }
61     }
62
63     protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions,
64         LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor)
65         throws CVSException {
66
67         checkResourcesManaged(session, resources);
68         DiffStructureVisitor visitor = new DiffStructureVisitor(session, localOptions);
69         visitor.visit(session, resources, monitor);
70         return resources;
71     }
72     
73     protected String JavaDoc getServerErrorMessage() {
74         return CVSMessages.Diff_serverError;
75     }
76 }
77
Popular Tags