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