public static @Nonnull <T extends GlobalConfigurationCategory> T get(Class<T> type) { T category = all().get(type); if(category == null){ throw new AssertionError("Category not found. It seems the " + type + " is not annotated with @Extension and so not registered"); } return category; }
@Override public final synchronized T remove(int index) { T t = get(index); remove(t); return t; }
/** * Gets the singleton instance. * * @return the {@link ItemDeletion} singleton. */ @CheckForNull private static ItemDeletion instance() { return ExtensionList.lookup(Queue.QueueDecisionHandler.class).get(ItemDeletion.class); }
public static void schedule(Thread originThread, Throwable cause, long approxDelay) { TcpSlaveAgentListenerRescheduler rescheduler = AperiodicWork.all().get(TcpSlaveAgentListenerRescheduler.class); rescheduler.originThread = originThread; rescheduler.cause = cause; rescheduler.recurrencePeriod = approxDelay; rescheduler.isActive = true; } }
@Override public T get(int index) { return ExtensionList.this.get(size()-index-1); }
/** * Short cut for getting the singleton instance. */ public static HudsonHomeDiskUsageMonitor get() { return all().get(HudsonHomeDiskUsageMonitor.class); }
public static PluginWrapperAdministrativeMonitor get() { return AdministrativeMonitor.all().get(PluginWrapperAdministrativeMonitor.class); } }
public static ApiTokenPropertyConfiguration get() { return GlobalConfiguration.all().get(ApiTokenPropertyConfiguration.class); }
public T get(int index) { return storage().get(index); }
private static FingerprintCleanupThread getInstance() { return ExtensionList.lookup(AsyncPeriodicWork.class).get(FingerprintCleanupThread.class); }
@Initializer(after = InitMilestone.PLUGINS_PREPARED, before = InitMilestone.PLUGINS_STARTED, fatal = false) public static void load() throws IOException { Map<String, Boolean> overrides = ExtensionList.lookup(CustomClassFilter.class).get(Contributed.class).overrides; overrides.clear(); Enumeration<URL> resources = Jenkins.getInstance().getPluginManager().uberClassLoader.getResources("META-INF/hudson.remoting.ClassFilter"); while (resources.hasMoreElements()) { try (InputStream is = resources.nextElement().openStream()) { for (String entry : IOUtils.readLines(is, StandardCharsets.UTF_8)) { if (entry.matches("#.*|\\s*")) { // skip } else if (entry.startsWith("!")) { overrides.put(entry.substring(1), false); } else { overrides.put(entry, true); } } } } Logger.getLogger(Contributed.class.getName()).log(Level.FINE, "plugin-defined entries: {0}", overrides); }
/** * Checks if the queue is clogged, and if so, * activate {@link AdministrativeMonitorImpl}. */ public void clogCheck() { AdministrativeMonitor.all().get(AdministrativeMonitorImpl.class).on = isClogged(); }
@Override public GlobalCredentialsConfiguration getTargetComponent(ConfigurationContext context) { return GlobalCredentialsConfiguration.all().get(GlobalCredentialsConfiguration.class); }
public static void invoke() { ExtensionList.lookup(AsyncPeriodicWork.class).get(WorkspaceCleanupThread.class).run(); }
/** * Convenience method allowing lookup of the only instance of a given type. * Equivalent to {@code ExtensionList.lookup(Class).get(Class)} if there is one instance, * and throws an {@code IllegalStateException} otherwise. * * @param type The type to look up. * @return the singleton instance of the given type in its list. * @throws IllegalStateException if there are no instances, or more than one * * @since 2.87 */ public static @Nonnull <U> U lookupSingleton(Class<U> type) { ExtensionList<U> all = lookup(type); if (all.size() != 1) { throw new IllegalStateException("Expected 1 instance of " + type.getName() + " but got " + all.size()); } return all.get(0); }
/** * Retrieve default implementation from Jenkins */ static ConfiguratorRegistry get() { return Jenkins.getInstance().getExtensionList(ConfiguratorRegistry.class).get(0); } }
/** * Utility method to mark the computer offline for derived classes. * * @return true * if the node was actually taken offline by this act (as opposed to us deciding not to do it, * or the computer already marked offline.) */ protected boolean markOffline(Computer c, OfflineCause oc) { if(isIgnored() || c.isTemporarilyOffline()) return false; // noop c.setTemporarilyOffline(true, oc); // notify the admin MonitorMarkedNodeOffline no = AdministrativeMonitor.all().get(MonitorMarkedNodeOffline.class); if(no!=null) no.active = true; return true; }
private PluginManagerConfigurator getPluginManagerConfigurator() { return j.jenkins.getExtensionList(PluginManagerConfigurator.class).get(0); }
@Override protected T instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException { final ExtensionList<T> list = Jenkins.getInstance().getExtensionList(target); if (list.size() != 1) { throw new ConfiguratorException("Expected a unique instance of extension "+target); } return (T) list.get(0); }
/** * Installs the default queue sorter. * * {@link Queue#Queue(LoadBalancer)} is too early to do this */ @Initializer(after=JOB_LOADED) public static void installDefaultQueueSorter() { ExtensionList<QueueSorter> all = all(); if (all.isEmpty()) return; Queue q = Jenkins.getInstance().getQueue(); if (q.getSorter()!=null) return; // someone has already installed something. leave that alone. q.setSorter(all.get(0)); if (all.size()>1) LOGGER.warning("Multiple QueueSorters are registered. Only the first one is used and the rest are ignored: "+all); }