Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-43507] Adapt MercurialSCMSource to use traits
  • Loading branch information
stephenc committed Jun 12, 2017
1 parent 2903930 commit fe7b13e
Show file tree
Hide file tree
Showing 14 changed files with 803 additions and 159 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -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>
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/hudson/plugins/mercurial/MercurialSCMBuilder.java
@@ -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;
}
}

0 comments on commit fe7b13e

Please sign in to comment.