Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-19314] Don't poll if last checkout has not completed
  • Loading branch information
mc1arke committed Oct 21, 2013
1 parent 612c500 commit 7b50354
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -459,12 +459,20 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr
final SCMRevisionState baseline, final CvsRepository[] repositories)
throws IOException, InterruptedException {

AbstractBuild<?, ?> build = project.getLastBuild();

// No previous build? everything has changed
if (null == project.getLastBuild()) {
if (null == build) {
listener.getLogger().println("No previous build found, scheduling build");
return PollingResult.BUILD_NOW;
}

if (!build.hasChangeSetComputed() && build.isBuilding()) {
listener.getLogger().println("Previous build has not finished checkout."
+ " Not triggering build as no valid baseline comparison available.");
return PollingResult.NO_CHANGES;
}

final EnvVars envVars = project.getLastBuild().getEnvironment(listener);

final Date currentPollDate = Calendar.getInstance().getTime();
Expand Down Expand Up @@ -786,6 +794,8 @@ protected void postCheckout(AbstractBuild<?, ?> build, File changelogFile, CvsRe
listener, build.getEnvironment(listener), workspace));
}
new CVSChangeLogSet(build,changes).toFile(changelogFile);
} else {
createEmptyChangeLog(changelogFile, listener, "changelog");
}

// add the current workspace state as an action
Expand Down
39 changes: 31 additions & 8 deletions src/test/java/hudson/scm/CVSSCMTest.java
Expand Up @@ -173,8 +173,8 @@ public void testExcludeRegions() throws IOException, InterruptedException {
files.add(new CvsFile("test.ext", "1.1", false));
files.add(new CvsFile("subdir/test.ext", "1.1", false));
files.add(new CvsFile("subdir/subdir2/test.ext", "1.1", false));
Project project = new CustomFreeStyleProject(jenkinsRule.getInstance(), "testProject");

CustomFreeStyleProject project = new CustomFreeStyleProject(jenkinsRule.getInstance(), "testProject");
project.getLastBuild().setChangeSetComputed(true);
CvsRepository repository = new CvsRepository("repo", false, null, Arrays.<CvsRepositoryItem>asList(),
Arrays.<ExcludedRegion>asList(new ExcludedRegion("^[^/]*\\.ext$")), 3, null);
Map<CvsRepository, List<CvsFile>> repositoryState = new HashMap<CvsRepository, List<CvsFile>>();
Expand All @@ -187,7 +187,8 @@ public void testExcludeRegions() throws IOException, InterruptedException {

CustomCvs customCvs = new CustomCvs(Arrays.asList(repository), false, false, false, false, false, false, false);
customCvs.setRepositoryState(files);
CvsRevisionState state = (CvsRevisionState)customCvs.compareRemoteRevisionWith(project, null, null, listener, revisionState, new CvsRepository[]{repository}).baseline;
PollingResult pollingResult = customCvs.compareRemoteRevisionWith(project, null, null, listener, revisionState, new CvsRepository[]{repository});
CvsRevisionState state = (CvsRevisionState)pollingResult.baseline;
List<CvsFile> result = state.getModuleFiles().get(repository);
assertEquals(3, result.size());

Expand Down Expand Up @@ -255,23 +256,45 @@ public String getContents() {

private static class CustomFreeStyleProject extends FreeStyleProject {

private CustomFreestyleBuild lastBuild;

public CustomFreeStyleProject(Jenkins parent, String name) {
super(parent, name);
}

public FreeStyleBuild getLastBuild() {
try {
return new FreeStyleBuild(this);
lastBuild = new CustomFreestyleBuild(this);
} catch (IOException e) {
throw new RuntimeException("Could not create build", e);
throw new RuntimeException(e);
}
}

public CustomFreestyleBuild getLastBuild() {
return lastBuild;
}

public FreeStyleBuild getLastCompletedBuild() {
return getLastBuild();
}
}

private static class CustomFreestyleBuild extends FreeStyleBuild {

private boolean isChangeLogComputed;

public CustomFreestyleBuild(FreeStyleProject project) throws IOException {
super(project);
}

public boolean hasChangeSetComputed() {
return isChangeLogComputed;
}

public void setChangeSetComputed(boolean computed) {
this.isChangeLogComputed = computed;
}


}

private static class CustomCvs extends CVSSCM {

private List<CvsFile> files;
Expand Down

0 comments on commit 7b50354

Please sign in to comment.