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