Package org.junit.platform.commons.util
Class PackageUtils
- java.lang.Object
-
- org.junit.platform.commons.util.PackageUtils
-
@API(status=INTERNAL, since="1.0") public final class PackageUtils extends java.lang.ObjectCollection of utilities for working with packages.DISCLAIMER
These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!
- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classPackageUtils.JavaNameUtilsCollection of utilities for working with qualified names in Java.
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringDEFAULT_PACKAGE_NAMEprivate static java.util.regex.PatternDOT_PATTERNCompiled"\."pattern used to split canonical package (and type) names.
-
Constructor Summary
Constructors Modifier Constructor Description privatePackageUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertPackageNameIsValid(java.lang.String packageName)Assert that the supplied package name is valid in terms of Java syntax.static java.util.Optional<java.lang.String>getAttribute(java.lang.Class<?> type, java.lang.String name)Get the value of the specified attribute name, specified as a string, or an emptyOptionalif the attribute was not found.static java.util.Optional<java.lang.String>getAttribute(java.lang.Class<?> type, java.util.function.Function<java.lang.Package,java.lang.String> function)Get the package attribute for the suppliedtypeusing the suppliedfunction.
-
-
-
Field Detail
-
DEFAULT_PACKAGE_NAME
static final java.lang.String DEFAULT_PACKAGE_NAME
- See Also:
- Constant Field Values
-
DOT_PATTERN
private static final java.util.regex.Pattern DOT_PATTERN
Compiled"\."pattern used to split canonical package (and type) names.
-
-
Method Detail
-
assertPackageNameIsValid
public static void assertPackageNameIsValid(java.lang.String packageName)
Assert that the supplied package name is valid in terms of Java syntax.Note: this method does not actually verify if the named package exists in the classpath.
The default package is represented by an empty string (
"").- Parameters:
packageName- the package name to validate- Throws:
PreconditionViolationException- if the supplied package name isnull, contains only whitespace, or contains parts that are not valid in terms of Java syntax (e.g., containing keywords such asvoid,import, etc.)- See Also:
PackageUtils.JavaNameUtils.isJavaName(String)
-
getAttribute
public static java.util.Optional<java.lang.String> getAttribute(java.lang.Class<?> type, java.util.function.Function<java.lang.Package,java.lang.String> function)Get the package attribute for the suppliedtypeusing the suppliedfunction.This method only returns a non-empty
Optionalvalue holder if the class loader for the supplied type created aPackageobject and the supplied function does not returnnullwhen applied.- Parameters:
type- the type to get the package attribute forfunction- a function that computes the package attribute value (e.g.,Package::getImplementationTitle); nevernull- Returns:
- an
Optionalcontaining the attribute value; nevernullbut potentially empty - Throws:
PreconditionViolationException- if the supplied type or function isnull- See Also:
Class.getPackage(),Package.getImplementationTitle(),Package.getImplementationVersion()
-
getAttribute
public static java.util.Optional<java.lang.String> getAttribute(java.lang.Class<?> type, java.lang.String name)Get the value of the specified attribute name, specified as a string, or an emptyOptionalif the attribute was not found. The attribute name is case-insensitive.This method also returns an empty
Optionalvalue holder if any exception is caught while loading the manifest file via the JAR file of the specified type.- Parameters:
type- the type to get the attribute forname- the attribute name as a string- Returns:
- an
Optionalcontaining the attribute value; nevernullbut potentially empty - Throws:
PreconditionViolationException- if the supplied type isnullor the specified name is blank- See Also:
Manifest.getMainAttributes()
-
-