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 java.util.Objects;
25  
26  import org.eclipse.aether.RepositorySystemSession;
27  import org.eclipse.aether.repository.RemoteRepository;
28  import org.eclipse.aether.spi.connector.transport.Transporter;
29  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
30  import org.eclipse.aether.spi.locator.Service;
31  import org.eclipse.aether.spi.locator.ServiceLocator;
32  import org.eclipse.aether.transfer.NoTransporterException;
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      public WagonTransporterFactory() {
54          // enables default constructor
55      }
56  
57      @Inject
58      WagonTransporterFactory(WagonProvider wagonProvider, WagonConfigurator wagonConfigurator) {
59          setWagonProvider(wagonProvider);
60          setWagonConfigurator(wagonConfigurator);
61      }
62  
63      @Override
64      public void initService(ServiceLocator locator) {
65          setWagonProvider(locator.getService(WagonProvider.class));
66          setWagonConfigurator(locator.getService(WagonConfigurator.class));
67      }
68  
69      /**
70       * Sets the wagon provider to use to acquire and release wagon instances.
71       *
72       * @param wagonProvider The wagon provider to use, may be {@code null}.
73       * @return This factory for chaining, never {@code null}.
74       */
75      public WagonTransporterFactory setWagonProvider(WagonProvider wagonProvider) {
76          this.wagonProvider = wagonProvider;
77          return this;
78      }
79  
80      /**
81       * Sets the wagon configurator to use to apply provider-specific configuration to wagon instances.
82       *
83       * @param wagonConfigurator The wagon configurator to use, may be {@code null}.
84       * @return This factory for chaining, never {@code null}.
85       */
86      public WagonTransporterFactory setWagonConfigurator(WagonConfigurator wagonConfigurator) {
87          this.wagonConfigurator = wagonConfigurator;
88          return this;
89      }
90  
91      @Override
92      public float getPriority() {
93          return priority;
94      }
95  
96      /**
97       * Sets the priority of this component.
98       *
99       * @param priority The priority.
100      * @return This component for chaining, never {@code null}.
101      */
102     public WagonTransporterFactory setPriority(float priority) {
103         this.priority = priority;
104         return this;
105     }
106 
107     @Override
108     public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
109             throws NoTransporterException {
110         Objects.requireNonNull(session, "session cannot be null");
111         Objects.requireNonNull(repository, "repository cannot be null");
112 
113         return new WagonTransporter(wagonProvider, wagonConfigurator, repository, session);
114     }
115 }