View Javadoc
1   package org.eclipse.aether.transport.http;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import javax.inject.Inject;
23  import javax.inject.Named;
24  
25  import java.util.Collections;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import org.eclipse.aether.RepositorySystemSession;
30  import org.eclipse.aether.repository.RemoteRepository;
31  import org.eclipse.aether.spi.connector.transport.Transporter;
32  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
33  import org.eclipse.aether.transfer.NoTransporterException;
34  
35  import static java.util.Objects.requireNonNull;
36  
37  /**
38   * A transporter factory for repositories using the {@code http:} or {@code https:} protocol. The provided transporters
39   * support uploads to WebDAV servers and resumable downloads.
40   */
41  @Named( "http" )
42  public final class HttpTransporterFactory
43      implements TransporterFactory
44  {
45      private static Map<String, ChecksumExtractor> getManuallyCreatedExtractors()
46      {
47          HashMap<String, ChecksumExtractor> map = new HashMap<>();
48          map.put( Nexus2ChecksumExtractor.NAME, new Nexus2ChecksumExtractor() );
49          map.put( XChecksumChecksumExtractor.NAME, new XChecksumChecksumExtractor() );
50          return Collections.unmodifiableMap( map );
51      }
52  
53      private float priority = 5.0f;
54  
55      private final Map<String, ChecksumExtractor> extractors;
56  
57      /**
58       * Ctor for ServiceLocator.
59       */
60      @Deprecated
61      public HttpTransporterFactory()
62      {
63          this( getManuallyCreatedExtractors() );
64      }
65  
66      /**
67       * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
68       * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
69       * will occur.
70       */
71      @Inject
72      public HttpTransporterFactory( Map<String, ChecksumExtractor> extractors )
73      {
74          this.extractors = requireNonNull( extractors );
75      }
76  
77      @Override
78      public float getPriority()
79      {
80          return priority;
81      }
82  
83      /**
84       * Sets the priority of this component.
85       *
86       * @param priority The priority.
87       * @return This component for chaining, never {@code null}.
88       */
89      public HttpTransporterFactory setPriority( float priority )
90      {
91          this.priority = priority;
92          return this;
93      }
94  
95      @Override
96      public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
97          throws NoTransporterException
98      {
99          requireNonNull( session, "session cannot be null" );
100         requireNonNull( repository, "repository cannot be null" );
101 
102         return new HttpTransporter( extractors, repository, session );
103     }
104 
105 }