1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl;
20
21 import java.net.URI;
22 import java.net.URISyntaxException;
23
24 import org.apache.maven.api.RemoteRepository;
25 import org.apache.maven.api.Session;
26 import org.apache.maven.api.di.Inject;
27 import org.apache.maven.api.di.Named;
28 import org.apache.maven.api.di.Singleton;
29 import org.apache.maven.api.services.Transport;
30 import org.apache.maven.api.services.TransportProvider;
31 import org.apache.maven.api.services.TransportProviderException;
32 import org.eclipse.aether.spi.connector.transport.TransporterProvider;
33 import org.eclipse.aether.transfer.NoTransporterException;
34
35 import static java.util.Objects.requireNonNull;
36
37 @Named
38 @Singleton
39 public class DefaultTransportProvider implements TransportProvider {
40 private final org.eclipse.aether.spi.connector.transport.TransporterProvider transporterProvider;
41
42 @Inject
43 public DefaultTransportProvider(TransporterProvider transporterProvider) {
44 this.transporterProvider = requireNonNull(transporterProvider);
45 }
46
47 @Override
48 public Transport transport(Session session, RemoteRepository repository) {
49 try {
50 URI baseURI = new URI(repository.getUrl());
51 return new DefaultTransport(
52 baseURI,
53 transporterProvider.newTransporter(
54 InternalSession.from(session).getSession(),
55 ((DefaultRemoteRepository) repository).getRepository()));
56 } catch (URISyntaxException e) {
57 throw new TransportProviderException("Remote repository URL invalid", e);
58 } catch (NoTransporterException e) {
59 throw new TransportProviderException("Unsupported remote repository", e);
60 }
61 }
62 }