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 final Map<String, ChecksumExtractor> EXTRACTORS;
46  
47      static
48      {
49          HashMap<String, ChecksumExtractor> map = new HashMap<>();
50          map.put( Nexus2ChecksumExtractor.NAME, new Nexus2ChecksumExtractor() );
51          map.put( XChecksumChecksumExtractor.NAME, new XChecksumChecksumExtractor() );
52          EXTRACTORS = Collections.unmodifiableMap( map );
53      }
54  
55      private float priority = 5.0f;
56  
57      private final Map<String, ChecksumExtractor> extractors;
58  
59      /**
60       * Ctor for ServiceLocator.
61       */
62      @Deprecated
63      public HttpTransporterFactory()
64      {
65          this( EXTRACTORS );
66      }
67  
68      /**
69       * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
70       * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
71       * will occur.
72       */
73      @Inject
74      public HttpTransporterFactory( Map<String, ChecksumExtractor> extractors )
75      {
76          this.extractors = requireNonNull( extractors );
77      }
78  
79      @Override
80      public float getPriority()
81      {
82          return priority;
83      }
84  
85      /**
86       * Sets the priority of this component.
87       *
88       * @param priority The priority.
89       * @return This component for chaining, never {@code null}.
90       */
91      public HttpTransporterFactory setPriority( float priority )
92      {
93          this.priority = priority;
94          return this;
95      }
96  
97      @Override
98      public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
99          throws NoTransporterException
100     {
101         requireNonNull( session, "session cannot be null" );
102         requireNonNull( repository, "repository cannot be null" );
103 
104         return new HttpTransporter( extractors, repository, session );
105     }
106 
107 }