Package de.thetaphi.forbiddenapis.maven
Class AbstractCheckMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
de.thetaphi.forbiddenapis.maven.AbstractCheckMojo
- All Implemented Interfaces:
Constants,org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
CheckMojo,TestCheckMojo
public abstract class AbstractCheckMojo
extends org.apache.maven.plugin.AbstractMojo
implements Constants
Base class for forbiddenapis Mojos.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]Specifies built-in signatures files (e.g., deprecated APIs for specific Java versions, unsafe method calls using default locale, default charset,...)private booleanDisable the internal JVM classloading cache when getting bytecode from the classpath.private String[]List of Ant patterns.private booleanFail the build, if a class referenced in the scanned code is missing.private booleanDeprecated.private booleanFail the build, if the bundled ASM library cannot read the class file format of the runtime library or the runtime library cannot be discovered.private booleanFail the build if violations have been found.private booleanIf a class is missing while parsing signatures files, all methods and fields from this class are silently ignored.private String[]List of Ant patterns which must match all relative class paths to be considered.private StringThe project packaging (pom, jar, etc.).private List<org.eclipse.aether.repository.RemoteRepository>private StringThe default compiler release version used to expand references to bundled JDK signatures.private org.eclipse.aether.RepositorySystemSessionprivate org.eclipse.aether.RepositorySystemprivate StringGives a multiline list of signatures, inline in the pom.xml.private SignaturesArtifact[]Lists all Maven artifacts, which contain signatures and comments for forbidden API calls.private File[]Lists all files, which contain signatures and comments for forbidden API calls.private String[]Specifies a list of forbidden API signatures for which violations should not be reported at all (i.e.private String[]Specifies a list of forbidden API signatures for which violations should lead to a warning only (i.e.private booleanSkip entire check.private String[]List of a custom Java annotations (full class names) that are used in the checked code to suppress errors.private StringThe default compiler target version used to expand references to bundled JDK signatures.Fields inherited from interface de.thetaphi.forbiddenapis.Constants
BS_JDK_NONPORTABLE, CLASS_CONSTRUCTOR_METHOD_NAME, CONSTRUCTOR_METHOD_NAME, DEPRECATED_DESCRIPTOR, DEPRECATED_TYPE, DEPRECATED_WARN_FAIL_ON_UNRESOLVABLE_SIGNATURES, ENDS_WITH_VERSION_PATTERN, JDK_SIG_PATTERN, LAMBDA_META_FACTORY_INTERNALNAME, LAMBDA_METHOD_NAME_PREFIX, SIGNATURE_POLYMORPHIC_DESCRIPTOR, SIGNATURE_POLYMORPHIC_PKG_INTERNALNAMEFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate URLcreateJarUrl(File f, String jarPath) private StringencodeUrlPath(String path) voidexecute()protected abstract Fileprovided by the concrete Mojos for compile and test classes processingprovided by the concrete Mojos for compile and test classes processingprotected Stringgets overridden for test, because it uses testTargetVersion as optional name to overrideprivate FileresolveSignaturesArtifact(SignaturesArtifact signaturesArtifact) Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
signaturesFiles
Lists all files, which contain signatures and comments for forbidden API calls. The signatures are resolved against the compile classpath.- Since:
- 1.0
-
signaturesArtifacts
Lists all Maven artifacts, which contain signatures and comments for forbidden API calls. The artifact needs to be specified like a Maven dependency. Resolution is not transitive. You can refer to plain text Maven artifacts (type="txt", e.g., with a separateclassifier):<signaturesArtifact> <groupId>org.apache.foobar</groupId> <artifactId>example</artifactId> <version>1.0</version> <classifier>signatures</classifier> <type>txt</type> </signaturesArtifact>
Alternatively, refer to signatures files inside JAR artifacts. In that case, the additional parameterpathhas to be given:<signaturesArtifact> <groupId>org.apache.foobar</groupId> <artifactId>example</artifactId> <version>1.0</version> <type>jar</type> <path>path/inside/jar/file/signatures.txt</path> </signaturesArtifact>
The signatures are resolved against the compile classpath.
- Since:
- 2.0
-
signatures
Gives a multiline list of signatures, inline in the pom.xml. Use an XML CDATA section to do that! The signatures are resolved against the compile classpath.- Since:
- 1.0
-
bundledSignatures
Specifies built-in signatures files (e.g., deprecated APIs for specific Java versions, unsafe method calls using default locale, default charset,...)- Since:
- 1.0
-
signaturesWithSeverityWarn
Specifies a list of forbidden API signatures for which violations should lead to a warning only (i.e. not fail the build). This takes precedence overfailOnViolation. In order to be effective the signature must be given in eitherbundledSignatures,signaturesFiles,signaturesArtifacts, orsignatures.- Since:
- 3.9
-
signaturesWithSeveritySuppress
Specifies a list of forbidden API signatures for which violations should not be reported at all (i.e. neither fail the build nor appear in the logs). This takes precedence overfailOnViolationandsignaturesWithSeverityWarn. In order to be effective the signature must be given in eitherbundledSignatures,signaturesFiles,signaturesArtifacts, orsignatures.- Since:
- 3.9
-
failOnUnsupportedJava
@Parameter(required=false, defaultValue="false") private boolean failOnUnsupportedJavaFail the build, if the bundled ASM library cannot read the class file format of the runtime library or the runtime library cannot be discovered.- Since:
- 1.0
-
failOnMissingClasses
@Parameter(required=false, defaultValue="true") private boolean failOnMissingClassesFail the build, if a class referenced in the scanned code is missing. This requires that you pass the whole classpath including all dependencies to this Mojo (Maven does this by default).- Since:
- 1.0
-
failOnUnresolvableSignatures
@Deprecated @Parameter(required=false, defaultValue="true") private boolean failOnUnresolvableSignaturesDeprecated.The settingfailOnUnresolvableSignatureswas deprecated and will be removed in next version. UseignoreSignaturesOfMissingClassesinstead.Fail the build if a signature is not resolving. If this parameter is set to to false, then such signatures are ignored. Defaults totrue.When disabling this setting, the task still prints a warning to inform the user about broken signatures. This cannot be disabled. There is a second setting
ignoreSignaturesOfMissingClassesthat can be used to silently ignore signatures that refer to methods or field in classes that are not on classpath, e.g. This is useful in multi-module Maven builds where a common set of signatures is used, that are not part of every sub-modules dependencies.- Since:
- 1.4
- See Also:
-
ignoreSignaturesOfMissingClasses
@Parameter(required=false, defaultValue="false") private boolean ignoreSignaturesOfMissingClassesIf a class is missing while parsing signatures files, all methods and fields from this class are silently ignored. This is useful in multi-module Maven projects where only some modules have the dependency to which the signature file(s) apply. This settings prints no warning at all, so verify the signatures at least once with full dependencies. Defaults tofalse.- Since:
- 3.0
-
failOnViolation
@Parameter(required=false, property="forbiddenapis.failOnViolation", defaultValue="true") private boolean failOnViolationFail the build if violations have been found. Defaults totrue.- Since:
- 2.0
-
disableClassloadingCache
@Parameter(required=false, defaultValue="false") private boolean disableClassloadingCacheDisable the internal JVM classloading cache when getting bytecode from the classpath. This setting slows down checks, but may work around issues with other Mojos, that do not close their class loaders. If you getFileNotFoundExceptions related to non-existent JAR entries you can try to work around using this setting.- Since:
- 2.2
-
targetVersion
The default compiler target version used to expand references to bundled JDK signatures. E.g., if you use "jdk-deprecated", it will expand to this version. This setting should be identical to the target version used in the compiler plugin.- Since:
- 1.0
-
releaseVersion
The default compiler release version used to expand references to bundled JDK signatures. E.g., if you use "jdk-deprecated", it will expand to this version. This setting should be identical to the release version used in the compiler plugin starting with Java 9. If given, this setting is used in preference totargetVersion.- Since:
- 3.1
-
includes
List of Ant patterns which must match all relative class paths to be considered. All relative class paths matching one or more of the given patterns and not matching any of the ones fromexcludesare considered. The given paths are relative toclassesDirectory. Can be changed to e.g. exclude several files (usingexcludes). The default is a single include with pattern**/*.class.- Since:
- 1.0
- See Also:
-
excludes
List of Ant patterns. All relative class paths matching one or more of the given patterns are skipped. The given paths are relative toclassesDirectory.- Since:
- 1.0
- See Also:
-
suppressAnnotations
List of a custom Java annotations (full class names) that are used in the checked code to suppress errors. Those annotations must have at leastRetentionPolicy.CLASS. They can be applied to classes, their methods, or fields. By default,@de.thetaphi.forbiddenapis.SuppressForbiddencan always be used, but needs theforbidden-apis.jarfile in classpath of compiled project, which may not be wanted. Instead of a full class name, a glob pattern may be used (e.g.,**.SuppressForbidden).- Since:
- 1.8
-
skip
@Parameter(required=false, property="forbiddenapis.skip", defaultValue="false") private boolean skipSkip entire check. Most useful on the command line via "-Dforbiddenapis.skip=true".- Since:
- 1.6
-
packaging
@Parameter(defaultValue="${project.packaging}", readonly=true, required=true) private String packagingThe project packaging (pom, jar, etc.). -
repoSystem
@Component private org.eclipse.aether.RepositorySystem repoSystem -
repoSession
@Parameter(defaultValue="${repositorySystemSession}", readonly=true, required=true) private org.eclipse.aether.RepositorySystemSession repoSession -
projectRepos
@Parameter(defaultValue="${project.remoteProjectRepositories}", readonly=true, required=true) private List<org.eclipse.aether.repository.RemoteRepository> projectRepos
-
-
Constructor Details
-
AbstractCheckMojo
public AbstractCheckMojo()
-
-
Method Details
-
getClassPathElements
provided by the concrete Mojos for compile and test classes processing -
getClassesDirectory
provided by the concrete Mojos for compile and test classes processing -
getTargetVersion
gets overridden for test, because it uses testTargetVersion as optional name to override -
resolveSignaturesArtifact
private File resolveSignaturesArtifact(SignaturesArtifact signaturesArtifact) throws org.eclipse.aether.resolution.ArtifactResolutionException - Throws:
org.eclipse.aether.resolution.ArtifactResolutionException
-
encodeUrlPath
-
createJarUrl
- Throws:
MalformedURLException
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException- Specified by:
executein interfaceorg.apache.maven.plugin.Mojo- Throws:
org.apache.maven.plugin.MojoExecutionException
-
failOnUnresolvableSignatureswas deprecated and will be removed in next version.