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.backend.remoterepository.extractor.MavenCentralResponseExtractor;
22  import org.apache.maven.search.backend.remoterepository.extractor.Nx2ResponseExtractor;
23  import org.apache.maven.search.backend.remoterepository.internal.Java11HttpClientRemoteRepositorySearchTransport;
24  import org.apache.maven.search.backend.remoterepository.internal.RemoteRepositorySearchBackendImpl;
25  
26  /**
27   * The remote repository search backend factory.
28   */
29  public class RemoteRepositorySearchBackendFactory {
30      public static final String BACKEND_ID = "search-rr";
31  
32      public static final String CENTRAL_REPOSITORY_ID = "central";
33  
34      public static final String CENTRAL_URI = "https://repo.maven.apache.org/maven2/";
35  
36      public static final String RAO_RELEASES_REPOSITORY_ID = "apache.releases.https";
37  
38      public static final String RAO_RELEASES_URI = "https://repository.apache.org/content/repositories/releases/";
39  
40      /**
41       * Creates "default" RR search backend against Maven Central suitable for most use cases.
42       */
43      public static RemoteRepositorySearchBackend createDefaultMavenCentral() {
44          return create(
45                  BACKEND_ID,
46                  CENTRAL_REPOSITORY_ID,
47                  CENTRAL_URI,
48                  new Java11HttpClientRemoteRepositorySearchTransport(),
49                  new MavenCentralResponseExtractor());
50      }
51  
52      /**
53       * Creates "default" RR search backend against repository.apache.org releases repository suitable for most use cases.
54       */
55      public static RemoteRepositorySearchBackend createDefaultRAOReleases() {
56          return create(
57                  BACKEND_ID,
58                  RAO_RELEASES_REPOSITORY_ID,
59                  RAO_RELEASES_URI,
60                  new Java11HttpClientRemoteRepositorySearchTransport(),
61                  new Nx2ResponseExtractor());
62      }
63  
64      /**
65       * Creates RR search backend using provided parameters.
66       */
67      public static RemoteRepositorySearchBackend create(
68              String backendId,
69              String repositoryId,
70              String baseUri,
71              RemoteRepositorySearchTransport transport,
72              ResponseExtractor responseExtractor) {
73          return new RemoteRepositorySearchBackendImpl(backendId, repositoryId, baseUri, transport, responseExtractor);
74      }
75  }