001package org.eclipse.aether.internal.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 static java.util.Objects.requireNonNull; 023 024import org.apache.maven.wagon.Wagon; 025import org.codehaus.plexus.PlexusContainer; 026import org.eclipse.aether.transport.wagon.WagonProvider; 027 028import javax.inject.Inject; 029import javax.inject.Named; 030import javax.inject.Singleton; 031 032/** 033 * A wagon provider backed by a Plexus container and the wagons registered with this container. 034 */ 035@Named( "plexus" ) 036@Singleton 037public class PlexusWagonProvider 038 implements WagonProvider 039{ 040 private final PlexusContainer container; 041 042 /** 043 * Creates a wagon provider using the specified Plexus container. 044 * 045 * @param container The Plexus container instance to use, must not be {@code null}. 046 */ 047 @Inject 048 public PlexusWagonProvider( final PlexusContainer container ) 049 { 050 this.container = requireNonNull( container, "plexus container cannot be null" ); 051 } 052 053 public Wagon lookup( String roleHint ) 054 throws Exception 055 { 056 return container.lookup( Wagon.class, roleHint ); 057 } 058 059 public void release( Wagon wagon ) 060 { 061 try 062 { 063 if ( wagon != null ) 064 { 065 container.release( wagon ); 066 } 067 } 068 catch ( Exception e ) 069 { 070 // too bad 071 } 072 } 073 074}