提交 a61cfe2c 编写于 作者: J Jesse Glick

[JENKINS-23365] Follow-up API fixes: introduce SCM.getKey(), and add an...

[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 df9dc4c8)
上级 0f859a38
......@@ -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<P extends AbstractProject<P,R>,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);
}
......
......@@ -159,7 +159,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,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<P,R> buildMixIn;
......
......@@ -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");
}
}
......
......@@ -419,6 +419,20 @@ public abstract class SCM implements Describable<SCM>, 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.
* <p>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.
* <p>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<SCM>, 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<SCM>, 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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册