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.io.File;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Date;
25 import org.apache.maven.artifact.repository.metadata.Metadata;
26 import org.eclipse.aether.artifact.Artifact;
27
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 final boolean legacyFormat;
37
38 protected MavenSnapshotMetadata(Metadata metadata, File file, boolean legacyFormat, Date timestamp) {
39 super(metadata, file, timestamp);
40 this.legacyFormat = legacyFormat;
41 }
42
43 protected static Metadata createRepositoryMetadata(Artifact artifact, boolean legacyFormat) {
44 Metadata metadata = new Metadata();
45 if (!legacyFormat) {
46 metadata.setModelVersion("1.1.0");
47 }
48 metadata.setGroupId(artifact.getGroupId());
49 metadata.setArtifactId(artifact.getArtifactId());
50 metadata.setVersion(artifact.getBaseVersion());
51
52 return metadata;
53 }
54
55 public void bind(Artifact artifact) {
56 artifacts.add(artifact);
57 }
58
59 public Object getKey() {
60 return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
61 }
62
63 public static Object getKey(Artifact artifact) {
64 return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
65 }
66
67 protected String getKey(String classifier, String extension) {
68 return classifier + ':' + extension;
69 }
70
71 public String getGroupId() {
72 return metadata.getGroupId();
73 }
74
75 public String getArtifactId() {
76 return metadata.getArtifactId();
77 }
78
79 public String getVersion() {
80 return metadata.getVersion();
81 }
82
83 public Nature getNature() {
84 return Nature.SNAPSHOT;
85 }
86 }