View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.transport.wagon;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  
24  import org.eclipse.aether.RepositorySystemSession;
25  import org.eclipse.aether.repository.RemoteRepository;
26  import org.eclipse.aether.spi.connector.transport.Transporter;
27  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
28  import org.eclipse.aether.spi.locator.Service;
29  import org.eclipse.aether.spi.locator.ServiceLocator;
30  import org.eclipse.aether.transfer.NoTransporterException;
31  
32  import static java.util.Objects.requireNonNull;
33  
34  /**
35   * A transporter factory using <a href="http://maven.apache.org/wagon/" target="_blank">Apache Maven Wagon</a>. Note
36   * that this factory merely serves as an adapter to the Wagon API and by itself does not provide any transport services
37   * unless one or more wagon implementations are registered with the {@link WagonProvider}.
38   */
39  @Named("wagon")
40  public final class WagonTransporterFactory implements TransporterFactory, Service {
41  
42      private WagonProvider wagonProvider;
43  
44      private WagonConfigurator wagonConfigurator;
45  
46      private float priority = -1.0f;
47  
48      /**
49       * Creates an (uninitialized) instance of this transporter factory. <em>Note:</em> In case of manual instantiation
50       * by clients, the new factory needs to be configured via its various mutators before first use or runtime errors
51       * will occur.
52       */
53      @Deprecated
54      public WagonTransporterFactory() {
55          // enables default constructor
56      }
57  
58      @Inject
59      public WagonTransporterFactory(WagonProvider wagonProvider, WagonConfigurator wagonConfigurator) {
60          setWagonProvider(wagonProvider);
61          setWagonConfigurator(wagonConfigurator);
62      }
63  
64      @Override
65      public void initService(ServiceLocator locator) {
66          setWagonProvider(locator.getService(WagonProvider.class));
67          setWagonConfigurator(locator.getService(WagonConfigurator.class));
68      }
69  
70      /**
71       * Sets the wagon provider to use to acquire and release wagon instances.
72       *
73       * @param wagonProvider The wagon provider to use, may be {@code null}.
74       * @return This factory for chaining, never {@code null}.
75       */
76      public WagonTransporterFactory setWagonProvider(WagonProvider wagonProvider) {
77          this.wagonProvider = wagonProvider;
78          return this;
79      }
80  
81      /**
82       * Sets the wagon configurator to use to apply provider-specific configuration to wagon instances.
83       *
84       * @param wagonConfigurator The wagon configurator to use, may be {@code null}.
85       * @return This factory for chaining, never {@code null}.
86       */
87      public WagonTransporterFactory setWagonConfigurator(WagonConfigurator wagonConfigurator) {
88          this.wagonConfigurator = wagonConfigurator;
89          return this;
90      }
91  
92      @Override
93      public float getPriority() {
94          return priority;
95      }
96  
97      /**
98       * Sets the priority of this component.
99       *
100      * @param priority The priority.
101      * @return This component for chaining, never {@code null}.
102      */
103     public WagonTransporterFactory setPriority(float priority) {
104         this.priority = priority;
105         return this;
106     }
107 
108     @Override
109     public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
110             throws NoTransporterException {
111         requireNonNull(session, "session cannot be null");
112         requireNonNull(repository, "repository cannot be null");
113 
114         return new WagonTransporter(wagonProvider, wagonConfigurator, repository, session);
115     }
116 }