001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.supplier; 020 021import java.util.HashMap; 022import java.util.Map; 023import java.util.function.Supplier; 024 025import org.apache.maven.model.building.DefaultModelBuilderFactory; 026import org.apache.maven.model.building.ModelBuilder; 027import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; 028import org.apache.maven.repository.internal.DefaultModelCacheFactory; 029import org.apache.maven.repository.internal.DefaultVersionRangeResolver; 030import org.apache.maven.repository.internal.DefaultVersionResolver; 031import org.apache.maven.repository.internal.ModelCacheFactory; 032import org.apache.maven.repository.internal.PluginsMetadataGeneratorFactory; 033import org.apache.maven.repository.internal.SnapshotMetadataGeneratorFactory; 034import org.apache.maven.repository.internal.VersionsMetadataGeneratorFactory; 035import org.eclipse.aether.RepositoryListener; 036import org.eclipse.aether.RepositorySystem; 037import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; 038import org.eclipse.aether.impl.ArtifactDescriptorReader; 039import org.eclipse.aether.impl.ArtifactResolver; 040import org.eclipse.aether.impl.DependencyCollector; 041import org.eclipse.aether.impl.Deployer; 042import org.eclipse.aether.impl.Installer; 043import org.eclipse.aether.impl.LocalRepositoryProvider; 044import org.eclipse.aether.impl.MetadataGeneratorFactory; 045import org.eclipse.aether.impl.MetadataResolver; 046import org.eclipse.aether.impl.OfflineController; 047import org.eclipse.aether.impl.RemoteRepositoryFilterManager; 048import org.eclipse.aether.impl.RemoteRepositoryManager; 049import org.eclipse.aether.impl.RepositoryConnectorProvider; 050import org.eclipse.aether.impl.RepositoryEventDispatcher; 051import org.eclipse.aether.impl.RepositorySystemLifecycle; 052import org.eclipse.aether.impl.UpdateCheckManager; 053import org.eclipse.aether.impl.UpdatePolicyAnalyzer; 054import org.eclipse.aether.impl.VersionRangeResolver; 055import org.eclipse.aether.impl.VersionResolver; 056import org.eclipse.aether.internal.impl.DefaultArtifactResolver; 057import org.eclipse.aether.internal.impl.DefaultChecksumPolicyProvider; 058import org.eclipse.aether.internal.impl.DefaultDeployer; 059import org.eclipse.aether.internal.impl.DefaultFileProcessor; 060import org.eclipse.aether.internal.impl.DefaultInstaller; 061import org.eclipse.aether.internal.impl.DefaultLocalPathComposer; 062import org.eclipse.aether.internal.impl.DefaultLocalPathPrefixComposerFactory; 063import org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider; 064import org.eclipse.aether.internal.impl.DefaultMetadataResolver; 065import org.eclipse.aether.internal.impl.DefaultOfflineController; 066import org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager; 067import org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider; 068import org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher; 069import org.eclipse.aether.internal.impl.DefaultRepositoryLayoutProvider; 070import org.eclipse.aether.internal.impl.DefaultRepositorySystem; 071import org.eclipse.aether.internal.impl.DefaultRepositorySystemLifecycle; 072import org.eclipse.aether.internal.impl.DefaultTrackingFileManager; 073import org.eclipse.aether.internal.impl.DefaultTransporterProvider; 074import org.eclipse.aether.internal.impl.DefaultUpdateCheckManager; 075import org.eclipse.aether.internal.impl.DefaultUpdatePolicyAnalyzer; 076import org.eclipse.aether.internal.impl.EnhancedLocalRepositoryManagerFactory; 077import org.eclipse.aether.internal.impl.LocalPathComposer; 078import org.eclipse.aether.internal.impl.LocalPathPrefixComposerFactory; 079import org.eclipse.aether.internal.impl.Maven2RepositoryLayoutFactory; 080import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; 081import org.eclipse.aether.internal.impl.TrackingFileManager; 082import org.eclipse.aether.internal.impl.checksum.DefaultChecksumAlgorithmFactorySelector; 083import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory; 084import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory; 085import org.eclipse.aether.internal.impl.checksum.Sha256ChecksumAlgorithmFactory; 086import org.eclipse.aether.internal.impl.checksum.Sha512ChecksumAlgorithmFactory; 087import org.eclipse.aether.internal.impl.checksum.SparseDirectoryTrustedChecksumsSource; 088import org.eclipse.aether.internal.impl.checksum.SummaryFileTrustedChecksumsSource; 089import org.eclipse.aether.internal.impl.checksum.TrustedToProvidedChecksumsSourceAdapter; 090import org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector; 091import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegate; 092import org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector; 093import org.eclipse.aether.internal.impl.collect.df.DfDependencyCollector; 094import org.eclipse.aether.internal.impl.filter.DefaultRemoteRepositoryFilterManager; 095import org.eclipse.aether.internal.impl.filter.GroupIdRemoteRepositoryFilterSource; 096import org.eclipse.aether.internal.impl.filter.PrefixesRemoteRepositoryFilterSource; 097import org.eclipse.aether.internal.impl.resolution.TrustedChecksumsArtifactResolverPostProcessor; 098import org.eclipse.aether.internal.impl.synccontext.DefaultSyncContextFactory; 099import org.eclipse.aether.internal.impl.synccontext.named.NameMapper; 100import org.eclipse.aether.internal.impl.synccontext.named.NameMappers; 101import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactory; 102import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl; 103import org.eclipse.aether.internal.impl.version.DefaultVersionSchemeSelector; 104import org.eclipse.aether.internal.impl.version.GenericVersionSchemeProvider; 105import org.eclipse.aether.named.NamedLockFactory; 106import org.eclipse.aether.named.providers.FileLockNamedLockFactory; 107import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory; 108import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory; 109import org.eclipse.aether.named.providers.NoopNamedLockFactory; 110import org.eclipse.aether.spi.checksums.ProvidedChecksumsSource; 111import org.eclipse.aether.spi.checksums.TrustedChecksumsSource; 112import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; 113import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory; 114import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector; 115import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider; 116import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilterSource; 117import org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory; 118import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider; 119import org.eclipse.aether.spi.connector.transport.TransporterFactory; 120import org.eclipse.aether.spi.connector.transport.TransporterProvider; 121import org.eclipse.aether.spi.io.FileProcessor; 122import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory; 123import org.eclipse.aether.spi.resolution.ArtifactResolverPostProcessor; 124import org.eclipse.aether.spi.synccontext.SyncContextFactory; 125import org.eclipse.aether.spi.version.VersionSchemeSelector; 126import org.eclipse.aether.transport.apache.ApacheTransporterFactory; 127import org.eclipse.aether.transport.file.FileTransporterFactory; 128import org.eclipse.aether.util.version.GenericVersionScheme; 129import org.eclipse.aether.version.VersionScheme; 130 131/** 132 * A simple {@link Supplier} of {@link org.eclipse.aether.RepositorySystem} instances, that on each call supplies newly 133 * constructed instance. For proper shut down, use {@link RepositorySystem#shutdown()} method on supplied instance(s). 134 * <p> 135 * Extend this class and override methods to customize, if needed. 136 * 137 * @since 1.9.15 138 */ 139public class RepositorySystemSupplier implements Supplier<RepositorySystem> { 140 protected FileProcessor getFileProcessor() { 141 return new DefaultFileProcessor(); 142 } 143 144 protected TrackingFileManager getTrackingFileManager() { 145 return new DefaultTrackingFileManager(); 146 } 147 148 protected LocalPathComposer getLocalPathComposer() { 149 return new DefaultLocalPathComposer(); 150 } 151 152 protected LocalPathPrefixComposerFactory getLocalPathPrefixComposerFactory() { 153 return new DefaultLocalPathPrefixComposerFactory(); 154 } 155 156 protected RepositorySystemLifecycle getRepositorySystemLifecycle() { 157 return new DefaultRepositorySystemLifecycle(); 158 } 159 160 protected OfflineController getOfflineController() { 161 return new DefaultOfflineController(); 162 } 163 164 protected UpdatePolicyAnalyzer getUpdatePolicyAnalyzer() { 165 return new DefaultUpdatePolicyAnalyzer(); 166 } 167 168 protected ChecksumPolicyProvider getChecksumPolicyProvider() { 169 return new DefaultChecksumPolicyProvider(); 170 } 171 172 protected UpdateCheckManager getUpdateCheckManager( 173 TrackingFileManager trackingFileManager, UpdatePolicyAnalyzer updatePolicyAnalyzer) { 174 return new DefaultUpdateCheckManager(trackingFileManager, updatePolicyAnalyzer); 175 } 176 177 protected Map<String, NamedLockFactory> getNamedLockFactories() { 178 HashMap<String, NamedLockFactory> result = new HashMap<>(); 179 result.put(NoopNamedLockFactory.NAME, new NoopNamedLockFactory()); 180 result.put(LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory()); 181 result.put(LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory()); 182 result.put(FileLockNamedLockFactory.NAME, new FileLockNamedLockFactory()); 183 return result; 184 } 185 186 protected Map<String, NameMapper> getNameMappers() { 187 HashMap<String, NameMapper> result = new HashMap<>(); 188 result.put(NameMappers.STATIC_NAME, NameMappers.staticNameMapper()); 189 result.put(NameMappers.GAV_NAME, NameMappers.gavNameMapper()); 190 result.put(NameMappers.DISCRIMINATING_NAME, NameMappers.discriminatingNameMapper()); 191 result.put(NameMappers.FILE_GAV_NAME, NameMappers.fileGavNameMapper()); 192 result.put(NameMappers.FILE_HGAV_NAME, NameMappers.fileHashingGavNameMapper()); 193 return result; 194 } 195 196 protected NamedLockFactoryAdapterFactory getNamedLockFactoryAdapterFactory( 197 Map<String, NamedLockFactory> namedLockFactories, 198 Map<String, NameMapper> nameMappers, 199 RepositorySystemLifecycle repositorySystemLifecycle) { 200 return new NamedLockFactoryAdapterFactoryImpl(namedLockFactories, nameMappers, repositorySystemLifecycle); 201 } 202 203 protected SyncContextFactory getSyncContextFactory(NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory) { 204 return new DefaultSyncContextFactory(namedLockFactoryAdapterFactory); 205 } 206 207 protected Map<String, ChecksumAlgorithmFactory> getChecksumAlgorithmFactories() { 208 HashMap<String, ChecksumAlgorithmFactory> result = new HashMap<>(); 209 result.put(Sha512ChecksumAlgorithmFactory.NAME, new Sha512ChecksumAlgorithmFactory()); 210 result.put(Sha256ChecksumAlgorithmFactory.NAME, new Sha256ChecksumAlgorithmFactory()); 211 result.put(Sha1ChecksumAlgorithmFactory.NAME, new Sha1ChecksumAlgorithmFactory()); 212 result.put(Md5ChecksumAlgorithmFactory.NAME, new Md5ChecksumAlgorithmFactory()); 213 return result; 214 } 215 216 protected ChecksumAlgorithmFactorySelector getChecksumAlgorithmFactorySelector( 217 Map<String, ChecksumAlgorithmFactory> checksumAlgorithmFactories) { 218 return new DefaultChecksumAlgorithmFactorySelector(checksumAlgorithmFactories); 219 } 220 221 protected Map<String, RepositoryLayoutFactory> getRepositoryLayoutFactories( 222 ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector) { 223 HashMap<String, RepositoryLayoutFactory> result = new HashMap<>(); 224 result.put( 225 Maven2RepositoryLayoutFactory.NAME, 226 new Maven2RepositoryLayoutFactory(checksumAlgorithmFactorySelector)); 227 return result; 228 } 229 230 protected RepositoryLayoutProvider getRepositoryLayoutProvider( 231 Map<String, RepositoryLayoutFactory> repositoryLayoutFactories) { 232 return new DefaultRepositoryLayoutProvider(repositoryLayoutFactories); 233 } 234 235 protected LocalRepositoryProvider getLocalRepositoryProvider( 236 LocalPathComposer localPathComposer, 237 TrackingFileManager trackingFileManager, 238 LocalPathPrefixComposerFactory localPathPrefixComposerFactory) { 239 HashMap<String, LocalRepositoryManagerFactory> localRepositoryProviders = new HashMap<>(2); 240 localRepositoryProviders.put( 241 SimpleLocalRepositoryManagerFactory.NAME, new SimpleLocalRepositoryManagerFactory(localPathComposer)); 242 localRepositoryProviders.put( 243 EnhancedLocalRepositoryManagerFactory.NAME, 244 new EnhancedLocalRepositoryManagerFactory( 245 localPathComposer, trackingFileManager, localPathPrefixComposerFactory)); 246 return new DefaultLocalRepositoryProvider(localRepositoryProviders); 247 } 248 249 protected RemoteRepositoryManager getRemoteRepositoryManager( 250 UpdatePolicyAnalyzer updatePolicyAnalyzer, ChecksumPolicyProvider checksumPolicyProvider) { 251 return new DefaultRemoteRepositoryManager(updatePolicyAnalyzer, checksumPolicyProvider); 252 } 253 254 protected Map<String, RemoteRepositoryFilterSource> getRemoteRepositoryFilterSources( 255 RepositorySystemLifecycle repositorySystemLifecycle, RepositoryLayoutProvider repositoryLayoutProvider) { 256 HashMap<String, RemoteRepositoryFilterSource> result = new HashMap<>(); 257 result.put( 258 GroupIdRemoteRepositoryFilterSource.NAME, 259 new GroupIdRemoteRepositoryFilterSource(repositorySystemLifecycle)); 260 result.put( 261 PrefixesRemoteRepositoryFilterSource.NAME, 262 new PrefixesRemoteRepositoryFilterSource(repositoryLayoutProvider)); 263 return result; 264 } 265 266 protected RemoteRepositoryFilterManager getRemoteRepositoryFilterManager( 267 Map<String, RemoteRepositoryFilterSource> remoteRepositoryFilterSources) { 268 return new DefaultRemoteRepositoryFilterManager(remoteRepositoryFilterSources); 269 } 270 271 protected Map<String, RepositoryListener> getRepositoryListeners() { 272 return new HashMap<>(); 273 } 274 275 protected RepositoryEventDispatcher getRepositoryEventDispatcher( 276 Map<String, RepositoryListener> repositoryListeners) { 277 return new DefaultRepositoryEventDispatcher(repositoryListeners); 278 } 279 280 protected Map<String, TrustedChecksumsSource> getTrustedChecksumsSources( 281 FileProcessor fileProcessor, 282 LocalPathComposer localPathComposer, 283 RepositorySystemLifecycle repositorySystemLifecycle) { 284 HashMap<String, TrustedChecksumsSource> result = new HashMap<>(); 285 result.put( 286 SparseDirectoryTrustedChecksumsSource.NAME, 287 new SparseDirectoryTrustedChecksumsSource(fileProcessor, localPathComposer)); 288 result.put( 289 SummaryFileTrustedChecksumsSource.NAME, 290 new SummaryFileTrustedChecksumsSource(localPathComposer, repositorySystemLifecycle)); 291 return result; 292 } 293 294 protected Map<String, ProvidedChecksumsSource> getProvidedChecksumsSources( 295 Map<String, TrustedChecksumsSource> trustedChecksumsSources) { 296 HashMap<String, ProvidedChecksumsSource> result = new HashMap<>(); 297 result.put( 298 TrustedToProvidedChecksumsSourceAdapter.NAME, 299 new TrustedToProvidedChecksumsSourceAdapter(trustedChecksumsSources)); 300 return result; 301 } 302 303 protected Map<String, TransporterFactory> getTransporterFactories() { 304 HashMap<String, TransporterFactory> result = new HashMap<>(); 305 result.put(FileTransporterFactory.NAME, new FileTransporterFactory()); 306 result.put(ApacheTransporterFactory.NAME, new ApacheTransporterFactory()); 307 return result; 308 } 309 310 protected TransporterProvider getTransporterProvider(Map<String, TransporterFactory> transporterFactories) { 311 return new DefaultTransporterProvider(transporterFactories); 312 } 313 314 protected BasicRepositoryConnectorFactory getBasicRepositoryConnectorFactory( 315 TransporterProvider transporterProvider, 316 RepositoryLayoutProvider repositoryLayoutProvider, 317 ChecksumPolicyProvider checksumPolicyProvider, 318 FileProcessor fileProcessor, 319 Map<String, ProvidedChecksumsSource> providedChecksumsSources) { 320 return new BasicRepositoryConnectorFactory( 321 transporterProvider, 322 repositoryLayoutProvider, 323 checksumPolicyProvider, 324 fileProcessor, 325 providedChecksumsSources); 326 } 327 328 protected Map<String, RepositoryConnectorFactory> getRepositoryConnectorFactories( 329 BasicRepositoryConnectorFactory basicRepositoryConnectorFactory) { 330 HashMap<String, RepositoryConnectorFactory> result = new HashMap<>(); 331 result.put(BasicRepositoryConnectorFactory.NAME, basicRepositoryConnectorFactory); 332 return result; 333 } 334 335 protected RepositoryConnectorProvider getRepositoryConnectorProvider( 336 Map<String, RepositoryConnectorFactory> repositoryConnectorFactories, 337 RemoteRepositoryFilterManager remoteRepositoryFilterManager) { 338 return new DefaultRepositoryConnectorProvider(repositoryConnectorFactories, remoteRepositoryFilterManager); 339 } 340 341 protected Installer getInstaller( 342 FileProcessor fileProcessor, 343 RepositoryEventDispatcher repositoryEventDispatcher, 344 Map<String, MetadataGeneratorFactory> metadataGeneratorFactories, 345 SyncContextFactory syncContextFactory) { 346 return new DefaultInstaller( 347 fileProcessor, repositoryEventDispatcher, metadataGeneratorFactories, syncContextFactory); 348 } 349 350 @SuppressWarnings("checkstyle:parameternumber") 351 protected Deployer getDeployer( 352 FileProcessor fileProcessor, 353 RepositoryEventDispatcher repositoryEventDispatcher, 354 RepositoryConnectorProvider repositoryConnectorProvider, 355 RemoteRepositoryManager remoteRepositoryManager, 356 UpdateCheckManager updateCheckManager, 357 Map<String, MetadataGeneratorFactory> metadataGeneratorFactories, 358 SyncContextFactory syncContextFactory, 359 OfflineController offlineController) { 360 return new DefaultDeployer( 361 fileProcessor, 362 repositoryEventDispatcher, 363 repositoryConnectorProvider, 364 remoteRepositoryManager, 365 updateCheckManager, 366 metadataGeneratorFactories, 367 syncContextFactory, 368 offlineController); 369 } 370 371 protected Map<String, DependencyCollectorDelegate> getDependencyCollectorDelegates( 372 RemoteRepositoryManager remoteRepositoryManager, 373 ArtifactDescriptorReader artifactDescriptorReader, 374 VersionRangeResolver versionRangeResolver) { 375 HashMap<String, DependencyCollectorDelegate> result = new HashMap<>(); 376 result.put( 377 DfDependencyCollector.NAME, 378 new DfDependencyCollector(remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver)); 379 result.put( 380 BfDependencyCollector.NAME, 381 new BfDependencyCollector(remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver)); 382 return result; 383 } 384 385 protected DependencyCollector getDependencyCollector( 386 Map<String, DependencyCollectorDelegate> dependencyCollectorDelegates) { 387 return new DefaultDependencyCollector(dependencyCollectorDelegates); 388 } 389 390 protected Map<String, ArtifactResolverPostProcessor> getArtifactResolverPostProcessors( 391 ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector, 392 Map<String, TrustedChecksumsSource> trustedChecksumsSources) { 393 HashMap<String, ArtifactResolverPostProcessor> result = new HashMap<>(); 394 result.put( 395 TrustedChecksumsArtifactResolverPostProcessor.NAME, 396 new TrustedChecksumsArtifactResolverPostProcessor( 397 checksumAlgorithmFactorySelector, trustedChecksumsSources)); 398 return result; 399 } 400 401 @SuppressWarnings("checkstyle:parameternumber") 402 protected ArtifactResolver getArtifactResolver( 403 FileProcessor fileProcessor, 404 RepositoryEventDispatcher repositoryEventDispatcher, 405 VersionResolver versionResolver, 406 UpdateCheckManager updateCheckManager, 407 RepositoryConnectorProvider repositoryConnectorProvider, 408 RemoteRepositoryManager remoteRepositoryManager, 409 SyncContextFactory syncContextFactory, 410 OfflineController offlineController, 411 Map<String, ArtifactResolverPostProcessor> artifactResolverPostProcessors, 412 RemoteRepositoryFilterManager remoteRepositoryFilterManager) { 413 return new DefaultArtifactResolver( 414 fileProcessor, 415 repositoryEventDispatcher, 416 versionResolver, 417 updateCheckManager, 418 repositoryConnectorProvider, 419 remoteRepositoryManager, 420 syncContextFactory, 421 offlineController, 422 artifactResolverPostProcessors, 423 remoteRepositoryFilterManager); 424 } 425 426 protected MetadataResolver getMetadataResolver( 427 RepositoryEventDispatcher repositoryEventDispatcher, 428 UpdateCheckManager updateCheckManager, 429 RepositoryConnectorProvider repositoryConnectorProvider, 430 RemoteRepositoryManager remoteRepositoryManager, 431 SyncContextFactory syncContextFactory, 432 OfflineController offlineController, 433 RemoteRepositoryFilterManager remoteRepositoryFilterManager) { 434 return new DefaultMetadataResolver( 435 repositoryEventDispatcher, 436 updateCheckManager, 437 repositoryConnectorProvider, 438 remoteRepositoryManager, 439 syncContextFactory, 440 offlineController, 441 remoteRepositoryFilterManager); 442 } 443 444 protected Map<String, VersionScheme> getVersionSchemes() { 445 HashMap<String, VersionScheme> result = new HashMap<>(); 446 result.put(GenericVersionSchemeProvider.NAME, new GenericVersionScheme()); 447 return result; 448 } 449 450 protected VersionSchemeSelector getVersionSchemeSelector(Map<String, VersionScheme> versionSchemes) { 451 return new DefaultVersionSchemeSelector(versionSchemes); 452 } 453 454 // Maven provided 455 456 protected Map<String, MetadataGeneratorFactory> getMetadataGeneratorFactories() { 457 // from maven-resolver-provider 458 HashMap<String, MetadataGeneratorFactory> result = new HashMap<>(); 459 result.put(PluginsMetadataGeneratorFactory.NAME, new PluginsMetadataGeneratorFactory()); 460 result.put(VersionsMetadataGeneratorFactory.NAME, new VersionsMetadataGeneratorFactory()); 461 result.put(SnapshotMetadataGeneratorFactory.NAME, new SnapshotMetadataGeneratorFactory()); 462 return result; 463 } 464 465 protected ArtifactDescriptorReader getArtifactDescriptorReader( 466 RemoteRepositoryManager remoteRepositoryManager, 467 VersionResolver versionResolver, 468 VersionRangeResolver versionRangeResolver, 469 ArtifactResolver artifactResolver, 470 ModelBuilder modelBuilder, 471 RepositoryEventDispatcher repositoryEventDispatcher, 472 ModelCacheFactory modelCacheFactory) { 473 // from maven-resolver-provider 474 return new DefaultArtifactDescriptorReader( 475 remoteRepositoryManager, 476 versionResolver, 477 versionRangeResolver, 478 artifactResolver, 479 modelBuilder, 480 repositoryEventDispatcher, 481 modelCacheFactory); 482 } 483 484 protected VersionResolver getVersionResolver( 485 MetadataResolver metadataResolver, 486 SyncContextFactory syncContextFactory, 487 RepositoryEventDispatcher repositoryEventDispatcher) { 488 // from maven-resolver-provider 489 return new DefaultVersionResolver(metadataResolver, syncContextFactory, repositoryEventDispatcher); 490 } 491 492 protected VersionRangeResolver getVersionRangeResolver( 493 MetadataResolver metadataResolver, 494 SyncContextFactory syncContextFactory, 495 RepositoryEventDispatcher repositoryEventDispatcher, 496 VersionSchemeSelector versionSchemeSelector) { 497 // from maven-resolver-provider 498 // TODO: hack here, until maven bits does not pick this change 499 return new DefaultVersionRangeResolver( 500 metadataResolver, 501 syncContextFactory, 502 repositoryEventDispatcher, 503 versionSchemeSelector.selectVersionScheme(GenericVersionSchemeProvider.NAME)); 504 } 505 506 protected ModelBuilder getModelBuilder() { 507 // from maven-model-builder 508 return new DefaultModelBuilderFactory().newInstance(); 509 } 510 511 protected ModelCacheFactory getModelCacheFactory() { 512 // from maven-resolver-provider 513 return new DefaultModelCacheFactory(); 514 } 515 516 @Override 517 public RepositorySystem get() { 518 FileProcessor fileProcessor = getFileProcessor(); 519 TrackingFileManager trackingFileManager = getTrackingFileManager(); 520 LocalPathComposer localPathComposer = getLocalPathComposer(); 521 LocalPathPrefixComposerFactory localPathPrefixComposerFactory = getLocalPathPrefixComposerFactory(); 522 RepositorySystemLifecycle repositorySystemLifecycle = getRepositorySystemLifecycle(); 523 OfflineController offlineController = getOfflineController(); 524 UpdatePolicyAnalyzer updatePolicyAnalyzer = getUpdatePolicyAnalyzer(); 525 ChecksumPolicyProvider checksumPolicyProvider = getChecksumPolicyProvider(); 526 527 UpdateCheckManager updateCheckManager = getUpdateCheckManager(trackingFileManager, updatePolicyAnalyzer); 528 529 Map<String, NamedLockFactory> namedLockFactories = getNamedLockFactories(); 530 Map<String, NameMapper> nameMappers = getNameMappers(); 531 NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory = 532 getNamedLockFactoryAdapterFactory(namedLockFactories, nameMappers, repositorySystemLifecycle); 533 SyncContextFactory syncContextFactory = getSyncContextFactory(namedLockFactoryAdapterFactory); 534 535 Map<String, ChecksumAlgorithmFactory> checksumAlgorithmFactories = getChecksumAlgorithmFactories(); 536 ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector = 537 getChecksumAlgorithmFactorySelector(checksumAlgorithmFactories); 538 539 Map<String, RepositoryLayoutFactory> repositoryLayoutFactories = 540 getRepositoryLayoutFactories(checksumAlgorithmFactorySelector); 541 RepositoryLayoutProvider repositoryLayoutProvider = getRepositoryLayoutProvider(repositoryLayoutFactories); 542 543 LocalRepositoryProvider localRepositoryProvider = 544 getLocalRepositoryProvider(localPathComposer, trackingFileManager, localPathPrefixComposerFactory); 545 546 RemoteRepositoryManager remoteRepositoryManager = 547 getRemoteRepositoryManager(updatePolicyAnalyzer, checksumPolicyProvider); 548 Map<String, RemoteRepositoryFilterSource> remoteRepositoryFilterSources = 549 getRemoteRepositoryFilterSources(repositorySystemLifecycle, repositoryLayoutProvider); 550 RemoteRepositoryFilterManager remoteRepositoryFilterManager = 551 getRemoteRepositoryFilterManager(remoteRepositoryFilterSources); 552 553 Map<String, RepositoryListener> repositoryListeners = getRepositoryListeners(); 554 RepositoryEventDispatcher repositoryEventDispatcher = getRepositoryEventDispatcher(repositoryListeners); 555 556 Map<String, TrustedChecksumsSource> trustedChecksumsSources = 557 getTrustedChecksumsSources(fileProcessor, localPathComposer, repositorySystemLifecycle); 558 Map<String, ProvidedChecksumsSource> providedChecksumsSources = 559 getProvidedChecksumsSources(trustedChecksumsSources); 560 561 Map<String, TransporterFactory> transporterFactories = getTransporterFactories(); 562 TransporterProvider transporterProvider = getTransporterProvider(transporterFactories); 563 564 BasicRepositoryConnectorFactory basic = getBasicRepositoryConnectorFactory( 565 transporterProvider, 566 repositoryLayoutProvider, 567 checksumPolicyProvider, 568 fileProcessor, 569 providedChecksumsSources); 570 Map<String, RepositoryConnectorFactory> repositoryConnectorFactories = getRepositoryConnectorFactories(basic); 571 RepositoryConnectorProvider repositoryConnectorProvider = 572 getRepositoryConnectorProvider(repositoryConnectorFactories, remoteRepositoryFilterManager); 573 574 Map<String, MetadataGeneratorFactory> metadataGeneratorFactories = getMetadataGeneratorFactories(); 575 576 Installer installer = 577 getInstaller(fileProcessor, repositoryEventDispatcher, metadataGeneratorFactories, syncContextFactory); 578 Deployer deployer = getDeployer( 579 fileProcessor, 580 repositoryEventDispatcher, 581 repositoryConnectorProvider, 582 remoteRepositoryManager, 583 updateCheckManager, 584 metadataGeneratorFactories, 585 syncContextFactory, 586 offlineController); 587 588 MetadataResolver metadataResolver = getMetadataResolver( 589 repositoryEventDispatcher, 590 updateCheckManager, 591 repositoryConnectorProvider, 592 remoteRepositoryManager, 593 syncContextFactory, 594 offlineController, 595 remoteRepositoryFilterManager); 596 597 Map<String, VersionScheme> versionSchemes = getVersionSchemes(); 598 VersionSchemeSelector versionSchemeSelector = getVersionSchemeSelector(versionSchemes); 599 VersionResolver versionResolver = 600 getVersionResolver(metadataResolver, syncContextFactory, repositoryEventDispatcher); 601 VersionRangeResolver versionRangeResolver = getVersionRangeResolver( 602 metadataResolver, syncContextFactory, repositoryEventDispatcher, versionSchemeSelector); 603 604 Map<String, ArtifactResolverPostProcessor> artifactResolverPostProcessors = 605 getArtifactResolverPostProcessors(checksumAlgorithmFactorySelector, trustedChecksumsSources); 606 ArtifactResolver artifactResolver = getArtifactResolver( 607 fileProcessor, 608 repositoryEventDispatcher, 609 versionResolver, 610 updateCheckManager, 611 repositoryConnectorProvider, 612 remoteRepositoryManager, 613 syncContextFactory, 614 offlineController, 615 artifactResolverPostProcessors, 616 remoteRepositoryFilterManager); 617 618 ModelBuilder modelBuilder = getModelBuilder(); 619 ModelCacheFactory modelCacheFactory = getModelCacheFactory(); 620 621 ArtifactDescriptorReader artifactDescriptorReader = getArtifactDescriptorReader( 622 remoteRepositoryManager, 623 versionResolver, 624 versionRangeResolver, 625 artifactResolver, 626 modelBuilder, 627 repositoryEventDispatcher, 628 modelCacheFactory); 629 630 Map<String, DependencyCollectorDelegate> dependencyCollectorDelegates = getDependencyCollectorDelegates( 631 remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver); 632 DependencyCollector dependencyCollector = getDependencyCollector(dependencyCollectorDelegates); 633 634 return new DefaultRepositorySystem( 635 versionResolver, 636 versionRangeResolver, 637 artifactResolver, 638 metadataResolver, 639 artifactDescriptorReader, 640 dependencyCollector, 641 installer, 642 deployer, 643 localRepositoryProvider, 644 syncContextFactory, 645 remoteRepositoryManager, 646 repositorySystemLifecycle); 647 } 648}