View Javadoc
1   package org.eclipse.aether.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 javax.inject.Inject;
23  import javax.inject.Named;
24  
25  import java.util.Objects;
26  
27  import org.eclipse.aether.RepositorySystemSession;
28  import org.eclipse.aether.repository.RemoteRepository;
29  import org.eclipse.aether.spi.connector.transport.Transporter;
30  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
31  import org.eclipse.aether.spi.locator.Service;
32  import org.eclipse.aether.spi.locator.ServiceLocator;
33  import org.eclipse.aether.transfer.NoTransporterException;
34  
35  /**
36   * A transporter factory using <a href="http://maven.apache.org/wagon/" target="_blank">Apache Maven Wagon</a>. Note
37   * that this factory merely serves as an adapter to the Wagon API and by itself does not provide any transport services
38   * unless one or more wagon implementations are registered with the {@link WagonProvider}.
39   */
40  @Named( "wagon" )
41  public final class WagonTransporterFactory
42      implements TransporterFactory, Service
43  {
44  
45      private WagonProvider wagonProvider;
46  
47      private WagonConfigurator wagonConfigurator;
48  
49      private float priority = -1.0f;
50  
51      /**
52       * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
53       * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
54       * will occur.
55       */
56      public WagonTransporterFactory()
57      {
58          // enables default constructor
59      }
60  
61      @Inject
62      WagonTransporterFactory( WagonProvider wagonProvider, WagonConfigurator wagonConfigurator )
63      {
64          setWagonProvider( wagonProvider );
65          setWagonConfigurator( wagonConfigurator );
66      }
67  
68      public void initService( ServiceLocator locator )
69      {
70          setWagonProvider( locator.getService( WagonProvider.class ) );
71          setWagonConfigurator( locator.getService( WagonConfigurator.class ) );
72      }
73  
74      /**
75       * Sets the wagon provider to use to acquire and release wagon instances.
76       *
77       * @param wagonProvider The wagon provider to use, may be {@code null}.
78       * @return This factory for chaining, never {@code null}.
79       */
80      public WagonTransporterFactory setWagonProvider( WagonProvider wagonProvider )
81      {
82          this.wagonProvider = wagonProvider;
83          return this;
84      }
85  
86      /**
87       * Sets the wagon configurator to use to apply provider-specific configuration to wagon instances.
88       *
89       * @param wagonConfigurator The wagon configurator to use, may be {@code null}.
90       * @return This factory for chaining, never {@code null}.
91       */
92      public WagonTransporterFactory setWagonConfigurator( WagonConfigurator wagonConfigurator )
93      {
94          this.wagonConfigurator = wagonConfigurator;
95          return this;
96      }
97  
98      public float getPriority()
99      {
100         return priority;
101     }
102 
103     /**
104      * Sets the priority of this component.
105      *
106      * @param priority The priority.
107      * @return This component for chaining, never {@code null}.
108      */
109     public WagonTransporterFactory setPriority( float priority )
110     {
111         this.priority = priority;
112         return this;
113     }
114 
115     public Transporter newInstance( RepositorySystemSession session, RemoteRepository repository )
116         throws NoTransporterException
117     {
118         Objects.requireNonNull( "session", "session cannot be null" );
119         Objects.requireNonNull( "repository", "repository cannot be null" );
120 
121         return new WagonTransporter( wagonProvider, wagonConfigurator, repository, session );
122     }
123 
124 }