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