use of org.apache.logging.log4j.plugins.util.PluginType in project logging-log4j2 by apache.
the class AbstractConfiguration method initialize.
/**
* Initialize the configuration.
*/
@Override
public void initialize() {
LOGGER.debug(Version.getProductString() + " initializing configuration {}", this);
runtimeStrSubstitutor.setConfiguration(this);
configurationStrSubstitutor.setConfiguration(this);
try {
ServiceLoaderUtil.loadServices(ScriptManagerFactory.class, layer -> ServiceLoader.load(layer, ScriptManagerFactory.class), null).stream().findFirst().ifPresent(scriptManagerFactory -> scriptManager = scriptManagerFactory.createScriptManager(this, watchManager));
} catch (final LinkageError | Exception e) {
// LOG4J2-1920 ScriptEngineManager is not available in Android
LOGGER.info("Cannot initialize scripting support because this JRE does not support it.", e);
}
pluginManager.collectPlugins(pluginPackages);
final PluginManager levelPlugins = new PluginManager(Level.CATEGORY);
levelPlugins.collectPlugins(pluginPackages);
final Map<String, PluginType<?>> plugins = levelPlugins.getPlugins();
if (plugins != null) {
for (final PluginType<?> type : plugins.values()) {
try {
// Cause the class to be initialized if it isn't already.
Loader.initializeClass(type.getPluginClass().getName(), type.getPluginClass().getClassLoader());
} catch (final Exception e) {
LOGGER.error("Unable to initialize {} due to {}", type.getPluginClass().getName(), e.getClass().getSimpleName(), e);
}
}
}
setup();
setupAdvertisement();
doConfigure();
setState(State.INITIALIZED);
LOGGER.debug("Configuration {} initialized", this);
}
use of org.apache.logging.log4j.plugins.util.PluginType in project logging-log4j2 by apache.
the class ConfigurationFactory method getInstance.
/**
* Returns the ConfigurationFactory.
* @return the ConfigurationFactory.
*/
public static ConfigurationFactory getInstance() {
// noinspection DoubleCheckedLocking
if (factories == null) {
LOCK.lock();
try {
if (factories == null) {
final List<ConfigurationFactory> list = new ArrayList<>();
final PropertiesUtil props = PropertiesUtil.getProperties();
final String factoryClass = props.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);
authorizationProvider = authorizationProvider(props);
}
} finally {
LOCK.unlock();
}
}
LOGGER.debug("Using configurationFactory {}", configFactory);
return configFactory;
}
use of org.apache.logging.log4j.plugins.util.PluginType in project logging-log4j2 by apache.
the class TypeConverterRegistry method loadKnownTypeConverters.
private void loadKnownTypeConverters(final Collection<PluginType<?>> knownTypes) {
for (final PluginType<?> knownType : knownTypes) {
final Class<?> clazz = knownType.getPluginClass();
if (TypeConverter.class.isAssignableFrom(clazz)) {
@SuppressWarnings("rawtypes") final Class<? extends TypeConverter> pluginClass = clazz.asSubclass(TypeConverter.class);
final Type conversionType = getTypeConverterSupportedType(pluginClass);
final TypeConverter<?> converter = ReflectionUtil.instantiate(pluginClass);
registerConverter(conversionType, converter);
}
}
}
use of org.apache.logging.log4j.plugins.util.PluginType in project logging-log4j2 by apache.
the class PluginProcessorTest method testNestedPlugin.
@Test
public void testNestedPlugin() throws Exception {
final Plugin p = FakePlugin.Nested.class.getAnnotation(Plugin.class);
final List<PluginType<?>> list = pluginService.getCategory(p.category());
assertNotNull(list);
final PluginEntry nested = getEntry(list, p.name());
assertNotNull(nested);
assertEquals(p.name().toLowerCase(), nested.getKey());
assertEquals(FakePlugin.Nested.class.getName(), nested.getClassName());
assertEquals(p.name(), nested.getName());
assertEquals(Plugin.EMPTY, p.elementType());
assertEquals(p.printObject(), nested.isPrintable());
assertEquals(p.deferChildren(), nested.isDefer());
}
use of org.apache.logging.log4j.plugins.util.PluginType in project logging-log4j2 by apache.
the class DefaultMergeStrategy method updateFilterNode.
private void updateFilterNode(final Node target, final Node targetChildNode, final Node sourceChildNode, final PluginManager pluginManager) {
if (CompositeFilter.class.isAssignableFrom(targetChildNode.getType().getPluginClass())) {
final Node node = new Node(targetChildNode, sourceChildNode.getName(), sourceChildNode.getType());
node.getChildren().addAll(sourceChildNode.getChildren());
node.getAttributes().putAll(sourceChildNode.getAttributes());
targetChildNode.getChildren().add(node);
} else {
final PluginType pluginType = pluginManager.getPluginType(FILTERS);
final Node filtersNode = new Node(targetChildNode, FILTERS, pluginType);
final Node node = new Node(filtersNode, sourceChildNode.getName(), sourceChildNode.getType());
node.getAttributes().putAll(sourceChildNode.getAttributes());
final List<Node> children = filtersNode.getChildren();
children.add(targetChildNode);
children.add(node);
final List<Node> nodes = target.getChildren();
nodes.remove(targetChildNode);
nodes.add(filtersNode);
}
}
Aggregations