001package org.eclipse.aether.transport.http; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import javax.inject.Inject; 023import javax.inject.Named; 024 025import java.util.Collections; 026import java.util.HashMap; 027import java.util.Map; 028 029import org.eclipse.aether.RepositorySystemSession; 030import org.eclipse.aether.repository.RemoteRepository; 031import org.eclipse.aether.spi.connector.transport.Transporter; 032import org.eclipse.aether.spi.connector.transport.TransporterFactory; 033import org.eclipse.aether.transfer.NoTransporterException; 034 035import static java.util.Objects.requireNonNull; 036 037/** 038 * A transporter factory for repositories using the {@code http:} or {@code https:} protocol. The provided transporters 039 * support uploads to WebDAV servers and resumable downloads. 040 */ 041@Named( "http" ) 042public final class HttpTransporterFactory 043 implements TransporterFactory 044{ 045 private static Map<String, ChecksumExtractor> getManuallyCreatedExtractors() 046 { 047 HashMap<String, ChecksumExtractor> map = new HashMap<>(); 048 map.put( Nexus2ChecksumExtractor.NAME, new Nexus2ChecksumExtractor() ); 049 map.put( XChecksumChecksumExtractor.NAME, new XChecksumChecksumExtractor() ); 050 return Collections.unmodifiableMap( map ); 051 } 052 053 private float priority = 5.0f; 054 055 private final Map<String, ChecksumExtractor> extractors; 056 057 /** 058 * Ctor for ServiceLocator. 059 */ 060 @Deprecated 061 public HttpTransporterFactory() 062 { 063 this( getManuallyCreatedExtractors() ); 064 } 065 066 /** 067 * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation 068 * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors 069 * will occur. 070 */ 071 @Inject 072 public HttpTransporterFactory( Map<String, ChecksumExtractor> extractors ) 073 { 074 this.extractors = requireNonNull( extractors ); 075 } 076 077 @Override 078 public float getPriority() 079 { 080 return priority; 081 } 082 083 /** 084 * Sets the priority of this component. 085 * 086 * @param priority The priority. 087 * @return This component for chaining, never {@code null}. 088 */ 089 public HttpTransporterFactory setPriority( float priority ) 090 { 091 this.priority = priority; 092 return this; 093 } 094 095 @Override 096 public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository ) 097 throws NoTransporterException 098 { 099 requireNonNull( session, "session cannot be null" ); 100 requireNonNull( repository, "repository cannot be null" ); 101 102 return new HttpTransporter( extractors, repository, session ); 103 } 104 105}