1 package org.eclipse.aether.internal.transport.wagon; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import org.apache.maven.wagon.Wagon; 23 import org.codehaus.plexus.PlexusContainer; 24 import org.codehaus.plexus.component.annotations.Component; 25 import org.codehaus.plexus.component.annotations.Requirement; 26 import org.eclipse.aether.transport.wagon.WagonProvider; 27 28 /** 29 * A wagon provider backed by a Plexus container and the wagons registered with this container. 30 */ 31 @Component( role = WagonProvider.class, hint = "plexus" ) 32 public class PlexusWagonProvider 33 implements WagonProvider 34 { 35 36 @Requirement 37 private PlexusContainer container; 38 39 /** 40 * Creates an uninitialized wagon provider. 41 * 42 * @noreference This constructor only supports the Plexus IoC container and should not be called directly by 43 * clients. 44 */ 45 public PlexusWagonProvider() 46 { 47 // enables no-arg constructor 48 } 49 50 /** 51 * Creates a wagon provider using the specified Plexus container. 52 * 53 * @param container The Plexus container instance to use, must not be {@code null}. 54 */ 55 public PlexusWagonProvider( PlexusContainer container ) 56 { 57 if ( container == null ) 58 { 59 throw new IllegalArgumentException( "plexus container has not been specified" ); 60 } 61 this.container = container; 62 } 63 64 public Wagon lookup( String roleHint ) 65 throws Exception 66 { 67 return container.lookup( Wagon.class, roleHint ); 68 } 69 70 public void release( Wagon wagon ) 71 { 72 try 73 { 74 if ( wagon != null ) 75 { 76 container.release( wagon ); 77 } 78 } 79 catch ( Exception e ) 80 { 81 // too bad 82 } 83 } 84 85 }