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.apache;
020
021import javax.inject.Inject;
022import javax.inject.Named;
023
024import org.eclipse.aether.RepositorySystemSession;
025import org.eclipse.aether.repository.RemoteRepository;
026import org.eclipse.aether.spi.connector.transport.http.ChecksumExtractor;
027import org.eclipse.aether.spi.connector.transport.http.HttpTransporter;
028import org.eclipse.aether.spi.connector.transport.http.HttpTransporterFactory;
029import org.eclipse.aether.transfer.NoTransporterException;
030
031import static java.util.Objects.requireNonNull;
032
033/**
034 * A transporter factory for repositories using the {@code http:} or {@code https:} protocol. The provided transporters
035 * support uploads to WebDAV servers and resumable downloads.
036 */
037@Named(ApacheTransporterFactory.NAME)
038public final class ApacheTransporterFactory implements HttpTransporterFactory {
039    public static final String NAME = "apache";
040
041    private float priority = 5.0f;
042
043    private final ChecksumExtractor checksumExtractor;
044
045    @Inject
046    public ApacheTransporterFactory(ChecksumExtractor checksumExtractor) {
047        this.checksumExtractor = requireNonNull(checksumExtractor, "checksumExtractor");
048    }
049
050    @Override
051    public float getPriority() {
052        return priority;
053    }
054
055    /**
056     * Sets the priority of this component.
057     *
058     * @param priority The priority.
059     * @return This component for chaining, never {@code null}.
060     */
061    public ApacheTransporterFactory setPriority(float priority) {
062        this.priority = priority;
063        return this;
064    }
065
066    @Override
067    public HttpTransporter newInstance(RepositorySystemSession session, RemoteRepository repository)
068            throws NoTransporterException {
069        requireNonNull(session, "session cannot be null");
070        requireNonNull(repository, "repository cannot be null");
071
072        return new ApacheTransporter(repository, session, checksumExtractor);
073    }
074}