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