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 static java.util.Objects.requireNonNull; 23 24 import org.apache.maven.wagon.Wagon; 25 import org.codehaus.plexus.PlexusContainer; 26 import org.codehaus.plexus.component.annotations.Component; 27 import org.codehaus.plexus.component.annotations.Requirement; 28 import org.eclipse.aether.transport.wagon.WagonProvider; 29 30 /** 31 * A wagon provider backed by a Plexus container and the wagons registered with this container. 32 */ 33 @Component( role = WagonProvider.class, hint = "plexus" ) 34 public class PlexusWagonProvider 35 implements WagonProvider 36 { 37 38 @Requirement 39 private PlexusContainer container; 40 41 /** 42 * Creates an uninitialized wagon provider. 43 * 44 * @noreference This constructor only supports the Plexus IoC container and should not be called directly by 45 * clients. 46 */ 47 public PlexusWagonProvider() 48 { 49 // enables no-arg constructor 50 } 51 52 /** 53 * Creates a wagon provider using the specified Plexus container. 54 * 55 * @param container The Plexus container instance to use, must not be {@code null}. 56 */ 57 public PlexusWagonProvider( PlexusContainer container ) 58 { 59 this.container = requireNonNull( container, "plexus container cannot be null" ); 60 } 61 62 public Wagon lookup( String roleHint ) 63 throws Exception 64 { 65 return container.lookup( Wagon.class, roleHint ); 66 } 67 68 public void release( Wagon wagon ) 69 { 70 try 71 { 72 if ( wagon != null ) 73 { 74 container.release( wagon ); 75 } 76 } 77 catch ( Exception e ) 78 { 79 // too bad 80 } 81 } 82 83 }