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.eclipse.aether.transport.http;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  
24  import java.util.Collections;
25  import java.util.HashMap;
26  import java.util.Map;
27  
28  import org.eclipse.aether.RepositorySystemSession;
29  import org.eclipse.aether.repository.RemoteRepository;
30  import org.eclipse.aether.spi.connector.transport.Transporter;
31  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
32  import org.eclipse.aether.transfer.NoTransporterException;
33  
34  import static java.util.Objects.requireNonNull;
35  
36  /**
37   * A transporter factory for repositories using the {@code http:} or {@code https:} protocol. The provided transporters
38   * support uploads to WebDAV servers and resumable downloads.
39   */
40  @Named(HttpTransporterFactory.NAME)
41  public final class HttpTransporterFactory implements TransporterFactory {
42      public static final String NAME = "http";
43  
44      private static Map<String, ChecksumExtractor> getManuallyCreatedExtractors() {
45          HashMap<String, ChecksumExtractor> map = new HashMap<>();
46          map.put(Nexus2ChecksumExtractor.NAME, new Nexus2ChecksumExtractor());
47          map.put(XChecksumChecksumExtractor.NAME, new XChecksumChecksumExtractor());
48          return Collections.unmodifiableMap(map);
49      }
50  
51      private float priority = 5.0f;
52  
53      private final Map<String, ChecksumExtractor> extractors;
54  
55      /**
56       * Ctor for ServiceLocator.
57       */
58      @Deprecated
59      public HttpTransporterFactory() {
60          this(getManuallyCreatedExtractors());
61      }
62  
63      /**
64       * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
65       * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
66       * will occur.
67       */
68      @Inject
69      public HttpTransporterFactory(Map<String, ChecksumExtractor> extractors) {
70          this.extractors = requireNonNull(extractors);
71      }
72  
73      @Override
74      public float getPriority() {
75          return priority;
76      }
77  
78      /**
79       * Sets the priority of this component.
80       *
81       * @param priority The priority.
82       * @return This component for chaining, never {@code null}.
83       */
84      public HttpTransporterFactory setPriority(float priority) {
85          this.priority = priority;
86          return this;
87      }
88  
89      @Override
90      public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
91              throws NoTransporterException {
92          requireNonNull(session, "session cannot be null");
93          requireNonNull(repository, "repository cannot be null");
94  
95          return new HttpTransporter(extractors, repository, session);
96      }
97  }