001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.internal.transport.wagon; 020 021import javax.inject.Inject; 022import javax.inject.Named; 023import javax.inject.Singleton; 024 025import org.apache.maven.wagon.Wagon; 026import org.codehaus.plexus.PlexusContainer; 027import org.eclipse.aether.transport.wagon.WagonProvider; 028 029import static java.util.Objects.requireNonNull; 030 031/** 032 * A wagon provider backed by a Plexus container and the wagons registered with this container. 033 */ 034@Named("plexus") 035@Singleton 036public class PlexusWagonProvider implements WagonProvider { 037 private final PlexusContainer container; 038 039 /** 040 * Creates a wagon provider using the specified Plexus container. 041 * 042 * @param container The Plexus container instance to use, must not be {@code null}. 043 */ 044 @Inject 045 public PlexusWagonProvider(final PlexusContainer container) { 046 this.container = requireNonNull(container, "plexus container cannot be null"); 047 } 048 049 public Wagon lookup(String roleHint) throws Exception { 050 return container.lookup(Wagon.class, roleHint); 051 } 052 053 public void release(Wagon wagon) { 054 try { 055 if (wagon != null) { 056 container.release(wagon); 057 } 058 } catch (Exception e) { 059 // too bad 060 } 061 } 062}