Skip to content
Permalink
Browse files

[JENKINS-43507] Fix trait drop-down list population

  • Loading branch information...
stephenc committed Jun 24, 2017
1 parent 2477059 commit 471e5b7b5288628810c4f344647e870fcc96f39f
@@ -30,6 +30,8 @@
import jenkins.scm.api.SCMHeadCategory;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMHeadAuthority;
import jenkins.scm.api.trait.SCMHeadAuthorityDescriptor;
import jenkins.scm.api.trait.SCMHeadFilter;
@@ -156,8 +158,16 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
public boolean isApplicableToContext(@NonNull Class<? extends SCMSourceContext> contextClass) {
return GitHubSCMSourceContext.class.isAssignableFrom(contextClass);
public Class<? extends SCMSourceContext> getContextClass() {
return GitHubSCMSourceContext.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return GitHubSCMSource.class;
}

/**
@@ -34,8 +34,10 @@
import jenkins.scm.api.SCMHeadCategory;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import jenkins.scm.api.mixin.ChangeRequestSCMHead2;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMHeadAuthority;
import jenkins.scm.api.trait.SCMHeadAuthorityDescriptor;
import jenkins.scm.api.trait.SCMSourceContext;
@@ -169,8 +171,16 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
public boolean isApplicableToContext(@NonNull Class<? extends SCMSourceContext> contextClass) {
return GitHubSCMSourceContext.class.isAssignableFrom(contextClass);
public Class<? extends SCMSourceContext> getContextClass() {
return GitHubSCMSourceContext.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return GitHubSCMSource.class;
}

/**
@@ -38,6 +38,7 @@
import hudson.model.Action;
import hudson.model.Item;
import hudson.model.TaskListener;
import hudson.plugins.git.GitSCM;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import java.io.FileNotFoundException;
@@ -52,6 +53,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Inject;
import jenkins.model.Jenkins;
import jenkins.plugins.git.traits.GitBrowserSCMSourceTrait;
import jenkins.scm.api.SCMNavigator;
import jenkins.scm.api.SCMNavigatorDescriptor;
@@ -67,6 +69,7 @@
import jenkins.scm.api.trait.SCMNavigatorTrait;
import jenkins.scm.api.trait.SCMNavigatorTraitDescriptor;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import jenkins.scm.api.trait.SCMTrait;
import jenkins.scm.api.trait.SCMTraitDescriptor;
import jenkins.scm.impl.UncategorizedSCMSourceCategory;
@@ -1379,10 +1382,12 @@ public boolean isApiUriSelectable() {
*/
@SuppressWarnings("unused") // jelly
public List<NamedArrayList<? extends SCMTraitDescriptor<?>>> getTraitsDescriptorLists() {
GitHubSCMSource.DescriptorImpl sourceDescriptor =
Jenkins.getActiveInstance().getDescriptorByType(GitHubSCMSource.DescriptorImpl.class);
List<SCMTraitDescriptor<?>> all = new ArrayList<>();
all.addAll(SCMNavigatorTrait._for(this, GitHubSCMNavigatorContext.class, GitHubSCMSourceBuilder.class));
all.addAll(SCMSourceTrait._for(null, GitHubSCMBuilder.class));
all.addAll(SCMSourceTrait._for(GitHubSCMSourceContext.class, null));
all.addAll(SCMSourceTrait._for(sourceDescriptor, GitHubSCMSourceContext.class, null));
all.addAll(SCMSourceTrait._for(sourceDescriptor, null, GitHubSCMBuilder.class));
Set<SCMTraitDescriptor<?>> dedup = new HashSet<>();
for (Iterator<SCMTraitDescriptor<?>> iterator = all.iterator(); iterator.hasNext(); ) {
SCMTraitDescriptor<?> d = iterator.next();
@@ -1411,7 +1416,7 @@ public boolean test(SCMTraitDescriptor<?> scmTraitDescriptor) {
@SuppressWarnings("unused") // jelly
public List<SCMTrait<? extends SCMTrait<?>>> getTraitsDefaults() {
List<SCMTrait<? extends SCMTrait<?>>> result = new ArrayList<>();
result.addAll(delegate.getTraitDefaults());
result.addAll(delegate.getTraitsDefaults());
return result;
}

@@ -42,6 +42,7 @@
import hudson.model.Actionable;
import hudson.model.Item;
import hudson.model.TaskListener;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.scm.SCM;
import hudson.util.FormValidation;
@@ -288,7 +289,7 @@ public GitHubSCMSource(@NonNull String repoOwner, @NonNull String repository) {
this.repository = repository;
pullRequestMetadataCache = new ConcurrentHashMap<>();
pullRequestContributorCache = new ConcurrentHashMap<>();
this.traits = new ArrayList<>(((DescriptorImpl) getDescriptor()).getTraitDefaults());
this.traits = new ArrayList<>(((DescriptorImpl) getDescriptor()).getTraitsDefaults());
}

/**
@@ -1563,11 +1564,11 @@ private static ListBoxModel nameAndValueModel(Collection<String> items) {
}

public List<NamedArrayList<? extends SCMTraitDescriptor<?>>> getTraitsDescriptorLists() {
List<SCMSourceTraitDescriptor> all = new ArrayList<>();
all.addAll(SCMSourceTrait._for(null, GitHubSCMBuilder.class));
all.addAll(SCMSourceTrait._for(GitHubSCMSourceContext.class, null));
List<SCMTraitDescriptor<?>> all = new ArrayList<>();
all.addAll(SCMSourceTrait._for(this, GitHubSCMSourceContext.class, null));
all.addAll(SCMSourceTrait._for(this, null, GitHubSCMBuilder.class));
Set<SCMTraitDescriptor<?>> dedup = new HashSet<>();
for (Iterator<SCMSourceTraitDescriptor> iterator = all.iterator(); iterator.hasNext(); ) {
for (Iterator<SCMTraitDescriptor<?>> iterator = all.iterator(); iterator.hasNext(); ) {
SCMTraitDescriptor<?> d = iterator.next();
if (dedup.contains(d)
|| d instanceof GitBrowserSCMSourceTrait.DescriptorImpl) {
@@ -1586,11 +1587,11 @@ private static ListBoxModel nameAndValueModel(Collection<String> items) {
return result;
}

public List<SCMSourceTrait> getTraitDefaults() {
public List<SCMSourceTrait> getTraitsDefaults() {
return Arrays.asList( // TODO finalize
new BranchDiscoveryTrait(1),
new OriginPullRequestDiscoveryTrait(1),
new ForkPullRequestDiscoveryTrait(1, new ForkPullRequestDiscoveryTrait.TrustContributors())
new BranchDiscoveryTrait(true, false),
new OriginPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.MERGE)),
new ForkPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.MERGE), new ForkPullRequestDiscoveryTrait.TrustContributors())
);
}

@@ -32,8 +32,10 @@
import jenkins.scm.api.SCMHeadCategory;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import jenkins.scm.api.mixin.ChangeRequestSCMHead2;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMHeadAuthority;
import jenkins.scm.api.trait.SCMHeadAuthorityDescriptor;
import jenkins.scm.api.trait.SCMSourceContext;
@@ -141,8 +143,16 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
public boolean isApplicableToContext(@NonNull Class<? extends SCMSourceContext> contextClass) {
return GitHubSCMSourceContext.class.isAssignableFrom(contextClass);
public Class<? extends SCMSourceContext> getContextClass() {
return GitHubSCMSourceContext.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return GitHubSCMSource.class;
}

/**
@@ -35,11 +35,13 @@
import hudson.model.Queue;
import hudson.model.queue.Tasks;
import hudson.plugins.git.GitSCM;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import hudson.security.ACL;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import jenkins.plugins.git.GitSCMBuilder;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
@@ -118,24 +120,32 @@ public String getDisplayName() {
* {@inheritDoc}
*/
@Override
public boolean isApplicableToContext(@NonNull Class<? extends SCMSourceContext> contextClass) {
return GitHubSCMSourceRequest.class.isAssignableFrom(contextClass);
public Class<? extends SCMSourceContext> getContextClass() {
return GitHubSCMSourceContext.class;
}

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

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicableToSCM(@NonNull SCMDescriptor<?> scm) {
return scm instanceof GitSCM.DescriptorImpl;
public Class<? extends SCMBuilder> getBuilderClass() {
return GitSCMBuilder.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCM> getScmClass() {
return GitSCM.class;
}

/**

0 comments on commit 471e5b7

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