1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import org.eclipse.aether.ConfigurationProperties;
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.repository.LocalRepository;
28 import org.eclipse.aether.repository.LocalRepositoryManager;
29 import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
30 import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
31 import org.eclipse.aether.util.ConfigUtils;
32
33 import static java.util.Objects.requireNonNull;
34
35
36
37
38
39
40
41
42 @Singleton
43 @Named(EnhancedLocalRepositoryManagerFactory.NAME)
44 public class EnhancedLocalRepositoryManagerFactory implements LocalRepositoryManagerFactory {
45 public static final String NAME = "enhanced";
46
47 static final String CONFIG_PROPS_PREFIX = ConfigurationProperties.PREFIX_LRM + NAME + ".";
48
49
50
51
52
53
54
55
56 public static final String CONFIG_PROP_TRACKING_FILENAME = CONFIG_PROPS_PREFIX + "trackingFilename";
57
58 public static final String DEFAULT_TRACKING_FILENAME = "_remote.repositories";
59
60 private float priority = 10.0f;
61
62 private final LocalPathComposer localPathComposer;
63
64 private final TrackingFileManager trackingFileManager;
65
66 private final LocalPathPrefixComposerFactory localPathPrefixComposerFactory;
67
68 @Inject
69 public EnhancedLocalRepositoryManagerFactory(
70 final LocalPathComposer localPathComposer,
71 final TrackingFileManager trackingFileManager,
72 final LocalPathPrefixComposerFactory localPathPrefixComposerFactory) {
73 this.localPathComposer = requireNonNull(localPathComposer);
74 this.trackingFileManager = requireNonNull(trackingFileManager);
75 this.localPathPrefixComposerFactory = requireNonNull(localPathPrefixComposerFactory);
76 }
77
78 @Override
79 public LocalRepositoryManager newInstance(RepositorySystemSession session, LocalRepository repository)
80 throws NoLocalRepositoryManagerException {
81 requireNonNull(session, "session cannot be null");
82 requireNonNull(repository, "repository cannot be null");
83
84 String trackingFilename = ConfigUtils.getString(session, "", CONFIG_PROP_TRACKING_FILENAME);
85 if (trackingFilename.isEmpty()
86 || trackingFilename.contains("/")
87 || trackingFilename.contains("\\")
88 || trackingFilename.contains("..")) {
89 trackingFilename = DEFAULT_TRACKING_FILENAME;
90 }
91
92 if ("".equals(repository.getContentType()) || "default".equals(repository.getContentType())) {
93 return new EnhancedLocalRepositoryManager(
94 repository.getBasedir(),
95 localPathComposer,
96 trackingFilename,
97 trackingFileManager,
98 localPathPrefixComposerFactory.createComposer(session));
99 } else {
100 throw new NoLocalRepositoryManagerException(repository);
101 }
102 }
103
104 @Override
105 public float getPriority() {
106 return priority;
107 }
108
109
110
111
112
113
114
115 public EnhancedLocalRepositoryManagerFactory setPriority(float priority) {
116 this.priority = priority;
117 return this;
118 }
119 }