jenkins.scm.api.trait.SCMSourceTraitDescriptor Java Examples

The following examples show how to use jenkins.scm.api.trait.SCMSourceTraitDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List<NamedArrayList<? extends SCMSourceTraitDescriptor>> getTraitsDescriptorLists() {
  List<NamedArrayList<? extends SCMSourceTraitDescriptor>> result = new ArrayList<>();
  List<SCMSourceTraitDescriptor> descriptors =
      SCMSourceTrait._for(this, GerritSCMSourceContext.class, GitSCMBuilder.class);
  NamedArrayList.select(
      descriptors,
      "Within Repository",
      NamedArrayList.anyOf(
          NamedArrayList.withAnnotation(Selection.class),
          NamedArrayList.withAnnotation(Discovery.class)),
      true,
      result);
  NamedArrayList.select(descriptors, "Additional", null, true, result);
  return result;
}
 
Example #2
Source File: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 5 votes vote down vote up
@Restricted(DoNotUse.class)
@DataBoundSetter
public void setExtensions(@CheckForNull List<GitSCMExtension> extensions) {
  List<SCMSourceTrait> traits = new ArrayList<>(this.traits);
  for (Iterator<SCMSourceTrait> iterator = traits.iterator(); iterator.hasNext(); ) {
    if (iterator.next() instanceof GitSCMExtensionTrait) {
      iterator.remove();
    }
  }
  EXTENSIONS:
  for (GitSCMExtension extension : Util.fixNull(extensions)) {
    for (SCMSourceTraitDescriptor d : SCMSourceTrait.all()) {
      if (d instanceof GitSCMExtensionTraitDescriptor) {
        GitSCMExtensionTraitDescriptor descriptor = (GitSCMExtensionTraitDescriptor) d;
        if (descriptor.getExtensionClass().isInstance(extension)) {
          try {
            SCMSourceTrait trait = descriptor.convertToTrait(extension);
            if (trait != null) {
              traits.add(trait);
              continue EXTENSIONS;
            }
          } catch (UnsupportedOperationException e) {
            LOGGER.log(
                Level.WARNING,
                "Could not convert " + extension.getClass().getName() + " to a trait",
                e);
          }
        }
      }
      LOGGER.log(
          Level.FINE,
          "Could not convert {0} to a trait (likely because this option does not "
              + "make sense for a GitSCMSource)",
          extension.getClass().getName());
    }
  }
  setTraits(traits);
}