View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.internal;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.util.Collections;
25  import java.util.HashSet;
26  import java.util.Set;
27  
28  import com.google.inject.AbstractModule;
29  import com.google.inject.Provides;
30  import com.google.inject.name.Names;
31  import org.apache.maven.model.building.DefaultModelBuilderFactory;
32  import org.apache.maven.model.building.ModelBuilder;
33  import org.eclipse.aether.impl.ArtifactDescriptorReader;
34  import org.eclipse.aether.impl.MetadataGeneratorFactory;
35  import org.eclipse.aether.impl.VersionRangeResolver;
36  import org.eclipse.aether.impl.VersionResolver;
37  import org.eclipse.aether.impl.guice.AetherModule;
38  import org.eclipse.aether.version.VersionScheme;
39  
40  /**
41   * MavenResolverModule
42   */
43  public final class MavenResolverModule extends AbstractModule {
44  
45      @Override
46      protected void configure() {
47          install(new AetherModule());
48          bind(VersionScheme.class).toProvider(new DefaultVersionSchemeProvider());
49          bind(ArtifactDescriptorReader.class)
50                  .to(DefaultArtifactDescriptorReader.class)
51                  .in(Singleton.class);
52          bind(VersionResolver.class).to(DefaultVersionResolver.class).in(Singleton.class);
53          bind(VersionRangeResolver.class).to(DefaultVersionRangeResolver.class).in(Singleton.class);
54          bind(MetadataGeneratorFactory.class)
55                  .annotatedWith(Names.named("snapshot"))
56                  .to(SnapshotMetadataGeneratorFactory.class)
57                  .in(Singleton.class);
58          bind(MetadataGeneratorFactory.class)
59                  .annotatedWith(Names.named("versions"))
60                  .to(VersionsMetadataGeneratorFactory.class)
61                  .in(Singleton.class);
62          bind(ModelBuilder.class).toInstance(new DefaultModelBuilderFactory().newInstance());
63          bind(ModelCacheFactory.class).to(DefaultModelCacheFactory.class).in(Singleton.class);
64      }
65  
66      @Provides
67      @Singleton
68      Set<MetadataGeneratorFactory> provideMetadataGeneratorFactories(
69              @Named("snapshot") MetadataGeneratorFactory snapshot,
70              @Named("versions") MetadataGeneratorFactory versions) {
71          Set<MetadataGeneratorFactory> factories = new HashSet<>(2);
72          factories.add(snapshot);
73          factories.add(versions);
74          return Collections.unmodifiableSet(factories);
75      }
76  }