use of org.apache.logging.log4j.plugins.util.PluginManager 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.PluginManager 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.PluginManager in project logging-log4j2 by apache.
the class ValidPortValidatorTest method setUp.
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<HostAndPort>) manager.getPluginType("HostAndPort");
assertNotNull(plugin, "Rebuild this module to ensure annotation processing has been done.");
node = new Node(null, "HostAndPort", plugin);
node.getAttributes().put("host", "localhost");
}
use of org.apache.logging.log4j.plugins.util.PluginManager in project logging-log4j2 by apache.
the class ValidatingPluginWithGenericSubclassFoo1BuilderTest method setUp.
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager("Test");
manager.collectPlugins();
plugin = (PluginType<PluginWithGenericSubclassFoo1Builder>) manager.getPluginType("PluginWithGenericSubclassFoo1Builder");
assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
node = new Node(null, "Validator", plugin);
}
use of org.apache.logging.log4j.plugins.util.PluginManager in project logging-log4j2 by apache.
the class ValidatingPluginWithFailoverTest method setUp.
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
final PluginManager manager = new PluginManager(Core.CATEGORY_NAME);
manager.collectPlugins();
plugin = (PluginType<FailoverAppender>) manager.getPluginType("failover");
assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
AppenderRef appenderRef = AppenderRef.createAppenderRef("List", Level.ALL, null);
node = new Node(null, "failover", plugin);
Node failoversNode = new Node(node, "Failovers", manager.getPluginType("Failovers"));
Node appenderRefNode = new Node(failoversNode, "appenderRef", manager.getPluginType("appenderRef"));
appenderRefNode.getAttributes().put("ref", "file");
appenderRefNode.setObject(appenderRef);
failoversNode.getChildren().add(appenderRefNode);
failoversNode.setObject(FailoversPlugin.createFailovers(appenderRef));
node.getAttributes().put("primary", "CONSOLE");
node.getAttributes().put("name", "Failover");
node.getChildren().add(failoversNode);
}
Aggregations