/*
(non-Javadoc)
@see org.springframework.plugin.core.PluginRegistry#getPluginsFor(java.lang.Object, org.springframework.plugin.core.PluginRegistry.ExceptionProvider)
967254
@Override
	public <E extends Exception> List<T> getPluginsFor(S delimiter, Supplier<E> ex) throws E {

		Assert.notNull(delimiter, "Delimiter must not be null!");
		Assert.notNull(ex, "Exception supplier must not be null!");

		List<T> result = getPluginsFor(delimiter);

		if (result.isEmpty()) {
			throw ex.get();
		}

		return result;
	}
1203093
private Plugin probeNextPlugin() {
        Plugin plugin = null;
        int i = 0;
        while (i < listPending.size()) {
            // ZAP: Removed unnecessary cast.
            plugin = listPending.get(i);
            if (isAllDependencyCompleted(plugin)) {
                return plugin;
            }
            i++;
        }
        
        return null;
    }
1219884
public List<AbstractPlugin> getPlugins() {
        if (pluginCache.isEmpty()) {
            LOGGER.info("Plugin cache miss, reload");

            load();
        }

        final List<AbstractPlugin> ret = new ArrayList<>();

        for (final Map.Entry<String, HashSet<AbstractPlugin>> entry : pluginCache.entrySet()) {
            ret.addAll(entry.getValue());
        }

        return ret;
    }
1002916
protected PluginRelease findReleaseForPlugin(String id, String version) throws PluginException {
        PluginInfo pluginInfo = getPluginsMap().get(id);
        if (pluginInfo == null) {
            log.info("Plugin with id {} does not exist in any repository", id);
            throw new PluginException("Plugin with id {} not found in any repository", id);
        }

        if (version == null) {
            return getLastPluginRelease(id);
        }

        for (PluginRelease release : pluginInfo.releases) {
            if (versionManager.compareVersions(version, release.version) == 0 && release.url != null) {
                return release;
            }
        }

        throw new PluginException("Plugin {} with version @{} does not exist in the repository", id, version);
    }
492111
@Override
    public List<JqassistantPlugin> getPlugins() {
        if (this.plugins == null) {
            final Enumeration<URL> resources;
            try {
                resources = pluginClassLoader.getResources(PLUGIN_RESOURCE);
            } catch (IOException e) {
                throw new IllegalStateException("Cannot get plugin resources.", e);
            }
            this.plugins = new ArrayList<>();
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                LOGGER.debug("Reading plugin descriptor from '{}'.", url);
                this.plugins.add(readPlugin(url));
            }
            SortedSet<String> pluginNames = new TreeSet<>();
            for (JqassistantPlugin plugin : plugins) {
                pluginNames.add(plugin.getName());
            }
            LOGGER.info("Loaded jQAssistant plugins {}.", pluginNames);
        }
        return this.plugins;
    }
126675
private AbstractPlugin load(final String pluginDirPath, final Map<String, HashSet<AbstractPlugin>> holder) throws Exception {
        final Properties props = new Properties();
        final ServletContext servletContext = AbstractServletListener.getServletContext();

        String plugin = StringUtils.substringAfter(pluginDirPath, "/plugins");
        plugin = plugin.replace("/", "");

        final File file = Latkes.getWebFile("/plugins/" + plugin + "/plugin.properties");
        props.load(new FileInputStream(file));

        final URL defaultClassesFileDirURL = servletContext.getResource("/plugins/" + plugin + "classes");
        URL classesFileDirURL = null;
        try {
            classesFileDirURL = servletContext.getResource(props.getProperty("classesDirPath"));
        } catch (final MalformedURLException e) {
            LOGGER.log(Level.ERROR, "Reads [" + props.getProperty("classesDirPath") + "] failed", e);
        }

        final URLClassLoader classLoader = new URLClassLoader(new URL[]{
                defaultClassesFileDirURL, classesFileDirURL}, PluginManager.class.getClassLoader());

        classLoaders.add(classLoader);

        String pluginClassName = props.getProperty(Plugin.PLUGIN_CLASS);
        if (StringUtils.isBlank(pluginClassName)) {
            pluginClassName = NotInteractivePlugin.class.getName();
        }

        final String rendererId = props.getProperty(Plugin.PLUGIN_RENDERER_ID);

        if (StringUtils.isBlank(rendererId)) {
            LOGGER.log(Level.WARN, "no renderer defined by this plugin[" + plugin + "]，this plugin will be ignore!");
            return null;
        }

        final Class<?> pluginClass = classLoader.loadClass(pluginClassName);

        LOGGER.log(Level.TRACE, "Loading plugin class[name={0}]", pluginClassName);
        final AbstractPlugin ret = (AbstractPlugin) pluginClass.newInstance();

        ret.setRendererId(rendererId);

        setPluginProps(plugin, ret, props);
        registerEventListeners(props, classLoader, ret);
        register(ret, holder);

        ret.changeStatus();

        return ret;
    }
942919
public List getPlugins(final Class pluginClass) {
        synchronized (pluginMap) {
            List pluginList = new ArrayList(pluginMap.size());
            Iterator iter = pluginMap.values().iterator();

            while (iter.hasNext()) {
                Object plugin = iter.next();

                if (pluginClass.isInstance(plugin)) {
                    pluginList.add(plugin);
                }
            }
            return pluginList;
        }
    }
228594
function _getPluginsForCurrentContext() {
        var curDoc = DocumentManager.getCurrentDocument();

        if (curDoc) {
            var languageId = curDoc.getLanguage().getId();
            return _providerRegistrationHandler.getProvidersForLanguageId(languageId);
        }

        return _providerRegistrationHandler.getProvidersForLanguageId(); //plugins registered for all
    }
7148
public Map<String, PluginInfo> getPluginsMap() {
        Map<String, PluginInfo> pluginsMap = new HashMap<>();
        for (UpdateRepository repository : getRepositories()) {
            pluginsMap.putAll(repository.getPlugins());
        }

        return pluginsMap;
    }
1248619
private ScriptPluginProvider getPlugin(
            final PluginMeta pluginMeta,
            final File file,
            final ProviderDef pluginDef,
            final ProviderIdent ident
    ) throws
            ProviderLoaderException, PluginException
    {
        if (null == fileExpandedDir) {
            final File dir;
            try {
                dir = expandScriptPlugin(file);
            } catch (IOException e) {
                throw new ProviderLoaderException(e, ident.getService(), ident.getProviderName());
            }
            fileExpandedDir = dir;
            if (pluginDef.getPluginType().equals("script")) {

                final File script = new File(fileExpandedDir, pluginDef.getScriptFile());
                //set executable bit for script-file of the provider
                try {
                    ScriptfileUtils.setExecutePermissions(script);
                } catch (IOException e) {
                    log.warn("Unable to set executable bit for script file: " + script + ": " + e.getMessage());
                }
            }
            debug("expanded plugin dir! " + fileExpandedDir);
        } else {
            debug("expanded plugin dir: " + fileExpandedDir);
        }
        if (pluginDef.getPluginType().equals("script")) {
            final File script = new File(fileExpandedDir, pluginDef.getScriptFile());
            if (!script.exists() || !script.isFile()) {
                throw new PluginException("Script file was not found: " + script.getAbsolutePath());
            }
        }
        return new ScriptPluginProviderImpl(pluginMeta, pluginDef, file, fileExpandedDir);
    }
1232032
public PluginRegistry load() throws PluginException {

        List<Path> pluginFiles = getPluginsProvider().provide(getPluginsDirectory());

        PluginRegistry pluginRegistry = new PluginRegistryContainer();

        // Loading information about all plugins first
        for (Path pluginFile : pluginFiles) {
            PluginMetadata pluginMetadata = getManifestReader().read(pluginFile);
            pluginRegistry.addPlugin(pluginMetadata);
        }

        // Iterating over the entire plugin set, checking for dependency resolution problems and loading classes
        for (String pluginName : pluginRegistry.getPluginNames()) {
            Optional<PluginMetadata> pluginMetadata = pluginRegistry.getPlugin(pluginName);
            if (pluginMetadata.isPresent()) {
                getDependencyChecker().check(pluginRegistry, pluginMetadata.get());

                ScanResult scanResult = getClassesScanner().scan(
                        pluginMetadata.get().getPath(),
                        getExtensionPoints()
                );
                for (Class extensionPoint : scanResult.getContents().getExtensionPoints()) {
                    pluginRegistry.addImplementations(
                            pluginMetadata.get(),
                            extensionPoint,
                            scanResult.getContents().getImplementations(extensionPoint)
                    );
                }
                pluginRegistry.addClassLoader(pluginMetadata.get(), scanResult.getClassLoader());

                List<Path> resources = getResourcesScanner().scan(pluginMetadata.get().getPath());
                pluginRegistry.addResources(pluginMetadata.get(), resources);
            }
        }
        return pluginRegistry;
    }
885582
public PluginWrapper whichPlugin(Class c) {
        PluginWrapper oneAndOnly = null;
        ClassLoader cl = c.getClassLoader();
        for (PluginWrapper p : activePlugins) {
            if (p.classLoader==cl) {
                if (oneAndOnly!=null)
                    return null;    // ambiguous
                oneAndOnly = p;
            }
        }
        return oneAndOnly;
    }
55592
public List<BeanDefinition> inspectPlugin(PluginConfig plugin) {
        Configuration conf = new ConfigurationImpl();
        Collection<PluginConfig> plugins = new LinkedList<PluginConfig>();
        plugins.add(plugin);
        conf.setPlugins(plugins);
        ConfigurationManager manager = new ConfigurationManager(conf, false, locateConfigurationProvider());
        manager.executeConfigurationProviders();
        return conf.getAvailableBeans(plugin);
    }
353778
@Override
	public LinkBuilder linkFor(Class<?> type, Object... parameters) {
		return getPluginFor(type).linkFor(type, parameters);
	}
1283979
@Override
  public final Field getFor(final Class<?> pClass, final String pFieldName) {
    Map<String, Field> fldMap = this.rapiFieldsMap.get(pClass);
    if (fldMap == null) {
      // There is no way to get from Map partially initialized bean
      // in this double-checked locking implementation
      // cause putting to the Map fully initialized bean
      synchronized (this.rapiFieldsMap) {
        fldMap = this.rapiFieldsMap.get(pClass);
        if (fldMap == null) {
          fldMap = new HashMap<String, Field>();
          Field[] fields = getUtlReflection().retrieveFields(pClass);
          for (Field field : fields) {
            fldMap.put(field.getName(), field);
          }
          this.rapiFieldsMap.put(pClass, fldMap);
        }
      }
    }
    return fldMap.get(pFieldName);
  }
647302
private Map findProviders() {
        Map providers = getContainer().getComponentDescriptorMap(Provider.class.getName());
        if (providers == null) {
            throw new Error("No providers discovered");
        }

        Set keys = providers.keySet();
        Map found = null;

        for (Iterator iter = keys.iterator(); iter.hasNext();) {
            String key = (String)iter.next();

            Provider provider;

            try {
                provider = (Provider) getContainer().lookup(Provider.class.getName(), key);
            }
            catch (Exception e) {
                log.warn("Failed to lookup provider for key: {}", key, e);
                continue;
            }

            if (provider != null) {
                if (found == null) {
                    found = new HashMap();
                }

                found.put(key, provider);
            }
        }

        return found;
    }
902943
public static List<String> getInstalledPlugins() {
        final List<Element> plugins = toList(getPluginConfiguration().getElementsByTagName("plugin"));
        return plugins.stream()
                .map((Element elem) -> elem.getAttributeNode("id"))
                .filter(Objects::nonNull)
                .map(Attr::getValue)
                .sorted()
                .collect(Collectors.toList());
    }