Index: src/main/java/hudson/plugins/clearcase/AbstractClearCaseScm.java =================================================================== --- src/main/java/hudson/plugins/clearcase/AbstractClearCaseScm.java (revision 29961) +++ src/main/java/hudson/plugins/clearcase/AbstractClearCaseScm.java (working copy) @@ -435,8 +435,10 @@ @Override public boolean pollChanges(AbstractProject project, Launcher launcher, FilePath workspace, TaskListener listener) throws IOException, InterruptedException { - Run lastBuild = project.getLastBuild(); - if (lastBuild == null) { // No previous build, run + // get last build where computer is online HUDSON-6184 + Run lastBuild = getLastBuild(project.getBuilds()); + // no computer is online + if (lastBuild == null) { return true; } @@ -452,6 +454,21 @@ return historyAction.hasChanges(buildTime, poNormalizedViewName, getBranchNames(), getViewPaths()); } + /** + * Get last build where computer is online + * + * @param all builds of project + * @return build where computer ran on is online + */ + private Run getLastBuild(List> builds) { + for (AbstractBuild build : builds) { + if (!getBuildComputer(build).isOffline()) { + return build; + } + } + return null; + } + private Date getBuildTime(Run lastBuild) { Date buildTime = lastBuild.getTimestamp().getTime(); if (getMultiSitePollBuffer() != 0) { Index: src/test/java/hudson/plugins/clearcase/AbstractClearCaseScmTest.java =================================================================== --- src/test/java/hudson/plugins/clearcase/AbstractClearCaseScmTest.java (revision 29961) +++ src/test/java/hudson/plugins/clearcase/AbstractClearCaseScmTest.java (working copy) @@ -51,6 +51,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -539,7 +540,7 @@ ignoring(build).getParent(); will(returnValue(project)); allowing(build).getTimestamp(); will(returnValue(mockedCalendar)); allowing(computer).getName(); will(returnValue("test-node")); - one(project).getLastBuild(); will(returnValue(build)); + one(project).getBuilds(); will(returnValue(new ArrayList>())); } }); AbstractClearCaseScm scm = new AbstractClearCaseScmDummy("viewname", "vob", ""); @@ -567,7 +568,7 @@ { ignoring(build).getParent(); will(returnValue(project)); allowing(build).getTimestamp(); will(returnValue(mockedCalendar)); - one(project).getLastBuild(); will(returnValue(build)); + one(project).getBuilds(); will(returnValue(new ArrayList>())); } }); AbstractClearCaseScm scm = new AbstractClearCaseScmDummy("viewname", "", false, false, false, "", @@ -594,7 +595,7 @@ { ignoring(build).getParent(); will(returnValue(project)); ignoring(build).getTimestamp(); will(returnValue(Calendar.getInstance())); - ignoring(project).getLastBuild(); will(returnValue(build)); + one(project).getBuilds(); will(returnValue(new ArrayList>())); one(project).getName(); will(returnValue("CCHudson")); allowing(computer).getName(); will(returnValue("test-node")); } @@ -607,7 +608,7 @@ public void testPollChangesFirstTime() throws Exception { classContext.checking(new Expectations() { { - one(project).getLastBuild(); will(returnValue(null)); + one(project).getBuilds(); will(returnValue(new ArrayList>())); } }); @@ -615,6 +616,20 @@ boolean hasChanges = scm.pollChanges(project, launcher, workspace, taskListener); assertTrue("The first time should always return true", hasChanges); } + + @Test + public void testPollChangesNoSlaveOnline() throws Exception { + classContext.checking(new Expectations() { + { + one(project).getBuilds(); will(returnValue(Arrays.asList(build))); + one(computer).isOffline(); will(returnValue(true)); + } + }); + + AbstractClearCaseScm scm = new AbstractClearCaseScmDummy("viewname", "vob", ""); + boolean hasChanges = scm.pollChanges(project, launcher, workspace, taskListener); + assertTrue("Changes should be polled if no slave is available", hasChanges); + } @Test public void testPollChangesWithNoHistory() throws Exception { @@ -635,7 +650,8 @@ { ignoring(build).getParent(); will(returnValue(project)); one(build).getTimestamp(); will(returnValue(mockedCalendar)); - one(project).getLastBuild(); will(returnValue(build)); + one(project).getBuilds(); will(returnValue(Arrays.asList(build))); + one(computer).isOffline(); will(returnValue(false)); } }); @@ -665,7 +681,7 @@ { ignoring(build).getParent(); will(returnValue(project)); one(build).getTimestamp(); will(returnValue(mockedCalendar)); - one(project).getLastBuild(); will(returnValue(build)); + one(project).getBuilds(); will(returnValue(new ArrayList>())); } }); AbstractClearCaseScm scm = new AbstractClearCaseScmDummy("viewname", "vob", ""); @@ -690,7 +706,7 @@ { ignoring(build).getParent(); will(returnValue(project)); one(build).getTimestamp(); will(returnValue(mockedCalendar)); - one(project).getLastBuild(); will(returnValue(build)); + one(project).getBuilds(); will(returnValue(new ArrayList>())); } }); @@ -715,7 +731,7 @@ { ignoring(build).getParent(); will(returnValue(project)); one(build).getTimestamp(); will(returnValue(mockedCalendar)); - one(project).getLastBuild(); will(returnValue(build)); + one(project).getBuilds(); will(returnValue(new ArrayList>())); ignoring(build).addAction(with(any(ClearCaseDataAction.class))); } }); @@ -741,9 +757,10 @@ classContext.checking(new Expectations() { { ignoring(matrixBuild).getParent(); will(returnValue(project)); - one(project).getLastBuild(); will(returnValue(matrixBuild)); one(matrixBuild).getTimestamp(); will(returnValue(mockedCalendar)); ignoring(build).addAction(with(any(ClearCaseDataAction.class))); + one(project).getBuilds(); will(returnValue(Arrays.asList(matrixBuild))); + one(computer).isOffline(); will(returnValue(false)); } }); @@ -765,8 +782,10 @@ { ignoring(build).getParent(); will(returnValue(project)); ignoring(build).getTimestamp(); will(returnValue(Calendar.getInstance())); - ignoring(project).getLastBuild(); will(returnValue(build)); ignoring(project).getName(); will(returnValue("CCHudson")); + one(project).getBuilds(); will(returnValue(Arrays.asList(build))); + one(computer).isOffline(); will(returnValue(false)); + } });