1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.file;
20
21 import javax.inject.Named;
22
23 import java.nio.file.FileSystemNotFoundException;
24 import java.nio.file.Paths;
25
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.repository.RemoteRepository;
28 import org.eclipse.aether.repository.RepositoryUriUtils;
29 import org.eclipse.aether.spi.connector.transport.Transporter;
30 import org.eclipse.aether.spi.connector.transport.TransporterFactory;
31 import org.eclipse.aether.transfer.NoTransporterException;
32
33 import static java.util.Objects.requireNonNull;
34
35
36
37
38 @Named(FileTransporterFactory.NAME)
39 public final class FileTransporterFactory implements TransporterFactory {
40 public static final String NAME = "file";
41
42 private float priority;
43
44
45
46
47
48
49 public FileTransporterFactory() {
50
51 }
52
53 @Override
54 public float getPriority() {
55 return priority;
56 }
57
58
59
60
61
62
63
64 public FileTransporterFactory setPriority(float priority) {
65 this.priority = priority;
66 return this;
67 }
68
69 @Override
70 public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
71 throws NoTransporterException {
72 requireNonNull(session, "session cannot be null");
73 requireNonNull(repository, "repository cannot be null");
74
75
76
77 FileTransporter.FileOp fileOp = FileTransporter.FileOp.COPY;
78 String repositoryUrl = repository.getUrl();
79 if (repositoryUrl.startsWith("symlink+")) {
80 fileOp = FileTransporter.FileOp.SYMLINK;
81 repositoryUrl = repositoryUrl.substring("symlink+".length());
82 } else if (repositoryUrl.startsWith("hardlink+")) {
83 fileOp = FileTransporter.FileOp.HARDLINK;
84 repositoryUrl = repositoryUrl.substring("hardlink+".length());
85 }
86 try {
87 return new FileTransporter(
88 Paths.get(RepositoryUriUtils.toUri(repositoryUrl)).toAbsolutePath(), fileOp);
89 } catch (FileSystemNotFoundException | IllegalArgumentException e) {
90 throw new NoTransporterException(repository, e);
91 }
92 }
93 }