View Javadoc
1   package org.apache.maven.resolver.examples.guice;
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  
26  import javax.inject.Named;
27  import javax.inject.Singleton;
28  
29  import org.apache.maven.repository.internal.MavenResolverModule;
30  import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
31  import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
32  import org.eclipse.aether.spi.connector.transport.TransporterFactory;
33  import org.eclipse.aether.transport.file.FileTransporterFactory;
34  import org.eclipse.aether.transport.http.HttpTransporterFactory;
35  
36  import com.google.inject.AbstractModule;
37  import com.google.inject.Provides;
38  import com.google.inject.name.Names;
39  
40  class DemoResolverModule
41      extends AbstractModule
42  {
43  
44      @Override
45      protected void configure()
46      {
47          install( new MavenResolverModule() );
48          // alternatively, use the Guice Multibindings extensions
49          bind( RepositoryConnectorFactory.class ).annotatedWith( Names.named( "basic" ) )
50                  .to( BasicRepositoryConnectorFactory.class );
51          bind( TransporterFactory.class ).annotatedWith( Names.named( "file" ) ).to( FileTransporterFactory.class );
52          bind( TransporterFactory.class ).annotatedWith( Names.named( "http" ) ).to( HttpTransporterFactory.class );
53      }
54  
55      @Provides
56      @Singleton
57      Set<RepositoryConnectorFactory> provideRepositoryConnectorFactories(
58              @Named( "basic" ) RepositoryConnectorFactory basic )
59      {
60          Set<RepositoryConnectorFactory> factories = new HashSet<>();
61          factories.add( basic );
62          return Collections.unmodifiableSet( factories );
63      }
64  
65      @Provides
66      @Singleton
67      Set<TransporterFactory> provideTransporterFactories( @Named( "file" ) TransporterFactory file,
68                                                           @Named( "http" ) TransporterFactory http )
69      {
70          Set<TransporterFactory> factories = new HashSet<>();
71          factories.add( file );
72          factories.add( http );
73          return Collections.unmodifiableSet( factories );
74      }
75  
76  }