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