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.codehaus.plexus.component.annotations.Component; 027import org.codehaus.plexus.component.annotations.Requirement; 028import org.eclipse.aether.transport.wagon.WagonProvider; 029 030/** 031 * A wagon provider backed by a Plexus container and the wagons registered with this container. 032 */ 033@Component( role = WagonProvider.class, hint = "plexus" ) 034public class PlexusWagonProvider 035 implements WagonProvider 036{ 037 038 @Requirement 039 private PlexusContainer container; 040 041 /** 042 * Creates an uninitialized wagon provider. 043 * 044 * @noreference This constructor only supports the Plexus IoC container and should not be called directly by 045 * clients. 046 */ 047 public PlexusWagonProvider() 048 { 049 // enables no-arg constructor 050 } 051 052 /** 053 * Creates a wagon provider using the specified Plexus container. 054 * 055 * @param container The Plexus container instance to use, must not be {@code null}. 056 */ 057 public PlexusWagonProvider( PlexusContainer container ) 058 { 059 this.container = requireNonNull( container, "plexus container cannot be null" ); 060 } 061 062 public Wagon lookup( String roleHint ) 063 throws Exception 064 { 065 return container.lookup( Wagon.class, roleHint ); 066 } 067 068 public void release( Wagon wagon ) 069 { 070 try 071 { 072 if ( wagon != null ) 073 { 074 container.release( wagon ); 075 } 076 } 077 catch ( Exception e ) 078 { 079 // too bad 080 } 081 } 082 083}