/projects/eclipse_SDK-3.7.1/plugins/org.eclipse.team.cvs.core.source_3.3.400.I20110510-0800/org/eclipse/team/internal/ccvs/core/client/Add.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 97 lines · 61 code · 13 blank · 23 comment · 19 complexity · 50f80f7f503a8f888dd57b7543ab80dc MD5 · raw file

  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. import org.eclipse.core.runtime.*;
  13. import org.eclipse.osgi.util.NLS;
  14. import org.eclipse.team.internal.ccvs.core.*;
  15. import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
  16. import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
  17. import org.eclipse.team.internal.ccvs.core.syncinfo.MutableFolderSyncInfo;
  18. public class Add extends Command {
  19. /*** Local options: specific to add ***/
  20. protected Add() { }
  21. protected String getRequestId() {
  22. return "add"; //$NON-NLS-1$
  23. }
  24. protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions,
  25. LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor)
  26. throws CVSException {
  27. // Check that all the arguments can give you an
  28. // repo that you will need while traversing the
  29. // file-structure
  30. for (int i = 0; i < resources.length; i++) {
  31. Assert.isNotNull(resources[i].getRemoteLocation(session.getLocalRoot()));
  32. }
  33. // Get a vistor and use it on every resource we should
  34. // work on
  35. AddStructureVisitor visitor = new AddStructureVisitor(session, localOptions);
  36. visitor.visit(session, resources, monitor);
  37. return resources;
  38. }
  39. /**
  40. * If the add succeeded then folders have to be initialized with the
  41. * sync info
  42. */
  43. protected IStatus commandFinished(Session session, GlobalOption[] globalOptions,
  44. LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor,
  45. IStatus status) throws CVSException {
  46. if (status.getCode() == CVSStatus.SERVER_ERROR) {
  47. return status;
  48. }
  49. for (int i = 0; i < resources.length; i++) {
  50. if (resources[i].isFolder()) {
  51. ICVSFolder mFolder = (ICVSFolder) resources[i];
  52. FolderSyncInfo info = mFolder.getParent().getFolderSyncInfo();
  53. if (info == null) {
  54. status = mergeStatus(status, new CVSStatus(IStatus.ERROR, NLS.bind(CVSMessages.Add_invalidParent, new String[] { mFolder.getRelativePath(session.getLocalRoot()) })));
  55. } else {
  56. String repository = info.getRepository() + "/" + mFolder.getName(); //$NON-NLS-1$
  57. MutableFolderSyncInfo newInfo = info.cloneMutable();
  58. newInfo.setRepository(repository);
  59. mFolder.setFolderSyncInfo(newInfo);
  60. }
  61. }
  62. }
  63. return status;
  64. }
  65. /* (non-Javadoc)
  66. * @see org.eclipse.team.internal.ccvs.core.client.Command#getDefaultCommandOutputListener()
  67. */
  68. protected ICommandOutputListener getDefaultCommandOutputListener() {
  69. return new CommandOutputListener() {
  70. public IStatus errorLine(String line,
  71. ICVSRepositoryLocation location, ICVSFolder commandRoot,
  72. IProgressMonitor monitor) {
  73. String serverMessage = getServerMessage(line, location);
  74. if (serverMessage != null) {
  75. if (serverMessage.indexOf("cvs commit") != -1 && serverMessage.indexOf("add") != -1 && serverMessage.indexOf("permanently") != -1) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
  76. return OK;
  77. if (serverMessage.startsWith("scheduling file") && serverMessage.indexOf("for addition") != -1) //$NON-NLS-1$ //$NON-NLS-2$
  78. return OK;
  79. }
  80. return super.errorLine(line, location, commandRoot, monitor);
  81. }
  82. };
  83. }
  84. }