Package de.thetaphi.forbiddenapis
Class Signatures
java.lang.Object
de.thetaphi.forbiddenapis.Signatures
- All Implemented Interfaces:
Constants
Utility class that is used to get an overview of all fields and implemented
methods of a class. It make the signatures available as Sets.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final NavigableSet<String>(package private) final Set<ClassPatternRule>set of patterns of forbidden classesprivate static final Stringprivate final booleanprivate booleandetermines default severity for violations if no severity on signature level is overridden.private booleanif enabled, the bundled signature to enable heuristics for detection of non-portable runtime calls is usedprivate static final Stringprivate static final Stringprivate final booleanprivate final Loggerprivate final RelatedClassLookupprivate intnumber of files that were interpreted as signatures file.private static final Pattern(package private) final Map<Pattern,ViolationSeverity> (package private) final Map<String,ViolationSeverity> Key is used to lookup forbidden signature in following formats.Key is used to lookup forbidden signature in following formats.private static final StringFields 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
ConstructorsConstructorDescriptionSignatures(Checker checker) Signatures(RelatedClassLookup lookup, Logger logger, boolean ignoreSignaturesOfMissingClasses, boolean failOnUnresolvableSignatures, boolean failOnViolation) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBundledSignatures(String name, String jdkTargetVersion) Reads a list of bundled API signatures from classpath.private voidaddBundledSignatures(String name, String jdkTargetVersion, boolean readExternal, Set<String> missingClasses) private voidaddSignature(String line, String defaultMessage, Signatures.UnresolvableReporting report, boolean localIgnoreMissingClasses, Set<String> missingClasses) Adds the method signature to the list of disallowed methods.booleancheckField(Reporter reporter, String internalClassName, String field) booleancheckMethod(Reporter reporter, String internalClassName, org.objectweb.asm.commons.Method method) booleanbooleanstatic StringfixTargetVersion(String name) private static StringformatTypePrintout(String printout, String what) (package private) static String(package private) static String(package private) static String(package private) static StringgetKey4New(String internalClassName) private Collection<String>getKeys(Signatures.UnresolvableReporting report, boolean localIgnoreMissingClasses, Set<String> missingClasses, String signature) private ViolationSeveritygetSeverityForClassName(String className) private ViolationSeveritygetSeverityForKey(String key) booleanReturns if there are any signatures.(package private) static booleanbooleanReturns if bundled signature to enable heuristics for detection of non-portable runtime calls is usedbooleanReturns if no signatures files / inline signatures were parsedprivate voidparseSignaturesFile(Reader reader, boolean isBundled, Set<String> missingClasses) private voidparseSignaturesStream(InputStream in, boolean isBundled, Set<String> missingClasses) voidparseSignaturesStream(InputStream in, String name) Reads a list of API signatures.voidparseSignaturesString(String signatures) Reads a list of API signatures from a String.private voidreportMissingSignatureClasses(Set<String> missingClasses) voidsetSignatureSeverity(String signature, ViolationSeverity severity) voidsetSignaturesSeverity(Collection<String> signatures, ViolationSeverity severity)
-
Field Details
-
BUNDLED_PREFIX
- See Also:
-
DEFAULT_MESSAGE_PREFIX
- See Also:
-
IGNORE_UNRESOLVABLE_LINE
- See Also:
-
IGNORE_MISSING_CLASSES_LINE
- See Also:
-
WILDCARD_ARGS
- See Also:
-
PATTERN_WILDCARD_ARGS
-
BUNDLED_SIGNATURES_NAMES
-
lookup
-
logger
-
failOnUnresolvableSignatures
private final boolean failOnUnresolvableSignatures -
ignoreSignaturesOfMissingClasses
private final boolean ignoreSignaturesOfMissingClasses -
signatures
Key is used to lookup forbidden signature in following formats. Keys are generated by the correspondinggetKey(String)(classes),getKey(String, Method)(methods),getKey(String, String)(fields) call. -
classPatterns
set of patterns of forbidden classes -
severityPerSignature
Key is used to lookup forbidden signature in following formats. Keys are generated by the correspondinggetKey(String)(classes),getKey(String, Method)(methods),getKey(String, String)(fields) call. -
severityPerClassPattern
-
forbidNonPortableRuntime
private boolean forbidNonPortableRuntimeif enabled, the bundled signature to enable heuristics for detection of non-portable runtime calls is used -
numberOfFiles
private int numberOfFilesnumber of files that were interpreted as signatures file. If 0, no (bundled) signatures files were added at all -
failOnViolation
private boolean failOnViolationdetermines default severity for violations if no severity on signature level is overridden. true = ERROR, false = WARNING
-
-
Constructor Details
-
Signatures
-
Signatures
public Signatures(RelatedClassLookup lookup, Logger logger, boolean ignoreSignaturesOfMissingClasses, boolean failOnUnresolvableSignatures, boolean failOnViolation)
-
-
Method Details
-
isKey
-
getKey
-
getKey
-
getKey
-
getKey4New
-
addSignature
private void addSignature(String line, String defaultMessage, Signatures.UnresolvableReporting report, boolean localIgnoreMissingClasses, Set<String> missingClasses) throws ParseException, IOException Adds the method signature to the list of disallowed methods. The Signature is checked against the given ClassLoader.- Throws:
ParseExceptionIOException
-
getKeys
private Collection<String> getKeys(Signatures.UnresolvableReporting report, boolean localIgnoreMissingClasses, Set<String> missingClasses, String signature) throws ParseException, IOException - Throws:
ParseExceptionIOException
-
reportMissingSignatureClasses
-
addBundledSignatures
private void addBundledSignatures(String name, String jdkTargetVersion, boolean readExternal, Set<String> missingClasses) throws IOException, ParseException - Throws:
IOExceptionParseException
-
parseSignaturesStream
private void parseSignaturesStream(InputStream in, boolean isBundled, Set<String> missingClasses) throws IOException, ParseException - Throws:
IOExceptionParseException
-
parseSignaturesFile
private void parseSignaturesFile(Reader reader, boolean isBundled, Set<String> missingClasses) throws IOException, ParseException - Throws:
IOExceptionParseException
-
addBundledSignatures
public void addBundledSignatures(String name, String jdkTargetVersion) throws IOException, ParseException Reads a list of bundled API signatures from classpath.- Throws:
IOExceptionParseException
-
parseSignaturesStream
Reads a list of API signatures. Closes the Reader when done (on Exception, too)!- 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 - Throws:
ParseExceptionIOException
-
setSignatureSeverity
public void setSignatureSeverity(String signature, ViolationSeverity severity) throws ParseException, IOException - Throws:
ParseExceptionIOException
-
isNonPortableRuntimeForbidden
public boolean isNonPortableRuntimeForbidden()Returns if bundled signature to enable heuristics for detection of non-portable runtime calls is used -
formatTypePrintout
-
checkType
-
checkMethod
-
checkNew
-
checkField
-
getSeverityForKey
-
getSeverityForClassName
-
fixTargetVersion
- Throws:
ParseException
-