-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCvsProjectset.java
More file actions
343 lines (283 loc) · 12.4 KB
/
CvsProjectset.java
File metadata and controls
343 lines (283 loc) · 12.4 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
* The MIT License
*
* Copyright (c) 2012, Michael Clarke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.scm;
import hudson.AbortException;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.*;
import hudson.scm.cvs.Messages;
import hudson.util.Secret;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.export.Exported;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
public class CvsProjectset extends AbstractCvs {
private static final Pattern PSF_PATTERN = Pattern.compile("<project reference=\"[^,]+,((:[a-z]+:)([a-z|A-Z|0-9|\\.\\-]+)" +
"(:([0-9]+)?)?([/|a-z|A-Z|_|0-9|\\-]+)),([/|A-Z|a-z|0-9|_|\\.|\\-]+),([A-Z|a-z|0-9|_|\\.|\\-|/]+)(,(.*?)){0,1}\"/>");
private final CvsRepository[] repositories;
private final boolean canUseUpdate;
private final String username;
private final Secret password;
private final CVSRepositoryBrowser browser;
private final boolean skipChangeLog;
private final boolean pruneEmptyDirectories;
private final boolean disableCvsQuiet;
private final boolean cleanOnFailedUpdate;
private final boolean forceCleanCopy;
@DataBoundConstructor
public CvsProjectset(final CvsRepository[] repositories, final boolean canUseUpdate, final String username, final String password,
final CVSRepositoryBrowser browser, final boolean skipChangeLog, final boolean pruneEmptyDirectories,
final boolean disableCvsQuiet, final boolean cleanOnFailedUpdate, final boolean forceCleanCopy) {
this.repositories = repositories;
this.username = Util.fixEmpty(username);
this.password = Secret.fromString(password);
this.canUseUpdate = canUseUpdate;
this.browser = browser;
this.skipChangeLog = skipChangeLog;
this.pruneEmptyDirectories = pruneEmptyDirectories;
this.disableCvsQuiet = disableCvsQuiet;
this.cleanOnFailedUpdate = cleanOnFailedUpdate;
this.forceCleanCopy = forceCleanCopy;
}
@Override
@Exported
public CvsRepository[] getRepositories() {
return repositories;
}
@Exported
public String getUsername() {
return username;
}
@Exported
public Secret getPassword() {
return password;
}
@Override
@Exported
public boolean isCanUseUpdate() {
return canUseUpdate;
}
@Override
protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, Launcher launcher,
FilePath workspace, TaskListener listener,
SCMRevisionState baseline)
throws IOException, InterruptedException {
return super.compareRemoteRevisionWith(project, launcher, workspace,
listener, baseline, getAllRepositories(workspace));
}
@Override
public PollingResult compareRemoteRevisionWith(Job<?, ?> project, Launcher launcher,
FilePath workspace, TaskListener listener,
SCMRevisionState baseline)
throws IOException, InterruptedException {
return super.compareRemoteRevisionWith(project, launcher, workspace,
listener, baseline, getAllRepositories(workspace));
}
@Override
public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace, BuildListener listener,
File changelogFile) throws IOException, InterruptedException {
try {
checkout(build, launcher, workspace, listener, changelogFile, null);
}
catch (AbortException e) {
return false;
}
return true;
}
@Override
public void checkout(final @Nonnull Run<?,?> build, final @Nonnull Launcher launcher, final @Nonnull FilePath workspace,
final @Nonnull TaskListener listener, final @CheckForNull File changelogFile,
final @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException {
if (!isCanUseUpdate()) {
workspace.deleteContents();
}
final String dateStamp;
synchronized (DATE_FORMATTER) {
dateStamp = DATE_FORMATTER.format(getCheckoutDate(build));
}
if (!checkout(getRepositories(), false, workspace, isCanUseUpdate(),
build, dateStamp, isPruneEmptyDirectories(), isCleanOnFailedUpdate(), listener)) {
throw new AbortException();
}
if (!checkout(getInnerRepositories(workspace), false, workspace, isCanUseUpdate(),
build, dateStamp, isPruneEmptyDirectories(), isCleanOnFailedUpdate(), listener)) {
throw new AbortException();
}
postCheckout(build, changelogFile, getAllRepositories(workspace), workspace, listener, isFlatten(), build.getEnvironment(listener));
}
private CvsRepository[] getInnerRepositories(FilePath workspace) throws IOException, InterruptedException {
List<CvsRepository> psfList = new ArrayList<CvsRepository>();
for (CvsRepository repository : getRepositories()) {
for (CvsRepositoryItem item : repository.getRepositoryItems()) {
for (CvsModule module : item.getModules()) {
FilePath projectsetFile = workspace.child(module.getCheckoutName())
.child(module.getProjectsetFileName());
if (!projectsetFile.exists()) {
throw new Error(Messages.CVSSCM_InvalidProjectset(module.getProjectsetFileName(),
module.getRemoteName()));
}
String psfContents = projectsetFile.readToString();
for (Matcher matcher = PSF_PATTERN.matcher(psfContents); matcher.find();) {
CvsModule innerModule = new CvsModule(matcher.group(7), matcher.group(8));
CvsRepositoryLocation innerLocation;
if (matcher.group(10) == null) {
innerLocation = new CvsRepositoryLocation.HeadRepositoryLocation();
}
else {
innerLocation = new CvsRepositoryLocation.BranchRepositoryLocation(matcher.group(10), false);
}
CvsRepositoryItem innerItem = new CvsRepositoryItem(innerLocation,
new CvsModule[]{innerModule});
CvsAuthentication authentication = getAuthenticationForCvsRoot(matcher.group(1));
StringBuilder root = new StringBuilder();
root.append(matcher.group(2));
String password = null;
if (authentication == null) {
if (username != null) {
root.append(getUsername());
root.append("@");
}
Secret secret = getPassword();
if (null != secret) {
password = secret.getPlainText();
}
}
// we don't actually do anything with the authentication details if they're available just now
// as they're automatically configured in a later call
root.append(matcher.group(3));
if (matcher.group(5) != null) {
root.append(":").append(matcher.group(5));
}
root.append(matcher.group(6));
CvsRepository innerRepository = new CvsRepository(root.toString(), password != null, password,
Arrays.asList(innerItem), new ArrayList<ExcludedRegion>(), 0, null);
psfList.add(innerRepository);
}
}
}
}
return psfList.toArray(new CvsRepository[psfList.size()]);
}
private CvsAuthentication getAuthenticationForCvsRoot(final String cvsRoot) {
for(CvsAuthentication authentication : getDescriptor().getAuthentication()) {
if (authentication.getCvsRoot().equals(cvsRoot)) {
return authentication;
}
}
return null;
}
private CvsRepository[] getAllRepositories(FilePath workspace) throws IOException, InterruptedException {
List<CvsRepository> returnList = new ArrayList<CvsRepository>();
returnList.addAll(Arrays.asList(getRepositories()));
returnList.addAll(Arrays.asList(getInnerRepositories(workspace)));
return returnList.toArray(new CvsRepository[returnList.size()]);
}
@Override
public boolean requiresWorkspaceForPolling() {
//we need to have the project-set files checked out so we can discover the rest of the projects
return true;
}
@Override
@Exported
public boolean isPruneEmptyDirectories() {
return pruneEmptyDirectories;
}
@Override
@Exported
public boolean isCleanOnFailedUpdate() {
return cleanOnFailedUpdate;
}
@Override
@Exported
public boolean isDisableCvsQuiet() {
return disableCvsQuiet;
}
@Override
@Exported
public boolean isSkipChangeLog() {
return skipChangeLog;
}
@Override
@Exported
public boolean isForceCleanCopy() {
return forceCleanCopy;
}
@Override
public boolean isFlatten() {
return false;
}
@Override
public RepositoryBrowser getBrowser() {
return browser;
}
@Override
public CvsProjectsetDescriptor getDescriptor() {
return (CvsProjectsetDescriptor) super.getDescriptor();
}
@Extension
public static class CvsProjectsetDescriptor extends AbstractCvsDescriptor<CvsProjectset> {
public CvsProjectsetDescriptor() {
super(CVSRepositoryBrowser.class);
}
@Override
public String getDisplayName() {
return "CVS Projectset";
}
@Override
public String getKnownHostsLocation() {
return CVSSCM.DescriptorImpl.getOrDie().getKnownHostsLocation();
}
@Override
public String getPrivateKeyLocation() {
return CVSSCM.DescriptorImpl.getOrDie().getPrivateKeyLocation();
}
@Override
public Secret getPrivateKeyPassword() {
return CVSSCM.DescriptorImpl.getOrDie().getPrivateKeyPassword();
}
@Override
public int getCompressionLevel() {
return CVSSCM.DescriptorImpl.getOrDie().getCompressionLevel();
}
@Override
public CvsAuthentication[] getAuthentication() {
return CVSSCM.DescriptorImpl.getOrDie().getAuthentication();
}
@Override
public String getChangelogEncoding() {
return CVSSCM.DescriptorImpl.getOrDie().getChangelogEncoding();
}
}
}