1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.buildcache.checksum;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.apache.maven.buildcache.xml.build.Artifact;
23 import org.apache.maven.project.MavenProject;
24
25
26
27
28 public class KeyUtils {
29
30 private static final String SEPARATOR = ":";
31
32 public static String getProjectKey(MavenProject project) {
33 return getProjectKey(project.getGroupId(), project.getArtifactId(), project.getVersion());
34 }
35
36 public static String getProjectKey(String groupId, String artifactId, String version) {
37 return StringUtils.joinWith(SEPARATOR, groupId, artifactId, version);
38 }
39
40 public static String getVersionlessProjectKey(MavenProject project) {
41 return StringUtils.joinWith(SEPARATOR, project.getGroupId(), project.getArtifactId());
42 }
43
44 public static String getArtifactKey(Artifact artifact) {
45 return getArtifactKey(
46 artifact.getGroupId(),
47 artifact.getArtifactId(),
48 artifact.getType(),
49 artifact.getClassifier(),
50 artifact.getVersion());
51 }
52
53 public static String getVersionlessArtifactKey(org.apache.maven.artifact.Artifact artifact) {
54 return getVersionlessArtifactKey(
55 artifact.getGroupId(), artifact.getArtifactId(), artifact.getType(), artifact.getClassifier());
56 }
57
58
59
60
61 public static String getArtifactKey(Artifact artifact, String type) {
62 return getArtifactKey(
63 artifact.getGroupId(), artifact.getArtifactId(), type, artifact.getClassifier(), artifact.getVersion());
64 }
65
66 public static String getArtifactKey(org.apache.maven.artifact.Artifact artifact) {
67 return getArtifactKey(
68 artifact.getGroupId(),
69 artifact.getArtifactId(),
70 artifact.getType(),
71 artifact.getClassifier(),
72 artifact.getVersion());
73 }
74
75 public static String getArtifactKey(
76 String groupId, String artifactId, String type, String classifier, String version) {
77 if (classifier != null) {
78 return StringUtils.joinWith(SEPARATOR, groupId, artifactId, type, classifier, version);
79 } else {
80 return StringUtils.joinWith(SEPARATOR, groupId, artifactId, type, version);
81 }
82 }
83
84 public static String getVersionlessArtifactKey(String groupId, String artifactId, String type, String classifier) {
85 if (classifier != null) {
86 return StringUtils.joinWith(SEPARATOR, groupId, artifactId, type, classifier);
87 } else {
88 return StringUtils.joinWith(SEPARATOR, groupId, artifactId, type);
89 }
90 }
91 }