1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl;
20
21 import java.util.Collection;
22
23 import org.apache.maven.api.DependencyCoordinate;
24 import org.apache.maven.api.DependencyScope;
25 import org.apache.maven.api.Exclusion;
26 import org.apache.maven.api.Type;
27 import org.apache.maven.api.VersionConstraint;
28 import org.apache.maven.api.annotations.Nonnull;
29 import org.apache.maven.api.annotations.Nullable;
30 import org.eclipse.aether.artifact.ArtifactProperties;
31
32 import static org.apache.maven.internal.impl.Utils.nonNull;
33
34 public class DefaultDependencyCoordinate implements DependencyCoordinate {
35 private final InternalSession session;
36 private final org.eclipse.aether.graph.Dependency dependency;
37
38 public DefaultDependencyCoordinate(
39 @Nonnull InternalSession session, @Nonnull org.eclipse.aether.graph.Dependency dependency) {
40 this.session = nonNull(session, "session");
41 this.dependency = nonNull(dependency, "dependency");
42 }
43
44 @Nonnull
45 public org.eclipse.aether.graph.Dependency getDependency() {
46 return dependency;
47 }
48
49 @Override
50 public String getGroupId() {
51 return dependency.getArtifact().getGroupId();
52 }
53
54 @Override
55 public String getArtifactId() {
56 return dependency.getArtifact().getArtifactId();
57 }
58
59 @Override
60 public String getClassifier() {
61 return dependency.getArtifact().getClassifier();
62 }
63
64 @Override
65 public VersionConstraint getVersion() {
66 return session.parseVersionConstraint(dependency.getArtifact().getVersion());
67 }
68
69 @Override
70 public String getExtension() {
71 return dependency.getArtifact().getExtension();
72 }
73
74 @Override
75 public Type getType() {
76 String type = dependency
77 .getArtifact()
78 .getProperty(ArtifactProperties.TYPE, dependency.getArtifact().getExtension());
79 return session.requireType(type);
80 }
81
82 @Nonnull
83 @Override
84 public DependencyScope getScope() {
85 return session.requireDependencyScope(dependency.getScope());
86 }
87
88 @Nullable
89 @Override
90 public Boolean getOptional() {
91 return dependency.getOptional();
92 }
93
94 @Nonnull
95 @Override
96 public Collection<Exclusion> getExclusions() {
97 return new MappedCollection<>(dependency.getExclusions(), this::toExclusion);
98 }
99
100 private Exclusion toExclusion(org.eclipse.aether.graph.Exclusion exclusion) {
101 return new Exclusion() {
102 @Nullable
103 @Override
104 public String getGroupId() {
105 return exclusion.getGroupId();
106 }
107
108 @Nullable
109 @Override
110 public String getArtifactId() {
111 return exclusion.getArtifactId();
112 }
113 };
114 }
115 }