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.LinkedHashMap; 023import java.util.Map; 024import java.util.concurrent.atomic.AtomicBoolean; 025import java.util.function.Supplier; 026 027import org.apache.maven.model.building.DefaultModelBuilderFactory; 028import org.apache.maven.model.building.ModelBuilder; 029import org.apache.maven.repository.internal.*; 030import org.apache.maven.repository.internal.relocation.DistributionManagementArtifactRelocationSource; 031import org.apache.maven.repository.internal.relocation.UserPropertiesArtifactRelocationSource; 032import org.eclipse.aether.RepositoryListener; 033import org.eclipse.aether.RepositorySystem; 034import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; 035import org.eclipse.aether.impl.ArtifactDescriptorReader; 036import org.eclipse.aether.impl.ArtifactResolver; 037import org.eclipse.aether.impl.DependencyCollector; 038import org.eclipse.aether.impl.Deployer; 039import org.eclipse.aether.impl.Installer; 040import org.eclipse.aether.impl.LocalRepositoryProvider; 041import org.eclipse.aether.impl.MetadataGeneratorFactory; 042import org.eclipse.aether.impl.MetadataResolver; 043import org.eclipse.aether.impl.OfflineController; 044import org.eclipse.aether.impl.RemoteRepositoryFilterManager; 045import org.eclipse.aether.impl.RemoteRepositoryManager; 046import org.eclipse.aether.impl.RepositoryConnectorProvider; 047import org.eclipse.aether.impl.RepositoryEventDispatcher; 048import org.eclipse.aether.impl.RepositorySystemLifecycle; 049import org.eclipse.aether.impl.UpdateCheckManager; 050import org.eclipse.aether.impl.UpdatePolicyAnalyzer; 051import org.eclipse.aether.impl.VersionRangeResolver; 052import org.eclipse.aether.impl.VersionResolver; 053import org.eclipse.aether.internal.impl.*; 054import org.eclipse.aether.internal.impl.checksum.DefaultChecksumAlgorithmFactorySelector; 055import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory; 056import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory; 057import org.eclipse.aether.internal.impl.checksum.Sha256ChecksumAlgorithmFactory; 058import org.eclipse.aether.internal.impl.checksum.Sha512ChecksumAlgorithmFactory; 059import org.eclipse.aether.internal.impl.checksum.SparseDirectoryTrustedChecksumsSource; 060import org.eclipse.aether.internal.impl.checksum.SummaryFileTrustedChecksumsSource; 061import org.eclipse.aether.internal.impl.checksum.TrustedToProvidedChecksumsSourceAdapter; 062import org.eclipse.aether.internal.impl.collect.DefaultDependencyCollector; 063import org.eclipse.aether.internal.impl.collect.DependencyCollectorDelegate; 064import org.eclipse.aether.internal.impl.collect.bf.BfDependencyCollector; 065import org.eclipse.aether.internal.impl.collect.df.DfDependencyCollector; 066import org.eclipse.aether.internal.impl.filter.DefaultRemoteRepositoryFilterManager; 067import org.eclipse.aether.internal.impl.filter.GroupIdRemoteRepositoryFilterSource; 068import org.eclipse.aether.internal.impl.filter.PrefixesRemoteRepositoryFilterSource; 069import org.eclipse.aether.internal.impl.resolution.TrustedChecksumsArtifactResolverPostProcessor; 070import org.eclipse.aether.internal.impl.synccontext.DefaultSyncContextFactory; 071import org.eclipse.aether.internal.impl.synccontext.named.NameMapper; 072import org.eclipse.aether.internal.impl.synccontext.named.NameMappers; 073import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactory; 074import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl; 075import org.eclipse.aether.internal.impl.transport.http.DefaultChecksumExtractor; 076import org.eclipse.aether.internal.impl.transport.http.Nx2ChecksumExtractor; 077import org.eclipse.aether.internal.impl.transport.http.XChecksumExtractor; 078import org.eclipse.aether.named.NamedLockFactory; 079import org.eclipse.aether.named.providers.FileLockNamedLockFactory; 080import org.eclipse.aether.named.providers.LocalReadWriteLockNamedLockFactory; 081import org.eclipse.aether.named.providers.LocalSemaphoreNamedLockFactory; 082import org.eclipse.aether.named.providers.NoopNamedLockFactory; 083import org.eclipse.aether.spi.checksums.ProvidedChecksumsSource; 084import org.eclipse.aether.spi.checksums.TrustedChecksumsSource; 085import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; 086import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory; 087import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector; 088import org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider; 089import org.eclipse.aether.spi.connector.filter.RemoteRepositoryFilterSource; 090import org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory; 091import org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider; 092import org.eclipse.aether.spi.connector.transport.TransporterFactory; 093import org.eclipse.aether.spi.connector.transport.TransporterProvider; 094import org.eclipse.aether.spi.connector.transport.http.ChecksumExtractor; 095import org.eclipse.aether.spi.connector.transport.http.ChecksumExtractorStrategy; 096import org.eclipse.aether.spi.io.FileProcessor; 097import org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory; 098import org.eclipse.aether.spi.resolution.ArtifactResolverPostProcessor; 099import org.eclipse.aether.spi.synccontext.SyncContextFactory; 100import org.eclipse.aether.transport.apache.ApacheTransporterFactory; 101import org.eclipse.aether.transport.file.FileTransporterFactory; 102import org.eclipse.aether.util.version.GenericVersionScheme; 103import org.eclipse.aether.version.VersionScheme; 104 105/** 106 * A simple memorizing {@link Supplier} of {@link org.eclipse.aether.RepositorySystem} instance, that on first call 107 * supplies lazily constructed instance, and on each subsequent call same instance. Hence, this instance should be 108 * thrown away immediately once repository system was created and there is no need for more instances. If new 109 * repository system instance needed, new instance of this class must be created. For proper shut down of returned 110 * repository system instance(s) use {@link RepositorySystem#shutdown()} method on supplied instance(s). 111 * <p> 112 * Since Resolver 2.0 this class offers access to various components via public getters, and allows even partial object 113 * graph construction. 114 * <p> 115 * Extend this class {@code createXXX()} methods and override to customize, if needed. The contract of this class makes 116 * sure that these (potentially overridden) methods are invoked only once, and instance created by those methods are 117 * memorized and kept as long as supplier instance is kept open. 118 * <p> 119 * This class is not thread safe and must be used from one thread only, while the constructed {@link RepositorySystem} 120 * is thread safe. 121 * <p> 122 * Important: Given the instance of supplier memorizes the supplier {@link RepositorySystem} instance it supplies, 123 * their lifecycle is shared as well: once supplied repository system is shut-down, this instance becomes closed as 124 * well. Any subsequent {@code getXXX} method invocation attempt will fail with {@link IllegalStateException}. 125 * 126 * @since 1.9.15 127 */ 128public class RepositorySystemSupplier implements Supplier<RepositorySystem> { 129 private final AtomicBoolean closed = new AtomicBoolean(false); 130 131 public RepositorySystemSupplier() {} 132 133 private void checkClosed() { 134 if (closed.get()) { 135 throw new IllegalStateException("Supplier is closed"); 136 } 137 } 138 139 private FileProcessor fileProcessor; 140 141 public final FileProcessor getFileProcessor() { 142 checkClosed(); 143 if (fileProcessor == null) { 144 fileProcessor = createFileProcessor(); 145 } 146 return fileProcessor; 147 } 148 149 protected FileProcessor createFileProcessor() { 150 return new DefaultFileProcessor(); 151 } 152 153 private TrackingFileManager trackingFileManager; 154 155 public final TrackingFileManager getTrackingFileManager() { 156 checkClosed(); 157 if (trackingFileManager == null) { 158 trackingFileManager = createTrackingFileManager(); 159 } 160 return trackingFileManager; 161 } 162 163 protected TrackingFileManager createTrackingFileManager() { 164 return new DefaultTrackingFileManager(); 165 } 166 167 private LocalPathComposer localPathComposer; 168 169 public final LocalPathComposer getLocalPathComposer() { 170 checkClosed(); 171 if (localPathComposer == null) { 172 localPathComposer = createLocalPathComposer(); 173 } 174 return localPathComposer; 175 } 176 177 protected LocalPathComposer createLocalPathComposer() { 178 return new DefaultLocalPathComposer(); 179 } 180 181 private LocalPathPrefixComposerFactory localPathPrefixComposerFactory; 182 183 public final LocalPathPrefixComposerFactory getLocalPathPrefixComposerFactory() { 184 checkClosed(); 185 if (localPathPrefixComposerFactory == null) { 186 localPathPrefixComposerFactory = createLocalPathPrefixComposerFactory(); 187 } 188 return localPathPrefixComposerFactory; 189 } 190 191 protected LocalPathPrefixComposerFactory createLocalPathPrefixComposerFactory() { 192 return new DefaultLocalPathPrefixComposerFactory(); 193 } 194 195 private RepositorySystemLifecycle repositorySystemLifecycle; 196 197 public final RepositorySystemLifecycle getRepositorySystemLifecycle() { 198 checkClosed(); 199 if (repositorySystemLifecycle == null) { 200 repositorySystemLifecycle = createRepositorySystemLifecycle(); 201 repositorySystemLifecycle.addOnSystemEndedHandler(() -> closed.set(true)); 202 } 203 return repositorySystemLifecycle; 204 } 205 206 protected RepositorySystemLifecycle createRepositorySystemLifecycle() { 207 return new DefaultRepositorySystemLifecycle(); 208 } 209 210 private OfflineController offlineController; 211 212 public final OfflineController getOfflineController() { 213 checkClosed(); 214 if (offlineController == null) { 215 offlineController = createOfflineController(); 216 } 217 return offlineController; 218 } 219 220 protected OfflineController createOfflineController() { 221 return new DefaultOfflineController(); 222 } 223 224 private UpdatePolicyAnalyzer updatePolicyAnalyzer; 225 226 public final UpdatePolicyAnalyzer getUpdatePolicyAnalyzer() { 227 checkClosed(); 228 if (updatePolicyAnalyzer == null) { 229 updatePolicyAnalyzer = createUpdatePolicyAnalyzer(); 230 } 231 return updatePolicyAnalyzer; 232 } 233 234 protected UpdatePolicyAnalyzer createUpdatePolicyAnalyzer() { 235 return new DefaultUpdatePolicyAnalyzer(); 236 } 237 238 private ChecksumPolicyProvider checksumPolicyProvider; 239 240 public final ChecksumPolicyProvider getChecksumPolicyProvider() { 241 checkClosed(); 242 if (checksumPolicyProvider == null) { 243 checksumPolicyProvider = createChecksumPolicyProvider(); 244 } 245 return checksumPolicyProvider; 246 } 247 248 protected ChecksumPolicyProvider createChecksumPolicyProvider() { 249 return new DefaultChecksumPolicyProvider(); 250 } 251 252 private UpdateCheckManager updateCheckManager; 253 254 public final UpdateCheckManager getUpdateCheckManager() { 255 checkClosed(); 256 if (updateCheckManager == null) { 257 updateCheckManager = createUpdateCheckManager(); 258 } 259 return updateCheckManager; 260 } 261 262 protected UpdateCheckManager createUpdateCheckManager() { 263 return new DefaultUpdateCheckManager(getTrackingFileManager(), getUpdatePolicyAnalyzer()); 264 } 265 266 private Map<String, NamedLockFactory> namedLockFactories; 267 268 public final Map<String, NamedLockFactory> getNamedLockFactories() { 269 checkClosed(); 270 if (namedLockFactories == null) { 271 namedLockFactories = createNamedLockFactories(); 272 } 273 return namedLockFactories; 274 } 275 276 protected Map<String, NamedLockFactory> createNamedLockFactories() { 277 HashMap<String, NamedLockFactory> result = new HashMap<>(); 278 result.put(NoopNamedLockFactory.NAME, new NoopNamedLockFactory()); 279 result.put(LocalReadWriteLockNamedLockFactory.NAME, new LocalReadWriteLockNamedLockFactory()); 280 result.put(LocalSemaphoreNamedLockFactory.NAME, new LocalSemaphoreNamedLockFactory()); 281 result.put(FileLockNamedLockFactory.NAME, new FileLockNamedLockFactory()); 282 return result; 283 } 284 285 private Map<String, NameMapper> nameMappers; 286 287 public final Map<String, NameMapper> getNameMappers() { 288 checkClosed(); 289 if (nameMappers == null) { 290 nameMappers = createNameMappers(); 291 } 292 return nameMappers; 293 } 294 295 protected Map<String, NameMapper> createNameMappers() { 296 HashMap<String, NameMapper> result = new HashMap<>(); 297 result.put(NameMappers.STATIC_NAME, NameMappers.staticNameMapper()); 298 result.put(NameMappers.GAV_NAME, NameMappers.gavNameMapper()); 299 result.put(NameMappers.DISCRIMINATING_NAME, NameMappers.discriminatingNameMapper()); 300 result.put(NameMappers.FILE_GAV_NAME, NameMappers.fileGavNameMapper()); 301 result.put(NameMappers.FILE_HGAV_NAME, NameMappers.fileHashingGavNameMapper()); 302 return result; 303 } 304 305 private NamedLockFactoryAdapterFactory namedLockFactoryAdapterFactory; 306 307 public final NamedLockFactoryAdapterFactory getNamedLockFactoryAdapterFactory() { 308 checkClosed(); 309 if (namedLockFactoryAdapterFactory == null) { 310 namedLockFactoryAdapterFactory = createNamedLockFactoryAdapterFactory(); 311 } 312 return namedLockFactoryAdapterFactory; 313 } 314 315 protected NamedLockFactoryAdapterFactory createNamedLockFactoryAdapterFactory() { 316 return new NamedLockFactoryAdapterFactoryImpl( 317 getNamedLockFactories(), getNameMappers(), getRepositorySystemLifecycle()); 318 } 319 320 private SyncContextFactory syncContextFactory; 321 322 public final SyncContextFactory getSyncContextFactory() { 323 checkClosed(); 324 if (syncContextFactory == null) { 325 syncContextFactory = createSyncContextFactory(); 326 } 327 return syncContextFactory; 328 } 329 330 protected SyncContextFactory createSyncContextFactory() { 331 return new DefaultSyncContextFactory(getNamedLockFactoryAdapterFactory()); 332 } 333 334 private Map<String, ChecksumAlgorithmFactory> checksumAlgorithmFactories; 335 336 public final Map<String, ChecksumAlgorithmFactory> getChecksumAlgorithmFactories() { 337 checkClosed(); 338 if (checksumAlgorithmFactories == null) { 339 checksumAlgorithmFactories = createChecksumAlgorithmFactories(); 340 } 341 return checksumAlgorithmFactories; 342 } 343 344 protected Map<String, ChecksumAlgorithmFactory> createChecksumAlgorithmFactories() { 345 HashMap<String, ChecksumAlgorithmFactory> result = new HashMap<>(); 346 result.put(Sha512ChecksumAlgorithmFactory.NAME, new Sha512ChecksumAlgorithmFactory()); 347 result.put(Sha256ChecksumAlgorithmFactory.NAME, new Sha256ChecksumAlgorithmFactory()); 348 result.put(Sha1ChecksumAlgorithmFactory.NAME, new Sha1ChecksumAlgorithmFactory()); 349 result.put(Md5ChecksumAlgorithmFactory.NAME, new Md5ChecksumAlgorithmFactory()); 350 return result; 351 } 352 353 private ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector; 354 355 public final ChecksumAlgorithmFactorySelector getChecksumAlgorithmFactorySelector() { 356 checkClosed(); 357 if (checksumAlgorithmFactorySelector == null) { 358 checksumAlgorithmFactorySelector = createChecksumAlgorithmFactorySelector(); 359 } 360 return checksumAlgorithmFactorySelector; 361 } 362 363 protected ChecksumAlgorithmFactorySelector createChecksumAlgorithmFactorySelector() { 364 return new DefaultChecksumAlgorithmFactorySelector(getChecksumAlgorithmFactories()); 365 } 366 367 private Map<String, RepositoryLayoutFactory> repositoryLayoutFactories; 368 369 public final Map<String, RepositoryLayoutFactory> getRepositoryLayoutFactories() { 370 checkClosed(); 371 if (repositoryLayoutFactories == null) { 372 repositoryLayoutFactories = createRepositoryLayoutFactories(); 373 } 374 return repositoryLayoutFactories; 375 } 376 377 protected Map<String, RepositoryLayoutFactory> createRepositoryLayoutFactories() { 378 HashMap<String, RepositoryLayoutFactory> result = new HashMap<>(); 379 result.put( 380 Maven2RepositoryLayoutFactory.NAME, 381 new Maven2RepositoryLayoutFactory(getChecksumAlgorithmFactorySelector())); 382 return result; 383 } 384 385 private RepositoryLayoutProvider repositoryLayoutProvider; 386 387 public final RepositoryLayoutProvider getRepositoryLayoutProvider() { 388 checkClosed(); 389 if (repositoryLayoutProvider == null) { 390 repositoryLayoutProvider = createRepositoryLayoutProvider(); 391 } 392 return repositoryLayoutProvider; 393 } 394 395 protected RepositoryLayoutProvider createRepositoryLayoutProvider() { 396 return new DefaultRepositoryLayoutProvider(getRepositoryLayoutFactories()); 397 } 398 399 private LocalRepositoryProvider localRepositoryProvider; 400 401 public final LocalRepositoryProvider getLocalRepositoryProvider() { 402 checkClosed(); 403 if (localRepositoryProvider == null) { 404 localRepositoryProvider = createLocalRepositoryProvider(); 405 } 406 return localRepositoryProvider; 407 } 408 409 protected LocalRepositoryProvider createLocalRepositoryProvider() { 410 LocalPathComposer localPathComposer = getLocalPathComposer(); 411 HashMap<String, LocalRepositoryManagerFactory> localRepositoryProviders = new HashMap<>(2); 412 localRepositoryProviders.put( 413 SimpleLocalRepositoryManagerFactory.NAME, new SimpleLocalRepositoryManagerFactory(localPathComposer)); 414 localRepositoryProviders.put( 415 EnhancedLocalRepositoryManagerFactory.NAME, 416 new EnhancedLocalRepositoryManagerFactory( 417 localPathComposer, getTrackingFileManager(), getLocalPathPrefixComposerFactory())); 418 return new DefaultLocalRepositoryProvider(localRepositoryProviders); 419 } 420 421 private RemoteRepositoryManager remoteRepositoryManager; 422 423 public final RemoteRepositoryManager getRemoteRepositoryManager() { 424 checkClosed(); 425 if (remoteRepositoryManager == null) { 426 remoteRepositoryManager = createRemoteRepositoryManager(); 427 } 428 return remoteRepositoryManager; 429 } 430 431 protected RemoteRepositoryManager createRemoteRepositoryManager() { 432 return new DefaultRemoteRepositoryManager(getUpdatePolicyAnalyzer(), getChecksumPolicyProvider()); 433 } 434 435 private Map<String, RemoteRepositoryFilterSource> remoteRepositoryFilterSources; 436 437 public final Map<String, RemoteRepositoryFilterSource> getRemoteRepositoryFilterSources() { 438 checkClosed(); 439 if (remoteRepositoryFilterSources == null) { 440 remoteRepositoryFilterSources = createRemoteRepositoryFilterSources(); 441 } 442 return remoteRepositoryFilterSources; 443 } 444 445 protected Map<String, RemoteRepositoryFilterSource> createRemoteRepositoryFilterSources() { 446 HashMap<String, RemoteRepositoryFilterSource> result = new HashMap<>(); 447 result.put( 448 GroupIdRemoteRepositoryFilterSource.NAME, 449 new GroupIdRemoteRepositoryFilterSource(getRepositorySystemLifecycle())); 450 result.put( 451 PrefixesRemoteRepositoryFilterSource.NAME, 452 new PrefixesRemoteRepositoryFilterSource(getRepositoryLayoutProvider())); 453 return result; 454 } 455 456 private RemoteRepositoryFilterManager remoteRepositoryFilterManager; 457 458 public final RemoteRepositoryFilterManager getRemoteRepositoryFilterManager() { 459 checkClosed(); 460 if (remoteRepositoryFilterManager == null) { 461 remoteRepositoryFilterManager = createRemoteRepositoryFilterManager(); 462 } 463 return remoteRepositoryFilterManager; 464 } 465 466 protected RemoteRepositoryFilterManager createRemoteRepositoryFilterManager() { 467 return new DefaultRemoteRepositoryFilterManager(getRemoteRepositoryFilterSources()); 468 } 469 470 private Map<String, RepositoryListener> repositoryListeners; 471 472 public final Map<String, RepositoryListener> getRepositoryListeners() { 473 checkClosed(); 474 if (repositoryListeners == null) { 475 repositoryListeners = createRepositoryListeners(); 476 } 477 return repositoryListeners; 478 } 479 480 protected Map<String, RepositoryListener> createRepositoryListeners() { 481 return new HashMap<>(); 482 } 483 484 private RepositoryEventDispatcher repositoryEventDispatcher; 485 486 public final RepositoryEventDispatcher getRepositoryEventDispatcher() { 487 checkClosed(); 488 if (repositoryEventDispatcher == null) { 489 repositoryEventDispatcher = createRepositoryEventDispatcher(); 490 } 491 return repositoryEventDispatcher; 492 } 493 494 protected RepositoryEventDispatcher createRepositoryEventDispatcher() { 495 return new DefaultRepositoryEventDispatcher(getRepositoryListeners()); 496 } 497 498 private Map<String, TrustedChecksumsSource> trustedChecksumsSources; 499 500 public final Map<String, TrustedChecksumsSource> getTrustedChecksumsSources() { 501 checkClosed(); 502 if (trustedChecksumsSources == null) { 503 trustedChecksumsSources = createTrustedChecksumsSources(); 504 } 505 return trustedChecksumsSources; 506 } 507 508 protected Map<String, TrustedChecksumsSource> createTrustedChecksumsSources() { 509 HashMap<String, TrustedChecksumsSource> result = new HashMap<>(); 510 result.put( 511 SparseDirectoryTrustedChecksumsSource.NAME, 512 new SparseDirectoryTrustedChecksumsSource(getFileProcessor(), getLocalPathComposer())); 513 result.put( 514 SummaryFileTrustedChecksumsSource.NAME, 515 new SummaryFileTrustedChecksumsSource(getLocalPathComposer(), getRepositorySystemLifecycle())); 516 return result; 517 } 518 519 private Map<String, ProvidedChecksumsSource> providedChecksumsSources; 520 521 public final Map<String, ProvidedChecksumsSource> getProvidedChecksumsSources() { 522 checkClosed(); 523 if (providedChecksumsSources == null) { 524 providedChecksumsSources = createProvidedChecksumsSources(); 525 } 526 return providedChecksumsSources; 527 } 528 529 protected Map<String, ProvidedChecksumsSource> createProvidedChecksumsSources() { 530 HashMap<String, ProvidedChecksumsSource> result = new HashMap<>(); 531 result.put( 532 TrustedToProvidedChecksumsSourceAdapter.NAME, 533 new TrustedToProvidedChecksumsSourceAdapter(getTrustedChecksumsSources())); 534 return result; 535 } 536 537 private Map<String, ChecksumExtractorStrategy> checksumExtractorStrategies; 538 539 public final Map<String, ChecksumExtractorStrategy> getChecksumExtractorStrategies() { 540 checkClosed(); 541 if (checksumExtractorStrategies == null) { 542 checksumExtractorStrategies = createChecksumExtractorStrategies(); 543 } 544 return checksumExtractorStrategies; 545 } 546 547 protected Map<String, ChecksumExtractorStrategy> createChecksumExtractorStrategies() { 548 HashMap<String, ChecksumExtractorStrategy> result = new HashMap<>(); 549 result.put(XChecksumExtractor.NAME, new XChecksumExtractor()); 550 result.put(Nx2ChecksumExtractor.NAME, new Nx2ChecksumExtractor()); 551 return result; 552 } 553 554 private ChecksumExtractor checksumExtractor; 555 556 public final ChecksumExtractor getChecksumExtractor() { 557 checkClosed(); 558 if (checksumExtractor == null) { 559 checksumExtractor = createChecksumExtractor(); 560 } 561 return checksumExtractor; 562 } 563 564 protected ChecksumExtractor createChecksumExtractor() { 565 return new DefaultChecksumExtractor(getChecksumExtractorStrategies()); 566 } 567 568 private Map<String, TransporterFactory> transporterFactories; 569 570 public final Map<String, TransporterFactory> getTransporterFactories() { 571 checkClosed(); 572 if (transporterFactories == null) { 573 transporterFactories = createTransporterFactories(); 574 } 575 return transporterFactories; 576 } 577 578 protected Map<String, TransporterFactory> createTransporterFactories() { 579 HashMap<String, TransporterFactory> result = new HashMap<>(); 580 result.put(FileTransporterFactory.NAME, new FileTransporterFactory()); 581 result.put(ApacheTransporterFactory.NAME, new ApacheTransporterFactory(getChecksumExtractor())); 582 return result; 583 } 584 585 private TransporterProvider transporterProvider; 586 587 public final TransporterProvider getTransporterProvider() { 588 checkClosed(); 589 if (transporterProvider == null) { 590 transporterProvider = createTransporterProvider(); 591 } 592 return transporterProvider; 593 } 594 595 protected TransporterProvider createTransporterProvider() { 596 return new DefaultTransporterProvider(getTransporterFactories()); 597 } 598 599 private BasicRepositoryConnectorFactory basicRepositoryConnectorFactory; 600 601 public final BasicRepositoryConnectorFactory getBasicRepositoryConnectorFactory() { 602 checkClosed(); 603 if (basicRepositoryConnectorFactory == null) { 604 basicRepositoryConnectorFactory = createBasicRepositoryConnectorFactory(); 605 } 606 return basicRepositoryConnectorFactory; 607 } 608 609 protected BasicRepositoryConnectorFactory createBasicRepositoryConnectorFactory() { 610 return new BasicRepositoryConnectorFactory( 611 getTransporterProvider(), 612 getRepositoryLayoutProvider(), 613 getChecksumPolicyProvider(), 614 getFileProcessor(), 615 getProvidedChecksumsSources()); 616 } 617 618 private Map<String, RepositoryConnectorFactory> repositoryConnectorFactories; 619 620 public final Map<String, RepositoryConnectorFactory> getRepositoryConnectorFactories() { 621 checkClosed(); 622 if (repositoryConnectorFactories == null) { 623 repositoryConnectorFactories = createRepositoryConnectorFactories(); 624 } 625 return repositoryConnectorFactories; 626 } 627 628 protected Map<String, RepositoryConnectorFactory> createRepositoryConnectorFactories() { 629 HashMap<String, RepositoryConnectorFactory> result = new HashMap<>(); 630 result.put(BasicRepositoryConnectorFactory.NAME, getBasicRepositoryConnectorFactory()); 631 return result; 632 } 633 634 private RepositoryConnectorProvider repositoryConnectorProvider; 635 636 public final RepositoryConnectorProvider getRepositoryConnectorProvider() { 637 checkClosed(); 638 if (repositoryConnectorProvider == null) { 639 repositoryConnectorProvider = createRepositoryConnectorProvider(); 640 } 641 return repositoryConnectorProvider; 642 } 643 644 protected RepositoryConnectorProvider createRepositoryConnectorProvider() { 645 return new DefaultRepositoryConnectorProvider( 646 getRepositoryConnectorFactories(), getRemoteRepositoryFilterManager()); 647 } 648 649 private Installer installer; 650 651 public final Installer getInstaller() { 652 checkClosed(); 653 if (installer == null) { 654 installer = createInstaller(); 655 } 656 return installer; 657 } 658 659 protected Installer createInstaller() { 660 return new DefaultInstaller( 661 getFileProcessor(), 662 getRepositoryEventDispatcher(), 663 getMetadataGeneratorFactories(), 664 getSyncContextFactory()); 665 } 666 667 private Deployer deployer; 668 669 public final Deployer getDeployer() { 670 checkClosed(); 671 if (deployer == null) { 672 deployer = createDeployer(); 673 } 674 return deployer; 675 } 676 677 protected Deployer createDeployer() { 678 return new DefaultDeployer( 679 getFileProcessor(), 680 getRepositoryEventDispatcher(), 681 getRepositoryConnectorProvider(), 682 getRemoteRepositoryManager(), 683 getUpdateCheckManager(), 684 getMetadataGeneratorFactories(), 685 getSyncContextFactory(), 686 getOfflineController()); 687 } 688 689 private Map<String, DependencyCollectorDelegate> dependencyCollectorDelegates; 690 691 public final Map<String, DependencyCollectorDelegate> getDependencyCollectorDelegates() { 692 checkClosed(); 693 if (dependencyCollectorDelegates == null) { 694 dependencyCollectorDelegates = createDependencyCollectorDelegates(); 695 } 696 return dependencyCollectorDelegates; 697 } 698 699 protected Map<String, DependencyCollectorDelegate> createDependencyCollectorDelegates() { 700 RemoteRepositoryManager remoteRepositoryManager = getRemoteRepositoryManager(); 701 ArtifactDescriptorReader artifactDescriptorReader = getArtifactDescriptorReader(); 702 VersionRangeResolver versionRangeResolver = getVersionRangeResolver(); 703 HashMap<String, DependencyCollectorDelegate> result = new HashMap<>(); 704 result.put( 705 DfDependencyCollector.NAME, 706 new DfDependencyCollector(remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver)); 707 result.put( 708 BfDependencyCollector.NAME, 709 new BfDependencyCollector(remoteRepositoryManager, artifactDescriptorReader, versionRangeResolver)); 710 return result; 711 } 712 713 private DependencyCollector dependencyCollector; 714 715 public final DependencyCollector getDependencyCollector() { 716 checkClosed(); 717 if (dependencyCollector == null) { 718 dependencyCollector = createDependencyCollector(); 719 } 720 return dependencyCollector; 721 } 722 723 protected DependencyCollector createDependencyCollector() { 724 return new DefaultDependencyCollector(getDependencyCollectorDelegates()); 725 } 726 727 private Map<String, ArtifactResolverPostProcessor> artifactResolverPostProcessors; 728 729 public final Map<String, ArtifactResolverPostProcessor> getArtifactResolverPostProcessors() { 730 checkClosed(); 731 if (artifactResolverPostProcessors == null) { 732 artifactResolverPostProcessors = createArtifactResolverPostProcessors(); 733 } 734 return artifactResolverPostProcessors; 735 } 736 737 protected Map<String, ArtifactResolverPostProcessor> createArtifactResolverPostProcessors() { 738 HashMap<String, ArtifactResolverPostProcessor> result = new HashMap<>(); 739 result.put( 740 TrustedChecksumsArtifactResolverPostProcessor.NAME, 741 new TrustedChecksumsArtifactResolverPostProcessor( 742 getChecksumAlgorithmFactorySelector(), getTrustedChecksumsSources())); 743 return result; 744 } 745 746 private ArtifactResolver artifactResolver; 747 748 public final ArtifactResolver getArtifactResolver() { 749 checkClosed(); 750 if (artifactResolver == null) { 751 artifactResolver = createArtifactResolver(); 752 } 753 return artifactResolver; 754 } 755 756 protected ArtifactResolver createArtifactResolver() { 757 return new DefaultArtifactResolver( 758 getFileProcessor(), 759 getRepositoryEventDispatcher(), 760 getVersionResolver(), 761 getUpdateCheckManager(), 762 getRepositoryConnectorProvider(), 763 getRemoteRepositoryManager(), 764 getSyncContextFactory(), 765 getOfflineController(), 766 getArtifactResolverPostProcessors(), 767 getRemoteRepositoryFilterManager()); 768 } 769 770 private MetadataResolver metadataResolver; 771 772 public final MetadataResolver getMetadataResolver() { 773 checkClosed(); 774 if (metadataResolver == null) { 775 metadataResolver = createMetadataResolver(); 776 } 777 return metadataResolver; 778 } 779 780 protected MetadataResolver createMetadataResolver() { 781 return new DefaultMetadataResolver( 782 getRepositoryEventDispatcher(), 783 getUpdateCheckManager(), 784 getRepositoryConnectorProvider(), 785 getRemoteRepositoryManager(), 786 getSyncContextFactory(), 787 getOfflineController(), 788 getRemoteRepositoryFilterManager()); 789 } 790 791 private VersionScheme versionScheme; 792 793 public final VersionScheme getVersionScheme() { 794 checkClosed(); 795 if (versionScheme == null) { 796 versionScheme = createVersionScheme(); 797 } 798 return versionScheme; 799 } 800 801 protected VersionScheme createVersionScheme() { 802 return new GenericVersionScheme(); 803 } 804 805 // Maven provided 806 807 private Map<String, MetadataGeneratorFactory> metadataGeneratorFactories; 808 809 public final Map<String, MetadataGeneratorFactory> getMetadataGeneratorFactories() { 810 checkClosed(); 811 if (metadataGeneratorFactories == null) { 812 metadataGeneratorFactories = createMetadataGeneratorFactories(); 813 } 814 return metadataGeneratorFactories; 815 } 816 817 protected Map<String, MetadataGeneratorFactory> createMetadataGeneratorFactories() { 818 // from maven-resolver-provider 819 HashMap<String, MetadataGeneratorFactory> result = new HashMap<>(); 820 result.put(PluginsMetadataGeneratorFactory.NAME, new PluginsMetadataGeneratorFactory()); 821 result.put(VersionsMetadataGeneratorFactory.NAME, new VersionsMetadataGeneratorFactory()); 822 result.put(SnapshotMetadataGeneratorFactory.NAME, new SnapshotMetadataGeneratorFactory()); 823 return result; 824 } 825 826 private LinkedHashMap<String, MavenArtifactRelocationSource> artifactRelocationSources; 827 828 public final LinkedHashMap<String, MavenArtifactRelocationSource> getMavenArtifactRelocationSources() { 829 checkClosed(); 830 if (artifactRelocationSources == null) { 831 artifactRelocationSources = createMavenArtifactRelocationSources(); 832 } 833 return artifactRelocationSources; 834 } 835 836 protected LinkedHashMap<String, MavenArtifactRelocationSource> createMavenArtifactRelocationSources() { 837 // from maven-resolver-provider 838 LinkedHashMap<String, MavenArtifactRelocationSource> result = new LinkedHashMap<>(); 839 result.put(UserPropertiesArtifactRelocationSource.NAME, new UserPropertiesArtifactRelocationSource()); 840 result.put( 841 DistributionManagementArtifactRelocationSource.NAME, 842 new DistributionManagementArtifactRelocationSource()); 843 return result; 844 } 845 846 private ArtifactDescriptorReader artifactDescriptorReader; 847 848 public final ArtifactDescriptorReader getArtifactDescriptorReader() { 849 checkClosed(); 850 if (artifactDescriptorReader == null) { 851 artifactDescriptorReader = createArtifactDescriptorReader(); 852 } 853 return artifactDescriptorReader; 854 } 855 856 protected ArtifactDescriptorReader createArtifactDescriptorReader() { 857 // from maven-resolver-provider 858 return new DefaultArtifactDescriptorReader( 859 getRemoteRepositoryManager(), 860 getVersionResolver(), 861 getVersionRangeResolver(), 862 getArtifactResolver(), 863 getModelBuilder(), 864 getRepositoryEventDispatcher(), 865 getModelCacheFactory(), 866 getMavenArtifactRelocationSources()); 867 } 868 869 private VersionResolver versionResolver; 870 871 public final VersionResolver getVersionResolver() { 872 checkClosed(); 873 if (versionResolver == null) { 874 versionResolver = createVersionResolver(); 875 } 876 return versionResolver; 877 } 878 879 protected VersionResolver createVersionResolver() { 880 // from maven-resolver-provider 881 return new DefaultVersionResolver( 882 getMetadataResolver(), getSyncContextFactory(), getRepositoryEventDispatcher()); 883 } 884 885 private VersionRangeResolver versionRangeResolver; 886 887 public final VersionRangeResolver getVersionRangeResolver() { 888 checkClosed(); 889 if (versionRangeResolver == null) { 890 versionRangeResolver = createVersionRangeResolver(); 891 } 892 return versionRangeResolver; 893 } 894 895 protected VersionRangeResolver createVersionRangeResolver() { 896 // from maven-resolver-provider 897 return new DefaultVersionRangeResolver( 898 getMetadataResolver(), getSyncContextFactory(), getRepositoryEventDispatcher(), getVersionScheme()); 899 } 900 901 private ModelBuilder modelBuilder; 902 903 public final ModelBuilder getModelBuilder() { 904 checkClosed(); 905 if (modelBuilder == null) { 906 modelBuilder = createModelBuilder(); 907 } 908 return modelBuilder; 909 } 910 911 protected ModelBuilder createModelBuilder() { 912 // from maven-model-builder 913 return new DefaultModelBuilderFactory().newInstance(); 914 } 915 916 private ModelCacheFactory modelCacheFactory; 917 918 public final ModelCacheFactory getModelCacheFactory() { 919 checkClosed(); 920 if (modelCacheFactory == null) { 921 modelCacheFactory = createModelCacheFactory(); 922 } 923 return modelCacheFactory; 924 } 925 926 protected ModelCacheFactory createModelCacheFactory() { 927 // from maven-resolver-provider 928 return new DefaultModelCacheFactory(); 929 } 930 931 private RepositorySystem repositorySystem; 932 933 public final RepositorySystem getRepositorySystem() { 934 checkClosed(); 935 if (repositorySystem == null) { 936 repositorySystem = createRepositorySystem(); 937 } 938 return repositorySystem; 939 } 940 941 protected RepositorySystem createRepositorySystem() { 942 return new DefaultRepositorySystem( 943 getVersionResolver(), 944 getVersionRangeResolver(), 945 getArtifactResolver(), 946 getMetadataResolver(), 947 getArtifactDescriptorReader(), 948 getDependencyCollector(), 949 getInstaller(), 950 getDeployer(), 951 getLocalRepositoryProvider(), 952 getSyncContextFactory(), 953 getRemoteRepositoryManager(), 954 getRepositorySystemLifecycle()); 955 } 956 957 @Override 958 public RepositorySystem get() { 959 return getRepositorySystem(); 960 } 961}