Skip to content
Browse files

[JENKINS-43507] Adapt MercurialSCMSource to use traits

  • Loading branch information...
stephenc committed May 4, 2017
1 parent 2903930 commit fe7b13e9769a83b0ba9a75034054ec622d22d33e
@@ -15,7 +15,8 @@


@@ -0,0 +1,100 @@
package hudson.plugins.mercurial;

import com.cloudbees.plugins.credentials.common.IdCredentials;
import hudson.plugins.mercurial.browser.HgBrowser;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.trait.SCMBuilder;

public class MercurialSCMBuilder<B extends MercurialSCMBuilder<B>> extends SCMBuilder<B, MercurialSCM> {
* The browser to use or {@code null} to use the "auto" browser.
private @CheckForNull HgBrowser browser;
* {@code true} to clean local modifications and untracked files.
private boolean clean;
* The {@link IdCredentials#getId()} of the credentials to use or {@code null} to use none / the installation
* defaults.
private @CheckForNull String credentialsId;
* The {@link MercurialInstallation#getName()}.
private @CheckForNull String installation;
* The repository to track. This can be URL or a local file path.
private final @Nonnull String source;

public MercurialSCMBuilder(@Nonnull SCMHead head, @CheckForNull SCMRevision revision, String source,
String credentialsId) {
super(MercurialSCM.class, head, revision);
this.source = source;
this.credentialsId = credentialsId;

public final HgBrowser browser() {
return browser;

public final boolean clean() {
return clean;

public final String credentialsId() {
return credentialsId;

public final String installation() {
return installation;

public final String source() {
return source;

@SuppressWarnings("unchecked") public @Nonnull B withBrowser(HgBrowser browser) {
this.browser = browser;
return (B) this;

@SuppressWarnings("unchecked") public @Nonnull B withClean(boolean clean) {
this.clean = clean;
return (B) this;

@SuppressWarnings("unchecked") public @Nonnull B withCredentialsId(String credentialsId) {
this.credentialsId = credentialsId;
return (B) this;

@SuppressWarnings("unchecked") public @Nonnull B withInstallation(String installation) {
this.installation = installation;
return (B) this;

@Override public @Nonnull MercurialSCM build() {
String rev = revision() instanceof MercurialSCMSource.MercurialRevision
? ((MercurialSCMSource.MercurialRevision) revision()).getHash()
: head().getName();
MercurialSCM result = new MercurialSCM(source());
if (revision() instanceof MercurialSCMSource.MercurialRevision) {
result.setRevision(((MercurialSCMSource.MercurialRevision) revision()).getHash());
} else {
return result;
Oops, something went wrong.

0 comments on commit fe7b13e

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.