Class EnforceBytecodeVersion
- java.lang.Object
-
- org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
-
- org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
-
- org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule
-
- org.apache.maven.enforcer.rules.dependency.EnforceBytecodeVersion
-
- All Implemented Interfaces:
EnforcerRuleBase
@Priority(10) @Named("enforceBytecodeVersion") public class EnforceBytecodeVersion extends AbstractStandardEnforcerRuleEnforcer rule that will check the bytecode version of each class of each dependency.- Since:
- 3.6.3
- See Also:
- Java class file general layout
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classEnforceBytecodeVersion.ChecksOptionsInput 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_9Default ignores when validating against jdk < 9 becausemodule-info.classwill always have level 1.9.private java.util.List<java.lang.String>excludesSpecify the excluded dependencies.private java.util.List<java.lang.String>ignorableClassesPatternsInternal: strings (regexp expressions) are collected here to ignore matched classes.private java.util.List<java.lang.String>ignoreClassesList of classes to fully ignore, interpreted as regular expression.private java.util.List<java.lang.String>ignoredScopesList of dependency scopes, to ignore dependencies in it.private booleanignoreOptionalsIf set, will ignore optional dependencies of the project.private java.util.List<java.lang.String>includesSpecify the included dependencies.private static java.util.Map<java.lang.String,java.lang.Integer>JDK_TO_MAJOR_VERSION_NUMBER_MAPPINGprivate intmaxJavaMajorVersionNumberIf unsure, don't use that parameter.private intmaxJavaMinorVersionNumberThis parameter is here for potentially advanced use cases, but it seems like it is actually always 0.private java.lang.StringmaxJdkVersionJDK version as used for example in the maven-compiler-plugin: 8, 11 and so on.private java.lang.StringmessageCustom message, optional.private static java.util.regex.PatternMULTI_RELEASEprivate booleanprocessOncePerSessionOptimization to calculate same JAR with same options once per session, by default is enabled.private ResolverUtilresolverUtilprivate java.util.List<java.lang.String>scopesList of dependency scopes, to include dependencies in it.private booleansearchTransitiveIf set, transitive hull of project is being processed, otherwise only direct dependencies.private org.apache.maven.execution.MavenSessionsessionprivate booleanstrictProcess module-info and Multi-Release JAR classes iftrue.
-
Constructor Summary
Constructors Constructor Description EnforceBytecodeVersion(org.apache.maven.execution.MavenSession session, ResolverUtil resolverUtil)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringasRegex(java.lang.String wildcard)Convert a wildcard into a regex.private java.util.List<org.eclipse.aether.graph.Dependency>checkDependencies(java.util.List<org.eclipse.aether.graph.Dependency> dependencies)(package private) static java.lang.IntegerdecodeMajorVersion(java.lang.String version)Visible for testing.private java.util.List<org.eclipse.aether.graph.Dependency>dependencyGraphToList(org.eclipse.aether.graph.DependencyNode root)voidexecute()This is the interface into the rule.private java.util.List<org.eclipse.aether.graph.Dependency>filterDependencies(java.util.List<org.eclipse.aether.graph.Dependency> dependencies)private java.lang.StringisBadDependency(org.eclipse.aether.graph.Dependency d)private static java.lang.StringperformCheck(EnforcerLogger log, EnforceBytecodeVersion.ChecksOptions options)(package private) static java.lang.StringrenderVersion(int major, int minor)Visible for testing.private voidvalidateAndPopulateParameters()-
Methods inherited from class org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule
formatLocation, getMessage, setMessage
-
Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
getCacheId, getLevel, getRuleName
-
Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
getLog, setLog
-
-
-
-
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 becausemodule-info.classwill 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.
-
maxJdkVersion
private java.lang.String maxJdkVersion
JDK version as used for example in the maven-compiler-plugin: 8, 11 and so on. If in need of more precise configuration please seemaxJavaMajorVersionNumberandmaxJavaMinorVersionNumberMandatory ifmaxJavaMajorVersionNumbernot specified.
-
maxJavaMajorVersionNumber
private int maxJavaMajorVersionNumber
If unsure, don't use that parameter. Better look atmaxJdkVersion. Mandatory ifmaxJdkVersionis not specified. see http://en.wikipedia.org/wiki/Java_class_file#General_layout
-
maxJavaMinorVersionNumber
private int maxJavaMinorVersionNumber
This parameter is here for potentially advanced use cases, but it seems like it is actually always 0.
-
excludes
private java.util.List<java.lang.String> excludes
Specify the excluded dependencies. This can be a list of artifacts in the formatgroupId[: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 formatgroupId[: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 istrue.
-
strict
private boolean strict
Process module-info and Multi-Release JAR classes iftrue.
-
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
-
resolverUtil
private final ResolverUtil resolverUtil
-
-
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 EnforcerRuleExceptionDescription copied from class:AbstractEnforcerRuleThis 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:
executein classAbstractEnforcerRule- Throws:
EnforcerRuleException- the enforcer rule exceptionEnforcerRuleError- in order to brake a build immediately
-
validateAndPopulateParameters
private void validateAndPopulateParameters() throws EnforcerRuleException- Throws:
EnforcerRuleException
-
checkDependencies
private java.util.List<org.eclipse.aether.graph.Dependency> checkDependencies(java.util.List<org.eclipse.aether.graph.Dependency> dependencies) throws EnforcerRuleException- Throws:
EnforcerRuleException
-
isBadDependency
private java.lang.String isBadDependency(org.eclipse.aether.graph.Dependency d) 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.
-
performCheck
private static java.lang.String performCheck(EnforcerLogger log, EnforceBytecodeVersion.ChecksOptions options) throws EnforcerRuleException
- Throws:
EnforcerRuleException
-
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)
-
-