Skip to content
Permalink
Browse files
Option to permit disable Strict Forbidden files
Add option to gerrit project to permit the disable of the default
strict forbidden file verification of an event

Enabling this option will allow an event to trigger a build if the event contains BOTH one or more wanted file paths/topics/branches AND one or more forbidden file paths.

In other words, with this option, the build will not get triggered if the change contains only forbidden files, otherwise it will get triggered.

[FIXED JENKINS-30620]

Change-Id: Icb84111c82a38db722ec09bf7538441bc1b9424a
  • Loading branch information
Scott Hebert committed Oct 1, 2015
1 parent a86fa5b commit 897bb7bdd132530b28401f0a628ce46d194f3c01
@@ -176,7 +176,7 @@ private static List<GerritProject> readAndParseTriggerConfig(BufferedReader read
topics = new ArrayList<Topic>();
filePaths = new ArrayList<FilePath>();
forbiddenFilePaths = new ArrayList<FilePath>();
dynamicGerritProject = new GerritProject(type, text, branches, topics, filePaths, forbiddenFilePaths);
dynamicGerritProject = new GerritProject(type, text, branches, topics, filePaths, forbiddenFilePaths, false);
} else if (SHORTNAME_BRANCH.equals(item)) { // Branch
if (branches == null) {
throw new ParseException("Line " + lineNr + ": attempt to use 'Branch' before 'Project'", lineNr);
@@ -54,6 +54,7 @@ public class GerritProject implements Describable<GerritProject> {
private List<FilePath> filePaths;
private List<Topic> topics;
private List<FilePath> forbiddenFilePaths;
private boolean disableStrictForbiddenFileVerification;

/**
* Default empty constructor.
@@ -70,6 +71,7 @@ public GerritProject() {
* @param topics the topic-rules
* @param filePaths the file-path rules.
* @param forbiddenFilePaths the forbidden file-path rules.
* @param disableStrictForbiddenFileVerification whether to be strict or not.
*/
@DataBoundConstructor
public GerritProject(
@@ -78,14 +80,32 @@ public GerritProject(
List<Branch> branches,
List<Topic> topics,
List<FilePath> filePaths,
List<FilePath> forbiddenFilePaths) {
List<FilePath> forbiddenFilePaths,
boolean disableStrictForbiddenFileVerification) {

this.compareType = compareType;
this.pattern = pattern;
this.branches = branches;
this.topics = topics;
this.filePaths = filePaths;
this.forbiddenFilePaths = forbiddenFilePaths;
this.disableStrictForbiddenFileVerification = disableStrictForbiddenFileVerification;
}

/**
* Whether to disable strict verification of forbidden files.
* @return true if disabled.
*/
public boolean isDisableStrictForbiddenFileVerification() {
return disableStrictForbiddenFileVerification;
}

/**
* Set whether to disable strict verification of forbidden files.
* @param disableStrictForbiddenFileVerification true to disable.
*/
public void setDisableStrictForbiddenFileVerification(boolean disableStrictForbiddenFileVerification) {
this.disableStrictForbiddenFileVerification = disableStrictForbiddenFileVerification;
}

/**
@@ -195,16 +215,32 @@ public void setForbiddenFilePaths(List<FilePath> forbiddenFilePaths) {
public boolean isInteresting(String project, String branch, String topic, List<String> files) {
if (compareType.matches(pattern, project)) {
for (Branch b : branches) {
boolean foundInterestingForbidden = false;
boolean foundInterestingTopicOrFile = false;
if (b.isInteresting(branch)) {
if (forbiddenFilePaths != null) {
for (FilePath ffp : forbiddenFilePaths) {
if (ffp.isInteresting(files)) {
return false;
foundInterestingForbidden = true;
break;
}
}
}
if (isInterestingTopic(topic) && isInterestingFile(files)) {
return true;
foundInterestingTopicOrFile = true;
}
if (disableStrictForbiddenFileVerification) {
// Here we want to be able to trigger a build if the event contains
// wanted topics or file paths even though there may be a forbidden file
return foundInterestingTopicOrFile;
} else {
if (foundInterestingForbidden) {
// we have a forbidden file and a wanted file path.
return false;
} else if (foundInterestingTopicOrFile) {
// we DO not have a forbidden file and but we have a wanted file path.
return true;
}
}
}
}
@@ -387,6 +387,13 @@
</f:repeatable>
</td>
</tr>
<tr>
<td colspan="4" valign="top" style="border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black;">
<label>Disable Strict Forbidden File Verification</label>
<f:checkbox name="disableStrictForbiddenFileVerification"
checked="${loop.isDisableStrictForbiddenFileVerification()}"/>
</td>
</tr>
</j:if>
</table>
</f:repeatable>
@@ -43,3 +43,8 @@
<p>
You can add more file path patterns by clicking on &quot;Add File path&quot;
</p>
<p><strong>Disabling strict forbidden file verification</strong></p>
<ul>
<li>Enabling this option will allow an event to trigger a build if the event contains <strong>BOTH</strong> one or more wanted file paths <strong>AND</strong> one or more forbidden file paths. </li>
<li>In other words, with this option, the build will not get triggered if the change contains only forbidden files, otherwise it will get triggered.</li>
</ul>
@@ -95,7 +95,7 @@ public void testIt() throws IOException, InterruptedException {
trigger.setGerritProjects(Collections.singletonList(
new GerritProject(CompareType.PLAIN, event.getChange().getProject(),
Collections.singletonList(new Branch(CompareType.PLAIN, event.getChange().getBranch())),
null, null, null)
null, null, null, false)
));
trigger.setSilentMode(false);
trigger.setGerritBuildSuccessfulCodeReviewValue(1);
@@ -63,7 +63,7 @@ private GerritProject createGerritProject(String pattern, CompareType compareTyp
List<Branch> branches = new LinkedList<Branch>();
Branch branch = new Branch(compareType, "master");
branches.add(branch);
GerritProject config = new GerritProject(CompareType.PLAIN, pattern, branches, null, null, null);
GerritProject config = new GerritProject(CompareType.PLAIN, pattern, branches, null, null, null, false);
return config;
}

@@ -918,7 +918,7 @@ public void testGerritEventRefUpdatedShortName() {
branches.add(br);

GerritProject gP = new GerritProject(
CompareType.PLAIN, "job", branches, null, null, null);
CompareType.PLAIN, "job", branches, null, null, null, false);

GerritTrigger trigger = Setup.createRefUpdatedTrigger(project);
Setup.setTrigger(trigger, project);
@@ -956,7 +956,7 @@ public void testGerritEventRefUpdatedLongName() {
branches.add(br);

GerritProject gP = new GerritProject(
CompareType.PLAIN, "job", branches, null, null, null);
CompareType.PLAIN, "job", branches, null, null, null, false);

GerritTrigger trigger = Setup.createRefUpdatedTrigger(project);
Setup.setTrigger(trigger, project);
@@ -994,7 +994,7 @@ public void testGerritEventRefUpdatedWithTag() {
branches.add(br);

GerritProject gP = new GerritProject(
CompareType.PLAIN, "job", branches, null, null, null);
CompareType.PLAIN, "job", branches, null, null, null, false);

GerritTrigger trigger = Setup.createRefUpdatedTrigger(project);
Setup.setTrigger(trigger, project);
@@ -152,7 +152,7 @@ private WorkflowJob createWorkflowJob(PatchsetCreated event) throws IOException
trigger.setGerritProjects(Collections.singletonList(
new GerritProject(CompareType.PLAIN, event.getChange().getProject(),
Collections.singletonList(new Branch(CompareType.PLAIN, event.getChange().getBranch())),
null, null, null)
null, null, null, false)
));
trigger.setSilentMode(false);
trigger.setGerritBuildSuccessfulCodeReviewValue(1);
@@ -75,43 +75,43 @@ public static Collection getParameters() {
List<Topic> topics = new LinkedList<Topic>();
Branch branch = new Branch(CompareType.PLAIN, "master");
branches.add(branch);
GerritProject config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
GerritProject config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config, "project", "master", null, true)});

branches = new LinkedList<Branch>();
branch = new Branch(CompareType.ANT, "**/master");
branches.add(branch);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config,
"project", "origin/master", null, true), });

branches = new LinkedList<Branch>();
branch = new Branch(CompareType.ANT, "**/master");
branches.add(branch);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config, "project", "master", null, true)});

