diff --git a/src/main/java/hudson/scm/AbstractCvs.java b/src/main/java/hudson/scm/AbstractCvs.java index 3e00049..d94e624 100644 --- a/src/main/java/hudson/scm/AbstractCvs.java +++ b/src/main/java/hudson/scm/AbstractCvs.java @@ -30,6 +30,7 @@ import hudson.Util; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; +import hudson.model.Job; import hudson.model.Run; import hudson.model.BuildListener; import hudson.model.TaskListener; @@ -477,8 +478,8 @@ public SCMRevisionState calcRevisionsFromBuild(final AbstractBuild build, @Override public @CheckForNull SCMRevisionState calcRevisionsFromBuild(@Nonnull Run build, @Nullable FilePath workspace, - @Nullable Launcher launcher, @Nonnull TaskListener listener) - throws IOException, InterruptedException { + @Nullable Launcher launcher, @Nonnull TaskListener listener) + throws IOException, InterruptedException { return build.getAction(CvsRevisionState.class); } @@ -503,6 +504,43 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject pr final EnvVars envVars = project.getLastBuild().getEnvironment(listener); + return worker_compareRemoteRevisionWith(envVars, build.getTime(), launcher, workspace, listener, baseline, repositories); + + } + + protected PollingResult compareRemoteRevisionWith(final Job project, final Launcher launcher, + final FilePath workspace, final TaskListener listener, + final SCMRevisionState baseline, final CvsRepository[] repositories) + throws IOException, InterruptedException { + + Run build = project.getLastBuild(); + + // No previous build? everything has changed + if (null == build) { + listener.getLogger().println("No previous build found, scheduling build"); + return PollingResult.BUILD_NOW; + } + + if (build instanceof AbstractBuild && !((AbstractBuild) 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 = build.getEnvironment(listener); + + return worker_compareRemoteRevisionWith(envVars, build.getTime(), launcher, workspace, listener, baseline, repositories); + + } + + + protected PollingResult worker_compareRemoteRevisionWith(final EnvVars envVars, final Date buildTime, + final Launcher launcher, + final FilePath workspace, final TaskListener listener, + final SCMRevisionState baseline, final CvsRepository[] repositories) + throws IOException, InterruptedException { + + final Date currentPollDate = Calendar.getInstance().getTime(); /* @@ -537,7 +575,7 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject pr } // get the list of current changed files in this repository - final List changes = calculateRepositoryState(build.getTime(), + final List changes = calculateRepositoryState(buildTime, currentPollDate, repository, listener, envVars, workspace); final List remoteFiles = remoteState.get(repository); diff --git a/src/main/java/hudson/scm/CVSSCM.java b/src/main/java/hudson/scm/CVSSCM.java index 066c912..11cc26f 100644 --- a/src/main/java/hudson/scm/CVSSCM.java +++ b/src/main/java/hudson/scm/CVSSCM.java @@ -252,6 +252,20 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject pr return super.compareRemoteRevisionWith(project, launcher, workspace, listener, baseline, getRepositories()); } + /** + * Checks for differences between the current workspace and the remote + * repository. + * + * @see SCM#compareRemoteRevisionWith(Job, Launcher, FilePath, TaskListener, SCMRevisionState) + */ + @Override + public PollingResult compareRemoteRevisionWith(final Job project, final Launcher launcher, + final FilePath workspace, final TaskListener listener, final SCMRevisionState baseline) + throws IOException, InterruptedException { + + return super.compareRemoteRevisionWith(project, launcher, workspace, listener, baseline, getRepositories()); + } + /** * If there are multiple modules, return the module directory of the first * one. diff --git a/src/main/java/hudson/scm/CvsProjectset.java b/src/main/java/hudson/scm/CvsProjectset.java index ec33459..0a3cbc1 100644 --- a/src/main/java/hudson/scm/CvsProjectset.java +++ b/src/main/java/hudson/scm/CvsProjectset.java @@ -112,24 +112,33 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject project, listener, baseline, getAllRepositories(workspace)); } + @Override + public PollingResult compareRemoteRevisionWith(Job project, Launcher launcher, + FilePath workspace, TaskListener listener, + SCMRevisionState baseline) + throws IOException, InterruptedException { + return super.compareRemoteRevisionWith(project, launcher, workspace, + listener, baseline, getAllRepositories(workspace)); + } + @Override public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changelogFile) throws IOException, InterruptedException { - try { - checkout(build, launcher, workspace, listener, changelogFile, null); - } - catch (AbortException e) { - return false; - } - + try { + checkout(build, launcher, workspace, listener, changelogFile, null); + } + catch (AbortException e) { + return false; + } + return true; } @Override public void checkout(final @Nonnull Run build, final @Nonnull Launcher launcher, final @Nonnull FilePath workspace, - final @Nonnull TaskListener listener, final @CheckForNull File changelogFile, - final @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException { + final @Nonnull TaskListener listener, final @CheckForNull File changelogFile, + final @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException { if (!isCanUseUpdate()) { workspace.deleteContents(); }