55
55
import hudson .scm .SCM ;
56
56
import hudson .security .ACL ;
57
57
import jenkins .model .Jenkins ;
58
+ import jenkins .scm .api .SCMFile ;
58
59
import jenkins .scm .api .SCMHead ;
59
60
import jenkins .scm .api .SCMHeadObserver ;
61
+ import jenkins .scm .api .SCMProbe ;
62
+ import jenkins .scm .api .SCMProbeStat ;
60
63
import jenkins .scm .api .SCMRevision ;
61
64
import jenkins .scm .api .SCMSource ;
62
65
import jenkins .scm .api .SCMSourceCriteria ;
63
66
import jenkins .scm .api .SCMSourceOwner ;
64
67
import org .apache .commons .lang .StringUtils ;
68
+ import org .eclipse .jgit .lib .FileMode ;
65
69
import org .eclipse .jgit .lib .ObjectId ;
66
70
import org .eclipse .jgit .lib .Repository ;
67
71
import org .eclipse .jgit .revwalk .RevCommit ;
@@ -225,33 +229,38 @@ public SCMRevision run(GitClient client, String remoteName) throws IOException,
225
229
}, listener , /* we don't prune remotes here, as we just want one head's revision */ false );
226
230
}
227
231
228
- @ NonNull
229
232
@ Override
230
- protected void retrieve (@ NonNull final SCMHeadObserver observer ,
233
+ protected void retrieve (@ CheckForNull final SCMSourceCriteria criteria ,
234
+ @ NonNull final SCMHeadObserver observer ,
231
235
@ NonNull final TaskListener listener )
232
236
throws IOException , InterruptedException {
233
237
doRetrieve (new Retriever <Void >() {
234
238
@ Override
235
239
public Void run (GitClient client , String remoteName ) throws IOException , InterruptedException {
236
240
final Repository repository = client .getRepository ();
237
241
listener .getLogger ().println ("Getting remote branches..." );
238
- SCMSourceCriteria branchCriteria = getCriteria ();
239
242
try (RevWalk walk = new RevWalk (repository )) {
240
243
walk .setRetainBody (false );
241
244
for (Branch b : client .getRemoteBranches ()) {
245
+ checkInterrupt ();
242
246
if (!b .getName ().startsWith (remoteName + "/" )) {
243
247
continue ;
244
248
}
245
249
final String branchName = StringUtils .removeStart (b .getName (), remoteName + "/" );
246
250
listener .getLogger ().println ("Checking branch " + branchName );
247
- if (isExcluded (branchName )) {
251
+ if (isExcluded (branchName )){
248
252
continue ;
249
253
}
250
- if (branchCriteria != null ) {
254
+ if (criteria != null ) {
251
255
RevCommit commit = walk .parseCommit (b .getSHA1 ());
252
256
final long lastModified = TimeUnit .SECONDS .toMillis (commit .getCommitTime ());
253
257
final RevTree tree = commit .getTree ();
254
- SCMSourceCriteria .Probe probe = new SCMSourceCriteria .Probe () {
258
+ SCMSourceCriteria .Probe probe = new SCMProbe () {
259
+ @ Override
260
+ public void close () throws IOException {
261
+ // no-op
262
+ }
263
+
255
264
@ Override
256
265
public String name () {
257
266
return branchName ;
@@ -263,13 +272,33 @@ public long lastModified() {
263
272
}
264
273
265
274
@ Override
266
- public boolean exists (@ NonNull String path ) throws IOException {
275
+ @ NonNull
276
+ public SCMProbeStat stat (@ NonNull String path ) throws IOException {
267
277
try (TreeWalk tw = TreeWalk .forPath (repository , path , tree )) {
268
- return tw != null ;
278
+ if (tw == null ) {
279
+ return SCMProbeStat .fromType (SCMFile .Type .NONEXISTENT );
280
+ }
281
+ FileMode fileMode = tw .getFileMode (0 );
282
+ if (fileMode == FileMode .MISSING ) {
283
+ return SCMProbeStat .fromType (SCMFile .Type .NONEXISTENT );
284
+ }
285
+ if (fileMode == FileMode .EXECUTABLE_FILE ) {
286
+ return SCMProbeStat .fromType (SCMFile .Type .REGULAR_FILE );
287
+ }
288
+ if (fileMode == FileMode .REGULAR_FILE ) {
289
+ return SCMProbeStat .fromType (SCMFile .Type .REGULAR_FILE );
290
+ }
291
+ if (fileMode == FileMode .SYMLINK ) {
292
+ return SCMProbeStat .fromType (SCMFile .Type .LINK );
293
+ }
294
+ if (fileMode == FileMode .TREE ) {
295
+ return SCMProbeStat .fromType (SCMFile .Type .DIRECTORY );
296
+ }
297
+ return SCMProbeStat .fromType (SCMFile .Type .OTHER );
269
298
}
270
299
}
271
300
};
272
- if (branchCriteria .isHead (probe , listener )) {
301
+ if (criteria .isHead (probe , listener )) {
273
302
listener .getLogger ().println ("Met criteria" );
274
303
} else {
275
304
listener .getLogger ().println ("Does not meet criteria" );
0 commit comments