CompoundPluginDescriptorFinder implements PluginDescriptorFinder { @Override public PluginDescriptor find(Path pluginPath) { for (PluginDescriptorFinder finder : finders) { if (finder.isApplicable(pluginPath)) { log.debug("'{}' is applicable for plugin '{}'", finder, pluginPath); try { PluginDescriptor pluginDescriptor = finder.find(pluginPath); if (pluginDescriptor != null) { return pluginDescriptor; } } catch (Exception e) { if (finders.indexOf(finder) == finders.size() - 1) { log.error(e.getMessage(), e); } else { log.debug(e.getMessage()); log.debug("Try to continue with the next finder"); } } } else { log.debug("'{}' is not applicable for plugin '{}'", finder, pluginPath); } } throw new PluginRuntimeException("No PluginDescriptorFinder for plugin '{}'", pluginPath); }  CompoundPluginDescriptorFinder add(PluginDescriptorFinder finder); int size(); @Override boolean isApplicable(Path pluginPath); @Override PluginDescriptor find(Path pluginPath);  }
@Test public void find() throws Exception { Path pluginPath = Files.createDirectories(pluginsPath.resolve("test-plugin-1")); storePropertiesToPath(getPlugin1Properties(), pluginPath); PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder() .add(new PropertiesPluginDescriptorFinder()); PluginDescriptor pluginDescriptor = descriptorFinder.find(pluginPath); assertNotNull(pluginDescriptor); assertEquals("test-plugin-1", pluginDescriptor.getPluginId()); assertEquals("0.0.1", pluginDescriptor.getVersion()); }
@Test public void testNotFound() { PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder(); assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3"))); }