001package org.eclipse.aether.impl.guice; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Collections; 023import java.util.HashSet; 024import java.util.Set; 025 026import javax.inject.Named; 027import javax.inject.Singleton; 028 029import org.eclipse.aether.RepositoryListener; 030import org.eclipse.aether.RepositorySystem; 031import org.eclipse.aether.impl.ArtifactResolver; 032import org.eclipse.aether.impl.DependencyCollector; 033import org.eclipse.aether.impl.Deployer; 034import org.eclipse.aether.impl.Installer; 035import org.eclipse.aether.impl.LocalRepositoryProvider; 036import org.eclipse.aether.impl.MetadataResolver; 037import org.eclipse.aether.impl.OfflineController; 038import org.eclipse.aether.impl.RemoteRepositoryManager; 039import org.eclipse.aether.impl.RepositoryConnectorProvider; 040import org.eclipse.aether.impl.RepositoryEventDispatcher; 041import org.eclipse.aether.impl.SyncContextFactory; 042import org.eclipse.aether.impl.UpdateCheckManager; 043import org.eclipse.aether.impl.UpdatePolicyAnalyzer; 044import org.eclipse.aether.internal.impl.DefaultArtifactResolver; 045import org.eclipse.aether.internal.impl.DefaultChecksumPolicyProvider; 046import org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector; 047import org.eclipse.aether.internal.impl.DefaultDeployer; 048import org.eclipse.aether.internal.impl.DefaultFileProcessor; 049import org.eclipse.aether.internal.impl.DefaultInstaller; 050import org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider; 051import org.eclipse.aether.internal.impl.DefaultMetadataResolver; 052import org.eclipse.aether.internal.impl.DefaultOfflineController; 053import org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager; 054import org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider; 055import org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher; 056import org.eclipse.aether.internal.impl.DefaultRepositoryLayoutProvider; 057import org.eclipse.aether.internal.impl.DefaultRepositorySystem; 058import org.eclipse.aether.internal.impl.DefaultSyncContextFactory; 059import org.eclipse.aether.internal.impl.DefaultTransporterProvider; 060import org.eclipse.aether.internal.impl.DefaultUpdateCheckManager; 061import org.eclipse.aether.internal.impl.DefaultUpdatePolicyAnalyzer; 062import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory; 063import org.eclipse.aether.internal.impl.Maven2RepositoryLayoutFactory; 064import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; 065import org.eclipse.aether.internal.impl.slf4j.Slf4jLoggerFactory; 066import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider; 067import org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory; 068import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider; 069import org.eclipse.aether.spi.connector.transport.TransporterProvider; 070import org.eclipse.aether.spi.io.FileProcessor; 071import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory; 072import org.eclipse.aether.spi.log.LoggerFactory; 073import org.slf4j.ILoggerFactory; 074 075import com.google.inject.AbstractModule; 076import com.google.inject.Provides; 077import com.google.inject.name.Names; 078 079/** 080 * A ready-made <a href="https://github.com/google/guice" target="_blank">Guice</a> module that sets up bindings 081 * for all components from this library. To acquire a complete repository system, clients need to bind an artifact 082 * descriptor reader, a version resolver, a version range resolver, zero or more metadata generator factories, some 083 * repository connector and transporter factories to access remote repositories. 084 * 085 * @noextend This class must not be extended by clients and will eventually be marked {@code final} without prior 086 * notice. 087 */ 088public class AetherModule 089 extends AbstractModule 090{ 091 092 /** 093 * Creates a new instance of this Guice module, typically for invoking 094 * {@link com.google.inject.Binder#install(com.google.inject.Module)}. 095 */ 096 public AetherModule() 097 { 098 } 099 100 /** 101 * Configures Guice with bindings for Aether components provided by this library. 102 */ 103 @Override 104 protected void configure() 105 { 106 bind( RepositorySystem.class ) // 107 .to( DefaultRepositorySystem.class ).in( Singleton.class ); 108 bind( ArtifactResolver.class ) // 109 .to( DefaultArtifactResolver.class ).in( Singleton.class ); 110 bind( DependencyCollector.class ) // 111 .to( DefaultDependencyCollector.class ).in( Singleton.class ); 112 bind( Deployer.class ) // 113 .to( DefaultDeployer.class ).in( Singleton.class ); 114 bind( Installer.class ) // 115 .to( DefaultInstaller.class ).in( Singleton.class ); 116 bind( MetadataResolver.class ) // 117 .to( DefaultMetadataResolver.class ).in( Singleton.class ); 118 bind( RepositoryLayoutProvider.class ) // 119 .to( DefaultRepositoryLayoutProvider.class ).in( Singleton.class ); 120 bind( RepositoryLayoutFactory.class ).annotatedWith( Names.named( "maven2" ) ) // 121 .to( Maven2RepositoryLayoutFactory.class ).in( Singleton.class ); 122 bind( TransporterProvider.class ) // 123 .to( DefaultTransporterProvider.class ).in( Singleton.class ); 124 bind( ChecksumPolicyProvider.class ) // 125 .to( DefaultChecksumPolicyProvider.class ).in( Singleton.class ); 126 bind( RepositoryConnectorProvider.class ) // 127 .to( DefaultRepositoryConnectorProvider.class ).in( Singleton.class ); 128 bind( RemoteRepositoryManager.class ) // 129 .to( DefaultRemoteRepositoryManager.class ).in( Singleton.class ); 130 bind( UpdateCheckManager.class ) // 131 .to( DefaultUpdateCheckManager.class ).in( Singleton.class ); 132 bind( UpdatePolicyAnalyzer.class ) // 133 .to( DefaultUpdatePolicyAnalyzer.class ).in( Singleton.class ); 134 bind( FileProcessor.class ) // 135 .to( DefaultFileProcessor.class ).in( Singleton.class ); 136 bind( SyncContextFactory.class ) // 137 .to( DefaultSyncContextFactory.class ).in( Singleton.class ); 138 bind( RepositoryEventDispatcher.class ) // 139 .to( DefaultRepositoryEventDispatcher.class ).in( Singleton.class ); 140 bind( OfflineController.class ) // 141 .to( DefaultOfflineController.class ).in( Singleton.class ); 142 bind( LocalRepositoryProvider.class ) // 143 .to( DefaultLocalRepositoryProvider.class ).in( Singleton.class ); 144 bind( LocalRepositoryManagerFactory.class ).annotatedWith( Names.named( "simple" ) ) // 145 .to( SimpleLocalRepositoryManagerFactory.class ).in( Singleton.class ); 146 bind( LocalRepositoryManagerFactory.class ).annotatedWith( Names.named( "enhanced" ) ) // 147 .to( EnhancedLocalRepositoryManagerFactory.class ).in( Singleton.class ); 148 149 install( new Slf4jModule() ); 150 151 } 152 153 @Provides 154 @Singleton 155 Set<LocalRepositoryManagerFactory> provideLocalRepositoryManagerFactories( 156 @Named( "simple" ) LocalRepositoryManagerFactory simple, 157 @Named( "enhanced" ) LocalRepositoryManagerFactory enhanced ) 158 { 159 Set<LocalRepositoryManagerFactory> factories = new HashSet<>(); 160 factories.add( simple ); 161 factories.add( enhanced ); 162 return Collections.unmodifiableSet( factories ); 163 } 164 165 @Provides 166 @Singleton 167 Set<RepositoryLayoutFactory> provideRepositoryLayoutFactories( @Named( "maven2" ) RepositoryLayoutFactory maven2 ) 168 { 169 Set<RepositoryLayoutFactory> factories = new HashSet<>(); 170 factories.add( maven2 ); 171 return Collections.unmodifiableSet( factories ); 172 } 173 174 @Provides 175 @Singleton 176 Set<RepositoryListener> providesRepositoryListeners() 177 { 178 return Collections.emptySet(); 179 } 180 181 private static class Slf4jModule 182 extends AbstractModule 183 { 184 185 @Override 186 protected void configure() 187 { 188 bind( LoggerFactory.class ) // 189 .to( Slf4jLoggerFactory.class ); 190 } 191 192 @Provides 193 @Singleton 194 ILoggerFactory getLoggerFactory() 195 { 196 return org.slf4j.LoggerFactory.getILoggerFactory(); 197 } 198 199 } 200 201}