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  
39  /**
40   * MavenResolverModule
41   */
42  @Deprecated
43  public final class MavenResolverModule extends AbstractModule {
44  
45      @Override
46      protected void configure() {
47          install(new AetherModule());
48          bind(ArtifactDescriptorReader.class)
49                  .to(DefaultArtifactDescriptorReader.class)
50                  .in(Singleton.class);
51          bind(VersionResolver.class).to(DefaultVersionResolver.class).in(Singleton.class);
52          bind(VersionRangeResolver.class).to(DefaultVersionRangeResolver.class).in(Singleton.class);
53          bind(MetadataGeneratorFactory.class)
54                  .annotatedWith(Names.named("snapshot"))
55                  .to(SnapshotMetadataGeneratorFactory.class)
56                  .in(Singleton.class);
57  
58          bind(MetadataGeneratorFactory.class)
59                  .annotatedWith(Names.named("versions"))
60                  .to(VersionsMetadataGeneratorFactory.class)
61                  .in(Singleton.class);
62  
63          bind(ModelBuilder.class).toInstance(new DefaultModelBuilderFactory().newInstance());
64          bind(ModelCacheFactory.class).to(DefaultModelCacheFactory.class).in(Singleton.class);
65      }
66  
67      @Provides
68      @Singleton
69      Set<MetadataGeneratorFactory> provideMetadataGeneratorFactories(
70              @Named("snapshot") MetadataGeneratorFactory snapshot,
71              @Named("versions") MetadataGeneratorFactory versions) {
72          Set<MetadataGeneratorFactory> factories = new HashSet<>(2);
73          factories.add(snapshot);
74          factories.add(versions);
75          return Collections.unmodifiableSet(factories);
76      }
77  }