1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.gitrepo;
44
45 import java.io.File;
46 import java.io.FileInputStream;
47 import java.io.FileOutputStream;
48 import java.io.IOException;
49 import java.nio.channels.FileChannel;
50 import java.util.ArrayList;
51 import java.util.Arrays;
52 import java.util.Collection;
53 import java.util.Collections;
54 import java.util.HashSet;
55 import java.util.List;
56 import java.util.Set;
57
58 import org.eclipse.jgit.lib.Repository;
59
60
61
62
63
64
65
66 public class RepoProject implements Comparable<RepoProject> {
67 private final String name;
68 private final String path;
69 private final String revision;
70 private final String remote;
71 private final Set<String> groups;
72 private final List<CopyFile> copyfiles;
73 private String url;
74 private String defaultRevision;
75
76
77
78
79 public static class CopyFile {
80 final Repository repo;
81 final String path;
82 final String src;
83 final String dest;
84
85
86
87
88
89
90
91
92
93
94
95 public CopyFile(Repository repo, String path, String src, String dest) {
96 this.repo = repo;
97 this.path = path;
98 this.src = src;
99 this.dest = dest;
100 }
101
102
103
104
105
106
107 public void copy() throws IOException {
108 File srcFile = new File(repo.getWorkTree(),
109 path + "/" + src);
110 File destFile = new File(repo.getWorkTree(), dest);
111 FileInputStream input = new FileInputStream(srcFile);
112 try {
113 FileOutputStream output = new FileOutputStream(destFile);
114 try {
115 FileChannel channel = input.getChannel();
116 output.getChannel().transferFrom(
117 channel, 0, channel.size());
118 } finally {
119 output.close();
120 }
121 } finally {
122 input.close();
123 }
124 }
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139 public RepoProject(String name, String path, String revision,
140 String remote, String groups) {
141 this.name = name;
142 if (path != null)
143 this.path = path;
144 else
145 this.path = name;
146 this.revision = revision;
147 this.remote = remote;
148 this.groups = new HashSet<String>();
149 if (groups != null && groups.length() > 0)
150 this.groups.addAll(Arrays.asList(groups.split(",")));
151 copyfiles = new ArrayList<CopyFile>();
152 }
153
154
155
156
157
158
159
160 public RepoProject setUrl(String url) {
161 this.url = url;
162 return this;
163 }
164
165
166
167
168
169
170
171 public RepoProject setDefaultRevision(String defaultRevision) {
172 this.defaultRevision = defaultRevision;
173 return this;
174 }
175
176
177
178
179
180
181 public String getName() {
182 return name;
183 }
184
185
186
187
188
189
190 public String getPath() {
191 return path;
192 }
193
194
195
196
197
198
199 public String getRevision() {
200 return revision == null ? defaultRevision : revision;
201 }
202
203
204
205
206
207
208 public List<CopyFile> getCopyFiles() {
209 return Collections.unmodifiableList(copyfiles);
210 }
211
212
213
214
215
216
217 public String getUrl() {
218 return url;
219 }
220
221
222
223
224
225
226 public String getRemote() {
227 return remote;
228 }
229
230
231
232
233
234
235
236 public boolean inGroup(String group) {
237 return groups.contains(group);
238 }
239
240
241
242
243
244
245 public void addCopyFile(CopyFile copyfile) {
246 copyfiles.add(copyfile);
247 }
248
249
250
251
252
253
254 public void addCopyFiles(Collection<CopyFile> copyfiles) {
255 this.copyfiles.addAll(copyfiles);
256 }
257
258 private String getPathWithSlash() {
259 if (path.endsWith("/"))
260 return path;
261 else
262 return path + "/";
263 }
264
265
266
267
268
269
270
271
272 public boolean isAncestorOf(RepoProject that) {
273 return that.getPathWithSlash().startsWith(this.getPathWithSlash());
274 }
275
276 @Override
277 public boolean equals(Object o) {
278 if (o instanceof RepoProject) {
279 RepoProject that = (RepoProject) o;
280 return this.getPathWithSlash().equals(that.getPathWithSlash());
281 }
282 return false;
283 }
284
285 @Override
286 public int hashCode() {
287 return this.getPathWithSlash().hashCode();
288 }
289
290 @Override
291 public int compareTo(RepoProject that) {
292 return this.getPathWithSlash().compareTo(that.getPathWithSlash());
293 }
294 }
295