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.

Transport.java 43KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. /*
  2. * Copyright (C) 2008-2009, Google Inc.
  3. * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
  4. * Copyright (C) 2008, 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 static org.eclipse.jgit.lib.RefDatabase.ALL;
  48. import java.io.BufferedReader;
  49. import java.io.IOException;
  50. import java.io.InputStream;
  51. import java.io.InputStreamReader;
  52. import java.io.OutputStream;
  53. import java.lang.ref.WeakReference;
  54. import java.lang.reflect.Field;
  55. import java.lang.reflect.Modifier;
  56. import java.net.URISyntaxException;
  57. import java.net.URL;
  58. import java.text.MessageFormat;
  59. import java.util.ArrayList;
  60. import java.util.Collection;
  61. import java.util.Collections;
  62. import java.util.Enumeration;
  63. import java.util.HashSet;
  64. import java.util.LinkedList;
  65. import java.util.List;
  66. import java.util.Map;
  67. import java.util.Vector;
  68. import java.util.concurrent.CopyOnWriteArrayList;
  69. import org.eclipse.jgit.errors.NotSupportedException;
  70. import org.eclipse.jgit.errors.TransportException;
  71. import org.eclipse.jgit.internal.JGitText;
  72. import org.eclipse.jgit.lib.Constants;
  73. import org.eclipse.jgit.lib.NullProgressMonitor;
  74. import org.eclipse.jgit.lib.ProgressMonitor;
  75. import org.eclipse.jgit.lib.Ref;
  76. import org.eclipse.jgit.lib.Repository;
  77. import org.eclipse.jgit.storage.pack.PackConfig;
  78. /**
  79. * Connects two Git repositories together and copies objects between them.
  80. * <p>
  81. * A transport can be used for either fetching (copying objects into the
  82. * caller's repository from the remote repository) or pushing (copying objects
  83. * into the remote repository from the caller's repository). Each transport
  84. * implementation is responsible for the details associated with establishing
  85. * the network connection(s) necessary for the copy, as well as actually
  86. * shuffling data back and forth.
  87. * <p>
  88. * Transport instances and the connections they create are not thread-safe.
  89. * Callers must ensure a transport is accessed by only one thread at a time.
  90. */
  91. public abstract class Transport {
  92. /** Type of operation a Transport is being opened for. */
  93. public enum Operation {
  94. /** Transport is to fetch objects locally. */
  95. FETCH,
  96. /** Transport is to push objects remotely. */
  97. PUSH;
  98. }
  99. private static final List<WeakReference<TransportProtocol>> protocols =
  100. new CopyOnWriteArrayList<WeakReference<TransportProtocol>>();
  101. static {
  102. // Registration goes backwards in order of priority.
  103. register(TransportLocal.PROTO_LOCAL);
  104. register(TransportBundleFile.PROTO_BUNDLE);
  105. register(TransportAmazonS3.PROTO_S3);
  106. register(TransportGitAnon.PROTO_GIT);
  107. register(TransportSftp.PROTO_SFTP);
  108. register(TransportHttp.PROTO_FTP);
  109. register(TransportHttp.PROTO_HTTP);
  110. register(TransportGitSsh.PROTO_SSH);
  111. registerByService();
  112. }
  113. private static void registerByService() {
  114. ClassLoader ldr = Thread.currentThread().getContextClassLoader();
  115. if (ldr == null)
  116. ldr = Transport.class.getClassLoader();
  117. Enumeration<URL> catalogs = catalogs(ldr);
  118. while (catalogs.hasMoreElements())
  119. scan(ldr, catalogs.nextElement());
  120. }
  121. private static Enumeration<URL> catalogs(ClassLoader ldr) {
  122. try {
  123. String prefix = "META-INF/services/"; //$NON-NLS-1$
  124. String name = prefix + Transport.class.getName();
  125. return ldr.getResources(name);
  126. } catch (IOException err) {
  127. return new Vector<URL>().elements();
  128. }
  129. }
  130. private static void scan(ClassLoader ldr, URL url) {
  131. BufferedReader br;
  132. try {
  133. InputStream urlIn = url.openStream();
  134. br = new BufferedReader(new InputStreamReader(urlIn, "UTF-8")); //$NON-NLS-1$
  135. } catch (IOException err) {
  136. // If we cannot read from the service list, go to the next.
  137. //
  138. return;
  139. }
  140. try {
  141. String line;
  142. while ((line = br.readLine()) != null) {
  143. line = line.trim();
  144. if (line.length() == 0)
  145. continue;
  146. int comment = line.indexOf('#');
  147. if (comment == 0)
  148. continue;
  149. if (comment != -1)
  150. line = line.substring(0, comment).trim();
  151. load(ldr, line);
  152. }
  153. } catch (IOException err) {
  154. // If we failed during a read, ignore the error.
  155. //
  156. } finally {
  157. try {
  158. br.close();
  159. } catch (IOException e) {
  160. // Ignore the close error; we are only reading.
  161. }
  162. }
  163. }
  164. private static void load(ClassLoader ldr, String cn) {
  165. Class<?> clazz;
  166. try {
  167. clazz = Class.forName(cn, false, ldr);
  168. } catch (ClassNotFoundException notBuiltin) {
  169. // Doesn't exist, even though the service entry is present.
  170. //
  171. return;
  172. }
  173. for (Field f : clazz.getDeclaredFields()) {
  174. if ((f.getModifiers() & Modifier.STATIC) == Modifier.STATIC
  175. && TransportProtocol.class.isAssignableFrom(f.getType())) {
  176. TransportProtocol proto;
  177. try {
  178. proto = (TransportProtocol) f.get(null);
  179. } catch (IllegalArgumentException e) {
  180. // If we cannot access the field, don't.
  181. continue;
  182. } catch (IllegalAccessException e) {
  183. // If we cannot access the field, don't.
  184. continue;
  185. }
  186. if (proto != null)
  187. register(proto);
  188. }
  189. }
  190. }
  191. /**
  192. * Register a TransportProtocol instance for use during open.
  193. * <p>
  194. * Protocol definitions are held by WeakReference, allowing them to be
  195. * garbage collected when the calling application drops all strongly held
  196. * references to the TransportProtocol. Therefore applications should use a
  197. * singleton pattern as described in {@link TransportProtocol}'s class
  198. * documentation to ensure their protocol does not get disabled by garbage
  199. * collection earlier than expected.
  200. * <p>
  201. * The new protocol is registered in front of all earlier protocols, giving
  202. * it higher priority than the built-in protocol definitions.
  203. *
  204. * @param proto
  205. * the protocol definition. Must not be null.
  206. */
  207. public static void register(TransportProtocol proto) {
  208. protocols.add(0, new WeakReference<TransportProtocol>(proto));
  209. }
  210. /**
  211. * Unregister a TransportProtocol instance.
  212. * <p>
  213. * Unregistering a protocol usually isn't necessary, as protocols are held
  214. * by weak references and will automatically clear when they are garbage
  215. * collected by the JVM. Matching is handled by reference equality, so the
  216. * exact reference given to {@link #register(TransportProtocol)} must be
  217. * used.
  218. *
  219. * @param proto
  220. * the exact object previously given to register.
  221. */
  222. public static void unregister(TransportProtocol proto) {
  223. for (WeakReference<TransportProtocol> ref : protocols) {
  224. TransportProtocol refProto = ref.get();
  225. if (refProto == null || refProto == proto)
  226. protocols.remove(ref);
  227. }
  228. }
  229. /**
  230. * Obtain a copy of the registered protocols.
  231. *
  232. * @return an immutable copy of the currently registered protocols.
  233. */
  234. public static List<TransportProtocol> getTransportProtocols() {
  235. int cnt = protocols.size();
  236. List<TransportProtocol> res = new ArrayList<TransportProtocol>(cnt);
  237. for (WeakReference<TransportProtocol> ref : protocols) {
  238. TransportProtocol proto = ref.get();
  239. if (proto != null)
  240. res.add(proto);
  241. else
  242. protocols.remove(ref);
  243. }
  244. return Collections.unmodifiableList(res);
  245. }
  246. /**
  247. * Open a new transport instance to connect two repositories.
  248. * <p>
  249. * This method assumes {@link Operation#FETCH}.
  250. *
  251. * @param local
  252. * existing local repository.
  253. * @param remote
  254. * location of the remote repository - may be URI or remote
  255. * configuration name.
  256. * @return the new transport instance. Never null. In case of multiple URIs
  257. * in remote configuration, only the first is chosen.
  258. * @throws URISyntaxException
  259. * the location is not a remote defined in the configuration
  260. * file and is not a well-formed URL.
  261. * @throws NotSupportedException
  262. * the protocol specified is not supported.
  263. * @throws TransportException
  264. * the transport cannot open this URI.
  265. */
  266. public static Transport open(final Repository local, final String remote)
  267. throws NotSupportedException, URISyntaxException,
  268. TransportException {
  269. return open(local, remote, Operation.FETCH);
  270. }
  271. /**
  272. * Open a new transport instance to connect two repositories.
  273. *
  274. * @param local
  275. * existing local repository.
  276. * @param remote
  277. * location of the remote repository - may be URI or remote
  278. * configuration name.
  279. * @param op
  280. * planned use of the returned Transport; the URI may differ
  281. * based on the type of connection desired.
  282. * @return the new transport instance. Never null. In case of multiple URIs
  283. * in remote configuration, only the first is chosen.
  284. * @throws URISyntaxException
  285. * the location is not a remote defined in the configuration
  286. * file and is not a well-formed URL.
  287. * @throws NotSupportedException
  288. * the protocol specified is not supported.
  289. * @throws TransportException
  290. * the transport cannot open this URI.
  291. */
  292. public static Transport open(final Repository local, final String remote,
  293. final Operation op) throws NotSupportedException,
  294. URISyntaxException, TransportException {
  295. final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote);
  296. if (doesNotExist(cfg))
  297. return open(local, new URIish(remote), null);
  298. return open(local, cfg, op);
  299. }
  300. /**
  301. * Open new transport instances to connect two repositories.
  302. * <p>
  303. * This method assumes {@link Operation#FETCH}.
  304. *
  305. * @param local
  306. * existing local repository.
  307. * @param remote
  308. * location of the remote repository - may be URI or remote
  309. * configuration name.
  310. * @return the list of new transport instances for every URI in remote
  311. * configuration.
  312. * @throws URISyntaxException
  313. * the location is not a remote defined in the configuration
  314. * file and is not a well-formed URL.
  315. * @throws NotSupportedException
  316. * the protocol specified is not supported.
  317. * @throws TransportException
  318. * the transport cannot open this URI.
  319. */
  320. public static List<Transport> openAll(final Repository local,
  321. final String remote) throws NotSupportedException,
  322. URISyntaxException, TransportException {
  323. return openAll(local, remote, Operation.FETCH);
  324. }
  325. /**
  326. * Open new transport instances to connect two repositories.
  327. *
  328. * @param local
  329. * existing local repository.
  330. * @param remote
  331. * location of the remote repository - may be URI or remote
  332. * configuration name.
  333. * @param op
  334. * planned use of the returned Transport; the URI may differ
  335. * based on the type of connection desired.
  336. * @return the list of new transport instances for every URI in remote
  337. * configuration.
  338. * @throws URISyntaxException
  339. * the location is not a remote defined in the configuration
  340. * file and is not a well-formed URL.
  341. * @throws NotSupportedException
  342. * the protocol specified is not supported.
  343. * @throws TransportException
  344. * the transport cannot open this URI.
  345. */
  346. public static List<Transport> openAll(final Repository local,
  347. final String remote, final Operation op)
  348. throws NotSupportedException, URISyntaxException,
  349. TransportException {
  350. final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote);
  351. if (doesNotExist(cfg)) {
  352. final ArrayList<Transport> transports = new ArrayList<Transport>(1);
  353. transports.add(open(local, new URIish(remote), null));
  354. return transports;
  355. }
  356. return openAll(local, cfg, op);
  357. }
  358. /**
  359. * Open a new transport instance to connect two repositories.
  360. * <p>
  361. * This method assumes {@link Operation#FETCH}.
  362. *
  363. * @param local
  364. * existing local repository.
  365. * @param cfg
  366. * configuration describing how to connect to the remote
  367. * repository.
  368. * @return the new transport instance. Never null. In case of multiple URIs
  369. * in remote configuration, only the first is chosen.
  370. * @throws NotSupportedException
  371. * the protocol specified is not supported.
  372. * @throws TransportException
  373. * the transport cannot open this URI.
  374. * @throws IllegalArgumentException
  375. * if provided remote configuration doesn't have any URI
  376. * associated.
  377. */
  378. public static Transport open(final Repository local, final RemoteConfig cfg)
  379. throws NotSupportedException, TransportException {
  380. return open(local, cfg, Operation.FETCH);
  381. }
  382. /**
  383. * Open a new transport instance to connect two repositories.
  384. *
  385. * @param local
  386. * existing local repository.
  387. * @param cfg
  388. * configuration describing how to connect to the remote
  389. * repository.
  390. * @param op
  391. * planned use of the returned Transport; the URI may differ
  392. * based on the type of connection desired.
  393. * @return the new transport instance. Never null. In case of multiple URIs
  394. * in remote configuration, only the first is chosen.
  395. * @throws NotSupportedException
  396. * the protocol specified is not supported.
  397. * @throws TransportException
  398. * the transport cannot open this URI.
  399. * @throws IllegalArgumentException
  400. * if provided remote configuration doesn't have any URI
  401. * associated.
  402. */
  403. public static Transport open(final Repository local,
  404. final RemoteConfig cfg, final Operation op)
  405. throws NotSupportedException, TransportException {
  406. final List<URIish> uris = getURIs(cfg, op);
  407. if (uris.isEmpty())
  408. throw new IllegalArgumentException(MessageFormat.format(
  409. JGitText.get().remoteConfigHasNoURIAssociated, cfg.getName()));
  410. final Transport tn = open(local, uris.get(0), cfg.getName());
  411. tn.applyConfig(cfg);
  412. return tn;
  413. }
  414. /**
  415. * Open new transport instances to connect two repositories.
  416. * <p>
  417. * This method assumes {@link Operation#FETCH}.
  418. *
  419. * @param local
  420. * existing local repository.
  421. * @param cfg
  422. * configuration describing how to connect to the remote
  423. * repository.
  424. * @return the list of new transport instances for every URI in remote
  425. * configuration.
  426. * @throws NotSupportedException
  427. * the protocol specified is not supported.
  428. * @throws TransportException
  429. * the transport cannot open this URI.
  430. */
  431. public static List<Transport> openAll(final Repository local,
  432. final RemoteConfig cfg) throws NotSupportedException,
  433. TransportException {
  434. return openAll(local, cfg, Operation.FETCH);
  435. }
  436. /**
  437. * Open new transport instances to connect two repositories.
  438. *
  439. * @param local
  440. * existing local repository.
  441. * @param cfg
  442. * configuration describing how to connect to the remote
  443. * repository.
  444. * @param op
  445. * planned use of the returned Transport; the URI may differ
  446. * based on the type of connection desired.
  447. * @return the list of new transport instances for every URI in remote
  448. * configuration.
  449. * @throws NotSupportedException
  450. * the protocol specified is not supported.
  451. * @throws TransportException
  452. * the transport cannot open this URI.
  453. */
  454. public static List<Transport> openAll(final Repository local,
  455. final RemoteConfig cfg, final Operation op)
  456. throws NotSupportedException, TransportException {
  457. final List<URIish> uris = getURIs(cfg, op);
  458. final List<Transport> transports = new ArrayList<Transport>(uris.size());
  459. for (final URIish uri : uris) {
  460. final Transport tn = open(local, uri, cfg.getName());
  461. tn.applyConfig(cfg);
  462. transports.add(tn);
  463. }
  464. return transports;
  465. }
  466. private static List<URIish> getURIs(final RemoteConfig cfg,
  467. final Operation op) {
  468. switch (op) {
  469. case FETCH:
  470. return cfg.getURIs();
  471. case PUSH: {
  472. List<URIish> uris = cfg.getPushURIs();
  473. if (uris.isEmpty())
  474. uris = cfg.getURIs();
  475. return uris;
  476. }
  477. default:
  478. throw new IllegalArgumentException(op.toString());
  479. }
  480. }
  481. private static boolean doesNotExist(final RemoteConfig cfg) {
  482. return cfg.getURIs().isEmpty() && cfg.getPushURIs().isEmpty();
  483. }
  484. /**
  485. * Open a new transport instance to connect two repositories.
  486. *
  487. * @param local
  488. * existing local repository.
  489. * @param uri
  490. * location of the remote repository.
  491. * @return the new transport instance. Never null.
  492. * @throws NotSupportedException
  493. * the protocol specified is not supported.
  494. * @throws TransportException
  495. * the transport cannot open this URI.
  496. */
  497. public static Transport open(final Repository local, final URIish uri)
  498. throws NotSupportedException, TransportException {
  499. return open(local, uri, null);
  500. }
  501. /**
  502. * Open a new transport instance to connect two repositories.
  503. *
  504. * @param local
  505. * existing local repository.
  506. * @param uri
  507. * location of the remote repository.
  508. * @param remoteName
  509. * name of the remote, if the remote as configured in
  510. * {@code local}; otherwise null.
  511. * @return the new transport instance. Never null.
  512. * @throws NotSupportedException
  513. * the protocol specified is not supported.
  514. * @throws TransportException
  515. * the transport cannot open this URI.
  516. */
  517. public static Transport open(Repository local, URIish uri, String remoteName)
  518. throws NotSupportedException, TransportException {
  519. for (WeakReference<TransportProtocol> ref : protocols) {
  520. TransportProtocol proto = ref.get();
  521. if (proto == null) {
  522. protocols.remove(ref);
  523. continue;
  524. }
  525. if (proto.canHandle(uri, local, remoteName))
  526. return proto.open(uri, local, remoteName);
  527. }
  528. throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri));
  529. }
  530. /**
  531. * Open a new transport with no local repository.
  532. * <p>
  533. * Note that the resulting transport instance can not be used for fetching
  534. * or pushing, but only for reading remote refs.
  535. *
  536. * @param uri
  537. * @return new Transport instance
  538. * @throws NotSupportedException
  539. * @throws TransportException
  540. */
  541. public static Transport open(URIish uri) throws NotSupportedException, TransportException {
  542. for (WeakReference<TransportProtocol> ref : protocols) {
  543. TransportProtocol proto = ref.get();
  544. if (proto == null) {
  545. protocols.remove(ref);
  546. continue;
  547. }
  548. if (proto.canHandle(uri, null, null))
  549. return proto.open(uri);
  550. }
  551. throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri));
  552. }
  553. /**
  554. * Convert push remote refs update specification from {@link RefSpec} form
  555. * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching
  556. * source part to local refs. expectedOldObjectId in RemoteRefUpdate is
  557. * always set as null. Tracking branch is configured if RefSpec destination
  558. * matches source of any fetch ref spec for this transport remote
  559. * configuration.
  560. *
  561. * @param db
  562. * local database.
  563. * @param specs
  564. * collection of RefSpec to convert.
  565. * @param fetchSpecs
  566. * fetch specifications used for finding localtracking refs. May
  567. * be null or empty collection.
  568. * @return collection of set up {@link RemoteRefUpdate}.
  569. * @throws IOException
  570. * when problem occurred during conversion or specification set
  571. * up: most probably, missing objects or refs.
  572. */
  573. public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
  574. final Repository db, final Collection<RefSpec> specs,
  575. Collection<RefSpec> fetchSpecs) throws IOException {
  576. if (fetchSpecs == null)
  577. fetchSpecs = Collections.emptyList();
  578. final List<RemoteRefUpdate> result = new LinkedList<RemoteRefUpdate>();
  579. final Collection<RefSpec> procRefs = expandPushWildcardsFor(db, specs);
  580. for (final RefSpec spec : procRefs) {
  581. String srcSpec = spec.getSource();
  582. final Ref srcRef = db.getRef(srcSpec);
  583. if (srcRef != null)
  584. srcSpec = srcRef.getName();
  585. String destSpec = spec.getDestination();
  586. if (destSpec == null) {
  587. // No destination (no-colon in ref-spec), DWIMery assumes src
  588. //
  589. destSpec = srcSpec;
  590. }
  591. if (srcRef != null && !destSpec.startsWith(Constants.R_REFS)) {
  592. // Assume the same kind of ref at the destination, e.g.
  593. // "refs/heads/foo:master", DWIMery assumes master is also
  594. // under "refs/heads/".
  595. //
  596. final String n = srcRef.getName();
  597. final int kindEnd = n.indexOf('/', Constants.R_REFS.length());
  598. destSpec = n.substring(0, kindEnd + 1) + destSpec;
  599. }
  600. final boolean forceUpdate = spec.isForceUpdate();
  601. final String localName = findTrackingRefName(destSpec, fetchSpecs);
  602. final RemoteRefUpdate rru = new RemoteRefUpdate(db, srcSpec,
  603. destSpec, forceUpdate, localName, null);
  604. result.add(rru);
  605. }
  606. return result;
  607. }
  608. private static Collection<RefSpec> expandPushWildcardsFor(
  609. final Repository db, final Collection<RefSpec> specs)
  610. throws IOException {
  611. final Map<String, Ref> localRefs = db.getRefDatabase().getRefs(ALL);
  612. final Collection<RefSpec> procRefs = new HashSet<RefSpec>();
  613. for (final RefSpec spec : specs) {
  614. if (spec.isWildcard()) {
  615. for (final Ref localRef : localRefs.values()) {
  616. if (spec.matchSource(localRef))
  617. procRefs.add(spec.expandFromSource(localRef));
  618. }
  619. } else {
  620. procRefs.add(spec);
  621. }
  622. }
  623. return procRefs;
  624. }
  625. private static String findTrackingRefName(final String remoteName,
  626. final Collection<RefSpec> fetchSpecs) {
  627. // try to find matching tracking refs
  628. for (final RefSpec fetchSpec : fetchSpecs) {
  629. if (fetchSpec.matchSource(remoteName)) {
  630. if (fetchSpec.isWildcard())
  631. return fetchSpec.expandFromSource(remoteName)
  632. .getDestination();
  633. else
  634. return fetchSpec.getDestination();
  635. }
  636. }
  637. return null;
  638. }
  639. /**
  640. * Default setting for {@link #fetchThin} option.
  641. */
  642. public static final boolean DEFAULT_FETCH_THIN = true;
  643. /**
  644. * Default setting for {@link #pushThin} option.
  645. */
  646. public static final boolean DEFAULT_PUSH_THIN = false;
  647. /**
  648. * Specification for fetch or push operations, to fetch or push all tags.
  649. * Acts as --tags.
  650. */
  651. public static final RefSpec REFSPEC_TAGS = new RefSpec(
  652. "refs/tags/*:refs/tags/*"); //$NON-NLS-1$
  653. /**
  654. * Specification for push operation, to push all refs under refs/heads. Acts
  655. * as --all.
  656. */
  657. public static final RefSpec REFSPEC_PUSH_ALL = new RefSpec(
  658. "refs/heads/*:refs/heads/*"); //$NON-NLS-1$
  659. /** The repository this transport fetches into, or pushes out of. */
  660. protected final Repository local;
  661. /** The URI used to create this transport. */
  662. protected final URIish uri;
  663. /** Name of the upload pack program, if it must be executed. */
  664. private String optionUploadPack = RemoteConfig.DEFAULT_UPLOAD_PACK;
  665. /** Specifications to apply during fetch. */
  666. private List<RefSpec> fetch = Collections.emptyList();
  667. /**
  668. * How {@link #fetch(ProgressMonitor, Collection)} should handle tags.
  669. * <p>
  670. * We default to {@link TagOpt#NO_TAGS} so as to avoid fetching annotated
  671. * tags during one-shot fetches used for later merges. This prevents
  672. * dragging down tags from repositories that we do not have established
  673. * tracking branches for. If we do not track the source repository, we most
  674. * likely do not care about any tags it publishes.
  675. */
  676. private TagOpt tagopt = TagOpt.NO_TAGS;
  677. /** Should fetch request thin-pack if remote repository can produce it. */
  678. private boolean fetchThin = DEFAULT_FETCH_THIN;
  679. /** Name of the receive pack program, if it must be executed. */
  680. private String optionReceivePack = RemoteConfig.DEFAULT_RECEIVE_PACK;
  681. /** Specifications to apply during push. */
  682. private List<RefSpec> push = Collections.emptyList();
  683. /** Should push produce thin-pack when sending objects to remote repository. */
  684. private boolean pushThin = DEFAULT_PUSH_THIN;
  685. /** Should push just check for operation result, not really push. */
  686. private boolean dryRun;
  687. /** Should an incoming (fetch) transfer validate objects? */
  688. private boolean checkFetchedObjects;
  689. /** Should refs no longer on the source be pruned from the destination? */
  690. private boolean removeDeletedRefs;
  691. /** Timeout in seconds to wait before aborting an IO read or write. */
  692. private int timeout;
  693. /** Pack configuration used by this transport to make pack file. */
  694. private PackConfig packConfig;
  695. /** Assists with authentication the connection. */
  696. private CredentialsProvider credentialsProvider;
  697. /**
  698. * Create a new transport instance.
  699. *
  700. * @param local
  701. * the repository this instance will fetch into, or push out of.
  702. * This must be the repository passed to
  703. * {@link #open(Repository, URIish)}.
  704. * @param uri
  705. * the URI used to access the remote repository. This must be the
  706. * URI passed to {@link #open(Repository, URIish)}.
  707. */
  708. protected Transport(final Repository local, final URIish uri) {
  709. final TransferConfig tc = local.getConfig().get(TransferConfig.KEY);
  710. this.local = local;
  711. this.uri = uri;
  712. this.checkFetchedObjects = tc.isFsckObjects();
  713. this.credentialsProvider = CredentialsProvider.getDefault();
  714. }
  715. /**
  716. * Create a minimal transport instance not tied to a single repository.
  717. *
  718. * @param uri
  719. */
  720. protected Transport(final URIish uri) {
  721. this.uri = uri;
  722. this.local = null;
  723. this.checkFetchedObjects = true;
  724. this.credentialsProvider = CredentialsProvider.getDefault();
  725. }
  726. /**
  727. * Get the URI this transport connects to.
  728. * <p>
  729. * Each transport instance connects to at most one URI at any point in time.
  730. *
  731. * @return the URI describing the location of the remote repository.
  732. */
  733. public URIish getURI() {
  734. return uri;
  735. }
  736. /**
  737. * Get the name of the remote executable providing upload-pack service.
  738. *
  739. * @return typically "git-upload-pack".
  740. */
  741. public String getOptionUploadPack() {
  742. return optionUploadPack;
  743. }
  744. /**
  745. * Set the name of the remote executable providing upload-pack services.
  746. *
  747. * @param where
  748. * name of the executable.
  749. */
  750. public void setOptionUploadPack(final String where) {
  751. if (where != null && where.length() > 0)
  752. optionUploadPack = where;
  753. else
  754. optionUploadPack = RemoteConfig.DEFAULT_UPLOAD_PACK;
  755. }
  756. /**
  757. * Get the description of how annotated tags should be treated during fetch.
  758. *
  759. * @return option indicating the behavior of annotated tags in fetch.
  760. */
  761. public TagOpt getTagOpt() {
  762. return tagopt;
  763. }
  764. /**
  765. * Set the description of how annotated tags should be treated on fetch.
  766. *
  767. * @param option
  768. * method to use when handling annotated tags.
  769. */
  770. public void setTagOpt(final TagOpt option) {
  771. tagopt = option != null ? option : TagOpt.AUTO_FOLLOW;
  772. }
  773. /**
  774. * Default setting is: {@link #DEFAULT_FETCH_THIN}
  775. *
  776. * @return true if fetch should request thin-pack when possible; false
  777. * otherwise
  778. * @see PackTransport
  779. */
  780. public boolean isFetchThin() {
  781. return fetchThin;
  782. }
  783. /**
  784. * Set the thin-pack preference for fetch operation. Default setting is:
  785. * {@link #DEFAULT_FETCH_THIN}
  786. *
  787. * @param fetchThin
  788. * true when fetch should request thin-pack when possible; false
  789. * when it shouldn't
  790. * @see PackTransport
  791. */
  792. public void setFetchThin(final boolean fetchThin) {
  793. this.fetchThin = fetchThin;
  794. }
  795. /**
  796. * @return true if fetch will verify received objects are formatted
  797. * correctly. Validating objects requires more CPU time on the
  798. * client side of the connection.
  799. */
  800. public boolean isCheckFetchedObjects() {
  801. return checkFetchedObjects;
  802. }
  803. /**
  804. * @param check
  805. * true to enable checking received objects; false to assume all
  806. * received objects are valid.
  807. */
  808. public void setCheckFetchedObjects(final boolean check) {
  809. checkFetchedObjects = check;
  810. }
  811. /**
  812. * Default setting is: {@link RemoteConfig#DEFAULT_RECEIVE_PACK}
  813. *
  814. * @return remote executable providing receive-pack service for pack
  815. * transports.
  816. * @see PackTransport
  817. */
  818. public String getOptionReceivePack() {
  819. return optionReceivePack;
  820. }
  821. /**
  822. * Set remote executable providing receive-pack service for pack transports.
  823. * Default setting is: {@link RemoteConfig#DEFAULT_RECEIVE_PACK}
  824. *
  825. * @param optionReceivePack
  826. * remote executable, if null or empty default one is set;
  827. */
  828. public void setOptionReceivePack(String optionReceivePack) {
  829. if (optionReceivePack != null && optionReceivePack.length() > 0)
  830. this.optionReceivePack = optionReceivePack;
  831. else
  832. this.optionReceivePack = RemoteConfig.DEFAULT_RECEIVE_PACK;
  833. }
  834. /**
  835. * Default setting is: {@value #DEFAULT_PUSH_THIN}
  836. *
  837. * @return true if push should produce thin-pack in pack transports
  838. * @see PackTransport
  839. */
  840. public boolean isPushThin() {
  841. return pushThin;
  842. }
  843. /**
  844. * Set thin-pack preference for push operation. Default setting is:
  845. * {@value #DEFAULT_PUSH_THIN}
  846. *
  847. * @param pushThin
  848. * true when push should produce thin-pack in pack transports;
  849. * false when it shouldn't
  850. * @see PackTransport
  851. */
  852. public void setPushThin(final boolean pushThin) {
  853. this.pushThin = pushThin;
  854. }
  855. /**
  856. * @return true if destination refs should be removed if they no longer
  857. * exist at the source repository.
  858. */
  859. public boolean isRemoveDeletedRefs() {
  860. return removeDeletedRefs;
  861. }
  862. /**
  863. * Set whether or not to remove refs which no longer exist in the source.
  864. * <p>
  865. * If true, refs at the destination repository (local for fetch, remote for
  866. * push) are deleted if they no longer exist on the source side (remote for
  867. * fetch, local for push).
  868. * <p>
  869. * False by default, as this may cause data to become unreachable, and
  870. * eventually be deleted on the next GC.
  871. *
  872. * @param remove true to remove refs that no longer exist.
  873. */
  874. public void setRemoveDeletedRefs(final boolean remove) {
  875. removeDeletedRefs = remove;
  876. }
  877. /**
  878. * Apply provided remote configuration on this transport.
  879. *
  880. * @param cfg
  881. * configuration to apply on this transport.
  882. */
  883. public void applyConfig(final RemoteConfig cfg) {
  884. setOptionUploadPack(cfg.getUploadPack());
  885. setOptionReceivePack(cfg.getReceivePack());
  886. setTagOpt(cfg.getTagOpt());
  887. fetch = cfg.getFetchRefSpecs();
  888. push = cfg.getPushRefSpecs();
  889. timeout = cfg.getTimeout();
  890. }
  891. /**
  892. * @return true if push operation should just check for possible result and
  893. * not really update remote refs, false otherwise - when push should
  894. * act normally.
  895. */
  896. public boolean isDryRun() {
  897. return dryRun;
  898. }
  899. /**
  900. * Set dry run option for push operation.
  901. *
  902. * @param dryRun
  903. * true if push operation should just check for possible result
  904. * and not really update remote refs, false otherwise - when push
  905. * should act normally.
  906. */
  907. public void setDryRun(final boolean dryRun) {
  908. this.dryRun = dryRun;
  909. }
  910. /** @return timeout (in seconds) before aborting an IO operation. */
  911. public int getTimeout() {
  912. return timeout;
  913. }
  914. /**
  915. * Set the timeout before willing to abort an IO call.
  916. *
  917. * @param seconds
  918. * number of seconds to wait (with no data transfer occurring)
  919. * before aborting an IO read or write operation with this
  920. * remote.
  921. */
  922. public void setTimeout(final int seconds) {
  923. timeout = seconds;
  924. }
  925. /**
  926. * Get the configuration used by the pack generator to make packs.
  927. *
  928. * If {@link #setPackConfig(PackConfig)} was previously given null a new
  929. * PackConfig is created on demand by this method using the source
  930. * repository's settings.
  931. *
  932. * @return the pack configuration. Never null.
  933. */
  934. public PackConfig getPackConfig() {
  935. if (packConfig == null)
  936. packConfig = new PackConfig(local);
  937. return packConfig;
  938. }
  939. /**
  940. * Set the configuration used by the pack generator.
  941. *
  942. * @param pc
  943. * configuration controlling packing parameters. If null the
  944. * source repository's settings will be used.
  945. */
  946. public void setPackConfig(PackConfig pc) {
  947. packConfig = pc;
  948. }
  949. /**
  950. * A credentials provider to assist with authentication connections..
  951. *
  952. * @param credentialsProvider
  953. * the credentials provider, or null if there is none
  954. */
  955. public void setCredentialsProvider(CredentialsProvider credentialsProvider) {
  956. this.credentialsProvider = credentialsProvider;
  957. }
  958. /**
  959. * The configured credentials provider.
  960. *
  961. * @return the credentials provider, or null if no credentials provider is
  962. * associated with this transport.
  963. */
  964. public CredentialsProvider getCredentialsProvider() {
  965. return credentialsProvider;
  966. }
  967. /**
  968. * Fetch objects and refs from the remote repository to the local one.
  969. * <p>
  970. * This is a utility function providing standard fetch behavior. Local
  971. * tracking refs associated with the remote repository are automatically
  972. * updated if this transport was created from a {@link RemoteConfig} with
  973. * fetch RefSpecs defined.
  974. *
  975. * @param monitor
  976. * progress monitor to inform the user about our processing
  977. * activity. Must not be null. Use {@link NullProgressMonitor} if
  978. * progress updates are not interesting or necessary.
  979. * @param toFetch
  980. * specification of refs to fetch locally. May be null or the
  981. * empty collection to use the specifications from the
  982. * RemoteConfig. Source for each RefSpec can't be null.
  983. * @return information describing the tracking refs updated.
  984. * @throws NotSupportedException
  985. * this transport implementation does not support fetching
  986. * objects.
  987. * @throws TransportException
  988. * the remote connection could not be established or object
  989. * copying (if necessary) failed or update specification was
  990. * incorrect.
  991. */
  992. public FetchResult fetch(final ProgressMonitor monitor,
  993. Collection<RefSpec> toFetch) throws NotSupportedException,
  994. TransportException {
  995. if (toFetch == null || toFetch.isEmpty()) {
  996. // If the caller did not ask for anything use the defaults.
  997. //
  998. if (fetch.isEmpty())
  999. throw new TransportException(JGitText.get().nothingToFetch);
  1000. toFetch = fetch;
  1001. } else if (!fetch.isEmpty()) {
  1002. // If the caller asked for something specific without giving
  1003. // us the local tracking branch see if we can update any of
  1004. // the local tracking branches without incurring additional
  1005. // object transfer overheads.
  1006. //
  1007. final Collection<RefSpec> tmp = new ArrayList<RefSpec>(toFetch);
  1008. for (final RefSpec requested : toFetch) {
  1009. final String reqSrc = requested.getSource();
  1010. for (final RefSpec configured : fetch) {
  1011. final String cfgSrc = configured.getSource();
  1012. final String cfgDst = configured.getDestination();
  1013. if (cfgSrc.equals(reqSrc) && cfgDst != null) {
  1014. tmp.add(configured);
  1015. break;
  1016. }
  1017. }
  1018. }
  1019. toFetch = tmp;
  1020. }
  1021. final FetchResult result = new FetchResult();
  1022. new FetchProcess(this, toFetch).execute(monitor, result);
  1023. return result;
  1024. }
  1025. /**
  1026. * Push objects and refs from the local repository to the remote one.
  1027. * <p>
  1028. * This is a utility function providing standard push behavior. It updates
  1029. * remote refs and send there necessary objects according to remote ref
  1030. * update specification. After successful remote ref update, associated
  1031. * locally stored tracking branch is updated if set up accordingly. Detailed
  1032. * operation result is provided after execution.
  1033. * <p>
  1034. * For setting up remote ref update specification from ref spec, see helper
  1035. * method {@link #findRemoteRefUpdatesFor(Collection)}, predefined refspecs
  1036. * ({@link #REFSPEC_TAGS}, {@link #REFSPEC_PUSH_ALL}) or consider using
  1037. * directly {@link RemoteRefUpdate} for more possibilities.
  1038. * <p>
  1039. * When {@link #isDryRun()} is true, result of this operation is just
  1040. * estimation of real operation result, no real action is performed.
  1041. *
  1042. * @see RemoteRefUpdate
  1043. *
  1044. * @param monitor
  1045. * progress monitor to inform the user about our processing
  1046. * activity. Must not be null. Use {@link NullProgressMonitor} if
  1047. * progress updates are not interesting or necessary.
  1048. * @param toPush
  1049. * specification of refs to push. May be null or the empty
  1050. * collection to use the specifications from the RemoteConfig
  1051. * converted by {@link #findRemoteRefUpdatesFor(Collection)}. No
  1052. * more than 1 RemoteRefUpdate with the same remoteName is
  1053. * allowed. These objects are modified during this call.
  1054. * @param out
  1055. * output stream to write messages to
  1056. * @return information about results of remote refs updates, tracking refs
  1057. * updates and refs advertised by remote repository.
  1058. * @throws NotSupportedException
  1059. * this transport implementation does not support pushing
  1060. * objects.
  1061. * @throws TransportException
  1062. * the remote connection could not be established or object
  1063. * copying (if necessary) failed at I/O or protocol level or
  1064. * update specification was incorrect.
  1065. * @since 3.0
  1066. */
  1067. public PushResult push(final ProgressMonitor monitor,
  1068. Collection<RemoteRefUpdate> toPush, OutputStream out)
  1069. throws NotSupportedException,
  1070. TransportException {
  1071. if (toPush == null || toPush.isEmpty()) {
  1072. // If the caller did not ask for anything use the defaults.
  1073. try {
  1074. toPush = findRemoteRefUpdatesFor(push);
  1075. } catch (final IOException e) {
  1076. throw new TransportException(MessageFormat.format(
  1077. JGitText.get().problemWithResolvingPushRefSpecsLocally, e.getMessage()), e);
  1078. }
  1079. if (toPush.isEmpty())
  1080. throw new TransportException(JGitText.get().nothingToPush);
  1081. }
  1082. final PushProcess pushProcess = new PushProcess(this, toPush, out);
  1083. return pushProcess.execute(monitor);
  1084. }
  1085. /**
  1086. * Push objects and refs from the local repository to the remote one.
  1087. * <p>
  1088. * This is a utility function providing standard push behavior. It updates
  1089. * remote refs and sends necessary objects according to remote ref update
  1090. * specification. After successful remote ref update, associated locally
  1091. * stored tracking branch is updated if set up accordingly. Detailed
  1092. * operation result is provided after execution.
  1093. * <p>
  1094. * For setting up remote ref update specification from ref spec, see helper
  1095. * method {@link #findRemoteRefUpdatesFor(Collection)}, predefined refspecs
  1096. * ({@link #REFSPEC_TAGS}, {@link #REFSPEC_PUSH_ALL}) or consider using
  1097. * directly {@link RemoteRefUpdate} for more possibilities.
  1098. * <p>
  1099. * When {@link #isDryRun()} is true, result of this operation is just
  1100. * estimation of real operation result, no real action is performed.
  1101. *
  1102. * @see RemoteRefUpdate
  1103. *
  1104. * @param monitor
  1105. * progress monitor to inform the user about our processing
  1106. * activity. Must not be null. Use {@link NullProgressMonitor} if
  1107. * progress updates are not interesting or necessary.
  1108. * @param toPush
  1109. * specification of refs to push. May be null or the empty
  1110. * collection to use the specifications from the RemoteConfig
  1111. * converted by {@link #findRemoteRefUpdatesFor(Collection)}. No
  1112. * more than 1 RemoteRefUpdate with the same remoteName is
  1113. * allowed. These objects are modified during this call.
  1114. *
  1115. * @return information about results of remote refs updates, tracking refs
  1116. * updates and refs advertised by remote repository.
  1117. * @throws NotSupportedException
  1118. * this transport implementation does not support pushing
  1119. * objects.
  1120. * @throws TransportException
  1121. * the remote connection could not be established or object
  1122. * copying (if necessary) failed at I/O or protocol level or
  1123. * update specification was incorrect.
  1124. */
  1125. public PushResult push(final ProgressMonitor monitor,
  1126. Collection<RemoteRefUpdate> toPush) throws NotSupportedException,
  1127. TransportException {
  1128. return push(monitor, toPush, null);
  1129. }
  1130. /**
  1131. * Convert push remote refs update specification from {@link RefSpec} form
  1132. * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching
  1133. * source part to local refs. expectedOldObjectId in RemoteRefUpdate is
  1134. * always set as null. Tracking branch is configured if RefSpec destination
  1135. * matches source of any fetch ref spec for this transport remote
  1136. * configuration.
  1137. * <p>
  1138. * Conversion is performed for context of this transport (database, fetch
  1139. * specifications).
  1140. *
  1141. * @param specs
  1142. * collection of RefSpec to convert.
  1143. * @return collection of set up {@link RemoteRefUpdate}.
  1144. * @throws IOException
  1145. * when problem occurred during conversion or specification set
  1146. * up: most probably, missing objects or refs.
  1147. */
  1148. public Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
  1149. final Collection<RefSpec> specs) throws IOException {
  1150. return findRemoteRefUpdatesFor(local, specs, fetch);
  1151. }
  1152. /**
  1153. * Begins a new connection for fetching from the remote repository.
  1154. * <p>
  1155. * If the transport has no local repository, the fetch connection can only
  1156. * be used for reading remote refs.
  1157. *
  1158. * @return a fresh connection to fetch from the remote repository.
  1159. * @throws NotSupportedException
  1160. * the implementation does not support fetching.
  1161. * @throws TransportException
  1162. * the remote connection could not be established.
  1163. */
  1164. public abstract FetchConnection openFetch() throws NotSupportedException,
  1165. TransportException;
  1166. /**
  1167. * Begins a new connection for pushing into the remote repository.
  1168. *
  1169. * @return a fresh connection to push into the remote repository.
  1170. * @throws NotSupportedException
  1171. * the implementation does not support pushing.
  1172. * @throws TransportException
  1173. * the remote connection could not be established
  1174. */
  1175. public abstract PushConnection openPush() throws NotSupportedException,
  1176. TransportException;
  1177. /**
  1178. * Close any resources used by this transport.
  1179. * <p>
  1180. * If the remote repository is contacted by a network socket this method
  1181. * must close that network socket, disconnecting the two peers. If the
  1182. * remote repository is actually local (same system) this method must close
  1183. * any open file handles used to read the "remote" repository.
  1184. */
  1185. public abstract void close();
  1186. }