View Javadoc
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.eclipse.aether.transport.wagon.WagonProvider;
27  
28  import javax.inject.Inject;
29  import javax.inject.Named;
30  import javax.inject.Singleton;
31  
32  /**
33   * A wagon provider backed by a Plexus container and the wagons registered with this container.
34   */
35  @Named( "plexus" )
36  @Singleton
37  public class PlexusWagonProvider
38      implements WagonProvider
39  {
40      private final PlexusContainer container;
41  
42      /**
43       * Creates a wagon provider using the specified Plexus container.
44       *
45       * @param container The Plexus container instance to use, must not be {@code null}.
46       */
47      @Inject
48      public PlexusWagonProvider( final PlexusContainer container )
49      {
50          this.container = requireNonNull( container, "plexus container cannot be null" );
51      }
52  
53      public Wagon lookup( String roleHint )
54          throws Exception
55      {
56          return container.lookup( Wagon.class, roleHint );
57      }
58  
59      public void release( Wagon wagon )
60      {
61          try
62          {
63              if ( wagon != null )
64              {
65                  container.release( wagon );
66              }
67          }
68          catch ( Exception e )
69          {
70              // too bad
71          }
72      }
73  
74  }