Class EnforceBytecodeVersion

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  EnforceBytecodeVersion.ChecksOptions
      Input is Dependency file, and it may have been inspected already, but, in multi-module environment the configuration may be different.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9
      Default ignores when validating against jdk < 9 because module-info.class will always have level 1.9.
      private java.util.List<java.lang.String> excludes
      Specify the excluded dependencies.
      private java.util.List<java.lang.String> ignorableClassesPatterns
      Internal: strings (regexp expressions) are collected here to ignore matched classes.
      private java.util.List<java.lang.String> ignoreClasses
      List of classes to fully ignore, interpreted as regular expression.
      private java.util.List<java.lang.String> ignoredScopes
      List of dependency scopes, to ignore dependencies in it.
      private boolean ignoreOptionals
      If set, will ignore optional dependencies of the project.
      private java.util.List<java.lang.String> includes
      Specify the included dependencies.
      private static java.util.Map<java.lang.String,​java.lang.Integer> JDK_TO_MAJOR_VERSION_NUMBER_MAPPING  
      private int maxJavaMajorVersionNumber
      If unsure, don't use that parameter.
      private int maxJavaMinorVersionNumber
      This parameter is here for potentially advanced use cases, but it seems like it is actually always 0.
      private java.lang.String maxJdkVersion
      JDK version as used for example in the maven-compiler-plugin: 8, 11 and so on.
      private java.lang.String message
      Custom message, optional.
      private static java.util.regex.Pattern MULTI_RELEASE  
      private boolean processOncePerSession
      Optimization to calculate same JAR with same options once per session, by default is enabled.
      private ResolverUtil resolverUtil  
      private java.util.List<java.lang.String> scopes
      List of dependency scopes, to include dependencies in it.
      private boolean searchTransitive
      If set, transitive hull of project is being processed, otherwise only direct dependencies.
      private org.apache.maven.execution.MavenSession session  
      private boolean strict
      Process module-info and Multi-Release JAR classes if true.
    • Field Detail

      • DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9

        private static final java.lang.String[] DEFAULT_CLASSES_IGNORE_BEFORE_JDK_9
        Default ignores when validating against jdk < 9 because module-info.class will always have level 1.9.
      • MULTI_RELEASE

        private static final java.util.regex.Pattern MULTI_RELEASE
      • JDK_TO_MAJOR_VERSION_NUMBER_MAPPING

        private static final java.util.Map<java.lang.String,​java.lang.Integer> JDK_TO_MAJOR_VERSION_NUMBER_MAPPING
      • message

        private java.lang.String message
        Custom message, optional. If configured, will be present on first line of the error message.
      • maxJavaMajorVersionNumber

        private int maxJavaMajorVersionNumber
        If unsure, don't use that parameter. Better look at maxJdkVersion. Mandatory if maxJdkVersion is not specified. see http://en.wikipedia.org/wiki/Java_class_file#General_layout
      • excludes

        private java.util.List<java.lang.String> excludes
        Specify the excluded dependencies. This can be a list of artifacts in the format groupId[:artifactId][:version]. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
      • includes

        private java.util.List<java.lang.String> includes
        Specify the included dependencies. This can be a list of artifacts in the format groupId[:artifactId][:version]. Any of the sections can be a wildcard by using '*' (ie group:*:1.0)
        Includes override the exclude rules. It is meant to allow wide exclusion rules with wildcards and still allow a smaller set of includes.
        For example, to ban all xerces except xerces-api -> exclude "xerces", include "xerces:xerces-api"
      • ignoreClasses

        private java.util.List<java.lang.String> ignoreClasses
        List of classes to fully ignore, interpreted as regular expression.
      • scopes

        private java.util.List<java.lang.String> scopes
        List of dependency scopes, to include dependencies in it. Default is to include all scopes.
      • ignoredScopes

        private java.util.List<java.lang.String> ignoredScopes
        List of dependency scopes, to ignore dependencies in it. Default is to not exclude any scope. Excluding scopes like ["test", "provided"] is usually right thing to do.
      • ignoreOptionals

        private boolean ignoreOptionals
        If set, will ignore optional dependencies of the project.
      • searchTransitive

        private boolean searchTransitive
        If set, transitive hull of project is being processed, otherwise only direct dependencies. Default is true.
      • strict

        private boolean strict
        Process module-info and Multi-Release JAR classes if true.
      • processOncePerSession

        private boolean processOncePerSession
        Optimization to calculate same JAR with same options once per session, by default is enabled.
      • ignorableClassesPatterns

        private final java.util.List<java.lang.String> ignorableClassesPatterns
        Internal: strings (regexp expressions) are collected here to ignore matched classes.
      • session

        private final org.apache.maven.execution.MavenSession session
    • Constructor Detail

      • EnforceBytecodeVersion

        @Inject
        EnforceBytecodeVersion​(org.apache.maven.execution.MavenSession session,
                               ResolverUtil resolverUtil)
    • Method Detail

      • renderVersion

        static java.lang.String renderVersion​(int major,
                                              int minor)
        Visible for testing.
      • decodeMajorVersion

        static java.lang.Integer decodeMajorVersion​(java.lang.String version)
        Visible for testing.
      • execute

        public void execute()
                     throws EnforcerRuleException
        Description copied from class: AbstractEnforcerRule
        This is the interface into the rule. This method should throw an exception containing a reason message if the rule fails the check. The plugin will then decide based on the fail flag and rule level if it should stop or just log the message as a warning.
        Specified by:
        execute in class AbstractEnforcerRule
        Throws:
        EnforcerRuleException - the enforcer rule exception
        EnforcerRuleError - in order to brake a build immediately
      • checkDependencies

        private java.util.List<org.eclipse.aether.graph.Dependency> checkDependencies​(java.util.List<org.eclipse.aether.graph.Dependency> dependencies)
                                                                               throws EnforcerRuleException
        Throws:
        EnforcerRuleException
      • asRegex

        private static java.lang.String asRegex​(java.lang.String wildcard)
        Convert a wildcard into a regex.
        Parameters:
        wildcard - the wildcard to convert.
        Returns:
        the equivalent regex.
      • dependencyGraphToList

        private java.util.List<org.eclipse.aether.graph.Dependency> dependencyGraphToList​(org.eclipse.aether.graph.DependencyNode root)
      • filterDependencies

        private java.util.List<org.eclipse.aether.graph.Dependency> filterDependencies​(java.util.List<org.eclipse.aether.graph.Dependency> dependencies)