001package org.eclipse.aether.transport.wagon;
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 org.eclipse.aether.RepositorySystemSession;
026import org.eclipse.aether.repository.RemoteRepository;
027import org.eclipse.aether.spi.connector.transport.Transporter;
028import org.eclipse.aether.spi.connector.transport.TransporterFactory;
029import org.eclipse.aether.spi.locator.Service;
030import org.eclipse.aether.spi.locator.ServiceLocator;
031import org.eclipse.aether.transfer.NoTransporterException;
032
033/**
034 * A transporter factory using <a href="http://maven.apache.org/wagon/" target="_blank">Apache Maven Wagon</a>. Note
035 * that this factory merely serves as an adapter to the Wagon API and by itself does not provide any transport services
036 * unless one or more wagon implementations are registered with the {@link WagonProvider}.
037 */
038@Named( "wagon" )
039public final class WagonTransporterFactory
040    implements TransporterFactory, Service
041{
042
043    private WagonProvider wagonProvider;
044
045    private WagonConfigurator wagonConfigurator;
046
047    private float priority = -1.0f;
048
049    /**
050     * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
051     * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
052     * will occur.
053     */
054    public WagonTransporterFactory()
055    {
056        // enables default constructor
057    }
058
059    @Inject
060    WagonTransporterFactory( WagonProvider wagonProvider, WagonConfigurator wagonConfigurator )
061    {
062        setWagonProvider( wagonProvider );
063        setWagonConfigurator( wagonConfigurator );
064    }
065
066    public void initService( ServiceLocator locator )
067    {
068        setWagonProvider( locator.getService( WagonProvider.class ) );
069        setWagonConfigurator( locator.getService( WagonConfigurator.class ) );
070    }
071
072    /**
073     * Sets the wagon provider to use to acquire and release wagon instances.
074     * 
075     * @param wagonProvider The wagon provider to use, may be {@code null}.
076     * @return This factory for chaining, never {@code null}.
077     */
078    public WagonTransporterFactory setWagonProvider( WagonProvider wagonProvider )
079    {
080        this.wagonProvider = wagonProvider;
081        return this;
082    }
083
084    /**
085     * Sets the wagon configurator to use to apply provider-specific configuration to wagon instances.
086     * 
087     * @param wagonConfigurator The wagon configurator to use, may be {@code null}.
088     * @return This factory for chaining, never {@code null}.
089     */
090    public WagonTransporterFactory setWagonConfigurator( WagonConfigurator wagonConfigurator )
091    {
092        this.wagonConfigurator = wagonConfigurator;
093        return this;
094    }
095
096    public float getPriority()
097    {
098        return priority;
099    }
100
101    /**
102     * Sets the priority of this component.
103     * 
104     * @param priority The priority.
105     * @return This component for chaining, never {@code null}.
106     */
107    public WagonTransporterFactory setPriority( float priority )
108    {
109        this.priority = priority;
110        return this;
111    }
112
113    public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
114        throws NoTransporterException
115    {
116        return new WagonTransporter( wagonProvider, wagonConfigurator, repository, session );
117    }
118
119}