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.RepositorySystemSession;
26 import org.eclipse.aether.repository.LocalRepository;
27 import org.eclipse.aether.repository.LocalRepositoryManager;
28 import org.eclipse.aether.repository.NoLocalRepositoryManagerException;
29 import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
30 import org.eclipse.aether.util.ConfigUtils;
31
32 import static java.util.Objects.requireNonNull;
33
34
35
36
37
38
39
40
41 @Singleton
42 @Named(EnhancedLocalRepositoryManagerFactory.NAME)
43 public class EnhancedLocalRepositoryManagerFactory implements LocalRepositoryManagerFactory {
44 public static final String NAME = "enhanced";
45 private static final String CONFIG_PROP_TRACKING_FILENAME = "aether.enhancedLocalRepository.trackingFilename";
46
47 private static final String DEFAULT_TRACKING_FILENAME = "_remote.repositories";
48
49 private float priority = 10.0f;
50
51 private final LocalPathComposer localPathComposer;
52
53 private final TrackingFileManager trackingFileManager;
54
55 private final LocalPathPrefixComposerFactory localPathPrefixComposerFactory;
56
57 @Inject
58 public EnhancedLocalRepositoryManagerFactory(
59 final LocalPathComposer localPathComposer,
60 final TrackingFileManager trackingFileManager,
61 final LocalPathPrefixComposerFactory localPathPrefixComposerFactory) {
62 this.localPathComposer = requireNonNull(localPathComposer);
63 this.trackingFileManager = requireNonNull(trackingFileManager);
64 this.localPathPrefixComposerFactory = requireNonNull(localPathPrefixComposerFactory);
65 }
66
67 @Override
68 public LocalRepositoryManager newInstance(RepositorySystemSession session, LocalRepository repository)
69 throws NoLocalRepositoryManagerException {
70 requireNonNull(session, "session cannot be null");
71 requireNonNull(repository, "repository cannot be null");
72
73 String trackingFilename = ConfigUtils.getString(session, "", CONFIG_PROP_TRACKING_FILENAME);
74 if (trackingFilename.isEmpty()
75 || trackingFilename.contains("/")
76 || trackingFilename.contains("\\")
77 || trackingFilename.contains("..")) {
78 trackingFilename = DEFAULT_TRACKING_FILENAME;
79 }
80
81 if ("".equals(repository.getContentType()) || "default".equals(repository.getContentType())) {
82 return new EnhancedLocalRepositoryManager(
83 repository.getBasedir(),
84 localPathComposer,
85 trackingFilename,
86 trackingFileManager,
87 localPathPrefixComposerFactory.createComposer(session));
88 } else {
89 throw new NoLocalRepositoryManagerException(repository);
90 }
91 }
92
93 @Override
94 public float getPriority() {
95 return priority;
96 }
97
98
99
100
101
102
103
104 public EnhancedLocalRepositoryManagerFactory setPriority(float priority) {
105 this.priority = priority;
106 return this;
107 }
108 }