Package de.thetaphi.forbiddenapis
Class Checker
java.lang.Object
de.thetaphi.forbiddenapis.Checker
- All Implemented Interfaces:
Constants,RelatedClassLookup
Forbidden APIs checker class.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final Map<String,ClassMetadata> Classes to check: key is the binary name (dotted)(package private) final Map<String,ClassMetadata> Cache of loaded classes: key is the binary name (dotted)(package private) final Signaturesfinal boolean(package private) final ClassLoader(package private) final Logger(package private) final Method(package private) final MethodRelated classes (binary name, dotted) which were not found while looking up class metadata [referenced (super)classes, interfaces,...](package private) final EnumSet<Checker.Option>private final NavigableSet<String>private final longdescriptors (not internal names) of all annotations that suppressFields 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
ConstructorsConstructorDescriptionChecker(Logger logger, ClassLoader loader, Checker.Option... options) Checker(Logger logger, ClassLoader loader, EnumSet<Checker.Option> options) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBundledSignatures(String name, String jdkTargetVersion) Reads a list of bundled API signatures from classpath.voidaddClassesToCheck(File... files) Parses and adds a multiple class files.voidaddClassesToCheck(File basedir, Iterable<String> relativeNames) Parses and adds a multiple class files.voidaddClassesToCheck(File basedir, String... relativeNames) Parses and adds a multiple class files.voidaddClassesToCheck(Iterable<File> files) Parses and adds a multiple class files.voidParses and adds a class from the given file to the list of classes to check.voidaddClassToCheck(InputStream in, String name) Deprecated.voidaddSuppressAnnotation(Class<? extends Annotation> anno) Adds the given annotation class for suppressing errors.voidaddSuppressAnnotation(String annoName) Adds suppressing annotation name in binary form (dotted).private CheckerResultcheckClass(ClassMetadata c, Pattern suppressAnnotationsPattern) Parses a class and checks for valid method invocationsgetClassFromClassLoader(String clazz) Reads a class (binary name) from the givenClassLoader.booleanReturns if there are any signatures.private booleanisRuntimeClass(URLConnection conn) private booleanisRuntimePath(URL url) private ClassMetadataloadClassFromJigsaw(String classname) Loads the class from Java9's module system and uses reflection to get methods and fields.lookupRelatedClass(String internalName, String internalNameOrig) booleanReturns if no signatures files / inline signatures were parsedvoidReads a list of API signatures from the given file.voidparseSignaturesFile(InputStream in, String name) Reads a list of API signatures.voidparseSignaturesFile(URL url) Reads a list of API signatures from the given URL.voidparseSignaturesString(String signatures) Reads a list of API signatures from a String.voidrun()voidsetSignaturesSeverity(Collection<String> signatures, ViolationSeverity severity) Adjusts the severity of a specific signature.voidstreamReadClassToCheck(InputStream in, String name) Parses and adds a class from the given stream to the list of classes to check.
-
Field Details
-
isSupportedJDK
public final boolean isSupportedJDK -
start
private final long start -
runtimePaths
-
logger
-
loader
-
method_Class_getModule
-
method_Module_getName
-
options
-
classesToCheck
Classes to check: key is the binary name (dotted) -
classpathClassCache
Cache of loaded classes: key is the binary name (dotted) -
missingClasses
Related classes (binary name, dotted) which were not found while looking up class metadata [referenced (super)classes, interfaces,...] -
forbiddenSignatures
-
suppressAnnotations
descriptors (not internal names) of all annotations that suppress
-
-
Constructor Details
-
Checker
-
Checker
-
-
Method Details
-
loadClassFromJigsaw
Loads the class from Java9's module system and uses reflection to get methods and fields.- Throws:
IOException
-
isRuntimePath
- Throws:
IOException
-
isRuntimeClass
- Throws:
IOException
-
getClassFromClassLoader
public ClassMetadata getClassFromClassLoader(String clazz) throws ClassNotFoundException, IOException Reads a class (binary name) from the givenClassLoader. If not found there, falls back to the list of classes to be checked.- Specified by:
getClassFromClassLoaderin interfaceRelatedClassLookup- Throws:
ClassNotFoundExceptionIOException
-
lookupRelatedClass
- Specified by:
lookupRelatedClassin interfaceRelatedClassLookup
-
addBundledSignatures
public void addBundledSignatures(String name, String jdkTargetVersion) throws IOException, ParseException Reads a list of bundled API signatures from classpath.- Throws:
IOExceptionParseException
-
parseSignaturesFile
Reads a list of API signatures. Closes the Reader when done (on Exception, too)!- Throws:
IOExceptionParseException
-
parseSignaturesFile
Reads a list of API signatures from the given URL.- Throws:
IOExceptionParseException
-
parseSignaturesFile
Reads a list of API signatures from the given file.- Throws:
IOExceptionParseException
-
parseSignaturesString
Reads a list of API signatures from a String.- Throws:
IOExceptionParseException
-
hasNoSignatures
public boolean hasNoSignatures()Returns if there are any signatures. -
noSignaturesFilesParsed
public boolean noSignaturesFilesParsed()Returns if no signatures files / inline signatures were parsed -
setSignaturesSeverity
public void setSignaturesSeverity(Collection<String> signatures, ViolationSeverity severity) throws ParseException, IOException Adjusts the severity of a specific signature.- Throws:
ParseExceptionIOException
-
streamReadClassToCheck
Parses and adds a class from the given stream to the list of classes to check. Does not log anything.- Throws:
IOException
-
addClassToCheck
Deprecated.Do not use anymore, usestreamReadClassToCheck(InputStream,String)Parses and adds a class from the given stream to the list of classes to check. Closes the stream when parsed (on Exception, too)! Does not log anything.- Throws:
IOException
-
addClassToCheck
Parses and adds a class from the given file to the list of classes to check. Does not log anything.- Throws:
IOException
-
addClassesToCheck
Parses and adds a multiple class files.- Throws:
IOException
-
addClassesToCheck
Parses and adds a multiple class files.- Throws:
IOException
-
addClassesToCheck
Parses and adds a multiple class files.- Throws:
IOException
-
addClassesToCheck
Parses and adds a multiple class files.- Throws:
IOException
-
addSuppressAnnotation
Adds the given annotation class for suppressing errors. -
addSuppressAnnotation
Adds suppressing annotation name in binary form (dotted). It may also be a glob pattern. The class name is not checked for existence. -
checkClass
private CheckerResult checkClass(ClassMetadata c, Pattern suppressAnnotationsPattern) throws ForbiddenApiException Parses a class and checks for valid method invocations- Throws:
ForbiddenApiException
-
run
- Throws:
ForbiddenApiException
-
runWithResults
- Throws:
ForbiddenApiException
-
streamReadClassToCheck(InputStream,String)