Search in sources :

Example 6 with PluginEntry

use of org.apache.logging.log4j.plugins.processor.PluginEntry in project logging-log4j2 by apache.

the class PluginProcessor method collectPlugins.

private String collectPlugins(String packageName, final Iterable<? extends Element> elements, List<PluginEntry> list) {
    boolean calculatePackage = packageName == null;
    final Elements elementUtils = processingEnv.getElementUtils();
    final ElementVisitor<PluginEntry, Plugin> pluginVisitor = new PluginElementVisitor(elementUtils);
    final ElementVisitor<Collection<PluginEntry>, Plugin> pluginAliasesVisitor = new PluginAliasesElementVisitor(elementUtils);
    for (final Element element : elements) {
        final Plugin plugin = element.getAnnotation(Plugin.class);
        if (plugin == null) {
            continue;
        }
        final PluginEntry entry = element.accept(pluginVisitor, plugin);
        list.add(entry);
        if (calculatePackage) {
            packageName = calculatePackage(elementUtils, element, packageName);
        }
        final Collection<PluginEntry> entries = element.accept(pluginAliasesVisitor, plugin);
        for (final PluginEntry pluginEntry : entries) {
            list.add(pluginEntry);
        }
    }
    return packageName;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PluginEntry(org.apache.logging.log4j.plugins.processor.PluginEntry) Collection(java.util.Collection) Elements(javax.lang.model.util.Elements) Plugin(org.apache.logging.log4j.plugins.Plugin)

Example 7 with PluginEntry

use of org.apache.logging.log4j.plugins.processor.PluginEntry 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());
}
Also used : PluginEntry(org.apache.logging.log4j.plugins.processor.PluginEntry) FakePlugin(org.apache.logging.log4j.plugins.test.validation.FakePlugin) PluginType(org.apache.logging.log4j.plugins.util.PluginType) FakePlugin(org.apache.logging.log4j.plugins.test.validation.FakePlugin) Plugin(org.apache.logging.log4j.plugins.Plugin) Test(org.junit.Test)

Example 8 with PluginEntry

use of org.apache.logging.log4j.plugins.processor.PluginEntry in project logging-log4j2 by apache.

the class PluginProcessorTest method testFakePluginAliasesContainSameInformation.

@Test
public void testFakePluginAliasesContainSameInformation() throws Exception {
    final PluginAliases aliases = FakePlugin.class.getAnnotation(PluginAliases.class);
    for (final String alias : aliases.value()) {
        final List<PluginType<?>> list = pluginService.getCategory(p.category());
        assertNotNull(list);
        final PluginEntry fake = getEntry(list, alias);
        assertNotNull(fake);
        verifyFakePluginEntry(alias, fake);
    }
}
Also used : PluginAliases(org.apache.logging.log4j.plugins.PluginAliases) PluginEntry(org.apache.logging.log4j.plugins.processor.PluginEntry) PluginType(org.apache.logging.log4j.plugins.util.PluginType) Test(org.junit.Test)

Example 9 with PluginEntry

use of org.apache.logging.log4j.plugins.processor.PluginEntry in project logging-log4j2 by apache.

the class PluginProcessorTest method testFakePluginFoundWithCorrectInformation.

@Test
public void testFakePluginFoundWithCorrectInformation() throws Exception {
    final List<PluginType<?>> list = pluginService.getCategory(p.category());
    assertNotNull(list);
    final PluginEntry fake = getEntry(list, p.name());
    assertNotNull(fake);
    verifyFakePluginEntry(p.name(), fake);
}
Also used : PluginEntry(org.apache.logging.log4j.plugins.processor.PluginEntry) PluginType(org.apache.logging.log4j.plugins.util.PluginType) Test(org.junit.Test)

Aggregations

PluginEntry (org.apache.logging.log4j.plugins.processor.PluginEntry)9 DecimalFormat (java.text.DecimalFormat)3 ArrayList (java.util.ArrayList)3 Plugin (org.apache.logging.log4j.plugins.Plugin)3 PluginType (org.apache.logging.log4j.plugins.util.PluginType)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PluginAliases (org.apache.logging.log4j.plugins.PluginAliases)2 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 Collection (java.util.Collection)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Messager (javax.annotation.processing.Messager)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1