1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.ant; |
16 |
| |
17 |
| import java.io.File; |
18 |
| |
19 |
| import org.apache.tools.ant.BuildException; |
20 |
| import org.apache.tools.ant.Task; |
21 |
| import org.apache.tools.ant.types.Path; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| public class ManifestClassPath extends Task |
36 |
| { |
37 |
| private String _property; |
38 |
| private Path _classpath; |
39 |
| private File _directory; |
40 |
| |
41 |
5
| public Path createClasspath()
|
42 |
| { |
43 |
5
| _classpath = new Path(getProject());
|
44 |
| |
45 |
5
| return _classpath;
|
46 |
| } |
47 |
| |
48 |
3
| public String getProperty()
|
49 |
| { |
50 |
3
| return _property;
|
51 |
| } |
52 |
| |
53 |
5
| public void setProperty(String string)
|
54 |
| { |
55 |
5
| _property = string;
|
56 |
| } |
57 |
| |
58 |
6
| public void execute()
|
59 |
| { |
60 |
6
| if (_classpath == null)
|
61 |
1
| throw new BuildException("You must specify a classpath to generate the manifest entry from");
|
62 |
| |
63 |
5
| if (_property == null)
|
64 |
1
| throw new BuildException("You must specify a property to assign the manifest classpath to");
|
65 |
| |
66 |
4
| StringBuffer buffer = new StringBuffer();
|
67 |
| |
68 |
4
| String[] paths = _classpath.list();
|
69 |
| |
70 |
4
| String stripPrefix = null;
|
71 |
| |
72 |
4
| if (_directory != null)
|
73 |
2
| stripPrefix = _directory.getPath();
|
74 |
| |
75 |
| |
76 |
| |
77 |
4
| boolean needSep = false;
|
78 |
| |
79 |
4
| for (int i = 0; i < paths.length; i++)
|
80 |
| { |
81 |
7
| String path = paths[i];
|
82 |
| |
83 |
7
| if (stripPrefix != null)
|
84 |
| { |
85 |
5
| if (!path.startsWith(stripPrefix))
|
86 |
1
| continue;
|
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
4
| if (path.length() == stripPrefix.length())
|
93 |
1
| continue;
|
94 |
| |
95 |
3
| if (needSep)
|
96 |
1
| buffer.append(' ');
|
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
3
| buffer.append(filter(path.substring(stripPrefix.length() + 1)));
|
102 |
| |
103 |
3
| needSep = true;
|
104 |
| |
105 |
| } |
106 |
| else |
107 |
| { |
108 |
2
| if (needSep)
|
109 |
1
| buffer.append(' ');
|
110 |
| |
111 |
2
| File f = new File(path);
|
112 |
| |
113 |
2
| buffer.append(f.getName());
|
114 |
| |
115 |
2
| needSep = true;
|
116 |
| } |
117 |
| } |
118 |
| |
119 |
4
| getProject().setProperty(_property, buffer.toString());
|
120 |
| } |
121 |
| |
122 |
1
| public File getDirectory()
|
123 |
| { |
124 |
1
| return _directory;
|
125 |
| } |
126 |
| |
127 |
| |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| |
134 |
| |
135 |
2
| public void setDirectory(File file)
|
136 |
| { |
137 |
2
| _directory = file;
|
138 |
| } |
139 |
| |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
3
| protected String filter(String value)
|
145 |
| { |
146 |
3
| if (File.separatorChar == '/')
|
147 |
0
| return value;
|
148 |
| |
149 |
3
| return value.replace(File.separatorChar, '/');
|
150 |
| } |
151 |
| } |