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