View Javadoc
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  
11  package org.eclipse.jgit.transport.resolver;
12  
13  import org.eclipse.jgit.errors.RepositoryNotFoundException;
14  import org.eclipse.jgit.lib.Repository;
15  import org.eclipse.jgit.transport.ServiceMayNotContinueException;
16  
17  /**
18   * Locate a Git {@link org.eclipse.jgit.lib.Repository} by name from the URL.
19   *
20   * @param <C>
21   *            type of connection.
22   */
23  public interface RepositoryResolver<C> {
24  	/**
25  	 * Resolver configured to open nothing.
26  	 */
27  	RepositoryResolver<?> NONE = (Object req, String name) -> {
28  		throw new RepositoryNotFoundException(name);
29  	};
30  
31  	/**
32  	 * Locate and open a reference to a {@link Repository}.
33  	 * <p>
34  	 * The caller is responsible for closing the returned Repository.
35  	 *
36  	 * @param req
37  	 *            the current request, may be used to inspect session state
38  	 *            including cookies or user authentication.
39  	 * @param name
40  	 *            name of the repository, as parsed out of the URL.
41  	 * @return the opened repository instance, never null.
42  	 * @throws RepositoryNotFoundException
43  	 *             the repository does not exist or the name is incorrectly
44  	 *             formatted as a repository name.
45  	 * @throws ServiceNotAuthorizedException
46  	 *             the repository may exist, but HTTP access is not allowed
47  	 *             without authentication, i.e. this corresponds to an HTTP 401
48  	 *             Unauthorized.
49  	 * @throws ServiceNotEnabledException
50  	 *             the repository may exist, but HTTP access is not allowed on the
51  	 *             target repository, for the current user.
52  	 * @throws ServiceMayNotContinueException
53  	 *             the repository may exist, but HTTP access is not allowed for
54  	 *             the current request. The exception message contains a detailed
55  	 *             message that should be shown to the user.
56  	 */
57  	Repository open(C req, String name) throws RepositoryNotFoundException,
58  			ServiceNotAuthorizedException, ServiceNotEnabledException,
59  			ServiceMayNotContinueException;
60  }