jenkins.model.Jenkins.getDescriptor()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(278)

本文整理了Java中jenkins.model.Jenkins.getDescriptor()方法的一些代码示例,展示了Jenkins.getDescriptor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jenkins.getDescriptor()方法的具体详情如下:
包路径:jenkins.model.Jenkins
类名称:Jenkins
方法名:getDescriptor

Jenkins.getDescriptor介绍

[英]Gets the Descriptor that corresponds to the given Describable type.

If you have an instance of type and call Describable#getDescriptor(), you'll get the same instance that this method returns.
[中]获取与给定可描述类型对应的描述符。
如果您有一个类型为的实例,并调用Describable#getDescriptor(),那么您将得到此方法返回的相同实例。

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Alias for {@link #getDescriptor(String)}.
 */
public Descriptor getDescriptorByName(String id) {
  return getDescriptor(id);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Works just like {@link #getDescriptor(Class)} but don't take no for an answer.
 *
 * @throws AssertionError
 *      If the descriptor is missing.
 * @since 1.326
 */
@Nonnull
public Descriptor getDescriptorOrDie(Class<? extends Describable> type) {
  Descriptor d = getDescriptor(type);
  if (d==null)
    throw new AssertionError(type+" is missing its descriptor");
  return d;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Creates a new job.
 *
 * <p>
 * This version infers the descriptor from the type of the top-level item.
 *
 * @throws IllegalArgumentException
 *      if the project of the given name already exists.
 */
public synchronized <T extends TopLevelItem> T createProject( Class<T> type, String name ) throws IOException {
  return type.cast(createProject((TopLevelItemDescriptor)getDescriptor(type),name));
}

代码示例来源:origin: jenkinsci/jenkins

public ProjectNamingStrategyDescriptor getDescriptor() {
  return (ProjectNamingStrategyDescriptor) Jenkins.getInstance().getDescriptor(getClass());
}

代码示例来源:origin: jenkinsci/jenkins

public Object getDynamic(String token) {
    return Jenkins.getInstance().getDescriptor(token);
  }
}

代码示例来源:origin: jenkinsci/jenkins

public Descriptor<ProxyConfiguration> getProxyDescriptor() {
  return Jenkins.getInstance().getDescriptor(ProxyConfiguration.class);
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public Descriptor<RemotingWorkDirSettings> getDescriptor() {
  return Jenkins.get().getDescriptor(RemotingWorkDirSettings.class);
}

代码示例来源:origin: jenkinsci/jenkins

public Descriptor getItemTypeDescriptorOrDie() {
  Class it = getItemType();
  if (it == null) {
    throw new AssertionError(clazz + " is not an array/collection type in " + displayName + ". See https://jenkins.io/redirect/developer/class-is-missing-descriptor");
  }
  Descriptor d = Jenkins.getInstance().getDescriptor(it);
  if (d==null)
    throw new AssertionError(it +" is missing its descriptor in "+displayName+". See https://jenkins.io/redirect/developer/class-is-missing-descriptor");
  return d;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Returns {@link Descriptor} whose 'clazz' is the same as {@link #getItemType() the item type}.
 */
public Descriptor getItemTypeDescriptor() {
  return Jenkins.getInstance().getDescriptor(getItemType());
}

代码示例来源:origin: jenkinsci/jenkins

private String resolve() {
    // the resolution has to be deferred to avoid ordering issue among descriptor registrations.
    return Jenkins.getInstance().getDescriptor(owner).getHelpFile(fieldNameToRedirectTo);
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
   * Filters a descriptor for {@link BuildStep}s by using {@link BuildStepDescriptor#isApplicable(Class)}.
   */
  public static <T extends BuildStep&Describable<T>>
  List<Descriptor<T>> filter(List<Descriptor<T>> base, Class<? extends AbstractProject> type) {
    // descriptor of the project
    Descriptor pd = Jenkins.getInstance().getDescriptor((Class) type);

    List<Descriptor<T>> r = new ArrayList<Descriptor<T>>(base.size());
    for (Descriptor<T> d : base) {
      if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(d))
        continue;

      if (d instanceof BuildStepDescriptor) {
        BuildStepDescriptor<T> bd = (BuildStepDescriptor<T>) d;
        if(!bd.isApplicable(type))  continue;
        r.add(bd);
      } else {
        // old plugins built before 1.150 may not implement BuildStepDescriptor
        r.add(d);
      }
    }
    return r;
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public Object onConvert(Type targetType, Class targetTypeErasure, Object jsonSource) {
  if (jsonSource instanceof JSONObject) {
    JSONObject json = (JSONObject) jsonSource;
    if (isApplicable(targetTypeErasure, json)) {
      LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {targetTypeErasure.getName(), json});
      try {
        return Jenkins.getActiveInstance().getDescriptor(targetTypeErasure).newInstance(Stapler.getCurrentRequest(), json);
      } catch (Exception x) {
        LOGGER.log(Level.WARNING, "falling back to default instantiation " + targetTypeErasure.getName() + " " + json, x);
      }
    }
  } else {
    LOGGER.log(Level.FINER, "ignoring non-object {0}", jsonSource);
  }
  return oldInterceptor.onConvert(targetType, targetTypeErasure, jsonSource);
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public Object instantiate(Class actualType, JSONObject json) {
  if (isApplicable(actualType, json)) {
    LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {actualType.getName(), json});
    try {
      final Descriptor descriptor = Jenkins.getActiveInstance().getDescriptor(actualType);
      if (descriptor != null) {
        return descriptor.newInstance(Stapler.getCurrentRequest(), json);
      } else {
        LOGGER.log(Level.WARNING, "Descriptor not found. Falling back to default instantiation "
            + actualType.getName() + " " + json);
      }
    } catch (Exception x) {
      LOGGER.log(Level.WARNING, "falling back to default instantiation " + actualType.getName() + " " + json, x);
      // If nested objects are not using newInstance, bindJSON will wind up throwing the same exception anyway,
      // so logging above will result in a duplicated stack trace.
      // However if they *are* then this is the only way to find errors in that newInstance.
      // Normally oldInterceptor.instantiate will just return DEFAULT, not actually do anything,
      // so we cannot try calling the default instantiation and then decide which problem to report.
    }
  }
  return oldInterceptor.instantiate(actualType, json);
}

代码示例来源:origin: jenkinsci/jenkins

/**
   * List up all {@link BuildWrapperDescriptor}s that are applicable for the given project.
   *
   * @return
   *      The signature doesn't use {@link BuildWrapperDescriptor} to maintain compatibility
   *      with {@link BuildWrapper} implementations before 1.150.
   */
  public static List<Descriptor<BuildWrapper>> getFor(AbstractProject<?, ?> project) {
    List<Descriptor<BuildWrapper>> result = new ArrayList<>();
    Descriptor pd = Jenkins.getInstance().getDescriptor((Class)project.getClass());

    for (Descriptor<BuildWrapper> w : BuildWrapper.all()) {
      if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(w))
        continue;
      if (w instanceof BuildWrapperDescriptor) {
        BuildWrapperDescriptor bwd = (BuildWrapperDescriptor) w;
        if(bwd.isApplicable(project))
          result.add(bwd);
      } else {
        // old BuildWrapper that doesn't implement BuildWrapperDescriptor
        result.add(w);
      }
    }
    return result;
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

public GitLabClient getClient() {
  if (StringUtils.isNotEmpty(gitLabConnection)) {
    GitLabConnectionConfig connectionConfig = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
    return connectionConfig != null ? connectionConfig.getClient(gitLabConnection) : null;
  }
  return null;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Determines which kinds of SCMs are applicable to a given project.
 * @param project a project on which we might be configuring SCM, or null if unknown
 * @return all descriptors which {@link SCMDescriptor#isApplicable(Job)} to it, also filtered by {@link TopLevelItemDescriptor#isApplicable};
 *         or simply {@link #all} if there is no project
 * @since 1.568
 */
public static List<SCMDescriptor<?>> _for(@CheckForNull final Job project) {
  if(project==null)   return all();
  
  final Descriptor pd = Jenkins.getInstance().getDescriptor((Class) project.getClass());
  List<SCMDescriptor<?>> r = new ArrayList<SCMDescriptor<?>>();
  for (SCMDescriptor<?> scmDescriptor : all()) {
    if(!scmDescriptor.isApplicable(project))    continue;
    if (pd instanceof TopLevelItemDescriptor) {
      TopLevelItemDescriptor apd = (TopLevelItemDescriptor) pd;
      if(!apd.isApplicable(scmDescriptor))    continue;
    }
    r.add(scmDescriptor);
  }
  return r;
}

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

private Descriptor getDescriptor() {
  return Jenkins.getInstance().getDescriptor(getTarget());
}

代码示例来源:origin: jenkinsci/configuration-as-code-plugin

static List<RootElementConfigurator> all() {
  List<RootElementConfigurator> configurators = new ArrayList<>();
  final Jenkins jenkins = Jenkins.getInstance();
  configurators.addAll(jenkins.getExtensionList(RootElementConfigurator.class));
  for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) {
    configurators.add(new GlobalConfigurationCategoryConfigurator(category));
  }
  for (ManagementLink link : ManagementLink.all()) {
    final String name = link.getUrlName();
    final Descriptor descriptor = Jenkins.getInstance().getDescriptor(name);
    if (descriptor != null)
      configurators.add(new DescriptorConfigurator(descriptor));
  }
  return configurators;
}

代码示例来源:origin: jenkinsci/gitlab-plugin

private void checkPermission(Permission permission) {
  if (((GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class)).isUseAuthenticatedEndpoint()) {
    if (!Jenkins.getActiveInstance().getACL().hasPermission(authentication, permission)) {
      String message = Messages.AccessDeniedException2_MissingPermission(authentication.getName(), permission.group.title+"/"+permission.name);
      LOGGER.finest("Unauthorized (Did you forget to add API Token to the web hook ?)");
      throw HttpResponses.errorWithoutStack(403, message);
    }
  }
}

代码示例来源:origin: jenkinsci/gitlab-plugin

public ListBoxModel doFillGitLabConnectionItems() {
    ListBoxModel options = new ListBoxModel();
    GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
    for (GitLabConnection connection : descriptor.getConnections()) {
      options.add(connection.getName(), connection.getName());
    }
    return options;
  }
}

相关文章

Jenkins类方法