Skip to content

Commit

Permalink
[JENKINS-23365] Follow-up API fixes: introduce SCM.getKey(), and add …
Browse files Browse the repository at this point in the history
…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 df9dc4c)
  • Loading branch information
jglick committed Jun 10, 2014
1 parent 0f859a3 commit a61cfe2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/AbstractBuild.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/hudson/scm/NullSCM.java
Expand Up @@ -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");
}
}

Expand Down
21 changes: 18 additions & 3 deletions core/src/main/java/hudson/scm/SCM.java
Expand Up @@ -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.
Expand All @@ -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");
Expand All @@ -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;
}

Expand Down

0 comments on commit a61cfe2

Please sign in to comment.