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