branches = new LinkedList<Branch>();
branch = new Branch(CompareType.ANT, "**/master");
branches.add(branch);
branch = new Branch(CompareType.REG_EXP, "feature/.*master");
branches.add(branch);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config, "project", "master", null, true)});

branches = new LinkedList<Branch>();
branch = new Branch(CompareType.PLAIN, "olstorp");
branches.add(branch);
branch = new Branch(CompareType.REG_EXP, "feature/.*master");
branches.add(branch);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config,
"project", "feature/mymaster", null, true), });

branches = new LinkedList<Branch>();
branch = new Branch(CompareType.ANT, "**/master");
branches.add(branch);
config = new GerritProject(CompareType.ANT, "vendor/**/project", branches, topics, null, null);
config = new GerritProject(CompareType.ANT, "vendor/**/project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config,
"vendor/semc/master/project", "origin/master", null, true), });

@@ -121,20 +121,20 @@ public static Collection getParameters() {
topics = new LinkedList<Topic>();
Topic topic = new Topic(CompareType.PLAIN, "topic");
topics.add(topic);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config, "project", "master", "topic", true)});

topics = new LinkedList<Topic>();
topic = new Topic(CompareType.ANT, "**/topic");
topics.add(topic);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config,
"project", "master", "team/topic", true), });

