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 final Map<String, ChecksumExtractor> EXTRACTORS;
046
047    static
048    {
049        HashMap<String, ChecksumExtractor> map = new HashMap<>();
050        map.put( Nexus2ChecksumExtractor.NAME, new Nexus2ChecksumExtractor() );
051        map.put( XChecksumChecksumExtractor.NAME, new XChecksumChecksumExtractor() );
052        EXTRACTORS = Collections.unmodifiableMap( map );
053    }
054
055    private float priority = 5.0f;
056
057    private final Map<String, ChecksumExtractor> extractors;
058
059    /**
060     * Ctor for ServiceLocator.
061     */
062    @Deprecated
063    public HttpTransporterFactory()
064    {
065        this( EXTRACTORS );
066    }
067
068    /**
069     * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
070     * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
071     * will occur.
072     */
073    @Inject
074    public HttpTransporterFactory( Map<String, ChecksumExtractor> extractors )
075    {
076        this.extractors = requireNonNull( extractors );
077    }
078
079    @Override
080    public float getPriority()
081    {
082        return priority;
083    }
084
085    /**
086     * Sets the priority of this component.
087     *
088     * @param priority The priority.
089     * @return This component for chaining, never {@code null}.
090     */
091    public HttpTransporterFactory setPriority( float priority )
092    {
093        this.priority = priority;
094        return this;
095    }
096
097    @Override
098    public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
099        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}