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 public float getPriority() {
54 return priority;
55 }
56
57
58
59
60
61
62
63 public FileTransporterFactory setPriority(float priority) {
64 this.priority = priority;
65 return this;
66 }
67
68 public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
69 throws NoTransporterException {
70 requireNonNull(session, "session cannot be null");
71 requireNonNull(repository, "repository cannot be null");
72
73 FileTransporter.FileOp fileOp = FileTransporter.FileOp.COPY;
74 String repositoryUrl = repository.getUrl();
75 if (repositoryUrl.startsWith("symlink+")) {
76 fileOp = FileTransporter.FileOp.SYMLINK;
77 repositoryUrl = repositoryUrl.substring("symlink+".length());
78 } else if (repositoryUrl.startsWith("hardlink+")) {
79 fileOp = FileTransporter.FileOp.HARDLINK;
80 repositoryUrl = repositoryUrl.substring("hardlink+".length());
81 }
82 try {
83 return new FileTransporter(
84 Paths.get(RepositoryUriUtils.toUri(repositoryUrl)).toAbsolutePath(), fileOp);
85 } catch (FileSystemNotFoundException | IllegalArgumentException e) {
86 throw new NoTransporterException(repository, e);
87 }
88 }
89 }