Skip to content
Permalink
Browse files

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 bfc7cbd995afc08d0bc0bbefaf741685ab3d2d13
Showing with 1,082 additions and 214 deletions.
  1. +22 −4 pom.xml
  2. +130 −0 src/main/java/hudson/plugins/mercurial/MercurialSCMBuilder.java
  3. +324 −149 src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java
  4. +74 −0 src/main/java/hudson/plugins/mercurial/MercurialSCMSourceContext.java
  5. +57 −0 src/main/java/hudson/plugins/mercurial/MercurialSCMSourceRequest.java
  6. +17 −16 src/main/java/hudson/plugins/mercurial/MercurialStatus.java
  7. +76 −0 src/main/java/hudson/plugins/mercurial/traits/CleanMercurialSCMSourceTrait.java
  8. +124 −0 src/main/java/hudson/plugins/mercurial/traits/MercurialBrowserSCMSourceTrait.java
  9. +184 −0 src/main/java/hudson/plugins/mercurial/traits/MercurialInstallationSCMSourceTrait.java
  10. +5 −28 src/main/resources/hudson/plugins/mercurial/MercurialSCMSource/config-detail.jelly
  11. +1 −0 src/main/resources/hudson/plugins/mercurial/MercurialSCMSource/config-detail_en.properties
  12. +1 −0 src/main/resources/hudson/plugins/mercurial/MercurialSCMSource/config-detail_en_US.properties
  13. +0 −4 src/main/resources/hudson/plugins/mercurial/MercurialSCMSource/help-branchPattern.html
  14. +0 −6 src/main/resources/hudson/plugins/mercurial/MercurialSCMSource/help-modules.html
  15. +0 −5 src/main/resources/hudson/plugins/mercurial/MercurialSCMSource/help-subdir.html
  16. +2 −2 ...ns/mercurial/{MercurialSCMSource/help-clean.html → traits/CleanMercurialSCMSourceTrait/help.html}
  17. +31 −0 src/main/resources/hudson/plugins/mercurial/traits/MercurialBrowserSCMSourceTrait/config.jelly
  18. +31 −0 src/main/resources/hudson/plugins/mercurial/traits/MercurialInstallationSCMSourceTrait/config.jelly
  19. +3 −0 src/main/resources/hudson/plugins/mercurial/traits/Messages.properties
26 pom.xml
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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;
}
}
Oops, something went wrong.

0 comments on commit bfc7cbd

Please sign in to comment.
You can’t perform that action at this time.