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 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   * MavenResolverModule
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  }