You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OperationResult.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (C) 2010, Google Inc.
  3. * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
  4. * Copyright (C) 2007-2009, Robin Rosenberg <robin.rosenberg@dewire.com>
  5. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  6. * and other copyright owners as documented in the project's IP log.
  7. *
  8. * This program and the accompanying materials are made available
  9. * under the terms of the Eclipse Distribution License v1.0 which
  10. * accompanies this distribution, is reproduced below, and is
  11. * available at http://www.eclipse.org/org/documents/edl-v10.php
  12. *
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or
  16. * without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * - Neither the name of the Eclipse Foundation, Inc. nor the
  28. * names of its contributors may be used to endorse or promote
  29. * products derived from this software without specific prior
  30. * written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  35. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  37. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  44. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. package org.eclipse.jgit.transport;
  47. import java.util.Collection;
  48. import java.util.Collections;
  49. import java.util.Map;
  50. import java.util.SortedMap;
  51. import java.util.TreeMap;
  52. import org.eclipse.jgit.lib.Ref;
  53. /**
  54. * Class holding result of operation on remote repository. This includes refs
  55. * advertised by remote repo and local tracking refs updates.
  56. */
  57. public abstract class OperationResult {
  58. Map<String, Ref> advertisedRefs = Collections.emptyMap();
  59. URIish uri;
  60. final SortedMap<String, TrackingRefUpdate> updates = new TreeMap<String, TrackingRefUpdate>();
  61. StringBuilder messageBuffer;
  62. /**
  63. * Get the URI this result came from.
  64. * <p>
  65. * Each transport instance connects to at most one URI at any point in time.
  66. *
  67. * @return the URI describing the location of the remote repository.
  68. */
  69. public URIish getURI() {
  70. return uri;
  71. }
  72. /**
  73. * Get the complete list of refs advertised by the remote.
  74. * <p>
  75. * The returned refs may appear in any order. If the caller needs these to
  76. * be sorted, they should be copied into a new array or List and then sorted
  77. * by the caller as necessary.
  78. *
  79. * @return available/advertised refs. Never null. Not modifiable. The
  80. * collection can be empty if the remote side has no refs (it is an
  81. * empty/newly created repository).
  82. */
  83. public Collection<Ref> getAdvertisedRefs() {
  84. return Collections.unmodifiableCollection(advertisedRefs.values());
  85. }
  86. /**
  87. * Get a single advertised ref by name.
  88. * <p>
  89. * The name supplied should be valid ref name. To get a peeled value for a
  90. * ref (aka <code>refs/tags/v1.0^{}</code>) use the base name (without
  91. * the <code>^{}</code> suffix) and look at the peeled object id.
  92. *
  93. * @param name
  94. * name of the ref to obtain.
  95. * @return the requested ref; null if the remote did not advertise this ref.
  96. */
  97. public final Ref getAdvertisedRef(final String name) {
  98. return advertisedRefs.get(name);
  99. }
  100. /**
  101. * Get the status of all local tracking refs that were updated.
  102. *
  103. * @return unmodifiable collection of local updates. Never null. Empty if
  104. * there were no local tracking refs updated.
  105. */
  106. public Collection<TrackingRefUpdate> getTrackingRefUpdates() {
  107. return Collections.unmodifiableCollection(updates.values());
  108. }
  109. /**
  110. * Get the status for a specific local tracking ref update.
  111. *
  112. * @param localName
  113. * name of the local ref (e.g. "refs/remotes/origin/master").
  114. * @return status of the local ref; null if this local ref was not touched
  115. * during this operation.
  116. */
  117. public TrackingRefUpdate getTrackingRefUpdate(final String localName) {
  118. return updates.get(localName);
  119. }
  120. void setAdvertisedRefs(final URIish u, final Map<String, Ref> ar) {
  121. uri = u;
  122. advertisedRefs = ar;
  123. }
  124. void add(final TrackingRefUpdate u) {
  125. updates.put(u.getLocalName(), u);
  126. }
  127. /**
  128. * Get the additional messages, if any, returned by the remote process.
  129. * <p>
  130. * These messages are most likely informational or error messages, sent by
  131. * the remote peer, to help the end-user correct any problems that may have
  132. * prevented the operation from completing successfully. Application UIs
  133. * should try to show these in an appropriate context.
  134. *
  135. * @return the messages returned by the remote, most likely terminated by a
  136. * newline (LF) character. The empty string is returned if the
  137. * remote produced no additional messages.
  138. */
  139. public String getMessages() {
  140. return messageBuffer != null ? messageBuffer.toString() : ""; //$NON-NLS-1$
  141. }
  142. void addMessages(final String msg) {
  143. if (msg != null && msg.length() > 0) {
  144. if (messageBuffer == null)
  145. messageBuffer = new StringBuilder();
  146. messageBuffer.append(msg);
  147. if (!msg.endsWith("\n")) //$NON-NLS-1$
  148. messageBuffer.append('\n');
  149. }
  150. }
  151. }