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