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