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