@@ -213,37 +213,32 @@ public void setForbiddenFilePaths(List<FilePath> forbiddenFilePaths) {
213
213
* @return true is the rules match.
214
214
*/
215
215
public boolean isInteresting (String project , String branch , String topic , List <String > files ) {
216
- if (compareType .matches (pattern , project )) {
217
- for (Branch b : branches ) {
218
- boolean foundInterestingForbidden = false ;
219
- boolean foundInterestingTopicOrFile = false ;
220
- if (b .isInteresting (branch )) {
221
- if (forbiddenFilePaths != null ) {
222
- for (FilePath ffp : forbiddenFilePaths ) {
223
- if (ffp .isInteresting (files )) {
224
- foundInterestingForbidden = true ;
225
- break ;
226
- }
227
- }
228
- }
229
- if (isInterestingTopic (topic ) && isInterestingFile (files )) {
230
- foundInterestingTopicOrFile = true ;
216
+ if (!compareType .matches (pattern , project )) {
217
+ return false ;
218
+ }
219
+ for (Branch b : branches ) {
220
+ if (!b .isInteresting (branch )) {
221
+ continue ;
222
+ }
223
+
224
+ if (forbiddenFilePaths != null ) {
225
+ // Forbidden file paths take precedence over included file paths.
226
+ if (disableStrictForbiddenFileVerification ) {
227
+ // We need to check if all paths match forbidden file paths.
228
+ if (areAllFilesForbidden (files )) {
229
+ return false ;
231
230
}
232
- if (disableStrictForbiddenFileVerification ) {
233
- // Here we want to be able to trigger a build if the event contains
234
- // wanted topics or file paths even though there may be a forbidden file
235
- return foundInterestingTopicOrFile ;
236
- } else {
237
- if (foundInterestingForbidden ) {
238
- // we have a forbidden file and a wanted file path.
231
+ } else {
232
+ for (FilePath ffp : forbiddenFilePaths ) {
233
+ if (ffp .isInteresting (files )) {
239
234
return false ;
240
- } else if (foundInterestingTopicOrFile ) {
241
- // we DO not have a forbidden file and but we have a wanted file path.
242
- return true ;
243
235
}
244
236
}
245
237
}
246
238
}
239
+
240
+ return isInterestingTopic (topic ) && isInterestingFile (files ));
241
+
247
242
}
248
243
return false ;
249
244
}
@@ -302,6 +297,39 @@ private boolean isInterestingFile(List<String> files) {
302
297
return true ;
303
298
}
304
299
300
+ /**
301
+ * Check if all files from the list match any of forbidden file paths.
302
+ *
303
+ * @param files the files to check.
304
+ * @return true if all files match forbidden file paths.
305
+ */
306
+ private boolean areAllFilesForbidden (List <String > files ) {
307
+ for (String file : files ) {
308
+ if (!isForbiddenFile (file )) {
309
+ return false ;
310
+ }
311
+ }
312
+ return true ;
313
+ }
314
+
315
+ /**
316
+ * Checks if file matches any of the forbidden file paths.
317
+ *
318
+ * @param file the file path to check.
319
+ * @return true if any of the forbidden path rules match.
320
+ */
321
+ private boolean isForbiddenFile (String file ) {
322
+ if (forbiddenFilePaths == null || forbiddenFilePaths .size () == 0 ) {
323
+ return false ;
324
+ }
325
+ for (FilePath f : forbiddenFilePaths ) {
326
+ if (f .isInterestingFile (file )) {
327
+ return true ;
328
+ }
329
+ }
330
+ return false ;
331
+ }
332
+
305
333
@ Override
306
334
public Descriptor <GerritProject > getDescriptor () {
307
335
return Hudson .getInstance ().getDescriptor (getClass ());
0 commit comments