Skip to content
Permalink
Browse files

[JENKINS-43507] Document the traits

  • Loading branch information...
stephenc committed May 3, 2017
1 parent 72cab2a commit f09e7a299a0ca5ebd1f8492c29255f934ef61d27
Showing with 545 additions and 115 deletions.
  1. +13 −11 src/main/java/jenkins/plugins/git/GitSCMSource.java
  2. +11 −2 src/main/java/jenkins/plugins/git/traits/AuthorInChangelogTrait.java
  3. +11 −0 src/main/java/jenkins/plugins/git/traits/CheckoutOptionTrait.java
  4. +11 −2 src/main/java/jenkins/plugins/git/traits/CleanAfterCheckoutTrait.java
  5. +11 −2 src/main/java/jenkins/plugins/git/traits/CleanBeforeCheckoutTrait.java
  6. +11 −0 src/main/java/jenkins/plugins/git/traits/CloneOptionTrait.java
  7. +37 −12 src/main/java/jenkins/plugins/git/traits/GitBrowserSCMSourceTrait.java
  8. +11 −2 src/main/java/jenkins/plugins/git/traits/GitLFSPullTrait.java
  9. +19 −0 src/main/java/jenkins/plugins/git/traits/GitSCMExtensionTrait.java
  10. +99 −13 src/main/java/jenkins/plugins/git/traits/GitSCMExtensionTraitDescriptor.java
  11. +38 −2 src/main/java/jenkins/plugins/git/traits/GitToolSCMSourceTrait.java
  12. +3 −0 src/main/java/jenkins/plugins/git/traits/IgnoreOnPushNotificationTrait.java
  13. +12 −1 src/main/java/jenkins/plugins/git/traits/LocalBranchTrait.java
  14. +9 −0 src/main/java/jenkins/plugins/git/traits/PruneStaleBranchTrait.java
  15. +93 −3 src/main/java/jenkins/plugins/git/traits/RefSpecsSCMSourceTrait.java
  16. +125 −65 src/main/java/jenkins/plugins/git/traits/RemoteNameSCMSourceTrait.java
  17. +11 −0 src/main/java/jenkins/plugins/git/traits/SubmoduleOptionTrait.java
  18. +11 −0 src/main/java/jenkins/plugins/git/traits/UserIdentityTrait.java
  19. +9 −0 src/main/java/jenkins/plugins/git/traits/WipeWorkspaceTrait.java
