1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl.synccontext.named;
20
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.stream.Collectors;
24
25 import org.eclipse.aether.RepositorySystemSession;
26 import org.eclipse.aether.artifact.Artifact;
27 import org.eclipse.aether.metadata.Metadata;
28 import org.eclipse.aether.named.NamedLockKey;
29 import org.eclipse.aether.spi.locking.LockingInhibitor;
30
31 import static java.util.Objects.requireNonNull;
32
33
34
35
36
37
38 public class InhibitingNameMapper implements NameMapper {
39 private final NameMapper delegate;
40 private final List<LockingInhibitor> lockingInhibitors;
41
42 public InhibitingNameMapper(NameMapper delegate, List<LockingInhibitor> lockingInhibitors) {
43 this.delegate = requireNonNull(delegate);
44 this.lockingInhibitors = requireNonNull(lockingInhibitors);
45 }
46
47 @Override
48 public boolean isFileSystemFriendly() {
49 return delegate.isFileSystemFriendly();
50 }
51
52 @Override
53 public Collection<NamedLockKey> nameLocks(
54 RepositorySystemSession session,
55 Collection<? extends Artifact> artifacts,
56 Collection<? extends Metadata> metadatas) {
57 if (artifacts != null) {
58 artifacts = artifacts.stream()
59 .filter(a -> lockingInhibitors.stream().noneMatch(i -> i.preventArtifactLocking(a)))
60 .collect(Collectors.toList());
61 }
62 if (metadatas != null) {
63 metadatas = metadatas.stream()
64 .filter(m -> lockingInhibitors.stream().noneMatch(i -> i.preventMetadataLocking(m)))
65 .collect(Collectors.toList());
66 }
67 return delegate.nameLocks(session, artifacts, metadatas);
68 }
69 }