1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.cmd.util;
20
21 import java.io.File;
22 import java.util.Iterator;
23 import java.util.Set;
24
25 /***
26 * Represents the path to a dependency. Consists of two parts, a relative part
27 * and the part that forms the prefix of this relative part. Together they form
28 * the absolute path to the dependency.
29 *
30 * @author W.H. Schraal
31 */
32 public class DependencyPath {
33
34 private File pathPrefix;
35 private File relativePath;
36
37 /***
38 * Create a new DependencyPath
39 *
40 * @param pathPrefix Prefix for the dependency path.
41 * @param relativePath Relative path to the dependency.
42 */
43 DependencyPath(File pathPrefix, File relativePath) {
44 this.pathPrefix = pathPrefix;
45 this.relativePath = relativePath;
46 }
47
48 public File getPathPrefix() {
49 return pathPrefix;
50 }
51
52 public File getRelativePath() {
53 return relativePath;
54 }
55
56 /***
57 * Retrieve the full absolute path to the dependency by concatenating the
58 * prefix and the relative path.
59 *
60 * @return The full path to the dependency.
61 */
62 public File getFullPath() {
63 return new File(getPathPrefix(), getRelativePath().getPath());
64 }
65
66 /***
67 * Does the dependency exist?
68 *
69 * @return Whether or not the dependency exists.
70 */
71 public boolean exists() {
72 return getFullPath().exists();
73 }
74
75 /***
76 * Concatenates all DependencyPaths in the given set to a separated String.
77 *
78 * @param dependencyPaths Set of DependencyPath Objects.
79 * @param relative Use relative paths?
80 * @param separator Separator char to use.
81 * @return Separated String.
82 */
83 public static String concat(Set dependencyPaths, boolean relative, char separator) {
84 String s = "";
85 Iterator it = dependencyPaths.iterator();
86 while (it.hasNext()) {
87 DependencyPath path = (DependencyPath) it.next();
88 if (relative) {
89 s += path.getRelativePath().getPath();
90 } else {
91 s += path.getFullPath().getPath();
92 }
93 if (it.hasNext()) {
94 s += separator;
95 }
96 }
97 return s;
98 }
99
100 }