View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.search.backend.remoterepository;
20  
21  import org.apache.maven.search.api.transport.Java11HttpClientTransport;
22  import org.apache.maven.search.api.transport.Transport;
23  import org.apache.maven.search.backend.remoterepository.extractor.MavenCentralResponseExtractor;
24  import org.apache.maven.search.backend.remoterepository.extractor.Nx2ResponseExtractor;
25  import org.apache.maven.search.backend.remoterepository.internal.RemoteRepositorySearchBackendImpl;
26  
27  /**
28   * The remote repository search backend factory.
29   */
30  public final class RemoteRepositorySearchBackendFactory {
31      public static final String BACKEND_ID = "search-rr";
32  
33      public static final String CENTRAL_REPOSITORY_ID = "central";
34  
35      public static final String CENTRAL_URI = "https://repo.maven.apache.org/maven2/";
36  
37      public static final String RAO_RELEASES_REPOSITORY_ID = "apache.releases.https";
38  
39      public static final String RAO_RELEASES_URI = "https://repository.apache.org/content/repositories/releases/";
40  
41      private RemoteRepositorySearchBackendFactory() {}
42  
43      /**
44       * Creates "default" RR search backend against Maven Central suitable for most use cases.
45       */
46      public static RemoteRepositorySearchBackend createDefaultMavenCentral() {
47          return create(
48                  BACKEND_ID,
49                  CENTRAL_REPOSITORY_ID,
50                  CENTRAL_URI,
51                  new Java11HttpClientTransport(),
52                  new MavenCentralResponseExtractor());
53      }
54  
55      /**
56       * Creates "default" RR search backend against repository.apache.org releases repository suitable for most use cases.
57       */
58      public static RemoteRepositorySearchBackend createDefaultRAOReleases() {
59          return create(
60                  BACKEND_ID,
61                  RAO_RELEASES_REPOSITORY_ID,
62                  RAO_RELEASES_URI,
63                  new Java11HttpClientTransport(),
64                  new Nx2ResponseExtractor());
65      }
66  
67      /**
68       * Creates RR search backend using provided parameters.
69       */
70      public static RemoteRepositorySearchBackend create(
71              String backendId,
72              String repositoryId,
73              String baseUri,
74              Transport transport,
75              ResponseExtractor responseExtractor) {
76          return new RemoteRepositorySearchBackendImpl(backendId, repositoryId, baseUri, transport, responseExtractor);
77      }
78  }