KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.team.internal.ccvs.core.*;
17 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
18 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
19 import org.eclipse.team.internal.ccvs.core.syncinfo.MutableFolderSyncInfo;
20
21 public class Add extends Command {
22     /*** Local options: specific to add ***/
23
24     protected Add() { }
25     protected String JavaDoc getRequestId() {
26         return "add"; //$NON-NLS-1$
27
}
28     
29     protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions,
30         LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor)
31         throws CVSException {
32
33         // Check that all the arguments can give you an
34
// repo that you will need while traversing the
35
// file-structure
36
for (int i = 0; i < resources.length; i++) {
37             Assert.isNotNull(resources[i].getRemoteLocation(session.getLocalRoot()));
38         }
39         
40         // Get a vistor and use it on every resource we should
41
// work on
42
AddStructureVisitor visitor = new AddStructureVisitor(session, localOptions);
43         visitor.visit(session, resources, monitor);
44         return resources;
45     }
46     
47     /**
48      * If the add succeeded then folders have to be initialized with the
49      * sync info
50      */

51     protected IStatus commandFinished(Session session, GlobalOption[] globalOptions,
52         LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor,
53         IStatus status) throws CVSException {
54         
55         if (status.getCode() == CVSStatus.SERVER_ERROR) {
56             return status;
57         }
58                 
59         for (int i = 0; i < resources.length; i++) {
60             if (resources[i].isFolder()) {
61                 ICVSFolder mFolder = (ICVSFolder) resources[i];
62                 FolderSyncInfo info = mFolder.getParent().getFolderSyncInfo();
63                 if (info == null) {
64                     status = mergeStatus(status, new CVSStatus(IStatus.ERROR, NLS.bind(CVSMessages.Add_invalidParent, new String JavaDoc[] { mFolder.getRelativePath(session.getLocalRoot()) })));
65                 } else {
66                     String JavaDoc repository = info.getRepository() + "/" + mFolder.getName(); //$NON-NLS-1$
67
MutableFolderSyncInfo newInfo = info.cloneMutable();
68                     newInfo.setRepository(repository);
69                     mFolder.setFolderSyncInfo(newInfo);
70                 }
71             }
72         }
73         return status;
74     }
75     
76     /* (non-Javadoc)
77      * @see org.eclipse.team.internal.ccvs.core.client.Command#getDefaultCommandOutputListener()
78      */

79     protected ICommandOutputListener getDefaultCommandOutputListener() {
80         return new CommandOutputListener() {
81             public IStatus errorLine(String JavaDoc line,
82                     ICVSRepositoryLocation location, ICVSFolder commandRoot,
83                     IProgressMonitor monitor) {
84                 
85                 String JavaDoc serverMessage = getServerMessage(line, location);
86                 if (serverMessage != null) {
87                     if (serverMessage.indexOf("cvs commit") != -1 && serverMessage.indexOf("add") != -1 && serverMessage.indexOf("permanently") != -1) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
88
return OK;
89                     if (serverMessage.startsWith("scheduling file") && serverMessage.indexOf("for addition") != -1) //$NON-NLS-1$ //$NON-NLS-2$
90
return OK;
91                 }
92                 return super.errorLine(line, location, commandRoot, monitor);
93             }
94         };
95     }
96
97 }
98
Popular Tags