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