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