1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal;
20
21 import java.nio.file.Path;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Date;
25
26 import org.apache.maven.artifact.repository.metadata.Metadata;
27 import org.eclipse.aether.artifact.Artifact;
28
29
30
31 abstract class MavenSnapshotMetadata extends MavenMetadata {
32 static final String SNAPSHOT = "SNAPSHOT";
33
34 protected final Collection<Artifact> artifacts = new ArrayList<>();
35
36 protected MavenSnapshotMetadata(Metadata metadata, Path path, Date timestamp) {
37 super(metadata, path, timestamp);
38 }
39
40 protected static Metadata createRepositoryMetadata(Artifact artifact) {
41 Metadata metadata = new Metadata();
42 metadata.setModelVersion("1.1.0");
43 metadata.setGroupId(artifact.getGroupId());
44 metadata.setArtifactId(artifact.getArtifactId());
45 metadata.setVersion(artifact.getBaseVersion());
46
47 return metadata;
48 }
49
50 public void bind(Artifact artifact) {
51 artifacts.add(artifact);
52 }
53
54 public Object getKey() {
55 return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
56 }
57
58 public static Object getKey(Artifact artifact) {
59 return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
60 }
61
62 protected String getKey(String classifier, String extension) {
63 return classifier + ':' + extension;
64 }
65
66 @Override
67 public String getGroupId() {
68 return metadata.getGroupId();
69 }
70
71 @Override
72 public String getArtifactId() {
73 return metadata.getArtifactId();
74 }
75
76 @Override
77 public String getVersion() {
78 return metadata.getVersion();
79 }
80
81 @Override
82 public Nature getNature() {
83 return Nature.SNAPSHOT;
84 }
85 }