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;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import org.eclipse.aether.artifact.Artifact;
25 import org.eclipse.aether.metadata.Metadata;
26
27 import static java.util.Objects.requireNonNull;
28
29
30
31
32
33
34 @Singleton
35 @Named
36 public final class DefaultLocalPathComposer implements LocalPathComposer {
37 @Override
38 public String getPathForArtifact(Artifact artifact, boolean local) {
39 requireNonNull(artifact);
40
41 StringBuilder path = new StringBuilder(128);
42
43 path.append(artifact.getGroupId().replace('.', '/')).append('/');
44
45 path.append(artifact.getArtifactId()).append('/');
46
47 path.append(artifact.getBaseVersion()).append('/');
48
49 path.append(artifact.getArtifactId()).append('-');
50 if (local) {
51 path.append(artifact.getBaseVersion());
52 } else {
53 path.append(artifact.getVersion());
54 }
55
56 if (!artifact.getClassifier().isEmpty()) {
57 path.append('-').append(artifact.getClassifier());
58 }
59
60 if (!artifact.getExtension().isEmpty()) {
61 path.append('.').append(artifact.getExtension());
62 }
63
64 return path.toString();
65 }
66
67 @Override
68 public String getPathForMetadata(Metadata metadata, String repositoryKey) {
69 requireNonNull(metadata);
70 requireNonNull(repositoryKey);
71
72 StringBuilder path = new StringBuilder(128);
73
74 if (!metadata.getGroupId().isEmpty()) {
75 path.append(metadata.getGroupId().replace('.', '/')).append('/');
76
77 if (!metadata.getArtifactId().isEmpty()) {
78 path.append(metadata.getArtifactId()).append('/');
79
80 if (!metadata.getVersion().isEmpty()) {
81 path.append(metadata.getVersion()).append('/');
82 }
83 }
84 }
85
86 path.append(insertRepositoryKey(metadata.getType(), repositoryKey));
87
88 return path.toString();
89 }
90
91 private String insertRepositoryKey(String metadataType, String repositoryKey) {
92 String result;
93 int idx = metadataType.indexOf('.');
94 if (idx < 0) {
95 result = metadataType + '-' + repositoryKey;
96 } else {
97 result = metadataType.substring(0, idx) + '-' + repositoryKey + metadataType.substring(idx);
98 }
99 return result;
100 }
101 }