%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
nl.toolforge.karma.core.cmd.util.DependencyPath |
|
|
1 | /* |
|
2 | Karma core - Core of the Karma application |
|
3 | Copyright (C) 2004 Toolforge <www.toolforge.nl> |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, write to the Free Software |
|
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
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 | 0 | DependencyPath(File pathPrefix, File relativePath) { |
44 | 0 | this.pathPrefix = pathPrefix; |
45 | 0 | this.relativePath = relativePath; |
46 | 0 | } |
47 | ||
48 | public File getPathPrefix() { |
|
49 | 0 | return pathPrefix; |
50 | } |
|
51 | ||
52 | public File getRelativePath() { |
|
53 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | String s = ""; |
85 | 0 | Iterator it = dependencyPaths.iterator(); |
86 | 0 | while (it.hasNext()) { |
87 | 0 | DependencyPath path = (DependencyPath) it.next(); |
88 | 0 | if (relative) { |
89 | 0 | s += path.getRelativePath().getPath(); |
90 | } else { |
|
91 | 0 | s += path.getFullPath().getPath(); |
92 | } |
|
93 | 0 | if (it.hasNext()) { |
94 | 0 | s += separator; |
95 | } |
|
96 | } |
|
97 | 0 | return s; |
98 | } |
|
99 | ||
100 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |