KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 import java.util.ArrayList JavaDoc;
14 import java.util.Arrays JavaDoc;
15 import java.util.List JavaDoc;
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.CVSStatus;
22 import org.eclipse.team.internal.ccvs.core.CVSTag;
23 import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
24 import org.eclipse.team.internal.ccvs.core.ICVSResource;
25 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
26 import org.eclipse.team.internal.ccvs.core.client.listeners.TagListener;
27
28 public class RTag extends RemoteCommand {
29     /*** Local options: specific to tag ***/
30     public static final LocalOption CREATE_BRANCH = Tag.CREATE_BRANCH;
31     public static final LocalOption CLEAR_FROM_REMOVED = new LocalOption("-a", null); //$NON-NLS-1$
32
public static final LocalOption FORCE_REASSIGNMENT = new LocalOption("-F", null); //$NON-NLS-1$
33
public static final LocalOption FORCE_BRANCH_REASSIGNMENT = new LocalOption("-B", null); //$NON-NLS-1$
34

35     /*** Default command output listener ***/
36     private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new TagListener();
37     
38     /**
39      * Makes a -r or -D option for a tag.
40      * Valid for: checkout export history rdiff update
41      */

42     public static LocalOption makeTagOption(CVSTag tag) {
43         int type = tag.getType();
44         switch (type) {
45             case CVSTag.BRANCH:
46             case CVSTag.VERSION:
47             case CVSTag.HEAD:
48                 return new LocalOption("-r", tag.getName()); //$NON-NLS-1$
49
case CVSTag.DATE:
50                 return new LocalOption("-D", tag.getName()); //$NON-NLS-1$
51
default:
52                 // Unknow tag type!!!
53
throw new IllegalArgumentException JavaDoc();
54         }
55     }
56     
57     protected String JavaDoc getRequestId() {
58         return "rtag"; //$NON-NLS-1$
59
}
60
61     protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions,
62         String JavaDoc[] arguments) throws CVSException {
63         if (arguments.length < 2) throw new IllegalArgumentException JavaDoc();
64         return super.computeWorkResources(session, localOptions, arguments);
65     }
66     
67     public IStatus execute(Session session, GlobalOption[] globalOptions,
68         LocalOption[] localOptions, CVSTag sourceTag, CVSTag tag, String JavaDoc[] arguments,
69         IProgressMonitor monitor) throws CVSException {
70         
71         if(tag.getType() != CVSTag.VERSION && tag.getType() != CVSTag.BRANCH) {
72             throw new CVSException(new CVSStatus(IStatus.ERROR, CVSMessages.Tag_notVersionOrBranchError));
73         }
74         
75         // Add the source tag to the local options
76
List JavaDoc modifiedLocalOptions = new ArrayList JavaDoc(localOptions.length + 1);
77         if (sourceTag==null) sourceTag = CVSTag.DEFAULT;
78         modifiedLocalOptions.addAll(Arrays.asList(localOptions));
79         modifiedLocalOptions.add(makeTagOption(sourceTag));
80         
81         // Add the CREATE_BRANCH option for a branch tag
82
if (tag.getType() == CVSTag.BRANCH) {
83             if ( ! CREATE_BRANCH.isElementOf(localOptions)) {
84                 modifiedLocalOptions.add(CREATE_BRANCH);
85             }
86         }
87         
88         // Add the tag name to the start of the arguments
89
String JavaDoc[] newArguments = new String JavaDoc[arguments.length + 1];
90         newArguments[0] = tag.getName();
91         System.arraycopy(arguments, 0, newArguments, 1, arguments.length);
92         
93         return execute(session, globalOptions,
94             (LocalOption[]) modifiedLocalOptions.toArray(new LocalOption[modifiedLocalOptions.size()]),
95             newArguments, null, monitor);
96     }
97     
98     public IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions,
99         CVSTag sourceTag, CVSTag tag, ICVSRemoteResource[] arguments, IProgressMonitor monitor)
100         throws CVSException {
101         
102         String JavaDoc[] stringArguments = convertArgumentsForOpenSession(arguments, session);
103
104         return execute(session, globalOptions, localOptions, sourceTag, tag, stringArguments, monitor);
105     }
106     
107     protected ICommandOutputListener getDefaultCommandOutputListener() {
108         return DEFAULT_OUTPUT_LISTENER;
109     }
110 }
111
Popular Tags