1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.minio;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23
24 import java.util.Map;
25
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.repository.RemoteRepository;
28 import org.eclipse.aether.spi.connector.transport.Transporter;
29 import org.eclipse.aether.spi.connector.transport.TransporterFactory;
30 import org.eclipse.aether.transfer.NoTransporterException;
31 import org.eclipse.aether.util.ConfigUtils;
32
33 import static java.util.Objects.requireNonNull;
34
35
36
37
38
39
40 @Named(MinioTransporterFactory.NAME)
41 public final class MinioTransporterFactory implements TransporterFactory {
42 public static final String NAME = "minio";
43
44 private static final float DEFAULT_PRIORITY = 0.0f;
45
46 private float priority = DEFAULT_PRIORITY;
47
48 private final Map<String, ObjectNameMapperFactory> objectNameMapperFactories;
49
50 @Inject
51 public MinioTransporterFactory(Map<String, ObjectNameMapperFactory> objectNameMapperFactories) {
52 this.objectNameMapperFactories = requireNonNull(objectNameMapperFactories, "objectNameMapperFactories");
53 }
54
55 @Override
56 public float getPriority() {
57 return priority;
58 }
59
60 public MinioTransporterFactory setPriority(float priority) {
61 this.priority = priority;
62 return this;
63 }
64
65 @Override
66 public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
67 throws NoTransporterException {
68 requireNonNull(session, "session cannot be null");
69 requireNonNull(repository, "repository cannot be null");
70
71
72
73 RemoteRepository adjusted = repository;
74 if ("minio+http".equalsIgnoreCase(repository.getProtocol())
75 || "minio+https".equalsIgnoreCase(repository.getProtocol())) {
76 adjusted = new RemoteRepository.Builder(repository)
77 .setUrl(repository.getUrl().substring("minio+".length()))
78 .build();
79 } else if ("s3+http".equalsIgnoreCase(repository.getProtocol())
80 || "s3+https".equalsIgnoreCase(repository.getProtocol())) {
81 adjusted = new RemoteRepository.Builder(repository)
82 .setUrl(repository.getUrl().substring("s3+".length()))
83 .build();
84 } else if (priority == DEFAULT_PRIORITY) {
85 throw new NoTransporterException(
86 repository,
87 "To use Minio transport with plain HTTP/HTTPS repositories, increase the Minio transport priority");
88 }
89 String objectNameMapperConf = ConfigUtils.getString(
90 session,
91 MinioTransporterConfigurationKeys.DEFAULT_OBJECT_NAME_MAPPER,
92 MinioTransporterConfigurationKeys.CONFIG_PROP_OBJECT_NAME_MAPPER + "." + repository.getId(),
93 MinioTransporterConfigurationKeys.CONFIG_PROP_OBJECT_NAME_MAPPER);
94 ObjectNameMapperFactory objectNameMapperFactory = objectNameMapperFactories.get(objectNameMapperConf);
95 if (objectNameMapperFactory == null) {
96 throw new IllegalArgumentException("Unknown object name mapper configured '" + objectNameMapperConf
97 + "' for repository " + repository.getId());
98 }
99 return new MinioTransporter(session, adjusted, objectNameMapperFactory);
100 }
101 }