topics = new LinkedList<Topic>();
topic = new Topic(CompareType.REG_EXP, ".*_topic");
topics.add(topic);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, null, null, false);
parameters.add(new InterestingScenario[]{new InterestingScenario(config,
"project", "master", "team-wolf_topic", true), });

@@ -78,7 +78,7 @@ public static Collection getParameters() {
filePaths.add(filePath);
List<FilePath> forbiddenFilePaths = null;
GerritProject config = new GerritProject(
CompareType.PLAIN, "project", branches, topics, filePaths, forbiddenFilePaths);
CompareType.PLAIN, "project", branches, topics, filePaths, forbiddenFilePaths, false);
List<String> files = new LinkedList<String>();
files.add("test.txt");
parameters.add(new InterestingScenarioWithFiles[]{new InterestingScenarioWithFiles(
@@ -93,7 +93,8 @@ public static Collection getParameters() {
files = new LinkedList<String>();
files.add("tests/test.txt");
forbiddenFilePaths = null;
config = new GerritProject(CompareType.REG_EXP, "project.*5", branches, topics, filePaths, forbiddenFilePaths);
config = new GerritProject(CompareType.REG_EXP, "project.*5", branches, topics, filePaths, forbiddenFilePaths,
false);
parameters.add(new InterestingScenarioWithFiles[]{new InterestingScenarioWithFiles(
config, "projectNumber5", "feature/mymaster", null, files, true), });

@@ -105,7 +106,7 @@ public static Collection getParameters() {
filePaths.add(filePath);
forbiddenFilePaths = null;
config = new GerritProject(
CompareType.ANT, "vendor/**/project", branches, topics, filePaths, forbiddenFilePaths);
CompareType.ANT, "vendor/**/project", branches, topics, filePaths, forbiddenFilePaths, false);
files = new LinkedList<String>();
files.add("resources/test.xml");
parameters.add(new InterestingScenarioWithFiles[]{new InterestingScenarioWithFiles(
@@ -120,7 +121,8 @@ public static Collection getParameters() {
files = new LinkedList<String>();
files.add("notintests/test.txt");
forbiddenFilePaths = null;
config = new GerritProject(CompareType.REG_EXP, "project.*5", branches, topics, filePaths, forbiddenFilePaths);
config = new GerritProject(CompareType.REG_EXP, "project.*5", branches, topics, filePaths, forbiddenFilePaths,
false);
parameters.add(new InterestingScenarioWithFiles[]{new InterestingScenarioWithFiles(
config, "projectNumber5", "feature/mymaster", null, files, false), });

@@ -135,13 +137,32 @@ public static Collection getParameters() {
forbiddenFilePaths = new LinkedList<FilePath>();
FilePath forbiddenFilePath = new FilePath(CompareType.PLAIN, "test2.txt");
forbiddenFilePaths.add(forbiddenFilePath);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, filePaths, forbiddenFilePaths);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, filePaths, forbiddenFilePaths, false);
files = new LinkedList<String>();
files.add("test.txt");
files.add("test2.txt");
parameters.add(new InterestingScenarioWithFiles[]{new InterestingScenarioWithFiles(
config, "project", "master", null, files, false), });

//Testing with Forbidden File Paths now BUT disableStrictForbiddenFileVerification
// is true
branches = new LinkedList<Branch>();
branch = new Branch(CompareType.PLAIN, "master");
branches.add(branch);
topics = new LinkedList<Topic>();
filePaths = new LinkedList<FilePath>();
filePath = new FilePath(CompareType.PLAIN, "test.txt");
filePaths.add(filePath);
forbiddenFilePaths = new LinkedList<FilePath>();
forbiddenFilePath = new FilePath(CompareType.PLAIN, "test2.txt");
forbiddenFilePaths.add(forbiddenFilePath);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, filePaths, forbiddenFilePaths, true);
files = new LinkedList<String>();
files.add("test.txt");
files.add("test2.txt");
parameters.add(new InterestingScenarioWithFiles[]{new InterestingScenarioWithFiles(
config, "project", "master", null, files, true), });

//Testing with Forbidden File Paths now BUT no filepaths defined
branches = new LinkedList<Branch>();
branch = new Branch(CompareType.PLAIN, "master");
@@ -151,7 +172,7 @@ public static Collection getParameters() {
forbiddenFilePaths = new LinkedList<FilePath>();
forbiddenFilePath = new FilePath(CompareType.PLAIN, "test2.txt");
forbiddenFilePaths.add(forbiddenFilePath);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, filePaths, forbiddenFilePaths);
config = new GerritProject(CompareType.PLAIN, "project", branches, topics, filePaths, forbiddenFilePaths, false);
files = new LinkedList<String>();
files.add("test.txt");
files.add("test2.txt");
@@ -170,7 +191,8 @@ public static Collection getParameters() {
files = new LinkedList<String>();
files.add("tests/test.txt");
files.add("tests/test2.txt");
config = new GerritProject(CompareType.REG_EXP, "project.*5", branches, topics, filePaths, forbiddenFilePaths);
config = new GerritProject(CompareType.REG_EXP, "project.*5", branches, topics, filePaths, forbiddenFilePaths,
false);
parameters.add(new InterestingScenarioWithFiles[]{new InterestingScenarioWithFiles(
config, "projectNumber5", "feature/mymaster", null, files, false), });

@@ -184,7 +206,7 @@ public static Collection getParameters() {
forbiddenFilePath = new FilePath(CompareType.ANT, "**/*skip*");
forbiddenFilePaths.add(forbiddenFilePath);
config = new GerritProject(
CompareType.ANT, "vendor/**/project", branches, topics, filePaths, forbiddenFilePaths);
CompareType.ANT, "vendor/**/project", branches, topics, filePaths, forbiddenFilePaths, false);
files = new LinkedList<String>();
files.add("resources/test.xml");
files.add("files/skip.txt");

0 comments on commit 897bb7b

Please sign in to comment.