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.MavenAetherModule;
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 MavenAetherModule() );
48          // alternatively, use the Guice Multibindings extensions
49          bind( RepositoryConnectorFactory.class ).annotatedWith( Names.named( "basic" ) ).to( BasicRepositoryConnectorFactory.class );
50          bind( TransporterFactory.class ).annotatedWith( Names.named( "file" ) ).to( FileTransporterFactory.class );
51          bind( TransporterFactory.class ).annotatedWith( Names.named( "http" ) ).to( HttpTransporterFactory.class );
52      }
53  
54      @Provides
55      @Singleton
56      Set<RepositoryConnectorFactory> provideRepositoryConnectorFactories( @Named( "basic" ) RepositoryConnectorFactory basic )
57      {
58          Set<RepositoryConnectorFactory> factories = new HashSet<RepositoryConnectorFactory>();
59          factories.add( basic );
60          return Collections.unmodifiableSet( factories );
61      }
62  
63      @Provides
64      @Singleton
65      Set<TransporterFactory> provideTransporterFactories( @Named( "file" ) TransporterFactory file,
66                                                           @Named( "http" ) TransporterFactory http )
67      {
68          Set<TransporterFactory> factories = new HashSet<TransporterFactory>();
69          factories.add( file );
70          factories.add( http );
71          return Collections.unmodifiableSet( factories );
72      }
73  
74  }