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.wagon;
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.Transporter;
027import org.eclipse.aether.spi.connector.transport.TransporterFactory;
028import org.eclipse.aether.transfer.NoTransporterException;
029
030import static java.util.Objects.requireNonNull;
031
032/**
033 * A transporter factory using <a href="http://maven.apache.org/wagon/" target="_blank">Apache Maven Wagon</a>. Note
034 * that this factory merely serves as an adapter to the Wagon API and by itself does not provide any transport services
035 * unless one or more wagon implementations are registered with the {@link WagonProvider}.
036 */
037@Named(WagonTransporterFactory.NAME)
038public final class WagonTransporterFactory implements TransporterFactory {
039    public static final String NAME = "wagon";
040
041    private final WagonProvider wagonProvider;
042
043    private final WagonConfigurator wagonConfigurator;
044
045    private float priority = -1.0f;
046
047    @Inject
048    public WagonTransporterFactory(WagonProvider wagonProvider, WagonConfigurator wagonConfigurator) {
049        this.wagonProvider = wagonProvider;
050        this.wagonConfigurator = wagonConfigurator;
051    }
052
053    @Override
054    public float getPriority() {
055        return priority;
056    }
057
058    /**
059     * Sets the priority of this component.
060     *
061     * @param priority The priority.
062     * @return This component for chaining, never {@code null}.
063     */
064    public WagonTransporterFactory setPriority(float priority) {
065        this.priority = priority;
066        return this;
067    }
068
069    @Override
070    public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
071            throws NoTransporterException {
072        requireNonNull(session, "session cannot be null");
073        requireNonNull(repository, "repository cannot be null");
074
075        return new WagonTransporter(wagonProvider, wagonConfigurator, repository, session);
076    }
077}