From e106880aba10a0399e092fc91532ef2d659c3034 Mon Sep 17 00:00:00 2001 From: draco2k8 Date: Wed, 18 Feb 2009 14:21:31 +0000 Subject: [PATCH] [FIXED HUDSON-848] Added ability for CVS polling to ignore commits of certain files as unimportant to the build process succeeding (e.g. HTML files) - thus a build would not be triggered. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15426 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/scm/CVSSCM.java | 95 ++++++++++++++++++- .../resources/hudson/scm/CVSSCM/config.jelly | 3 + war/resources/help/_cvs/excludedRegions.html | 12 +++ 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 war/resources/help/_cvs/excludedRegions.html diff --git a/core/src/main/java/hudson/scm/CVSSCM.java b/core/src/main/java/hudson/scm/CVSSCM.java index 79821e5d0f..4ce04c36d5 100644 --- a/core/src/main/java/hudson/scm/CVSSCM.java +++ b/core/src/main/java/hudson/scm/CVSSCM.java @@ -31,6 +31,7 @@ import hudson.Proc; import hudson.Util; import static hudson.Util.fixEmpty; import static hudson.Util.fixNull; +import static hudson.Util.fixEmptyAndTrim; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.model.BuildListener; @@ -93,6 +94,7 @@ import java.util.TreeSet; import java.util.concurrent.ExecutionException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import net.sf.json.JSONObject; @@ -140,8 +142,10 @@ public class CVSSCM extends SCM implements Serializable { private boolean isTag; + private String excludedRegions; + @DataBoundConstructor - public CVSSCM(String cvsRoot, String module,String branch,String cvsRsh,boolean canUseUpdate, boolean legacy, boolean isTag) { + public CVSSCM(String cvsRoot, String module,String branch,String cvsRsh,boolean canUseUpdate, boolean legacy, boolean isTag, String excludedRegions) { if(fixNull(branch).equals("HEAD")) branch = null; @@ -152,6 +156,7 @@ public class CVSSCM extends SCM implements Serializable { this.canUseUpdate = canUseUpdate; this.flatten = !legacy && getAllModulesNormalized().length==1; this.isTag = isTag; + this.excludedRegions = excludedRegions; } @Override @@ -217,6 +222,32 @@ public class CVSSCM extends SCM implements Serializable { return module; } + public String getExcludedRegions() { + return excludedRegions; + } + + public String[] getExcludedRegionsNormalized() { + return excludedRegions == null ? null : excludedRegions.split("[\\r\\n]+"); + } + + private Pattern[] getExcludedRegionsPatterns() { + String[] excludedRegions = getExcludedRegionsNormalized(); + if (excludedRegions != null) + { + Pattern[] patterns = new Pattern[excludedRegions.length]; + + int i = 0; + for (String excludedRegion : excludedRegions) + { + patterns[i++] = Pattern.compile(excludedRegion); + } + + return patterns; + } + + return null; + } + /** * List up all modules to check out. */ @@ -257,7 +288,43 @@ public class CVSSCM extends SCM implements Serializable { List changedFiles = update(true, launcher, dir, listener, new Date()); - return changedFiles!=null && !changedFiles.isEmpty(); + if (changedFiles != null && !changedFiles.isEmpty()) + { + Pattern[] patterns = getExcludedRegionsPatterns(); + + if (patterns != null) + { + boolean areThereChanges = false; + + for (String changedFile : changedFiles) + { + boolean patternMatched = false; + + for (Pattern pattern : patterns) + { + if (pattern.matcher(changedFile).matches()) + { + patternMatched = true; + break; + } + } + + if (!patternMatched) + { + areThereChanges = true; + break; + } + } + + return areThereChanges; + } + + // no excluded patterns so just return true as + // changedFiles != null && !changedFiles.isEmpty() is true + return true; + } + + return false; } private void configureDate(ArgumentListBuilder cmd, Date date) { // #192 @@ -1170,6 +1237,30 @@ public class CVSSCM extends SCM implements Serializable { }.process(); } + /** + * Validates the excludeRegions Regex + */ + public void doExcludeRegionsCheck(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + new FormFieldValidator(req,rsp,false) { + protected void check() throws IOException, ServletException { + String v = fixEmptyAndTrim(request.getParameter("value")); + + if(v != null) { + String[] regions = v.split("\\r\\n"); + for (String region : regions) { + try { + Pattern.compile(region); + } + catch (PatternSyntaxException e) { + error("Invalid regular expression. " + e.getMessage()); + } + } + } + ok(); + } + }.process(); + } + /** * Checks if the given pserver CVSROOT value exists in the pass file. */ diff --git a/core/src/main/resources/hudson/scm/CVSSCM/config.jelly b/core/src/main/resources/hudson/scm/CVSSCM/config.jelly index ba2d6923af..fe854e6ca8 100644 --- a/core/src/main/resources/hudson/scm/CVSSCM/config.jelly +++ b/core/src/main/resources/hudson/scm/CVSSCM/config.jelly @@ -48,5 +48,8 @@ THE SOFTWARE. + + + \ No newline at end of file diff --git a/war/resources/help/_cvs/excludedRegions.html b/war/resources/help/_cvs/excludedRegions.html new file mode 100644 index 0000000000..7cfae8125f --- /dev/null +++ b/war/resources/help/_cvs/excludedRegions.html @@ -0,0 +1,12 @@ +
+ If set, and Hudson is set to poll for changes, Hudson will ignore any files and/or folders in this list when determining if a build needs to be triggered. +

Each exclusion uses regular expression pattern matching, and must be separated by a new line. +

+

+	 src/main/web/.*\.html
+	 src/main/web/.*\.jpeg
+	 src/main/web/.*\.gif
+  
+ The example above illustrates that if only html/jpeg/gif files have been committed to the SCM a build will not occur. +

More information on regular expressions can be found here. +

\ No newline at end of file -- GitLab