提交 e106880a 编写于 作者: D draco2k8

[FIXED HUDSON-848] Added ability for CVS polling to ignore commits of certain...

[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
上级 1a0b5187
......@@ -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<String> 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.
*/
......
......@@ -48,5 +48,8 @@ THE SOFTWARE.
<f:checkbox name="cvs.canUseUpdate" checked="${h.defaultToTrue(scm.canUseUpdate)}"/>
</f:entry>
<t:listScmBrowsers name="cvs.browser" />
<f:entry title="${%Excluded Regions}" help="/help/_cvs/excludedRegions.html">
<f:textarea name="cvs.excludedRegions" value="${scm.excludedRegions}" checkUrl="'${rootURL}/scm/CVSSCM/excludeRegionsCheck?value='+escape(this.value)"/>
</f:entry>
</f:advanced>
</j:jelly>
\ No newline at end of file
<div>
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.
<p/>Each exclusion uses regular expression pattern matching, and must be separated by a new line.
<p/>
<pre>
src/main/web/.*\.html
src/main/web/.*\.jpeg
src/main/web/.*\.gif
</pre>
The example above illustrates that if only html/jpeg/gif files have been committed to the SCM a build will not occur.
<p/>More information on regular expressions can be found <a href="http://www.regular-expressions.info/">here</a>.
</div>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册