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

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

本文整理了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

  1. /**
  2. * Alias for {@link #getDescriptor(String)}.
  3. */
  4. public Descriptor getDescriptorByName(String id) {
  5. return getDescriptor(id);
  6. }

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

  1. /**
  2. * Works just like {@link #getDescriptor(Class)} but don't take no for an answer.
  3. *
  4. * @throws AssertionError
  5. * If the descriptor is missing.
  6. * @since 1.326
  7. */
  8. @Nonnull
  9. public Descriptor getDescriptorOrDie(Class<? extends Describable> type) {
  10. Descriptor d = getDescriptor(type);
  11. if (d==null)
  12. throw new AssertionError(type+" is missing its descriptor");
  13. return d;
  14. }

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

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

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

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

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

  1. public Object getDynamic(String token) {
  2. return Jenkins.getInstance().getDescriptor(token);
  3. }
  4. }

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Filters a descriptor for {@link BuildStep}s by using {@link BuildStepDescriptor#isApplicable(Class)}.
  3. */
  4. public static <T extends BuildStep&Describable<T>>
  5. List<Descriptor<T>> filter(List<Descriptor<T>> base, Class<? extends AbstractProject> type) {
  6. // descriptor of the project
  7. Descriptor pd = Jenkins.getInstance().getDescriptor((Class) type);
  8. List<Descriptor<T>> r = new ArrayList<Descriptor<T>>(base.size());
  9. for (Descriptor<T> d : base) {
  10. if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(d))
  11. continue;
  12. if (d instanceof BuildStepDescriptor) {
  13. BuildStepDescriptor<T> bd = (BuildStepDescriptor<T>) d;
  14. if(!bd.isApplicable(type)) continue;
  15. r.add(bd);
  16. } else {
  17. // old plugins built before 1.150 may not implement BuildStepDescriptor
  18. r.add(d);
  19. }
  20. }
  21. return r;
  22. }
  23. }

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

  1. @Override
  2. public Object onConvert(Type targetType, Class targetTypeErasure, Object jsonSource) {
  3. if (jsonSource instanceof JSONObject) {
  4. JSONObject json = (JSONObject) jsonSource;
  5. if (isApplicable(targetTypeErasure, json)) {
  6. LOGGER.log(Level.FINE, "switching to newInstance {0} {1}", new Object[] {targetTypeErasure.getName(), json});
  7. try {
  8. return Jenkins.getActiveInstance().getDescriptor(targetTypeErasure).newInstance(Stapler.getCurrentRequest(), json);
  9. } catch (Exception x) {
  10. LOGGER.log(Level.WARNING, "falling back to default instantiation " + targetTypeErasure.getName() + " " + json, x);
  11. }
  12. }
  13. } else {
  14. LOGGER.log(Level.FINER, "ignoring non-object {0}", jsonSource);
  15. }
  16. return oldInterceptor.onConvert(targetType, targetTypeErasure, jsonSource);
  17. }

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

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

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

  1. /**
  2. * List up all {@link BuildWrapperDescriptor}s that are applicable for the given project.
  3. *
  4. * @return
  5. * The signature doesn't use {@link BuildWrapperDescriptor} to maintain compatibility
  6. * with {@link BuildWrapper} implementations before 1.150.
  7. */
  8. public static List<Descriptor<BuildWrapper>> getFor(AbstractProject<?, ?> project) {
  9. List<Descriptor<BuildWrapper>> result = new ArrayList<>();
  10. Descriptor pd = Jenkins.getInstance().getDescriptor((Class)project.getClass());
  11. for (Descriptor<BuildWrapper> w : BuildWrapper.all()) {
  12. if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(w))
  13. continue;
  14. if (w instanceof BuildWrapperDescriptor) {
  15. BuildWrapperDescriptor bwd = (BuildWrapperDescriptor) w;
  16. if(bwd.isApplicable(project))
  17. result.add(bwd);
  18. } else {
  19. // old BuildWrapper that doesn't implement BuildWrapperDescriptor
  20. result.add(w);
  21. }
  22. }
  23. return result;
  24. }
  25. }

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

  1. public GitLabClient getClient() {
  2. if (StringUtils.isNotEmpty(gitLabConnection)) {
  3. GitLabConnectionConfig connectionConfig = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
  4. return connectionConfig != null ? connectionConfig.getClient(gitLabConnection) : null;
  5. }
  6. return null;
  7. }

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

  1. /**
  2. * Determines which kinds of SCMs are applicable to a given project.
  3. * @param project a project on which we might be configuring SCM, or null if unknown
  4. * @return all descriptors which {@link SCMDescriptor#isApplicable(Job)} to it, also filtered by {@link TopLevelItemDescriptor#isApplicable};
  5. * or simply {@link #all} if there is no project
  6. * @since 1.568
  7. */
  8. public static List<SCMDescriptor<?>> _for(@CheckForNull final Job project) {
  9. if(project==null) return all();
  10. final Descriptor pd = Jenkins.getInstance().getDescriptor((Class) project.getClass());
  11. List<SCMDescriptor<?>> r = new ArrayList<SCMDescriptor<?>>();
  12. for (SCMDescriptor<?> scmDescriptor : all()) {
  13. if(!scmDescriptor.isApplicable(project)) continue;
  14. if (pd instanceof TopLevelItemDescriptor) {
  15. TopLevelItemDescriptor apd = (TopLevelItemDescriptor) pd;
  16. if(!apd.isApplicable(scmDescriptor)) continue;
  17. }
  18. r.add(scmDescriptor);
  19. }
  20. return r;
  21. }

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

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

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

  1. static List<RootElementConfigurator> all() {
  2. List<RootElementConfigurator> configurators = new ArrayList<>();
  3. final Jenkins jenkins = Jenkins.getInstance();
  4. configurators.addAll(jenkins.getExtensionList(RootElementConfigurator.class));
  5. for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) {
  6. configurators.add(new GlobalConfigurationCategoryConfigurator(category));
  7. }
  8. for (ManagementLink link : ManagementLink.all()) {
  9. final String name = link.getUrlName();
  10. final Descriptor descriptor = Jenkins.getInstance().getDescriptor(name);
  11. if (descriptor != null)
  12. configurators.add(new DescriptorConfigurator(descriptor));
  13. }
  14. return configurators;
  15. }

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

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

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

  1. public ListBoxModel doFillGitLabConnectionItems() {
  2. ListBoxModel options = new ListBoxModel();
  3. GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
  4. for (GitLabConnection connection : descriptor.getConnections()) {
  5. options.add(connection.getName(), connection.getName());
  6. }
  7. return options;
  8. }
  9. }

相关文章

Jenkins类方法