1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal;
20
21 import com.google.inject.AbstractModule;
22 import com.google.inject.Provides;
23 import com.google.inject.name.Names;
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.Set;
27 import javax.inject.Named;
28 import javax.inject.Singleton;
29 import org.apache.maven.model.building.DefaultModelBuilderFactory;
30 import org.apache.maven.model.building.ModelBuilder;
31 import org.eclipse.aether.impl.ArtifactDescriptorReader;
32 import org.eclipse.aether.impl.MetadataGeneratorFactory;
33 import org.eclipse.aether.impl.VersionRangeResolver;
34 import org.eclipse.aether.impl.VersionResolver;
35 import org.eclipse.aether.impl.guice.AetherModule;
36 import org.eclipse.aether.version.VersionScheme;
37
38
39
40
41 public final class MavenResolverModule extends AbstractModule {
42
43 @Override
44 protected void configure() {
45 install(new AetherModule());
46 bind(VersionScheme.class).toProvider(new DefaultVersionSchemeProvider());
47 bind(ArtifactDescriptorReader.class)
48 .to(DefaultArtifactDescriptorReader.class)
49 .in(Singleton.class);
50 bind(VersionResolver.class).to(DefaultVersionResolver.class).in(Singleton.class);
51 bind(VersionRangeResolver.class).to(DefaultVersionRangeResolver.class).in(Singleton.class);
52 bind(MetadataGeneratorFactory.class)
53 .annotatedWith(Names.named("snapshot"))
54 .to(SnapshotMetadataGeneratorFactory.class)
55 .in(Singleton.class);
56 bind(MetadataGeneratorFactory.class)
57 .annotatedWith(Names.named("versions"))
58 .to(VersionsMetadataGeneratorFactory.class)
59 .in(Singleton.class);
60 bind(ModelBuilder.class).toInstance(new DefaultModelBuilderFactory().newInstance());
61 bind(ModelCacheFactory.class).to(DefaultModelCacheFactory.class).in(Singleton.class);
62 }
63
64 @Provides
65 @Singleton
66 Set<MetadataGeneratorFactory> provideMetadataGeneratorFactories(
67 @Named("snapshot") MetadataGeneratorFactory snapshot,
68 @Named("versions") MetadataGeneratorFactory versions) {
69 Set<MetadataGeneratorFactory> factories = new HashSet<>(2);
70 factories.add(snapshot);
71 factories.add(versions);
72 return Collections.unmodifiableSet(factories);
73 }
74 }