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