From f15347b1222c36c41767af841671d5d0ac4a4d15 Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 24 Apr 2019 21:19:37 +0200 Subject: [PATCH 1/3] #proposed fix for JENKINS-33016: https://issues.jenkins-ci.org/browse/JENKINS-33016 This fix takes the proposed solution of PR#41 https://github.com/jenkinsci/cvs-plugin/pull/41 with some improvements related to plugin backwards compability --- src/main/java/hudson/scm/AbstractCvs.java | 68 ++++++++++++++++----- src/main/java/hudson/scm/CVSSCM.java | 27 ++++---- src/main/java/hudson/scm/CvsProjectset.java | 9 +++ 3 files changed, 77 insertions(+), 27 deletions(-) diff --git a/src/main/java/hudson/scm/AbstractCvs.java b/src/main/java/hudson/scm/AbstractCvs.java index c5a9d73..164ad48 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; @@ -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); @@ -816,19 +854,21 @@ protected void postCheckout(Run build, File changelogFile, CvsRepository[] // build change log final Run lastCompleteBuild = build.getPreviousBuiltBuild(); - if (lastCompleteBuild != null && !isSkipChangeLog()) { - final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild); - final Date checkoutDate = getCheckoutDate(build); - - final List changes = new ArrayList(); - for (CvsRepository location : repositories) { - changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location, - listener, build.getEnvironment(listener), workspace)); - } - new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile); - } else { - createEmptyChangeLog(changelogFile, listener, "changelog"); - } + if( null != changelogFile) { + if (lastCompleteBuild != null && !isSkipChangeLog()) { + final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild); + final Date checkoutDate = getCheckoutDate(build); + + final List changes = new ArrayList(); + for (CvsRepository location : repositories) { + changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location, + listener, build.getEnvironment(listener), workspace)); + } + new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile); + } else { + createEmptyChangeLog(changelogFile, listener, "changelog"); + } + } // add the current workspace state as an action build.getActions().add(new CvsRevisionState(calculateWorkspaceState(workspace, repositories, flatten, envVars, listener))); diff --git a/src/main/java/hudson/scm/CVSSCM.java b/src/main/java/hudson/scm/CVSSCM.java index 967915c..46e6777 100644 --- a/src/main/java/hudson/scm/CVSSCM.java +++ b/src/main/java/hudson/scm/CVSSCM.java @@ -250,6 +250,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. @@ -361,19 +375,6 @@ private String getBranchName() { return locationName; } - @Override - public boolean checkout(final AbstractBuild build, final Launcher launcher, final FilePath workspace, - final BuildListener listener, final File changelogFile) throws IOException, InterruptedException { - 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, diff --git a/src/main/java/hudson/scm/CvsProjectset.java b/src/main/java/hudson/scm/CvsProjectset.java index ec33459..dcf39e5 100644 --- a/src/main/java/hudson/scm/CvsProjectset.java +++ b/src/main/java/hudson/scm/CvsProjectset.java @@ -112,6 +112,15 @@ 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 { From cec3e8f7134ae62fab679739d28dd7f2532fa52e Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 24 Apr 2019 21:27:57 +0200 Subject: [PATCH 2/3] re-added lost checkout method --- src/main/java/hudson/scm/CVSSCM.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/hudson/scm/CVSSCM.java b/src/main/java/hudson/scm/CVSSCM.java index 46e6777..056fc68 100644 --- a/src/main/java/hudson/scm/CVSSCM.java +++ b/src/main/java/hudson/scm/CVSSCM.java @@ -375,6 +375,19 @@ private String getBranchName() { return locationName; } + @Override + public boolean checkout(final AbstractBuild build, final Launcher launcher, final FilePath workspace, + final BuildListener listener, final File changelogFile) throws IOException, InterruptedException { + 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, From 246de9ff630e2422da095da81d9d24a90e3fe2eb Mon Sep 17 00:00:00 2001 From: mroesel Date: Thu, 25 Apr 2019 08:53:12 +0200 Subject: [PATCH 3/3] converted tabs to spaces --- src/main/java/hudson/scm/AbstractCvs.java | 44 ++++++++++----------- src/main/java/hudson/scm/CvsProjectset.java | 18 ++++----- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/hudson/scm/AbstractCvs.java b/src/main/java/hudson/scm/AbstractCvs.java index 164ad48..c093452 100644 --- a/src/main/java/hudson/scm/AbstractCvs.java +++ b/src/main/java/hudson/scm/AbstractCvs.java @@ -478,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); } @@ -504,9 +504,9 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject pr final EnvVars envVars = project.getLastBuild().getEnvironment(listener); - return worker_compareRemoteRevisionWith(envVars, build.getTime(), launcher, workspace, listener, baseline, repositories); + 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, @@ -529,13 +529,13 @@ protected PollingResult compareRemoteRevisionWith(final Job project, final final EnvVars envVars = build.getEnvironment(listener); - return worker_compareRemoteRevisionWith(envVars, build.getTime(), launcher, workspace, listener, baseline, repositories); + 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 Launcher launcher, final FilePath workspace, final TaskListener listener, final SCMRevisionState baseline, final CvsRepository[] repositories) throws IOException, InterruptedException { @@ -854,21 +854,21 @@ protected void postCheckout(Run build, File changelogFile, CvsRepository[] // build change log final Run lastCompleteBuild = build.getPreviousBuiltBuild(); - if( null != changelogFile) { - if (lastCompleteBuild != null && !isSkipChangeLog()) { - final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild); - final Date checkoutDate = getCheckoutDate(build); - - final List changes = new ArrayList(); - for (CvsRepository location : repositories) { - changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location, - listener, build.getEnvironment(listener), workspace)); - } - new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile); - } else { - createEmptyChangeLog(changelogFile, listener, "changelog"); - } - } + if( null != changelogFile) { + if (lastCompleteBuild != null && !isSkipChangeLog()) { + final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild); + final Date checkoutDate = getCheckoutDate(build); + + final List changes = new ArrayList(); + for (CvsRepository location : repositories) { + changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location, + listener, build.getEnvironment(listener), workspace)); + } + new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile); + } else { + createEmptyChangeLog(changelogFile, listener, "changelog"); + } + } // add the current workspace state as an action build.getActions().add(new CvsRevisionState(calculateWorkspaceState(workspace, repositories, flatten, envVars, listener))); diff --git a/src/main/java/hudson/scm/CvsProjectset.java b/src/main/java/hudson/scm/CvsProjectset.java index dcf39e5..0a3cbc1 100644 --- a/src/main/java/hudson/scm/CvsProjectset.java +++ b/src/main/java/hudson/scm/CvsProjectset.java @@ -124,21 +124,21 @@ public PollingResult compareRemoteRevisionWith(Job project, Launcher launc @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(); }