/** * Alias for {@link #getDescriptor(String)}. */ public Descriptor getDescriptorByName(String id) { return getDescriptor(id); }
/** * 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; }
/** * 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)); }
public ProjectNamingStrategyDescriptor getDescriptor() { return (ProjectNamingStrategyDescriptor) Jenkins.getInstance().getDescriptor(getClass()); }
public Object getDynamic(String token) { return Jenkins.getInstance().getDescriptor(token); } }
public Descriptor<ProxyConfiguration> getProxyDescriptor() { return Jenkins.getInstance().getDescriptor(ProxyConfiguration.class); }
@Override public Descriptor<RemotingWorkDirSettings> getDescriptor() { return Jenkins.get().getDescriptor(RemotingWorkDirSettings.class); }
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; }
/** * Returns {@link Descriptor} whose 'clazz' is the same as {@link #getItemType() the item type}. */ public Descriptor getItemTypeDescriptor() { return Jenkins.getInstance().getDescriptor(getItemType()); }
private String resolve() { // the resolution has to be deferred to avoid ordering issue among descriptor registrations. return Jenkins.getInstance().getDescriptor(owner).getHelpFile(fieldNameToRedirectTo); } }
/** * 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; } }
@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); }
@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); }
/** * 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; } }
public GitLabClient getClient() { if (StringUtils.isNotEmpty(gitLabConnection)) { GitLabConnectionConfig connectionConfig = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class); return connectionConfig != null ? connectionConfig.getClient(gitLabConnection) : null; } return null; }
/** * 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; }
private Descriptor getDescriptor() { return Jenkins.getInstance().getDescriptor(getTarget()); }
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; }
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); } } }
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; } }