Package de.thetaphi.forbiddenapis.ant
Class AntTask
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
de.thetaphi.forbiddenapis.ant.AntTask
Task to check if a set of class files contains calls to forbidden APIs
from a given classpath and list of API signatures (either inline or as pointer to files).
In contrast to other ANT tasks, this tool does only visit the given classpath
and the system classloader, not ANT's class loader.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.tools.ant.types.resources.Unionprivate final Collection<BundledSignaturesType>private final org.apache.tools.ant.types.resources.Unionprivate org.apache.tools.ant.types.Pathprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate final Collection<SeverityOverrideType>private final Collection<SuppressAnnotationType>private StringFields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, projectFields 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_INTERNALNAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(org.apache.tools.ant.types.ResourceCollection rc) Set of class files to checkprivate <T extends org.apache.tools.ant.ProjectComponent & org.apache.tools.ant.types.ResourceCollection>
TaddSignaturesResource(T res) voidSupport for API signatures list as nested textCreates a bundled signatures instanceorg.apache.tools.ant.types.PathClasspath asnested element Adds an override for forbidden API signatures for which violations should not be reported at all (i.e.Collection of arbitrary Ant resources or<bundled/>elements.org.apache.tools.ant.types.resources.FileResourceSingle file with API signatures asnested element org.apache.tools.ant.types.FileListList of files with API signatures asnested element org.apache.tools.ant.types.FileSetSet of files with API signatures asnested element Creates a instance of an annotation class name that suppresses error reporting in classes/methods/fields.voidexecute()voidsetBundledSignatures(String name) A bundled signatures namevoidsetClasspath(org.apache.tools.ant.types.Path classpath) Classpath as classpath= attributevoidsetClasspathRef(org.apache.tools.ant.types.Reference r) Classpath as classpathRef= attributevoidSets a directory as base for class files.voidsetDisableClassloadingCache(boolean disableClassloadingCache) Disable the internal JVM classloading cache when getting bytecode from the classpath.voidsetFailOnMissingClasses(boolean failOnMissingClasses) Fail the build, if a referenced class is missing.voidsetFailOnUnresolvableSignatures(boolean failOnUnresolvableSignatures) Deprecated.voidsetFailOnUnsupportedJava(boolean failOnUnsupportedJava) Fail the build, if the bundled ASM library cannot read the class file format of the runtime library or the runtime library cannot be discovered.voidsetFailOnViolation(boolean failOnViolation) Fail the build if violations have been found.voidsetIgnoreEmptyFileSet(boolean ignoreEmptyFileset) Ignore empty fileset/resource collection.voidsetIgnoreSignaturesOfMissingClasses(boolean ignoreSignaturesOfMissingClasses) If a class is missing while parsing signatures files, all methods and fields from this class are silently ignored.voidsetRestrictClassFilename(boolean restrictClassFilename) Automatically restrict resource names included to files with a name ending in '.class'.voidsetSignaturesFile(File file) A file with API signatures signaturesFile= attributevoidsetSuppressAnnotation(String classname) Class name of annotation that suppresses error reporting in classes/methods/fields.voidsetTargetVersion(String targetVersion) The default compiler target version used to expand references to bundled JDK signatures.Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Field Details
-
classFiles
private final org.apache.tools.ant.types.resources.Union classFiles -
apiSignatures
private final org.apache.tools.ant.types.resources.Union apiSignatures -
bundledSignatures
-
suppressAnnotations
-
severityOverrides
-
classpath
private org.apache.tools.ant.types.Path classpath -
failOnUnsupportedJava
private boolean failOnUnsupportedJava -
restrictClassFilename
private boolean restrictClassFilename -
failOnMissingClasses
private boolean failOnMissingClasses -
failOnUnresolvableSignatures
private boolean failOnUnresolvableSignatures -
ignoreSignaturesOfMissingClasses
private boolean ignoreSignaturesOfMissingClasses -
failOnViolation
private boolean failOnViolation -
ignoreEmptyFileset
private boolean ignoreEmptyFileset -
targetVersion
-
disableClassloadingCache
private boolean disableClassloadingCache
-
-
Constructor Details
-
AntTask
public AntTask()
-
-
Method Details
-
execute
public void execute() throws org.apache.tools.ant.BuildException- Overrides:
executein classorg.apache.tools.ant.Task- Throws:
org.apache.tools.ant.BuildException
-
add
public void add(org.apache.tools.ant.types.ResourceCollection rc) Set of class files to check -
setDir
Sets a directory as base for class files. The implicit pattern '**/*.class' is used to only scan class files. -
addSignaturesResource
private <T extends org.apache.tools.ant.ProjectComponent & org.apache.tools.ant.types.ResourceCollection> T addSignaturesResource(T res) -
createSignaturesFileSet
public org.apache.tools.ant.types.FileSet createSignaturesFileSet()Set of files with API signatures asnested element -
createSignaturesFileList
public org.apache.tools.ant.types.FileList createSignaturesFileList()List of files with API signatures asnested element -
createSignaturesFile
public org.apache.tools.ant.types.resources.FileResource createSignaturesFile()Single file with API signatures asnested element -
createSignatures
Collection of arbitrary Ant resources or<bundled/>elements. -
setSignaturesFile
A file with API signatures signaturesFile= attribute -
addText
Support for API signatures list as nested text -
createBundledSignatures
Creates a bundled signatures instance -
setBundledSignatures
A bundled signatures name -
createSeverityOverride
Adds an override for forbidden API signatures for which violations should not be reported at all (i.e. neither fail the build nor appear in the logs). Each signature must be listed in a separate XML element (in text) and apriorityattribute. This takes precedence overfailOnViolation. In order to be effective the signature must be given in one of the signatures elements (e.g., it can be used to disable a bundled signature which is not yet ready to be enforced).- Since:
- 3.9
-
createSuppressAnnotation
Creates a instance of an annotation class name that suppresses error reporting in classes/methods/fields. -
setSuppressAnnotation
Class name of annotation that suppresses error reporting in classes/methods/fields. -
setClasspath
public void setClasspath(org.apache.tools.ant.types.Path classpath) Classpath as classpath= attribute -
setClasspathRef
public void setClasspathRef(org.apache.tools.ant.types.Reference r) Classpath as classpathRef= attribute -
createClasspath
public org.apache.tools.ant.types.Path createClasspath()Classpath asnested element -
setFailOnUnsupportedJava
public void setFailOnUnsupportedJava(boolean failOnUnsupportedJava) Fail the build, if the bundled ASM library cannot read the class file format of the runtime library or the runtime library cannot be discovered. Defaults tofalse. -
setFailOnMissingClasses
public void setFailOnMissingClasses(boolean failOnMissingClasses) Fail the build, if a referenced class is missing. This requires that you pass the whole classpath including all dependencies. If you don't have all classes in the filesets, the application classes must be reachable through this classpath, too. Defaults totrue. -
setFailOnUnresolvableSignatures
Deprecated.UsesetIgnoreSignaturesOfMissingClasses(boolean)instead.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
#setIgnoreMissingSignaturesClasses()that 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 builds where a common set of signatures is used, that are not part of every sub-modules dependencies.- See Also:
-
#setIgnoreMissingSignaturesClasses()
-
setIgnoreSignaturesOfMissingClasses
public void setIgnoreSignaturesOfMissingClasses(boolean ignoreSignaturesOfMissingClasses) If a class is missing while parsing signatures files, all methods and fields from this class are silently ignored. This is useful in multi-module 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
-
setRestrictClassFilename
public void setRestrictClassFilename(boolean restrictClassFilename) Automatically restrict resource names included to files with a name ending in '.class'. This makes filesets easier, as the includes="**/*.class" is not needed. Defaults totrue. -
setIgnoreEmptyFileSet
public void setIgnoreEmptyFileSet(boolean ignoreEmptyFileset) Ignore empty fileset/resource collection. Defaults tofalse. -
setFailOnViolation
public void setFailOnViolation(boolean failOnViolation) Fail the build if violations have been found. If this parameter is set tofalse, then the build will continue even if violations have been found. Defaults totrue. -
setTargetVersion
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 task. Defaults tonull.- Since:
- 2.1
-
setDisableClassloadingCache
public void setDisableClassloadingCache(boolean disableClassloadingCache) Disable the internal JVM classloading cache when getting bytecode from the classpath. This setting slows down checks, but may work around issues with other tasks, 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. The default isfalse.- Since:
- 2.2
-
setIgnoreSignaturesOfMissingClasses(boolean)instead.