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