Class CodeSourceLocations
java.lang.Object
com.ultikits.ultitools.utils.CodeSourceLocations
Turns a module's
CodeSource.getLocation() URL into the File it names. Message
catalogue loading and module resource extraction use this same resolver for JAR paths and
exploded class directories, including paths with spaces or non-ASCII characters.
Internal to the framework; not a public API.
- Since:
- 6.3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclassNamesInDirectory(Path codeRoot, Path subtree) Enumerates binary class names rooted atcodeRoot, visiting onlysubtree.static @Nullable PathdirectoryOf(Class<?> type) Returns the defining class directory, or null for a JAR or an unavailable code source.static @Nullable Class<?> findLocatedClass(Class<?> runtimeClass) Returns the class that owns the location, so directory scans can also use its defining loader.static @Nullable URLfindOnSuperclassChain(Class<?> runtimeClass) Finds the first usable code location from the runtime class through its superclasses.static booleanisCandidateClassFile(String name) Returns true if the file name or slash-separated JAR entry names a.classfile other than a package descriptor (package-info.class) or module descriptor (module-info.class).static booleanisDefinedInDirectory(Class<?> entity, Path directory) Checks the defining (not inherited) code source against a normalized scan root.static @Nullable PathpackageDirectory(Path codeRoot, String basePackage) Resolves a dotted package against a normalized class directory.static File
-
Constructor Details
-
CodeSourceLocations
private CodeSourceLocations()
-
-
Method Details
-
findOnSuperclassChain
Finds the first usable code location from the runtime class through its superclasses. A normal Paper plugin has its own location, so its JAR remains the result without visiting any superclass. A generated subclass may have no CodeSource or a CodeSource without a location; both allow the search to continue, stopping before the Paper API.- Parameters:
runtimeClass- the plugin's runtime class- Returns:
- the nearest non-null code location, or null if none exists
-
findLocatedClass
-
toFile
Resolves a code-source URL as aFile, decoding percent escapes through the URL'sURI.URL.getPath()does not decode: a server installed under a path with a space or a non-ASCII character yields%20/%E6...escapes that name no file, sonew File(url.getPath())finds nothing there. URI decoding, unlikeURLDecoder, also leaves a literal'+'in a folder name as a plus sign.Falls back to the raw-path rule the framework used before (the URL's undecoded path, with a leading character dropped when the path is not empty and does not start with
'/') in two cases, so resolving a location never adds a failure path where reading the raw path never failed:URISyntaxException-- the URL is not a valid URI at all, for example an unescaped space in a hand-builtfile:URL;IllegalArgumentException--File(java.net.URI)rejects a URI with an authority component, a query or a fragment, or an opaque URI.
- Parameters:
location- theCodeSource.getLocation()URL, nevernull- Returns:
- the location as a
File; nevernull
-
isDefinedInDirectory
-
directoryOf
-
packageDirectory
Resolves a dotted package against a normalized class directory. The returned path need not exist; component discovery may fall back to another root, whereas entity ownership may not. Returns null if the requested path would leave the class directory. -
isCandidateClassFile
Returns true if the file name or slash-separated JAR entry names a.classfile other than a package descriptor (package-info.class) or module descriptor (module-info.class). Callers apply their ownMETA-INFrule. -
classNamesInDirectory
Enumerates binary class names rooted atcodeRoot, visiting onlysubtree. Excludes package descriptors (package-info.class), module descriptors (module-info.class), and entries under the rootMETA-INFdirectory. The caller closes the returned stream. Names are candidates only: for source-local discovery, compare the resolved class'sdirectoryOf(Class)withcodeRoot.- Throws:
IOException
-