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