/** * Constructs an Interpolator using a given StrLookup and a list of packages to find Lookup plugins in. * * @param defaultLookup the default StrLookup to use as a fallback * @param pluginPackages a list of packages to scan for Lookup plugins * @since 2.1 */ public Interpolator(final StrLookup defaultLookup, final List<String> pluginPackages) { this.defaultLookup = defaultLookup == null ? new MapLookup(new HashMap<String, String>()) : defaultLookup; final PluginManager manager = new PluginManager(CATEGORY); manager.collectPlugins(pluginPackages); final Map<String, PluginType<?>> plugins = manager.getPlugins(); for (final Map.Entry<String, PluginType<?>> entry : plugins.entrySet()) { try { final Class<? extends StrLookup> clazz = entry.getValue().getPluginClass().asSubclass(StrLookup.class); strLookupMap.put(entry.getKey(), ReflectionUtil.instantiate(clazz)); } catch (final Throwable t) { handleError(entry.getKey(), t); } } }
private static Collection<ConfigurationFactory> findFactories() { final PluginManager manager = new PluginManager(ConfigurationFactory.CATEGORY); manager.collectPlugins(); final Collection<ConfigurationFactory> factories = new ArrayList<>(); for (final PluginType<?> type : manager.getPlugins().values()) { final ConfigurationFactory factory = tryCreateFactory(type); if (factory != null) { factories.add(factory); } } return factories; }
/** * Constructor. * * @param config * The current Configuration. * @param converterKey * The key to lookup the converters. * @param expectedClass * The expected base Class of each Converter. * @param filterClass * Filter the returned plugins after calling the plugin manager. */ public PatternParser(final Configuration config, final String converterKey, final Class<?> expectedClass, final Class<?> filterClass) { this.config = config; final PluginManager manager = new PluginManager(converterKey); manager.collectPlugins(config == null ? null : config.getPluginPackages()); final Map<String, PluginType<?>> plugins = manager.getPlugins(); final Map<String, Class<PatternConverter>> converters = new LinkedHashMap<>(); for (final PluginType<?> type : plugins.values()) { try { @SuppressWarnings("unchecked") final Class<PatternConverter> clazz = (Class<PatternConverter>) type.getPluginClass(); if (filterClass != null && !filterClass.isAssignableFrom(clazz)) { continue; } final ConverterKeys keys = clazz.getAnnotation(ConverterKeys.class); if (keys != null) { for (final String key : keys.value()) { if (converters.containsKey(key)) { LOGGER.warn("Converter key '{}' is already mapped to '{}'. " + "Sorry, Dave, I can't let you do that! Ignoring plugin [{}].", key, converters.get(key), clazz); } else { converters.put(key, clazz); } } } } catch (final Exception ex) { LOGGER.error("Error processing plugin " + type.getElementName(), ex); } } converterRules = converters; }
/** * Constructor. */ protected AbstractConfiguration(final LoggerContext loggerContext, final ConfigurationSource configurationSource) { this.loggerContext = new WeakReference<>(loggerContext); // The loggerContext is null for the NullConfiguration class. // this.loggerContext = new WeakReference(Objects.requireNonNull(loggerContext, "loggerContext is null")); this.configurationSource = Objects.requireNonNull(configurationSource, "configurationSource is null"); componentMap.put(Configuration.CONTEXT_PROPERTIES, properties); pluginManager = new PluginManager(Node.CATEGORY); rootNode = new Node(); setState(State.INITIALIZING); }
/** * Returns the ConfigurationFactory. * @return the ConfigurationFactory. */ public static ConfigurationFactory getInstance() { // volatile works in Java 1.6+, so double-checked locking also works properly //noinspection DoubleCheckedLocking if (factories == null) { LOCK.lock(); try { if (factories == null) { final List<ConfigurationFactory> list = new ArrayList<>(); final String factoryClass = PropertiesUtil.getProperties().getStringProperty(CONFIGURATION_FACTORY_PROPERTY); if (factoryClass != null) { addFactory(list, factoryClass); } final PluginManager manager = new PluginManager(CATEGORY); manager.collectPlugins(); final Map<String, PluginType<?>> plugins = manager.getPlugins(); final List<Class<? extends ConfigurationFactory>> ordered = new ArrayList<>(plugins.size()); for (final PluginType<?> type : plugins.values()) { try { ordered.add(type.getPluginClass().asSubclass(ConfigurationFactory.class)); } catch (final Exception ex) { LOGGER.warn("Unable to add class {}", type.getPluginClass(), ex); } } Collections.sort(ordered, OrderComparator.getInstance()); for (final Class<? extends ConfigurationFactory> clazz : ordered) { addFactory(list, clazz); } // see above comments about double-checked locking //noinspection NonThreadSafeLazyInitialization factories = Collections.unmodifiableList(list); } } finally { LOCK.unlock(); } } LOGGER.debug("Using configurationFactory {}", configFactory); return configFactory; }
private TypeConverterRegistry() { LOGGER.trace("TypeConverterRegistry initializing."); final PluginManager manager = new PluginManager(TypeConverters.CATEGORY); manager.collectPlugins(); loadKnownTypeConverters(manager.getPlugins().values()); registerPrimitiveTypes(); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final PluginManager manager = new PluginManager("Test"); manager.collectPlugins(); plugin = (PluginType<ValidatingPlugin>) manager.getPluginType("Validator"); assertNotNull("Rebuild this module to make sure annotaion processing kicks in.", plugin); node = new Node(null, "Validator", plugin); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final PluginManager manager = new PluginManager("Test"); manager.collectPlugins(); plugin = (PluginType<ValidatingPluginWithGenericBuilder>) manager.getPluginType("ValidatingPluginWithGenericBuilder"); assertNotNull("Rebuild this module to make sure annotaion processing kicks in.", plugin); node = new Node(null, "Validator", plugin); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final PluginManager manager = new PluginManager("Test"); manager.collectPlugins(); plugin = (PluginType<ValidatingPluginWithTypedBuilder>) manager .getPluginType("ValidatingPluginWithTypedBuilder"); assertNotNull("Rebuild this module to make sure annotaion processing kicks in.", plugin); node = new Node(null, "Validator", plugin); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final PluginManager manager = new PluginManager("Test"); manager.collectPlugins(); plugin = (PluginType<HostAndPort>) manager.getPluginType("HostAndPort"); assertNotNull("Rebuild this module to ensure annotation processing has been done.", plugin); node = new Node(null, "HostAndPort", plugin); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final PluginManager manager = new PluginManager("Test"); manager.collectPlugins(); plugin = (PluginType<PluginWithGenericSubclassFoo1Builder>) manager.getPluginType("PluginWithGenericSubclassFoo1Builder"); assertNotNull("Rebuild this module to make sure annotaion processing kicks in.", plugin); node = new Node(null, "Validator", plugin); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { final PluginManager manager = new PluginManager("Test"); manager.collectPlugins(); plugin = (PluginType<HostAndPort>) manager.getPluginType("HostAndPort"); assertNotNull("Rebuild this module to ensure annotation processing has been done.", plugin); node = new Node(null, "HostAndPort", plugin); node.getAttributes().put("host", "localhost"); }
public PluginManager getPluginManager() { return pluginManager; }
public void setPluginManager(final PluginManager pluginManager) { this.pluginManager = pluginManager; }
@Override public PluginManager getPluginManager() { return pluginManager; }
@Test public void testPlugin(){ PluginManager pm = new PluginManager(PatternConverter.CATEGORY); pm.collectPlugins(); for(Entry<String, PluginType<?>> entry : pm.getPlugins().entrySet()){ logger.info("{} : {}", entry.getKey(), entry.getValue()); } logger.error("[testPlugin]", new IOException("io exception message...")); }
/** * Merge the soure node tree into the target node tree. * @param target The target Node tree. * @param source The source Node tree. */ void mergConfigurations(Node target, Node source, PluginManager pluginManager);