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.io.PathProcessor;
29  import org.eclipse.aether.transfer.NoTransporterException;
30  
31  import static java.util.Objects.requireNonNull;
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(WagonTransporterFactory.NAME)
39  public final class WagonTransporterFactory implements TransporterFactory {
40      public static final String NAME = "wagon";
41  
42      private final WagonProvider wagonProvider;
43  
44      private final WagonConfigurator wagonConfigurator;
45  
46      private final PathProcessor pathProcessor;
47  
48      private float priority = -1.0f;
49  
50      @Inject
51      public WagonTransporterFactory(
52              WagonProvider wagonProvider, WagonConfigurator wagonConfigurator, PathProcessor pathProcessor) {
53          this.wagonProvider = wagonProvider;
54          this.wagonConfigurator = wagonConfigurator;
55          this.pathProcessor = pathProcessor;
56      }
57  
58      @Override
59      public float getPriority() {
60          return priority;
61      }
62  
63      /**
64       * Sets the priority of this component.
65       *
66       * @param priority The priority.
67       * @return This component for chaining, never {@code null}.
68       */
69      public WagonTransporterFactory setPriority(float priority) {
70          this.priority = priority;
71          return this;
72      }
73  
74      @Override
75      public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
76              throws NoTransporterException {
77          requireNonNull(session, "session cannot be null");
78          requireNonNull(repository, "repository cannot be null");
79  
80          return new WagonTransporter(wagonProvider, wagonConfigurator, repository, session, pathProcessor);
81      }
82  }