Skip to content
Permalink
Browse files

[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!).
  • Loading branch information
jglick committed Jun 10, 2014
1 parent abf3359 commit df9dc4c850374daeeda72ee37177ba1fe2bcebd6
@@ -43,6 +43,7 @@
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 void defaultCheckout() throws IOException, InterruptedException {
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 @@
/**
* 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 @@
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 @@ private boolean is1_346OrLater() {
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 @@ private boolean is1_346OrLater() {
* 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 void checkout(@Nonnull Run<?,?> build, @Nonnull Launcher launcher, @Nonnu

@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;
}

0 comments on commit df9dc4c

Please sign in to comment.
You can’t perform that action at this time.