1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.jdk;
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.http.ChecksumExtractor;
27 import org.eclipse.aether.spi.connector.transport.http.HttpTransporter;
28 import org.eclipse.aether.spi.connector.transport.http.HttpTransporterFactory;
29 import org.eclipse.aether.spi.io.PathProcessor;
30 import org.eclipse.aether.transfer.NoTransporterException;
31
32 import static java.util.Objects.requireNonNull;
33
34
35
36
37
38
39 @Named(JdkTransporterFactory.NAME)
40 public final class JdkTransporterFactory implements HttpTransporterFactory {
41 public static final String NAME = "jdk";
42
43 private float priority = 10.0f;
44
45 private final ChecksumExtractor checksumExtractor;
46
47 private final PathProcessor pathProcessor;
48
49 @Inject
50 public JdkTransporterFactory(ChecksumExtractor checksumExtractor, PathProcessor pathProcessor) {
51 this.checksumExtractor = requireNonNull(checksumExtractor, "checksumExtractor");
52 this.pathProcessor = requireNonNull(pathProcessor, "pathProcessor");
53 }
54
55 @Override
56 public float getPriority() {
57 return priority;
58 }
59
60 public JdkTransporterFactory setPriority(float priority) {
61 this.priority = priority;
62 return this;
63 }
64
65 @Override
66 public HttpTransporter newInstance(RepositorySystemSession session, RemoteRepository repository)
67 throws NoTransporterException {
68 requireNonNull(session, "session cannot be null");
69 requireNonNull(repository, "repository cannot be null");
70
71 if (!"http".equalsIgnoreCase(repository.getProtocol()) && !"https".equalsIgnoreCase(repository.getProtocol())) {
72 throw new NoTransporterException(repository);
73 }
74
75 return new JdkTransporter(session, repository, javaVersion(), checksumExtractor, pathProcessor);
76 }
77
78 private static int javaVersion() {
79 try {
80 final String version = System.getProperty("java.version", "11" );
81 final int dot = version.indexOf('.');
82 final int hyphen = version.indexOf('-');
83 final int sep = (dot > 0 && dot < hyphen || hyphen < 0) ? dot : hyphen;
84 return Integer.parseInt(sep > 0 ? version.substring(0, sep) : version);
85 } catch (final NumberFormatException nfe) {
86 return 11;
87 }
88 }
89 }