1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18 import java.io.File;
19
20 import org.apache.commons.io.FileUtils;
21 import org.kuali.common.util.nullify.NullUtils;
22
23 public class RepositoryUtils {
24
25 private static final String FS = File.separator;
26 private static final String DEFAULT_MAVEN_REPO_PATH = ".m2" + FS + "repository";
27
28 public static final String toString(Artifact artifact) {
29 StringBuilder sb = new StringBuilder();
30 sb.append(artifact.getGroupId());
31 sb.append(":");
32 sb.append(artifact.getArtifactId());
33 sb.append(":");
34 sb.append(artifact.getVersion());
35 if (!NullUtils.isNullOrNone(artifact.getClassifier())) {
36 sb.append(":");
37 sb.append(artifact.getClassifier());
38 }
39 sb.append(":");
40 sb.append(artifact.getPackaging());
41 return sb.toString();
42 }
43
44 public static final String getRepositoryPath(Artifact artifact) {
45 StringBuilder sb = new StringBuilder();
46 sb.append(Str.getPath(artifact.getGroupId()));
47 sb.append(FS);
48 sb.append(artifact.getArtifactId());
49 sb.append(FS);
50 sb.append(artifact.getVersion());
51 return sb.toString();
52 }
53
54 public static final String getFilename(Artifact artifact) {
55 StringBuilder sb = new StringBuilder();
56 sb.append(artifact.getArtifactId());
57 sb.append("-");
58 sb.append(artifact.getVersion());
59 if (!NullUtils.isNullOrNone(artifact.getClassifier())) {
60 sb.append("-");
61 sb.append(artifact.getClassifier());
62 }
63 sb.append(".");
64 sb.append(artifact.getPackaging());
65 return sb.toString();
66 }
67
68 public static final File getDefaultLocalRepositoryDir() {
69 return new File(FileUtils.getUserDirectoryPath() + FS + DEFAULT_MAVEN_REPO_PATH);
70 }
71
72 public static final File getFile(Artifact artifact) {
73 return getFile(getDefaultLocalRepositoryDir(), artifact);
74 }
75
76 public static final File getFile(File localRepositoryDir, Artifact artifact) {
77 String path = getRepositoryPath(artifact);
78 String filename = getFilename(artifact);
79 return new File(localRepositoryDir.getAbsolutePath() + FS + path, filename);
80 }
81
82 }