1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.impl.guice;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.Map;
28 import java.util.Set;
29
30 import com.google.inject.AbstractModule;
31 import com.google.inject.Provides;
32 import com.google.inject.name.Names;
33 import org.eclipse.aether.RepositoryListener;
34 import org.eclipse.aether.RepositorySystem;
35 import org.eclipse.aether.impl.ArtifactResolver;
36 import org.eclipse.aether.impl.DependencyCollector;
37 import org.eclipse.aether.impl.Deployer;
38 import org.eclipse.aether.impl.Installer;
39 import org.eclipse.aether.impl.LocalRepositoryProvider;
40 import org.eclipse.aether.impl.MetadataResolver;
41 import org.eclipse.aether.impl.OfflineController;
42 import org.eclipse.aether.impl.RemoteRepositoryFilterManager;
43 import org.eclipse.aether.impl.RemoteRepositoryManager;
44 import org.eclipse.aether.impl.RepositoryConnectorProvider;
45 import org.eclipse.aether.impl.RepositoryEventDispatcher;
46 import org.eclipse.aether.impl.RepositorySystemLifecycle;
47 import org.eclipse.aether.impl.UpdateCheckManager;
48 import org.eclipse.aether.impl.UpdatePolicyAnalyzer;
49 import org.eclipse.aether.internal.impl.DefaultArtifactResolver;
50 import org.eclipse.aether.internal.impl.DefaultChecksumPolicyProvider;
51 import org.eclipse.aether.internal.impl.DefaultDeployer;
52 import org.eclipse.aether.internal.impl.DefaultFileProcessor;
53 import org.eclipse.aether.internal.impl.DefaultInstaller;
54 import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
55 import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory;
56 import org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider;
57 import org.eclipse.aether.internal.impl.DefaultMetadataResolver;
58 import org.eclipse.aether.internal.impl.DefaultOfflineController;
59 import org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager;
60 import org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider;
61 import org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher;
62 import org.eclipse.aether.internal.impl.DefaultRepositoryLayoutProvider;
63 import org.eclipse.aether.internal.impl.DefaultRepositorySystem;
64 import org.eclipse.aether.internal.impl.DefaultRepositorySystemLifecycle;
65 import org.eclipse.aether.internal.impl.DefaultTrackingFileManager;
66 import org.eclipse.aether.internal.impl.DefaultTransporterProvider;
67 import org.eclipse.aether.internal.impl.DefaultUpdateCheckManager;
68 import org.eclipse.aether.internal.impl.DefaultUpdatePolicyAnalyzer;
69 import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory;
70 import org.eclipse.aether.internal.impl.LocalPathComposer;
71 import org.eclipse.aether.internal.impl.LocalPathPrefixComposerFactory;
72 import org.eclipse.aether.internal.impl.Maven2RepositoryLayoutFactory;
73 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
74 import org.eclipse.aether.internal.impl.TrackingFileManager;
75 import org.eclipse.aether.internal.impl.checksum.DefaultChecksumAlgorithmFactorySelector;
76 import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory;
77 import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory;
78 import org.eclipse.aether.internal.impl.checksum.Sha256ChecksumAlgorithmFactory;
79 import org.eclipse.aether.internal.impl.checksum.Sha512ChecksumAlgorithmFactory;
80 import org.eclipse.aether.internal.impl.checksum.SparseDirectoryTrustedChecksumsSource;
81 import org.eclipse.aether.internal.impl.checksum.SummaryFileTrustedChecksumsSource;
82 import org.eclipse.aether.internal.impl.checksum.TrustedToProvidedChecksumsSourceAdapter;
83 import org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector;
84 import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegate;
85 import org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector;
86 import org.eclipse.aether.internal.impl.collect.df.DfDependencyCollector;
87 import org.eclipse.aether.internal.impl.filter.DefaultRemoteRepositoryFilterManager;
88 import org.eclipse.aether.internal.impl.filter.GroupIdRemoteRepositoryFilterSource;
89 import org.eclipse.aether.internal.impl.filter.PrefixesRemoteRepositoryFilterSource;
90 import org.eclipse.aether.internal.impl.resolution.TrustedChecksumsArtifactResolverPostProcessor;
91 import org.eclipse.aether.internal.impl.slf4j.Slf4jLoggerFactory;
92 import org.eclipse.aether.internal.impl.synccontext.DefaultSyncContextFactory;
93 import org.eclipse.aether.internal.impl.synccontext.named.NameMapper;
94 import org.eclipse.aether.internal.impl.synccontext.named.NameMappers;
95 import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactory;
96 import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl;
97 import org.eclipse.aether.internal.impl.synccontext.named.providers.DiscriminatingNameMapperProvider;
98 import org.eclipse.aether.internal.impl.synccontext.named.providers.FileGAVNameMapperProvider;
99 import org.eclipse.aether.internal.impl.synccontext.named.providers.FileHashingGAVNameMapperProvider;
100 import org.eclipse.aether.internal.impl.synccontext.named.providers.GAVNameMapperProvider;
101 import org.eclipse.aether.internal.impl.synccontext.named.providers.StaticNameMapperProvider;
102 import org.eclipse.aether.named.NamedLockFactory;
103 import org.eclipse.aether.named.providers.FileLockNamedLockFactory;
104 import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory;
105 import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory;
106 import org.eclipse.aether.named.providers.NoopNamedLockFactory;
107 import org.eclipse.aether.spi.checksums.ProvidedChecksumsSource;
108 import org.eclipse.aether.spi.checksums.TrustedChecksumsSource;
109 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory;
110 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector;
111 import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider;
112 import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilterSource;
113 import org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory;
114 import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider;
115 import org.eclipse.aether.spi.connector.transport.TransporterProvider;
116 import org.eclipse.aether.spi.io.FileProcessor;
117 import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory;
118 import org.eclipse.aether.spi.log.LoggerFactory;
119 import org.eclipse.aether.spi.resolution.ArtifactResolverPostProcessor;
120 import org.eclipse.aether.spi.synccontext.SyncContextFactory;
121 import org.slf4j.ILoggerFactory;
122
123
124
125
126
127
128
129
130
131
132
133
134 @Deprecated
135 public class AetherModule extends AbstractModule {
136
137
138
139
140
141 public AetherModule() {}
142
143
144
145
146
147 @Override
148 protected void configure() {
149 bind(RepositorySystem.class)
150 .to(DefaultRepositorySystem.class)
151 .in(Singleton.class);
152 bind(ArtifactResolver.class)
153 .to(DefaultArtifactResolver.class)
154 .in(Singleton.class);
155
156 bind(DependencyCollector.class)
157 .to(DefaultDependencyCollector.class)
158 .in(Singleton.class);
159 bind(DependencyCollectorDelegate.class)
160 .annotatedWith(Names.named(BfDependencyCollector.NAME))
161 .to(BfDependencyCollector.class)
162 .in(Singleton.class);
163 bind(DependencyCollectorDelegate.class)
164 .annotatedWith(Names.named(DfDependencyCollector.NAME))
165 .to(DfDependencyCollector.class)
166 .in(Singleton.class);
167
168 bind(Deployer.class)
169 .to(DefaultDeployer.class)
170 .in(Singleton.class);
171 bind(Installer.class)
172 .to(DefaultInstaller.class)
173 .in(Singleton.class);
174 bind(MetadataResolver.class)
175 .to(DefaultMetadataResolver.class)
176 .in(Singleton.class);
177 bind(RepositoryLayoutProvider.class)
178 .to(DefaultRepositoryLayoutProvider.class)
179 .in(Singleton.class);
180 bind(RepositoryLayoutFactory.class)
181 .annotatedWith(Names.named("maven2"))
182 .to(Maven2RepositoryLayoutFactory.class)
183 .in(Singleton.class);
184 bind(TransporterProvider.class)
185 .to(DefaultTransporterProvider.class)
186 .in(Singleton.class);
187 bind(ChecksumPolicyProvider.class)
188 .to(DefaultChecksumPolicyProvider.class)
189 .in(Singleton.class);
190 bind(RepositoryConnectorProvider.class)
191 .to(DefaultRepositoryConnectorProvider.class)
192 .in(Singleton.class);
193 bind(RemoteRepositoryManager.class)
194 .to(DefaultRemoteRepositoryManager.class)
195 .in(Singleton.class);
196 bind(UpdateCheckManager.class)
197 .to(DefaultUpdateCheckManager.class)
198 .in(Singleton.class);
199 bind(UpdatePolicyAnalyzer.class)
200 .to(DefaultUpdatePolicyAnalyzer.class)
201 .in(Singleton.class);
202 bind(FileProcessor.class)
203 .to(DefaultFileProcessor.class)
204 .in(Singleton.class);
205 bind(RepositoryEventDispatcher.class)
206 .to(DefaultRepositoryEventDispatcher.class)
207 .in(Singleton.class);
208 bind(OfflineController.class)
209 .to(DefaultOfflineController.class)
210 .in(Singleton.class);
211
212 bind(LocalPathComposer.class).to(DefaultLocalPathComposer.class).in(Singleton.class);
213 bind(LocalPathPrefixComposerFactory.class)
214 .to(DefaultLocalPathPrefixComposerFactory.class)
215 .in(Singleton.class);
216
217 bind(LocalRepositoryProvider.class)
218 .to(DefaultLocalRepositoryProvider.class)
219 .in(Singleton.class);
220 bind(LocalRepositoryManagerFactory.class)
221 .annotatedWith(Names.named("simple"))
222 .to(SimpleLocalRepositoryManagerFactory.class)
223 .in(Singleton.class);
224 bind(LocalRepositoryManagerFactory.class)
225 .annotatedWith(Names.named("enhanced"))
226 .to(EnhancedLocalRepositoryManagerFactory.class)
227 .in(Singleton.class);
228 bind(TrackingFileManager.class).to(DefaultTrackingFileManager.class).in(Singleton.class);
229
230 bind(ProvidedChecksumsSource.class)
231 .annotatedWith(Names.named(TrustedToProvidedChecksumsSourceAdapter.NAME))
232 .to(TrustedToProvidedChecksumsSourceAdapter.class)
233 .in(Singleton.class);
234
235 bind(TrustedChecksumsSource.class)
236 .annotatedWith(Names.named(SparseDirectoryTrustedChecksumsSource.NAME))
237 .to(SparseDirectoryTrustedChecksumsSource.class)
238 .in(Singleton.class);
239 bind(TrustedChecksumsSource.class)
240 .annotatedWith(Names.named(SummaryFileTrustedChecksumsSource.NAME))
241 .to(SummaryFileTrustedChecksumsSource.class)
242 .in(Singleton.class);
243
244 bind(ArtifactResolverPostProcessor.class)
245 .annotatedWith(Names.named(TrustedChecksumsArtifactResolverPostProcessor.NAME))
246 .to(TrustedChecksumsArtifactResolverPostProcessor.class)
247 .in(Singleton.class);
248
249 bind(ChecksumAlgorithmFactory.class)
250 .annotatedWith(Names.named(Md5ChecksumAlgorithmFactory.NAME))
251 .to(Md5ChecksumAlgorithmFactory.class);
252 bind(ChecksumAlgorithmFactory.class)
253 .annotatedWith(Names.named(Sha1ChecksumAlgorithmFactory.NAME))
254 .to(Sha1ChecksumAlgorithmFactory.class);
255 bind(ChecksumAlgorithmFactory.class)
256 .annotatedWith(Names.named(Sha256ChecksumAlgorithmFactory.NAME))
257 .to(Sha256ChecksumAlgorithmFactory.class);
258 bind(ChecksumAlgorithmFactory.class)
259 .annotatedWith(Names.named(Sha512ChecksumAlgorithmFactory.NAME))
260 .to(Sha512ChecksumAlgorithmFactory.class);
261 bind(ChecksumAlgorithmFactorySelector.class)
262 .to(DefaultChecksumAlgorithmFactorySelector.class)
263 .in(Singleton.class);
264
265 bind(RepositorySystemLifecycle.class)
266 .to(DefaultRepositorySystemLifecycle.class)
267 .in(Singleton.class);
268
269 bind(NamedLockFactoryAdapterFactory.class)
270 .to(NamedLockFactoryAdapterFactoryImpl.class)
271 .in(Singleton.class);
272 bind(SyncContextFactory.class).to(DefaultSyncContextFactory.class).in(Singleton.class);
273 bind(org.eclipse.aether.impl.SyncContextFactory.class)
274 .to(org.eclipse.aether.internal.impl.synccontext.legacy.DefaultSyncContextFactory.class)
275 .in(Singleton.class);
276
277 bind(NameMapper.class)
278 .annotatedWith(Names.named(NameMappers.STATIC_NAME))
279 .toProvider(StaticNameMapperProvider.class)
280 .in(Singleton.class);
281 bind(NameMapper.class)
282 .annotatedWith(Names.named(NameMappers.GAV_NAME))
283 .toProvider(GAVNameMapperProvider.class)
284 .in(Singleton.class);
285 bind(NameMapper.class)
286 .annotatedWith(Names.named(NameMappers.DISCRIMINATING_NAME))
287 .toProvider(DiscriminatingNameMapperProvider.class)
288 .in(Singleton.class);
289 bind(NameMapper.class)
290 .annotatedWith(Names.named(NameMappers.FILE_GAV_NAME))
291 .toProvider(FileGAVNameMapperProvider.class)
292 .in(Singleton.class);
293 bind(NameMapper.class)
294 .annotatedWith(Names.named(NameMappers.FILE_HGAV_NAME))
295 .toProvider(FileHashingGAVNameMapperProvider.class)
296 .in(Singleton.class);
297
298 bind(NamedLockFactory.class)
299 .annotatedWith(Names.named(NoopNamedLockFactory.NAME))
300 .to(NoopNamedLockFactory.class)
301 .in(Singleton.class);
302 bind(NamedLockFactory.class)
303 .annotatedWith(Names.named(LocalReadWriteLockNamedLockFactory.NAME))
304 .to(LocalReadWriteLockNamedLockFactory.class)
305 .in(Singleton.class);
306 bind(NamedLockFactory.class)
307 .annotatedWith(Names.named(LocalSemaphoreNamedLockFactory.NAME))
308 .to(LocalSemaphoreNamedLockFactory.class)
309 .in(Singleton.class);
310 bind(NamedLockFactory.class)
311 .annotatedWith(Names.named(FileLockNamedLockFactory.NAME))
312 .to(FileLockNamedLockFactory.class)
313 .in(Singleton.class);
314
315 bind(RemoteRepositoryFilterManager.class)
316 .to(DefaultRemoteRepositoryFilterManager.class)
317 .in(Singleton.class);
318 bind(RemoteRepositoryFilterSource.class)
319 .annotatedWith(Names.named(GroupIdRemoteRepositoryFilterSource.NAME))
320 .to(GroupIdRemoteRepositoryFilterSource.class)
321 .in(Singleton.class);
322 bind(RemoteRepositoryFilterSource.class)
323 .annotatedWith(Names.named(PrefixesRemoteRepositoryFilterSource.NAME))
324 .to(PrefixesRemoteRepositoryFilterSource.class)
325 .in(Singleton.class);
326
327 install(new Slf4jModule());
328 }
329
330 @Provides
331 @Singleton
332 Map<String, RemoteRepositoryFilterSource> remoteRepositoryFilterSources(
333 @Named(GroupIdRemoteRepositoryFilterSource.NAME) RemoteRepositoryFilterSource groupId,
334 @Named(PrefixesRemoteRepositoryFilterSource.NAME) RemoteRepositoryFilterSource prefixes) {
335 Map<String, RemoteRepositoryFilterSource> result = new HashMap<>();
336 result.put(GroupIdRemoteRepositoryFilterSource.NAME, groupId);
337 result.put(PrefixesRemoteRepositoryFilterSource.NAME, prefixes);
338 return Collections.unmodifiableMap(result);
339 }
340
341 @Provides
342 @Singleton
343 Map<String, ArtifactResolverPostProcessor> artifactResolverProcessors(
344 @Named(TrustedChecksumsArtifactResolverPostProcessor.NAME) ArtifactResolverPostProcessor trustedChecksums) {
345 Map<String, ArtifactResolverPostProcessor> result = new HashMap<>();
346 result.put(TrustedChecksumsArtifactResolverPostProcessor.NAME, trustedChecksums);
347 return Collections.unmodifiableMap(result);
348 }
349
350 @Provides
351 @Singleton
352 Map<String, DependencyCollectorDelegate> dependencyCollectorDelegates(
353 @Named(BfDependencyCollector.NAME) DependencyCollectorDelegate bf,
354 @Named(DfDependencyCollector.NAME) DependencyCollectorDelegate df) {
355 Map<String, DependencyCollectorDelegate> result = new HashMap<>();
356 result.put(BfDependencyCollector.NAME, bf);
357 result.put(DfDependencyCollector.NAME, df);
358 return Collections.unmodifiableMap(result);
359 }
360
361 @Provides
362 @Singleton
363 Map<String, ProvidedChecksumsSource> providedChecksumSources(
364 @Named(TrustedToProvidedChecksumsSourceAdapter.NAME) ProvidedChecksumsSource adapter) {
365 Map<String, ProvidedChecksumsSource> result = new HashMap<>();
366 result.put(TrustedToProvidedChecksumsSourceAdapter.NAME, adapter);
367 return Collections.unmodifiableMap(result);
368 }
369
370 @Provides
371 @Singleton
372 Map<String, TrustedChecksumsSource> trustedChecksumSources(
373 @Named(SparseDirectoryTrustedChecksumsSource.NAME) TrustedChecksumsSource sparse,
374 @Named(SummaryFileTrustedChecksumsSource.NAME) TrustedChecksumsSource compact) {
375 Map<String, TrustedChecksumsSource> result = new HashMap<>();
376 result.put(SparseDirectoryTrustedChecksumsSource.NAME, sparse);
377 result.put(SummaryFileTrustedChecksumsSource.NAME, compact);
378 return Collections.unmodifiableMap(result);
379 }
380
381 @Provides
382 @Singleton
383 Map<String, ChecksumAlgorithmFactory> provideChecksumTypes(
384 @Named(Sha512ChecksumAlgorithmFactory.NAME) ChecksumAlgorithmFactory sha512,
385 @Named(Sha256ChecksumAlgorithmFactory.NAME) ChecksumAlgorithmFactory sha256,
386 @Named(Sha1ChecksumAlgorithmFactory.NAME) ChecksumAlgorithmFactory sha1,
387 @Named(Md5ChecksumAlgorithmFactory.NAME) ChecksumAlgorithmFactory md5) {
388 Map<String, ChecksumAlgorithmFactory> result = new HashMap<>();
389 result.put(Sha512ChecksumAlgorithmFactory.NAME, sha512);
390 result.put(Sha256ChecksumAlgorithmFactory.NAME, sha256);
391 result.put(Sha1ChecksumAlgorithmFactory.NAME, sha1);
392 result.put(Md5ChecksumAlgorithmFactory.NAME, md5);
393 return Collections.unmodifiableMap(result);
394 }
395
396 @Provides
397 @Singleton
398 Map<String, NameMapper> provideNameMappers(
399 @Named(NameMappers.STATIC_NAME) NameMapper staticNameMapper,
400 @Named(NameMappers.GAV_NAME) NameMapper gavNameMapper,
401 @Named(NameMappers.DISCRIMINATING_NAME) NameMapper discriminatingNameMapper,
402 @Named(NameMappers.FILE_GAV_NAME) NameMapper fileGavNameMapper,
403 @Named(NameMappers.FILE_HGAV_NAME) NameMapper fileHashingGavNameMapper) {
404 Map<String, NameMapper> result = new HashMap<>();
405 result.put(NameMappers.STATIC_NAME, staticNameMapper);
406 result.put(NameMappers.GAV_NAME, gavNameMapper);
407 result.put(NameMappers.DISCRIMINATING_NAME, discriminatingNameMapper);
408 result.put(NameMappers.FILE_GAV_NAME, fileGavNameMapper);
409 result.put(NameMappers.FILE_HGAV_NAME, fileHashingGavNameMapper);
410 return Collections.unmodifiableMap(result);
411 }
412
413 @Provides
414 @Singleton
415 Map<String, NamedLockFactory> provideNamedLockFactories(
416 @Named(LocalReadWriteLockNamedLockFactory.NAME) NamedLockFactory localRwLock,
417 @Named(LocalSemaphoreNamedLockFactory.NAME) NamedLockFactory localSemaphore,
418 @Named(FileLockNamedLockFactory.NAME) NamedLockFactory fileLockFactory) {
419 Map<String, NamedLockFactory> result = new HashMap<>();
420 result.put(LocalReadWriteLockNamedLockFactory.NAME, localRwLock);
421 result.put(LocalSemaphoreNamedLockFactory.NAME, localSemaphore);
422 result.put(FileLockNamedLockFactory.NAME, fileLockFactory);
423 return Collections.unmodifiableMap(result);
424 }
425
426 @Provides
427 @Singleton
428 Set<LocalRepositoryManagerFactory> provideLocalRepositoryManagerFactories(
429 @Named("simple") LocalRepositoryManagerFactory simple,
430 @Named("enhanced") LocalRepositoryManagerFactory enhanced) {
431 Set<LocalRepositoryManagerFactory> result = new HashSet<>();
432 result.add(simple);
433 result.add(enhanced);
434 return Collections.unmodifiableSet(result);
435 }
436
437 @Provides
438 @Singleton
439 Set<RepositoryLayoutFactory> provideRepositoryLayoutFactories(@Named("maven2") RepositoryLayoutFactory maven2) {
440 Set<RepositoryLayoutFactory> result = new HashSet<>();
441 result.add(maven2);
442 return Collections.unmodifiableSet(result);
443 }
444
445 @Provides
446 @Singleton
447 Set<RepositoryListener> providesRepositoryListeners() {
448 return Collections.emptySet();
449 }
450
451 private static class Slf4jModule extends AbstractModule {
452
453 @Override
454 protected void configure() {
455 bind(LoggerFactory.class)
456 .to(Slf4jLoggerFactory.class);
457 }
458
459 @Provides
460 @Singleton
461 ILoggerFactory getLoggerFactory() {
462 return org.slf4j.LoggerFactory.getILoggerFactory();
463 }
464 }
465 }