提交 e2e3ac2e 编写于 作者: M mindless

[FIXED HUDSON-3168] "return changesFound;" was inside for-loop for multiple locations,

so pollChanges always returned after checking only first location.
Also fixed form field validator to handle unix newlines.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15981 71c3de6d-444a-0410-be80-ed276b4c234a
上级 c1852a75
......@@ -281,13 +281,11 @@ public class SubversionSCM extends SCM implements Serializable {
private Pattern[] getExcludedRegionsPatterns() {
String[] excludedRegions = getExcludedRegionsNormalized();
if (excludedRegions != null)
{
if (excludedRegions != null) {
Pattern[] patterns = new Pattern[excludedRegions.length];
int i = 0;
for (String excludedRegion : excludedRegions)
{
for (String excludedRegion : excludedRegions) {
patterns[i++] = Pattern.compile(excludedRegion);
}
......@@ -473,7 +471,7 @@ public class SubversionSCM extends SCM implements Serializable {
}
/**
/**
* Either run "svn co" or "svn up" equivalent.
*/
private static class CheckOutTask implements FileCallable<List<External>> {
......@@ -865,7 +863,6 @@ public class SubversionSCM extends SCM implements Serializable {
}
try {
if (!repositoryLocationsExist(lastBuild, listener)) {
// Disable this project, see issue #763
......@@ -904,17 +901,14 @@ public class SubversionSCM extends SCM implements Serializable {
if(ext.url.equals(url) && ext.isRevisionFixed())
continue OUTER;
boolean changesFound = false;
try {
final SVNURL decodedURL = SVNURL.parseURIDecoded(url);
SvnInfo remoteInfo = new SvnInfo(parseSvnInfo(decodedURL,authProvider));
listener.getLogger().println(Messages.SubversionSCM_pollChanges_remoteRevisionAt(url,remoteInfo.revision));
if(remoteInfo.revision > localInfo.getValue()) {
Pattern[] excludedPatterns = getExcludedRegionsPatterns();
if (excludedPatterns == null) {
changesFound = true; // change found
} else {
try {
try {
final SVNURL decodedURL = SVNURL.parseURIDecoded(url);
SvnInfo remoteInfo = new SvnInfo(parseSvnInfo(decodedURL,authProvider));
listener.getLogger().println(Messages.SubversionSCM_pollChanges_remoteRevisionAt(url,remoteInfo.revision));
if(remoteInfo.revision > localInfo.getValue()) {
boolean changesFound = true;
Pattern[] excludedPatterns = getExcludedRegionsPatterns();
if (excludedPatterns != null) {
SVNLogHandler handler = new SVNLogHandler(excludedPatterns);
final SVNClientManager manager = createSvnClientManager(authProvider);
try {
......@@ -931,28 +925,22 @@ public class SubversionSCM extends SCM implements Serializable {
}
changesFound = handler.isChangesFound();
} catch (SVNException e) {
e.printStackTrace(listener.error("Failed to check repository revision for "+ url));
changesFound = false;
}
}
if (changesFound) {
listener.getLogger().println(Messages.SubversionSCM_pollChanges_changedFrom(localInfo.getValue()));
}
}
} catch (SVNException e) {
e.printStackTrace(listener.error("Failed to check repository revision for "+ url));
changesFound = false;
}
return changesFound;
}
if (changesFound) {
listener.getLogger().println(Messages.SubversionSCM_pollChanges_changedFrom(localInfo.getValue()));
return true;
}
}
} catch (SVNException e) {
e.printStackTrace(listener.error("Failed to check repository revision for "+ url));
}
}
return false; // no change
}
private final class SVNLogHandler implements ISVNLogEntryHandler {
private final class SVNLogHandler implements ISVNLogEntryHandler {
private boolean changesFound = false;
private Pattern[] excludedPatterns;
......@@ -1001,7 +989,7 @@ public class SubversionSCM extends SCM implements Serializable {
changesFound = true;
}
}
}
}
public ChangeLogParser createChangeLogParser() {
return new SubversionChangeLogParser();
......@@ -1584,7 +1572,7 @@ public class SubversionSCM extends SCM implements Serializable {
}.process();
}
/**
/**
* Validates the excludeRegions Regex
*/
public void doExcludeRegionsCheck(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
......@@ -1593,7 +1581,7 @@ public class SubversionSCM extends SCM implements Serializable {
String v = fixEmptyAndTrim(request.getParameter("value"));
if(v != null) {
String[] regions = v.split("\\r\\n");
String[] regions = v.split("[\\r\\n]+");
for (String region : regions) {
try {
Pattern.compile(region);
......
......@@ -31,6 +31,8 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.*;
import java.io.FileWriter;
import java.util.Map;
import org.dom4j.Document;
import org.dom4j.io.DOMReader;
import org.jvnet.hudson.test.Bug;
......@@ -51,7 +53,7 @@ public class SubversionSCMTest extends HudsonTestCase {
// create a build
FreeStyleProject p = createFreeStyleProject();
p.setScm(loadSvnRepo());
FreeStyleBuild b = p.scheduleBuild2(0).get();
FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserCause()).get();
System.out.println(b.getLog());
assertBuildStatus(Result.SUCCESS,b);
......@@ -108,7 +110,7 @@ public class SubversionSCMTest extends HudsonTestCase {
true, null, null
));
FreeStyleBuild b = p.scheduleBuild2(0).get();
FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserCause()).get();
System.out.println(b.getLog());
assertBuildStatus(Result.SUCCESS,b);
assertTrue(p.getWorkspace().child("trivial-ant/build.xml").exists());
......@@ -123,7 +125,7 @@ public class SubversionSCMTest extends HudsonTestCase {
true, null, null
));
FreeStyleBuild b = p.scheduleBuild2(0).get();
FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserCause()).get();
System.out.println(b.getLog());
assertBuildStatus(Result.SUCCESS,b);
assertTrue(p.getWorkspace().child("jasf/maven.xml").exists());
......@@ -141,12 +143,12 @@ public class SubversionSCMTest extends HudsonTestCase {
true, null, null
));
FreeStyleBuild b = p.scheduleBuild2(0).get();
FreeStyleBuild b = p.scheduleBuild2(0, new Cause.UserCause()).get();
System.out.println(b.getLog());
assertTrue(b.getLog().contains("At revision 13000"));
assertBuildStatus(Result.SUCCESS,b);
b = p.scheduleBuild2(0).get();
b = p.scheduleBuild2(0, new Cause.UserCause()).get();
System.out.println(b.getLog());
assertTrue(b.getLog().contains("At revision 13000"));
assertBuildStatus(Result.SUCCESS,b);
......@@ -161,7 +163,7 @@ public class SubversionSCMTest extends HudsonTestCase {
// fetch the current workspace
FreeStyleProject p = createFreeStyleProject();
p.setScm(loadSvnRepo());
p.scheduleBuild2(0).get();
p.scheduleBuild2(0, new Cause.UserCause()).get();
// as a baseline, this shouldn't detect any change
TaskListener listener = createTaskListener();
......@@ -173,7 +175,7 @@ public class SubversionSCMTest extends HudsonTestCase {
assertTrue(p.pollSCMChanges(listener));
// build it once again to switch
p.scheduleBuild2(0).get();
p.scheduleBuild2(0, new Cause.UserCause()).get();
// then no more change should be detected
assertFalse(p.pollSCMChanges(listener));
......@@ -197,4 +199,38 @@ public class SubversionSCMTest extends HudsonTestCase {
assertTrue(p.getWorkspace().child("jasf/maven.xml").exists());
}
/**
* Test that multiple repository URLs are all polled.
*/
@Bug(3168)
public void testPollMultipleRepositories() throws Exception {
// fetch the current workspaces
FreeStyleProject p = createFreeStyleProject();
String svnBase = "file://" + new CopyExisting(getClass().getResource("/svn-repo.zip")).allocate().toURI().toURL().getPath();
p.setScm(new SubversionSCM(
new String[] { svnBase + "trunk/a", svnBase + "branches" },
new String[] { null, null }, true, null, null));
AbstractBuild build = p.scheduleBuild2(0, new Cause.UserCause()).get();
// as a baseline, this shouldn't detect any change
TaskListener listener = createTaskListener();
assertFalse(p.pollSCMChanges(listener));
// Force older "current revision" for each repository, make sure both are detected
Map<String,Long> revInfo = SubversionSCM.parseRevisionFile(build);
for (String outOfDateItem : new String[] { "branches", "trunk/a" }) {
FileWriter out = new FileWriter(SubversionSCM.getRevisionFile(build));
for (Map.Entry<String,Long> entry : revInfo.entrySet()) {
out.write(entry.getKey());
out.write('/');
out.write(Long.toString(
entry.getValue().longValue() - (entry.getKey().endsWith(outOfDateItem) ? 1 : 0)));
out.write('\n');
}
out.close();
// now the polling should indicate that we need a new build
assertTrue("change was not detected!", p.pollSCMChanges(listener));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册