From a61cfe2c91e78c7053090eb3040b0280958dfebe Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 10 Jun 2014 19:29:34 -0400 Subject: [PATCH] [JENKINS-23365] Follow-up API fixes: introduce SCM.getKey(), and add an SCMRevisionState baseline argument to checkout. Necessary in order to produce correct changelogs by SCM plugins which actually use SCMRevisionState correctly (unlike git-plugin!). (cherry picked from commit df9dc4c850374daeeda72ee37177ba1fe2bcebd6) --- .../main/java/hudson/model/AbstractBuild.java | 3 ++- .../java/hudson/model/AbstractProject.java | 2 +- core/src/main/java/hudson/scm/NullSCM.java | 6 +++--- core/src/main/java/hudson/scm/SCM.java | 21 ++++++++++++++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index 02777e97fd..797d2dae2b 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -43,6 +43,7 @@ import hudson.scm.ChangeLogSet; import hudson.scm.ChangeLogSet.Entry; import hudson.scm.NullChangeLogParser; import hudson.scm.SCM; +import hudson.scm.SCMRevisionState; import hudson.slaves.NodeProperty; import hudson.slaves.WorkspaceList; import hudson.slaves.WorkspaceList.Lease; @@ -625,7 +626,7 @@ public abstract class AbstractBuild

,R extends Abs SCM scm = project.getScm(); for (SCMListener l : SCMListener.all()) { try { - l.onCheckout(build, scm, build.getWorkspace(), listener, changeLogFile, project.pollingBaseline); + l.onCheckout(build, scm, build.getWorkspace(), listener, changeLogFile, build.getAction(SCMRevisionState.class)); } catch (Exception e) { throw new IOException(e); } diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 5ddadd6ade..1f7b818f22 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -159,7 +159,7 @@ public abstract class AbstractProject

,R extends A /** * State returned from {@link SCM#poll(AbstractProject, Launcher, FilePath, TaskListener, SCMRevisionState)}. */ - volatile transient SCMRevisionState pollingBaseline = null; + private volatile transient SCMRevisionState pollingBaseline = null; private transient LazyBuildMixIn buildMixIn; diff --git a/core/src/main/java/hudson/scm/NullSCM.java b/core/src/main/java/hudson/scm/NullSCM.java index 404a02c118..1bb60a2fbf 100644 --- a/core/src/main/java/hudson/scm/NullSCM.java +++ b/core/src/main/java/hudson/scm/NullSCM.java @@ -48,9 +48,9 @@ public class NullSCM extends SCM { return PollingResult.NO_CHANGES; } - @Override public void checkout(Run build, Launcher launcher, FilePath remoteDir, TaskListener listener, File changeLogFile) throws IOException, InterruptedException { - if (changeLogFile != null) { - createEmptyChangeLog(changeLogFile, listener, "log"); + @Override public void checkout(Run build, Launcher launcher, FilePath workspace, TaskListener listener, File changelogFile, SCMRevisionState baseline) throws IOException, InterruptedException { + if (changelogFile != null) { + createEmptyChangeLog(changelogFile, listener, "log"); } } diff --git a/core/src/main/java/hudson/scm/SCM.java b/core/src/main/java/hudson/scm/SCM.java index 56e685ccd9..630ad53e00 100644 --- a/core/src/main/java/hudson/scm/SCM.java +++ b/core/src/main/java/hudson/scm/SCM.java @@ -419,6 +419,20 @@ public abstract class SCM implements Describable, ExtensionPoint { return false; } + /** + * Should create a key by which this SCM configuration might be distinguished from others in the same project. + * Should be invariable across builds but otherwise as distinctive as possible. + *

Could include information such as the relative paths used in {@link #getModuleRoots(FilePath, AbstractBuild)}, + * and/or configured repository URLs and branch names, and/or labels set for this purpose by the user. + *

The result may be used for various purposes, but it may be long and/or include URL-unsafe characters, + * so to use in a URL path component you may need to first wrap it in {@link Util#getDigestOf(String)} or otherwise encode it. + * @return by default, just {@link #getType} + * @since 1.568 + */ + public @Nonnull String getKey() { + return getType(); + } + /** * Obtains a fresh workspace of the module(s) into the specified directory * of the specified machine. @@ -440,14 +454,14 @@ public abstract class SCM implements Describable, ExtensionPoint { * When there's no change, this file should contain an empty entry. * See {@link #createEmptyChangeLog(File, TaskListener, String)}. * May be null, in which case no changelog was requested. - * + * @param baseline version from the previous build to use for changelog creation, if requested and available * @throws InterruptedException * interruption is usually caused by the user aborting the build. * this exception will cause the build to be aborted. * @throws AbortException in case of a routine failure * @since 1.568 */ - public void checkout(@Nonnull Run build, @Nonnull Launcher launcher, @Nonnull FilePath workspace, @Nonnull TaskListener listener, @CheckForNull File changelogFile) throws IOException, InterruptedException { + public void checkout(@Nonnull Run build, @Nonnull Launcher launcher, @Nonnull FilePath workspace, @Nonnull TaskListener listener, @CheckForNull File changelogFile, @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException { if (build instanceof AbstractBuild && listener instanceof BuildListener && Util.isOverridden(SCM.class, getClass(), "checkout", AbstractBuild.class, Launcher.class, FilePath.class, BuildListener.class, File.class)) { if (changelogFile == null) { changelogFile = File.createTempFile("changelog", ".xml"); @@ -470,7 +484,8 @@ public abstract class SCM implements Describable, ExtensionPoint { @Deprecated public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, @Nonnull File changelogFile) throws IOException, InterruptedException { - checkout((Run) build, launcher, workspace, listener, changelogFile); + AbstractBuild prev = build.getPreviousBuild(); + checkout((Run) build, launcher, workspace, listener, changelogFile, prev != null ? prev.getAction(SCMRevisionState.class) : null); return true; } -- GitLab