KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.CVSStatus;
19 import org.eclipse.team.internal.ccvs.core.CVSTag;
20 import org.eclipse.team.internal.ccvs.core.ICVSResource;
21 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
22 import org.eclipse.team.internal.ccvs.core.client.listeners.TagListener;
23
24 public class Tag extends Command {
25     /*** Local options: specific to tag ***/
26     public static final LocalOption CREATE_BRANCH = new LocalOption("-b", null); //$NON-NLS-1$
27
public static final LocalOption FORCE_REASSIGNMENT = new LocalOption("-F", null); //$NON-NLS-1$
28

29     /*** Default command output listener ***/
30     private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new TagListener();
31     
32     // handle added and removed resources in a special way
33
private boolean customBehaviorEnabled;
34     
35     protected Tag(boolean customBehaviorEnabled) {
36         this.customBehaviorEnabled = customBehaviorEnabled;
37     }
38     
39     protected Tag() {
40         this(false);
41     }
42     
43     protected String JavaDoc getRequestId() {
44         return "tag"; //$NON-NLS-1$
45
}
46
47     protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions,
48         String JavaDoc[] arguments) throws CVSException {
49             
50         if (arguments.length < 1) throw new IllegalArgumentException JavaDoc();
51         String JavaDoc[] allButFirst = new String JavaDoc[arguments.length - 1];
52         System.arraycopy(arguments, 1, allButFirst, 0, arguments.length - 1);
53         return super.computeWorkResources(session, localOptions, allButFirst);
54     }
55
56     public IStatus execute(Session session, GlobalOption[] globalOptions,
57         LocalOption[] localOptions, CVSTag tag, String JavaDoc[] arguments, ICommandOutputListener listener,
58         IProgressMonitor monitor) throws CVSException {
59         
60         if(tag.getType() != CVSTag.VERSION && tag.getType() != CVSTag.BRANCH) {
61             throw new CVSException(new CVSStatus(IStatus.ERROR, CVSMessages.Tag_notVersionOrBranchError));
62         }
63         
64         // Add the CREATE_BRANCH option for a branch tag
65
if (tag.getType() == CVSTag.BRANCH) {
66             if ( ! CREATE_BRANCH.isElementOf(localOptions)) {
67                 LocalOption[] newLocalOptions = new LocalOption[localOptions.length + 1];
68                 System.arraycopy(localOptions, 0, newLocalOptions, 0, localOptions.length);
69                 newLocalOptions[newLocalOptions.length - 1] = CREATE_BRANCH;
70                 localOptions = newLocalOptions;
71             }
72         }
73         
74         // Add the tag name to the start of the arguments
75
String JavaDoc[] newArguments = new String JavaDoc[arguments.length + 1];
76         newArguments[0] = tag.getName();
77         System.arraycopy(arguments, 0, newArguments, 1, arguments.length);
78         
79         return execute(session, globalOptions, localOptions, newArguments, listener, monitor);
80     }
81
82     public IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions,
83         CVSTag tag, ICVSResource[] arguments, ICommandOutputListener listener, IProgressMonitor monitor)
84         throws CVSException {
85         
86         String JavaDoc[] stringArguments = convertArgumentsForOpenSession(arguments, session);
87
88         return execute(session, globalOptions, localOptions, tag, stringArguments, listener, monitor);
89     }
90     
91     protected ICommandOutputListener getDefaultCommandOutputListener() {
92         return DEFAULT_OUTPUT_LISTENER;
93     }
94         
95     protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions,
96         LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor)
97         throws CVSException {
98
99         // Send all folders that are already managed to the server
100
if (customBehaviorEnabled) {
101             new TagFileSender(session, localOptions).visit(session, resources, monitor);
102         } else {
103             new FileStructureVisitor(session, localOptions, false, false).visit(session, resources, monitor);
104         }
105         return resources;
106     }
107 }
108
Popular Tags