Skip to content

Commit

Permalink
[JENKINS-43507] Javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Jun 19, 2017
1 parent 19b1697 commit da85c37
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import jenkins.scm.impl.trait.RegexSCMSourceFilterTrait; import jenkins.scm.impl.trait.RegexSCMSourceFilterTrait;
import jenkins.scm.impl.trait.Selection; import jenkins.scm.impl.trait.Selection;
import jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait; import jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait;
import net.jcip.annotations.GuardedBy;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon; import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet; import org.jenkins.ui.icon.IconSet;
Expand Down Expand Up @@ -226,7 +227,7 @@ public GitHubSCMNavigator(String apiUri, String repoOwner, String scanCredential
this(repoOwner); this(repoOwner);
setCredentialsId(scanCredentialsId); setCredentialsId(scanCredentialsId);
setApiUri(apiUri); setApiUri(apiUri);
if (checkoutCredentialsId != null && !GitHubSCMSource.DescriptorImpl.SAME.equals(checkoutCredentialsId)) { if (checkoutCredentialsId != null && !DescriptorImpl.SAME.equals(checkoutCredentialsId)) {
traits.add(new SSHCheckoutTrait(checkoutCredentialsId)); traits.add(new SSHCheckoutTrait(checkoutCredentialsId));
} }
} }
Expand Down Expand Up @@ -351,7 +352,7 @@ private Object readResolve() {
} }
traits.add(new ForkPullRequestDiscoveryTrait(s, new ForkPullRequestDiscoveryTrait.TrustContributors())); traits.add(new ForkPullRequestDiscoveryTrait(s, new ForkPullRequestDiscoveryTrait.TrustContributors()));
} }
if (!GitHubSCMSource.DescriptorImpl.SAME.equals(checkoutCredentialsId)) { if (!DescriptorImpl.SAME.equals(checkoutCredentialsId)) {
traits.add(new SSHCheckoutTrait(checkoutCredentialsId)); traits.add(new SSHCheckoutTrait(checkoutCredentialsId));
} }
if ((includes != null && !"*".equals(includes)) || (excludes != null && !"".equals(excludes))) { if ((includes != null && !"*".equals(includes)) || (excludes != null && !"".equals(excludes))) {
Expand Down Expand Up @@ -787,7 +788,7 @@ public String getCheckoutCredentialsId() {
); );
} }
} }
return GitHubSCMSource.DescriptorImpl.SAME; return DescriptorImpl.SAME;
} }


/** /**
Expand Down Expand Up @@ -1276,19 +1277,45 @@ protected SCMSourceCategory[] createCategories() {
}; };
} }


/**
* Validates the selected credentials.
*
* @param context the context.
* @param apiUri the end-point.
* @param credentialsId the credentials.
* @return validation results.
* @since 2.2.0
*/
@Restricted(NoExternalUse.class) // stapler @Restricted(NoExternalUse.class) // stapler
public FormValidation doCheckCredentialsId(@CheckForNull @AncestorInPath Item context, public FormValidation doCheckCredentialsId(@CheckForNull @AncestorInPath Item context,
@QueryParameter String apiUri, @QueryParameter String apiUri,
@QueryParameter String credentialsId) { @QueryParameter String credentialsId) {
return Connector.checkScanCredentials(context, apiUri, credentialsId); return Connector.checkScanCredentials(context, apiUri, credentialsId);
} }


@Restricted(NoExternalUse.class) /**
* Populates the drop-down list of credentials.
*
* @param context the context.
* @param apiUri the end-point.
* @return the drop-down list.
* @since 2.2.0
*/
@Restricted(NoExternalUse.class) // stapler
public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context, public ListBoxModel doFillCredentialsIdItems(@CheckForNull @AncestorInPath Item context,
@QueryParameter String apiUri) { @QueryParameter String apiUri) {
return Connector.listScanCredentials(context, apiUri); return Connector.listScanCredentials(context, apiUri);
} }