@@ -27,6 +27,7 @@
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.Extension;
@@ -59,6 +60,7 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import jenkins.model.Jenkins;
import jenkins.plugins.git.traits.GitBrowserSCMSourceTrait;
import jenkins.plugins.git.traits.GitSCMExtensionTrait;
@@ -198,7 +200,7 @@ private Object readResolve() throws ObjectStreamException {
for (SCMSourceTraitDescriptor d : SCMSourceTrait.all()) {
if (d instanceof GitSCMExtensionTraitDescriptor) {
GitSCMExtensionTraitDescriptor descriptor = (GitSCMExtensionTraitDescriptor) d;
if (descriptor.getExtensionDescriptor() == extension.getDescriptor()) {
if (descriptor.getExtensionClass().isInstance(extension)) {
try {
SCMSourceTrait trait = descriptor.convertToTrait(extension);
if (trait != null) {
@@ -241,16 +243,16 @@ private RefSpecsSCMSourceTrait asRefSpecsSCMSourceTrait(String rawRefSpecs, Stri
defaults.add("+refs/heads/*:refs/remotes/"+remoteName+"/*");
}
if (!defaults.contains(rawRefSpecs.trim())) {
List<RefSpecsSCMSourceTrait.RefSpecTemplate> templates = new ArrayList<>();
List<String> templates = new ArrayList<>();
for (String rawRefSpec : rawRefSpecs.split(" ")) {
if (defaults.contains(rawRefSpec)) {
templates.add(new RefSpecsSCMSourceTrait.RefSpecTemplate(AbstractGitSCMSource.REF_SPEC_DEFAULT));
templates.add(AbstractGitSCMSource.REF_SPEC_DEFAULT);
} else {
templates.add(new RefSpecsSCMSourceTrait.RefSpecTemplate(rawRefSpec));
templates.add(rawRefSpec);
}
}
if (!templates.isEmpty()) {
return new RefSpecsSCMSourceTrait(templates);
return new RefSpecsSCMSourceTrait(templates.toArray(new String[templates.size()]));
}
}
}
@@ -303,7 +305,7 @@ public void setGitTool(String gitTool) {
@Restricted(DoNotUse.class)
@DataBoundSetter
@Deprecated
public void setExtensions(List<GitSCMExtension> extensions) {
public void setExtensions(@CheckForNull List<GitSCMExtension> extensions) {
for (Iterator<SCMSourceTrait> iterator = traits.iterator(); iterator.hasNext(); ) {
if (iterator.next() instanceof GitSCMExtensionTrait) {
iterator.remove();
@@ -314,7 +316,7 @@ public void setExtensions(List<GitSCMExtension> extensions) {
for (SCMSourceTraitDescriptor d : SCMSourceTrait.all()) {
if (d instanceof GitSCMExtensionTraitDescriptor) {
GitSCMExtensionTraitDescriptor descriptor = (GitSCMExtensionTraitDescriptor) d;
if (descriptor.getExtensionDescriptor() == extension.getDescriptor()) {
if (descriptor.getExtensionClass().isInstance(extension)) {
try {
SCMSourceTrait trait = descriptor.convertToTrait(extension);
if (trait != null) {
@@ -367,14 +369,14 @@ public String getRawRefSpecs() {
}
StringBuilder result = new StringBuilder();
boolean first = true;
for (RefSpecsSCMSourceTrait.RefSpecTemplate template: refSpecs.getTemplates()) {
Pattern placeholder = Pattern.compile(AbstractGitSCMSource.REF_SPEC_REMOTE_NAME_PLACEHOLDER);
for (String template : refSpecs.asStrings()) {
if (first) {
first = false;
} else {
result.append(' ');
}
result.append(template.getValue().replaceAll(AbstractGitSCMSource.REF_SPEC_REMOTE_NAME_PLACEHOLDER,
remoteName));
result.append(placeholder.matcher(template).replaceAll(remoteName));
}
return result.toString();
}
@@ -500,7 +502,7 @@ public ListBoxModel doFillGitToolItems() {
}

public List<SCMSourceTrait> getDefaultTraits() {
return Collections.<SCMSourceTrait>emptyList();
return Collections.emptyList();
}
}

@@ -27,12 +27,21 @@

import hudson.Extension;
import hudson.plugins.git.extensions.impl.AuthorInChangelog;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link AuthorInChangelog} as a {@link SCMSourceTrait}.
*
* @since 3.4.0
*/
public class AuthorInChangelogTrait extends GitSCMExtensionTrait<AuthorInChangelog> {
/**
* Stapler constructor.
*/
@DataBoundConstructor
public AuthorInChangelogTrait(AuthorInChangelog extension) {
super(extension);
public AuthorInChangelogTrait() {
super(new AuthorInChangelog());
}

/**
@@ -27,9 +27,20 @@

import hudson.Extension;
import hudson.plugins.git.extensions.impl.CheckoutOption;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link CheckoutOption} as a {@link SCMSourceTrait}.
*
* @since 3.4.0
*/
public class CheckoutOptionTrait extends GitSCMExtensionTrait<CheckoutOption> {
/**
* Stapler constructor.
*
* @param extension the {@link CheckoutOption}
*/
@DataBoundConstructor
public CheckoutOptionTrait(CheckoutOption extension) {
super(extension);
@@ -27,12 +27,21 @@

import hudson.Extension;
import hudson.plugins.git.extensions.impl.CleanCheckout;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link CleanCheckout} as a {@link SCMSourceTrait}.
*
* @since 3.4.0
*/
public class CleanAfterCheckoutTrait extends GitSCMExtensionTrait<CleanCheckout> {
/**
* Stapler constructor.
*/
@DataBoundConstructor
public CleanAfterCheckoutTrait(CleanCheckout extension) {
super(extension);
public CleanAfterCheckoutTrait() {
super(new CleanCheckout());
}

/**
@@ -27,12 +27,21 @@

import hudson.Extension;
import hudson.plugins.git.extensions.impl.CleanBeforeCheckout;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link CleanBeforeCheckout} as a {@link SCMSourceTrait}.
*
* @since 3.4.0
*/
public class CleanBeforeCheckoutTrait extends GitSCMExtensionTrait<CleanBeforeCheckout> {
/**
* Stapler constructor.
*/
@DataBoundConstructor
public CleanBeforeCheckoutTrait(CleanBeforeCheckout extension) {
super(extension);
public CleanBeforeCheckoutTrait() {
super(new CleanBeforeCheckout());
}

/**
@@ -27,9 +27,20 @@

import hudson.Extension;
import hudson.plugins.git.extensions.impl.CloneOption;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link CloneOption} as a {@link SCMSourceTrait}.
*
* @since 3.4.0
*/
public class CloneOptionTrait extends GitSCMExtensionTrait<CloneOption> {
/**
* Stapler constructor.
*
* @param extension the {@link CloneOption}
*/
@DataBoundConstructor
public CloneOptionTrait(CloneOption extension) {
super(extension);
@@ -25,6 +25,7 @@

package jenkins.plugins.git.traits;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Descriptor;
@@ -46,15 +47,35 @@
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link GitRepositoryBrowser} configuration of a {@link AbstractGitSCMSource} as a {@link SCMSourceTrait}.
*
* @since 3.4.0
*/
public class GitBrowserSCMSourceTrait extends SCMSourceTrait {

/**
* The configured {@link GitRepositoryBrowser} or {@code null} to use the "auto" browser.
*/
@CheckForNull
private final GitRepositoryBrowser browser;

/**
* Stapler constructor.
*
* @param browser the {@link GitRepositoryBrowser} or {@code null} to use the "auto" browser.
*/
@DataBoundConstructor
public GitBrowserSCMSourceTrait(GitRepositoryBrowser browser) {
public GitBrowserSCMSourceTrait(@CheckForNull GitRepositoryBrowser browser) {
this.browser = browser;
}

/**
* Gets the {@link GitRepositoryBrowser}..
*
* @return the {@link GitRepositoryBrowser} or {@code null} to use the "auto" browser.
*/
@CheckForNull
public GitRepositoryBrowser getBrowser() {
return browser;
}
@@ -81,47 +102,51 @@ public String getDisplayName() {
return "Configure Repository Browser";
}

/**
* Expose the {@link GitRepositoryBrowser} instances to stapler.
*
* @return the {@link GitRepositoryBrowser} instances
*/
@Restricted(NoExternalUse.class) // stapler
public List<Descriptor<RepositoryBrowser<?>>> getBrowserDescriptors() {
return getSCMDescriptor().getBrowserDescriptors();
return ((GitSCM.DescriptorImpl) Jenkins.getActiveInstance().getDescriptor(GitSCM.class))
.getBrowserDescriptors();
}

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicableToBuilder(@NonNull Class<? extends SCMBuilder> builderClass) {
return super.isApplicableToBuilder(builderClass) && GitSCMBuilder.class.isAssignableFrom(builderClass);
return super.isApplicableToBuilder(builderClass)
&& GitSCMBuilder.class.isAssignableFrom(builderClass);
}

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicableToContext(@NonNull Class<? extends SCMSourceContext> contextClass) {
return super.isApplicableToContext(contextClass) && GitSCMSourceContext.class
.isAssignableFrom(contextClass);
return super.isApplicableToContext(contextClass)
&& GitSCMSourceContext.class.isAssignableFrom(contextClass);
}

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicableToSCM(@NonNull Class<? extends SCM> scmClass) {
return super.isApplicableToSCM(scmClass) && AbstractGitSCMSource.class.isAssignableFrom(scmClass);
return super.isApplicableToSCM(scmClass)
&& AbstractGitSCMSource.class.isAssignableFrom(scmClass);
}

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicableTo(SCMSource source) {
return super.isApplicableTo(source) && source instanceof AbstractGitSCMSource;
return super.isApplicableTo(source)
&& source instanceof AbstractGitSCMSource;
}

private GitSCM.DescriptorImpl getSCMDescriptor() {
return (GitSCM.DescriptorImpl) Jenkins.getActiveInstance().getDescriptor(GitSCM.class);
}

}
}
@@ -27,12 +27,21 @@

import hudson.Extension;
import hudson.plugins.git.extensions.impl.GitLFSPull;
import jenkins.scm.api.trait.SCMSourceTrait;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Exposes {@link GitLFSPull} as a {@link SCMSourceTrait}.
*
* @since 3.4.0
*/
public class GitLFSPullTrait extends GitSCMExtensionTrait<GitLFSPull> {
/**
* Stapler constructor.
*/
@DataBoundConstructor
public GitLFSPullTrait(GitLFSPull extension) {
super(extension);
public GitLFSPullTrait() {
super(new GitLFSPull());
}

/**
@@ -32,14 +32,33 @@
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMSourceTrait;

/**
* Base class for exposing a {@link GitSCMExtension} as a {@link SCMSourceTrait}.
*
* @param <E> the {@link GitSCMExtension} that is being exposed
* @sinec 3.4.0
*/
public abstract class GitSCMExtensionTrait<E extends GitSCMExtension> extends SCMSourceTrait {
/**
* The extension.
*/
@NonNull
private final E extension;

/**
* Constructor.
*
* @param extension the extension.
*/
public GitSCMExtensionTrait(@NonNull E extension) {
this.extension = extension;
}

/**
* Gets the extension.
*
* @return the extension.
*/
@NonNull
public E getExtension() {
return extension;
Oops, something went wrong.

0 comments on commit f09e7a2

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