RepositoryResolver.java

  1. /*
  2.  * Copyright (C) 2009-2010, Google Inc. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.transport.resolver;

  11. import org.eclipse.jgit.errors.RepositoryNotFoundException;
  12. import org.eclipse.jgit.lib.Repository;
  13. import org.eclipse.jgit.transport.ServiceMayNotContinueException;

  14. /**
  15.  * Locate a Git {@link org.eclipse.jgit.lib.Repository} by name from the URL.
  16.  *
  17.  * @param <C>
  18.  *            type of connection.
  19.  */
  20. public interface RepositoryResolver<C> {
  21.     /**
  22.      * Resolver configured to open nothing.
  23.      */
  24.     RepositoryResolver<?> NONE = (Object req, String name) -> {
  25.         throw new RepositoryNotFoundException(name);
  26.     };

  27.     /**
  28.      * Locate and open a reference to a {@link Repository}.
  29.      * <p>
  30.      * The caller is responsible for closing the returned Repository.
  31.      *
  32.      * @param req
  33.      *            the current request, may be used to inspect session state
  34.      *            including cookies or user authentication.
  35.      * @param name
  36.      *            name of the repository, as parsed out of the URL.
  37.      * @return the opened repository instance, never null.
  38.      * @throws RepositoryNotFoundException
  39.      *             the repository does not exist or the name is incorrectly
  40.      *             formatted as a repository name.
  41.      * @throws ServiceNotAuthorizedException
  42.      *             the repository may exist, but HTTP access is not allowed
  43.      *             without authentication, i.e. this corresponds to an HTTP 401
  44.      *             Unauthorized.
  45.      * @throws ServiceNotEnabledException
  46.      *             the repository may exist, but HTTP access is not allowed on the
  47.      *             target repository, for the current user.
  48.      * @throws ServiceMayNotContinueException
  49.      *             the repository may exist, but HTTP access is not allowed for
  50.      *             the current request. The exception message contains a detailed
  51.      *             message that should be shown to the user.
  52.      */
  53.     Repository open(C req, String name) throws RepositoryNotFoundException,
  54.             ServiceNotAuthorizedException, ServiceNotEnabledException,
  55.             ServiceMayNotContinueException;
  56. }