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.io.IOException;
22 import java.io.UncheckedIOException;
23 import java.nio.file.Path;
24 import java.util.Collection;
25 import java.util.stream.Collectors;
26
27 import org.eclipse.aether.RepositorySystemSession;
28 import org.eclipse.aether.artifact.Artifact;
29 import org.eclipse.aether.metadata.Metadata;
30 import org.eclipse.aether.util.DirectoryUtils;
31
32 import static java.util.Objects.requireNonNull;
33
34
35
36
37
38
39
40
41 public class BasedirNameMapper implements NameMapper {
42 private static final String CONFIG_PROP_LOCKS_DIR = "aether.syncContext.named.basedir.locksDir";
43
44 private final NameMapper delegate;
45
46 public BasedirNameMapper(final NameMapper delegate) {
47 this.delegate = requireNonNull(delegate);
48 }
49
50 @Override
51 public boolean isFileSystemFriendly() {
52 return delegate.isFileSystemFriendly();
53 }
54
55 @Override
56 public Collection<String> nameLocks(
57 final RepositorySystemSession session,
58 final Collection<? extends Artifact> artifacts,
59 final Collection<? extends Metadata> metadatas) {
60 try {
61 final Path basedir = DirectoryUtils.resolveDirectory(session, ".locks", CONFIG_PROP_LOCKS_DIR, false);
62
63 return delegate.nameLocks(session, artifacts, metadatas).stream()
64 .map(name -> basedir.resolve(name).toAbsolutePath().toString())
65 .collect(Collectors.toList());
66 } catch (IOException e) {
67 throw new UncheckedIOException(e);
68 }
69 }
70 }