Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #103 from stephenc/jenkins-43507
[JENKINS-43507] Allow SCMSource and SCMNavigator subtypes to share common traits
  • Loading branch information
stephenc committed Jun 27, 2017
2 parents eb08ce4 + 120115b commit bfc7cbd
Show file tree
Hide file tree
Showing 19 changed files with 1,082 additions and 214 deletions.
26 changes: 22 additions & 4 deletions pom.xml
Expand Up @@ -7,15 +7,16 @@
<relativePath />
</parent>
<artifactId>mercurial</artifactId>
<version>1.62-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<name>Jenkins Mercurial plugin</name>
<description>Allows Jenkins to check out projects from the Mercurial SCM.</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/Mercurial+Plugin</url>

<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-alpha-1</scm-api-plugin.version>
</properties>

<developers>
Expand Down Expand Up @@ -70,6 +71,11 @@
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
Expand Down Expand Up @@ -122,7 +128,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>2.0.0</version>
<version>2.0.11-alpha-1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -175,4 +181,16 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
<build>
<plugins>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<configuration>
<compatibleSinceVersion>2.0</compatibleSinceVersion>
</configuration>
</plugin>
</plugins>
</build>

</project>
130 changes: 130 additions & 0 deletions src/main/java/hudson/plugins/mercurial/MercurialSCMBuilder.java
@@ -0,0 +1,130 @@
/*
* The MIT License
*
* Copyright (c) 2017 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

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 @Nonnull String source;

public MercurialSCMBuilder(@Nonnull SCMHead head, @CheckForNull SCMRevision revision, @Nonnull String source,
@CheckForNull 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;
}

@SuppressWarnings("unchecked")
public @Nonnull
B withSource(String source) {
this.source = source;
return (B) this;
}

@Override public @Nonnull MercurialSCM build() {
SCMRevision revision = revision();
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 bfc7cbd

Please sign in to comment.