Skip to content
Permalink
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 @@

<properties>
<jenkins.version>1.642.3</jenkins.version>
<scm-api-plugin.version>2.1.0</scm-api-plugin.version>
<no-test-jar>false</no-test-jar>
<scm-api-plugin.version>2.2.0-20170504.132618-8</scm-api-plugin.version>
</properties>

<developers>
@@ -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.setRevisionType(MercurialSCM.RevisionType.CHANGESET);
result.setRevision(((MercurialSCMSource.MercurialRevision) revision()).getHash());
} else {
result.setRevisionType(MercurialSCM.RevisionType.BRANCH);
result.setRevision(head().getName());
}
result.setBrowser(browser());
result.setClean(clean());
result.setCredentialsId(credentialsId());
result.setInstallation(installation());
result.setDisableChangeLog(false);
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.