1. /*
  2. * Copyright 2000-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. /*
  18. * Portions of this software are based upon public domain software
  19. * originally written at the National Center for Supercomputing Applications,
  20. * University of Illinois, Urbana-Champaign.
  21. */
  22. package org.apache.tools.ant.taskdefs.optional.perforce;
  23. import org.apache.tools.ant.BuildException;
  24. /**
  25. * Open file(s) for edit.
  26. * P4Change should be used to obtain a new changelist for P4Edit as,
  27. * although P4Edit can open files to the default change,
  28. * P4Submit cannot yet submit to it.
  29. * Example Usage:<br>
  30. * <p4edit change="${p4.change}" view="//depot/project/foo.txt" />
  31. *
  32. *
  33. * @todo Should call reopen if file is already open in one of our changelists perhaps?
  34. *
  35. * @ant.task category="scm"
  36. */
  37. public class P4Edit extends P4Base {
  38. /**
  39. * number of the change list to work on
  40. */
  41. public String change = null;
  42. /**
  43. * An existing changelist number to assign files to; optional
  44. * but strongly recommended.
  45. * @param change the change list number
  46. */
  47. public void setChange(String change) {
  48. this.change = change;
  49. }
  50. /**
  51. * Run the p4 edit command
  52. * @throws BuildException if there is no view specified
  53. */
  54. public void execute() throws BuildException {
  55. if (change != null) {
  56. P4CmdOpts = "-c " + change;
  57. }
  58. if (P4View == null) {
  59. throw new BuildException("No view specified to edit");
  60. }
  61. execP4Command("-s edit " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this));
  62. }
  63. }