Class PluginProcessor

  • All Implemented Interfaces:
    javax.annotation.processing.Processor

    @SupportedAnnotationTypes("org.apache.logging.log4j.core.config.plugins.Plugin")
    @SupportedOptions("log4j.plugin.processor.minAllowedMessageKind")
    public class PluginProcessor
    extends javax.annotation.processing.AbstractProcessor
    Annotation processor for pre-scanning Log4j 2 plugins.
    • Constructor Summary

      Constructors 
      Constructor Description
      PluginProcessor()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void collectPlugins​(java.lang.Iterable<? extends javax.lang.model.element.Element> elements)  
      private static java.lang.String expectedFieldNameInASetter​(java.lang.String fieldName)
      Helper method to get the expected Method name in a field.
      javax.lang.model.SourceVersion getSupportedSourceVersion()  
      void init​(javax.annotation.processing.ProcessingEnvironment processingEnv)  
      private void printMessage​(javax.tools.Diagnostic.Kind kind, java.lang.String message)
      Prints a message via the Messager only if kind is at least as severe as the configured minimum allowed kind.
      private void printMessage​(javax.tools.Diagnostic.Kind kind, java.lang.String message, javax.lang.model.element.Element element)
      Prints a message via the Messager only if kind is at least as severe as the configured minimum allowed kind.
      boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations, javax.annotation.processing.RoundEnvironment roundEnv)  
      private void processBuilderAttribute​(java.lang.Iterable<? extends javax.lang.model.element.Element> elements)  
      private void processBuilderAttribute​(javax.lang.model.element.VariableElement element)  
      private void writeCacheFile​(javax.lang.model.element.Element... elements)  
      • Methods inherited from class javax.annotation.processing.AbstractProcessor

        getCompletions, getSupportedAnnotationTypes, getSupportedOptions, isInitialized
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_ELEMENT_ARRAY

        private static final javax.lang.model.element.Element[] EMPTY_ELEMENT_ARRAY
      • SUPPRESS_WARNING_PUBLIC_SETTER_STRING

        private static final java.lang.String SUPPRESS_WARNING_PUBLIC_SETTER_STRING
        See Also:
        Constant Field Values
      • MIN_ALLOWED_MESSAGE_KIND_OPTION

        static final java.lang.String MIN_ALLOWED_MESSAGE_KIND_OPTION
        Annotation processor option that controls the minimum Diagnostic.Kind of messages emitted by this processor.

        Some build environments (e.g. Maven with -Werror) treat compiler notes or warnings as errors. Setting this option to WARNING or ERROR suppresses informational notes emitted during normal processing.

        Accepted values (case-insensitive): NOTE, WARNING, MANDATORY_WARNING, ERROR, OTHER. Defaults to NOTE.

        See Also:
        Constant Field Values
      • PLUGIN_CACHE_FILE

        public static final java.lang.String PLUGIN_CACHE_FILE
        The location of the plugin cache data file. This file is written to by this processor, and read from by PluginManager.
        See Also:
        Constant Field Values
      • processedElements

        private final java.util.List<javax.lang.model.element.Element> processedElements
      • minAllowedMessageKind

        private javax.tools.Diagnostic.Kind minAllowedMessageKind
      • PLUGIN_BUILDER_ATTRIBUTE_ANNOTATION

        private static final java.lang.String PLUGIN_BUILDER_ATTRIBUTE_ANNOTATION
        See Also:
        Constant Field Values
    • Constructor Detail

      • PluginProcessor

        public PluginProcessor()
    • Method Detail

      • init

        public void init​(javax.annotation.processing.ProcessingEnvironment processingEnv)
        Specified by:
        init in interface javax.annotation.processing.Processor
        Overrides:
        init in class javax.annotation.processing.AbstractProcessor
      • getSupportedSourceVersion

        public javax.lang.model.SourceVersion getSupportedSourceVersion()
        Specified by:
        getSupportedSourceVersion in interface javax.annotation.processing.Processor
        Overrides:
        getSupportedSourceVersion in class javax.annotation.processing.AbstractProcessor
      • printMessage

        private void printMessage​(javax.tools.Diagnostic.Kind kind,
                                  java.lang.String message)
        Prints a message via the Messager only if kind is at least as severe as the configured minimum allowed kind.
      • printMessage

        private void printMessage​(javax.tools.Diagnostic.Kind kind,
                                  java.lang.String message,
                                  javax.lang.model.element.Element element)
        Prints a message via the Messager only if kind is at least as severe as the configured minimum allowed kind.
      • process

        public boolean process​(java.util.Set<? extends javax.lang.model.element.TypeElement> annotations,
                               javax.annotation.processing.RoundEnvironment roundEnv)
        Specified by:
        process in interface javax.annotation.processing.Processor
        Specified by:
        process in class javax.annotation.processing.AbstractProcessor
      • processBuilderAttribute

        private void processBuilderAttribute​(java.lang.Iterable<? extends javax.lang.model.element.Element> elements)
      • processBuilderAttribute

        private void processBuilderAttribute​(javax.lang.model.element.VariableElement element)
      • expectedFieldNameInASetter

        private static java.lang.String expectedFieldNameInASetter​(java.lang.String fieldName)
        Helper method to get the expected Method name in a field. For example if the field name is 'isopen', then the expected setter would be 'setOpen' or 'withOpen' This method is supposed to return the capitalized 'Open', fieldName which is expected in the setter.
        Parameters:
        fieldName - who's setter we are checking.
        Returns:
        The expected fieldName that will come after withxxxx or setxxxx
      • collectPlugins

        private void collectPlugins​(java.lang.Iterable<? extends javax.lang.model.element.Element> elements)
      • writeCacheFile

        private void writeCacheFile​(javax.lang.model.element.Element... elements)
                             throws java.io.IOException
        Throws:
        java.io.IOException