1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 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 30 public static final LocalOption CREATE_BRANCH = Tag.CREATE_BRANCH; 31 public static final LocalOption CLEAR_FROM_REMOVED = new LocalOption("-a", null); public static final LocalOption FORCE_REASSIGNMENT = new LocalOption("-F", null); public static final LocalOption FORCE_BRANCH_REASSIGNMENT = new LocalOption("-B", null); 35 36 private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new TagListener(); 37 38 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()); case CVSTag.DATE: 50 return new LocalOption("-D", tag.getName()); default: 52 throw new IllegalArgumentException (); 54 } 55 } 56 57 protected String getRequestId() { 58 return "rtag"; } 60 61 protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, 62 String [] arguments) throws CVSException { 63 if (arguments.length < 2) throw new IllegalArgumentException (); 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 [] 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 List modifiedLocalOptions = new ArrayList (localOptions.length + 1); 77 if (sourceTag==null) sourceTag = CVSTag.DEFAULT; 78 modifiedLocalOptions.addAll(Arrays.asList(localOptions)); 79 modifiedLocalOptions.add(makeTagOption(sourceTag)); 80 81 if (tag.getType() == CVSTag.BRANCH) { 83 if ( ! CREATE_BRANCH.isElementOf(localOptions)) { 84 modifiedLocalOptions.add(CREATE_BRANCH); 85 } 86 } 87 88 String [] newArguments = new String [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 [] 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 |