/**
* Legacy method.
*
* @param context the context.
* @param apiUri the endpoint.
* @param scanCredentialsId the scan credentials.
* @return the {@link ListBoxModel}
* @deprecated use {@link #doCheckCredentialsId(Item, String, String)}
*/
@Deprecated @Deprecated
@Restricted(NoExternalUse.class) @Restricted(NoExternalUse.class)
public FormValidation doCheckScanCredentialsId(@CheckForNull @AncestorInPath Item context, public FormValidation doCheckScanCredentialsId(@CheckForNull @AncestorInPath Item context,
Expand All @@ -1297,12 +1324,26 @@ public FormValidation doCheckScanCredentialsId(@CheckForNull @AncestorInPath Ite
return doCheckCredentialsId(context, apiUri, scanCredentialsId); return doCheckCredentialsId(context, apiUri, scanCredentialsId);
} }


/**
* Legacy method.
*
* @param context the context.
* @param apiUri the endpoint.
* @return the {@link ListBoxModel}
* @deprecated use {@link #doFillCredentialsIdItems(Item, String)}
*/
@Deprecated @Deprecated
@Restricted(NoExternalUse.class) @Restricted(NoExternalUse.class)
@RestrictedSince("2.2.0")
public ListBoxModel doFillScanCredentialsIdItems(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri) { public ListBoxModel doFillScanCredentialsIdItems(@CheckForNull @AncestorInPath Item context, @QueryParameter String apiUri) {
return doFillCredentialsIdItems(context, apiUri); return doFillCredentialsIdItems(context, apiUri);
} }


/**
* Returns the available GitHub endpoint items.
*
* @return the available GitHub endpoint items.
*/
@Restricted(NoExternalUse.class) // stapler @Restricted(NoExternalUse.class) // stapler
@SuppressWarnings("unused") // stapler @SuppressWarnings("unused") // stapler
public ListBoxModel doFillApiUriItems() { public ListBoxModel doFillApiUriItems() {
Expand All @@ -1314,11 +1355,23 @@ public ListBoxModel doFillApiUriItems() {
return result; return result;
} }


/**
* Returns {@code true} if there is more than one GitHub endpoint configured, and consequently the UI should
* provide the ability to select the endpoint.
*
* @return {@code true} if there is more than one GitHub endpoint configured.
*/
@SuppressWarnings("unused") // jelly @SuppressWarnings("unused") // jelly
public boolean isApiUriSelectable() { public boolean isApiUriSelectable() {
return !GitHubConfiguration.get().getEndpoints().isEmpty(); return !GitHubConfiguration.get().getEndpoints().isEmpty();
} }


/**
* Returns the {@link SCMTraitDescriptor} instances grouped into categories.
*
* @return the categorized list of {@link SCMTraitDescriptor} instances.
* @since 2.2.0
*/
@SuppressWarnings("unused") // jelly @SuppressWarnings("unused") // jelly
public List<NamedArrayList<? extends SCMTraitDescriptor<?>>> getTraitsDescriptorLists() { public List<NamedArrayList<? extends SCMTraitDescriptor<?>>> getTraitsDescriptorLists() {
List<SCMTraitDescriptor<?>> all = new ArrayList<>(); List<SCMTraitDescriptor<?>> all = new ArrayList<>();
Expand Down Expand Up @@ -1432,24 +1485,47 @@ public List<SCMTrait<? extends SCMTrait<?>>> getTraitsDefaults() {
* A {@link SCMNavigatorRequest.Witness} that counts how many sources have been observed. * A {@link SCMNavigatorRequest.Witness} that counts how many sources have been observed.
*/ */
private static class WitnessImpl implements SCMNavigatorRequest.Witness { private static class WitnessImpl implements SCMNavigatorRequest.Witness {
/**
* The count of repositories matches.
*/
@GuardedBy("this")
private int count; private int count;
/**
* The listener to log to.
*/
@NonNull
private final TaskListener listener; private final TaskListener listener;


public WitnessImpl(TaskListener listener) { /**
* Constructor.
*
* @param listener the listener to log to.
*/
public WitnessImpl(@NonNull TaskListener listener) {
this.listener = listener; this.listener = listener;
} }


/**
* {@inheritDoc}
*/
@Override @Override
public void record(@NonNull String name, boolean isMatch) { public void record(@NonNull String name, boolean isMatch) {
if (isMatch) { if (isMatch) {
listener.getLogger().format("Proposing %s%n", name); listener.getLogger().format("Proposing %s%n", name);
count++; synchronized (this) {
count++;
}
} else { } else {
listener.getLogger().format("Ignoring %s%n", name); listener.getLogger().format("Ignoring %s%n", name);
} }
} }


public int getCount() { /**
* Returns the count of repositories matches.
*
* @return the count of repositories matches.
*/
public synchronized int getCount() {
return count; return count;
} }
} }
Expand All @@ -1458,12 +1534,23 @@ public int getCount() {
* Our {@link SCMNavigatorRequest.SourceLambda}. * Our {@link SCMNavigatorRequest.SourceLambda}.
*/ */
private class SourceFactory implements SCMNavigatorRequest.SourceLambda { private class SourceFactory implements SCMNavigatorRequest.SourceLambda {
/**
* The request.
*/
private final GitHubSCMNavigatorRequest request; private final GitHubSCMNavigatorRequest request;


/**
* Constructor.
*
* @param request the request to decorate {@link SCMSource} instances with.
*/
public SourceFactory(GitHubSCMNavigatorRequest request) { public SourceFactory(GitHubSCMNavigatorRequest request) {
this.request = request; this.request = request;
} }


/**
* {@inheritDoc}
*/
@NonNull @NonNull
@Override @Override
public SCMSource create(@NonNull String name) { public SCMSource create(@NonNull String name) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1625,14 +1625,14 @@ public void given__legacyCode__when__setPattern_custom__then__patternSetAndTrait
@Test @Test
public void given__legacyCode__when__checkoutCredentials_SAME__then__noTraitAdded() { public void given__legacyCode__when__checkoutCredentials_SAME__then__noTraitAdded() {
GitHubSCMNavigator instance = new GitHubSCMNavigator(null, "test", "scan", GitHubSCMSource.DescriptorImpl.SAME); GitHubSCMNavigator instance = new GitHubSCMNavigator(null, "test", "scan", GitHubSCMSource.DescriptorImpl.SAME);
assertThat(instance.getCheckoutCredentialsId(), is(GitHubSCMSource.DescriptorImpl.SAME)); assertThat(instance.getCheckoutCredentialsId(), is(GitHubSCMNavigator.DescriptorImpl.SAME));
assertThat(instance.getTraits(), not(Matchers.<SCMTrait<?>>hasItem(instanceOf(SSHCheckoutTrait.class)))); assertThat(instance.getTraits(), not(Matchers.<SCMTrait<?>>hasItem(instanceOf(SSHCheckoutTrait.class))));
} }


@Test @Test
public void given__legacyCode__when__checkoutCredentials_null__then__noTraitAdded() { public void given__legacyCode__when__checkoutCredentials_null__then__noTraitAdded() {
GitHubSCMNavigator instance = new GitHubSCMNavigator(null, "test", "scan", null); GitHubSCMNavigator instance = new GitHubSCMNavigator(null, "test", "scan", null);
assertThat(instance.getCheckoutCredentialsId(), is(GitHubSCMSource.DescriptorImpl.SAME)); assertThat(instance.getCheckoutCredentialsId(), is(GitHubSCMNavigator.DescriptorImpl.SAME));
assertThat(instance.getTraits(), not(Matchers.<SCMTrait<?>>hasItem(instanceOf(SSHCheckoutTrait.class)))); assertThat(instance.getTraits(), not(Matchers.<SCMTrait<?>>hasItem(instanceOf(SSHCheckoutTrait.class))));
} }


Expand Down

0 comments on commit da85c37

Please sign in to comment.