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.transfer.NoTransporterException;
29  
30  import static java.util.Objects.requireNonNull;
31  
32  /**
33   * A transporter factory using <a href="http://maven.apache.org/wagon/" target="_blank">Apache Maven Wagon</a>. Note
34   * that this factory merely serves as an adapter to the Wagon API and by itself does not provide any transport services
35   * unless one or more wagon implementations are registered with the {@link WagonProvider}.
36   */
37  @Named(WagonTransporterFactory.NAME)
38  public final class WagonTransporterFactory implements TransporterFactory {
39      public static final String NAME = "wagon";
40  
41      private final WagonProvider wagonProvider;
42  
43      private final WagonConfigurator wagonConfigurator;
44  
45      private float priority = -1.0f;
46  
47      @Inject
48      public WagonTransporterFactory(WagonProvider wagonProvider, WagonConfigurator wagonConfigurator) {
49          this.wagonProvider = wagonProvider;
50          this.wagonConfigurator = wagonConfigurator;
51      }
52  
53      @Override
54      public float getPriority() {
55          return priority;
56      }
57  
58      /**
59       * Sets the priority of this component.
60       *
61       * @param priority The priority.
62       * @return This component for chaining, never {@code null}.
63       */
64      public WagonTransporterFactory setPriority(float priority) {
65          this.priority = priority;
66          return this;
67      }
68  
69      @Override
70      public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
71              throws NoTransporterException {
72          requireNonNull(session, "session cannot be null");
73          requireNonNull(repository, "repository cannot be null");
74  
75          return new WagonTransporter(wagonProvider, wagonConfigurator, repository, session);
76      }
77  }