Interface PackageContainerGroup
- All Superinterfaces:
AutoCloseable,Closeable,ContainerGroup
- All Known Subinterfaces:
OutputContainerGroup
- Since:
- 0.0.1
- Author:
- Ashley Scopes
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddPackage(Container container) Add a container to this group.voidaddPackage(PathRoot path) Add a path to this group.Get a class loader for this group of containers.Find the first occurrence of a given path to a file in packages or modules.getFileForInput(String packageName, String relativeName) Get aFileObjectthat can have content read from it.getFileForOutput(String packageName, String relativeName) Get aFileObjectthat can have content written to it for the given file.getJavaFileForInput(String className, JavaFileObject.Kind kind) Get aJavaFileObjectthat can have content read from it for the given file.getJavaFileForOutput(String className, JavaFileObject.Kind kind) Get aJavaFileObjectthat can have content written to it for the given class.Get the package-oriented location that this group of paths is for.Get the package containers in this group.inferBinaryName(PathFileObject fileObject) Try to infer the binary name of a given file object.booleanisEmpty()Determine if this group has no paths registered.voidlistFileObjects(String packageName, Set<? extends JavaFileObject.Kind> kinds, boolean recurse, Collection<JavaFileObject> collection) List all the file objects that match the given criteria in this group.Methods inherited from interface io.github.ascopes.jct.containers.ContainerGroup
contains, getRelease, getServiceLoader
-
Method Details
-
addPackage
Add a container to this group.The provided container will be closed when this group is closed.
- Parameters:
container- the container to add.
-
addPackage
Add a path to this group.Note that this will destroy the
classloaderif one is already allocated.If the path points to some form of archive (such as a JAR), then this may open that archive in a new resource internally. If this occurs, then the resource will always be freed by this class by calling
Closeable.close().Any other closable resources passed to this function will not be closed by this implementation. You must handle the lifecycle of those objects yourself.
- Parameters:
path- the path to add.
-
getClassLoader
Get a class loader for this group of containers.Note that adding additional containers to this group after accessing this class loader may result in the class loader being destroyed or re-created.
- Returns:
- the class loader.
-
getFile
Find the first occurrence of a given path to a file in packages or modules.Modules are treated as subdirectories.
- Parameters:
fragment- the first part of the path.fragments- any additional parts of the path.- Returns:
- the first occurrence of the path in this group, or null if not found.
- Throws:
IllegalArgumentException- if the provided path is absolute.
-
getFileForInput
Get aFileObjectthat can have content read from it.This will return
nullif no file is found matching the criteria.- Parameters:
packageName- the package name of the file to read.relativeName- the relative name of the file to read.- Returns:
- the file object, or null if the file is not found.
-
getFileForOutput
Get aFileObjectthat can have content written to it for the given file.This will attempt to write to the first writeable path in this group.
nullwill be returned if no writeable paths exist in this group.- Parameters:
packageName- the name of the package the file is in.relativeName- the relative name of the file within the package.- Returns:
- the
FileObjectto write to, or null if this group has no paths that can be written to.
-
getJavaFileForInput
Get aJavaFileObjectthat can have content read from it for the given file.This will return
nullif no file is found matching the criteria.- Parameters:
className- the binary name of the class to read.kind- the kind of file to read.- Returns:
- the
JavaFileObjectto write to, or null if this group has no paths that can be written to.
-
getJavaFileForOutput
Get aJavaFileObjectthat can have content written to it for the given class.This will attempt to write to the first writeable path in this group.
nullwill be returned if no writeable paths exist in this group.- Parameters:
className- the name of the class.kind- the kind of the class file.- Returns:
- the
JavaFileObjectto write to, or null if this group has no paths that can be written to.
-
getLocation
Get the package-oriented location that this group of paths is for.- Specified by:
getLocationin interfaceContainerGroup- Returns:
- the package-oriented location.
-
getPackages
Get the package containers in this group.- Returns:
- the containers.
-
inferBinaryName
Try to infer the binary name of a given file object.- Parameters:
fileObject- the file object to infer the binary name for.- Returns:
- the binary name if known, or null otherwise.
-
isEmpty
boolean isEmpty()Determine if this group has no paths registered.- Returns:
trueif no paths are registered.falseif paths are registered.
-
listFileObjects
void listFileObjects(String packageName, Set<? extends JavaFileObject.Kind> kinds, boolean recurse, Collection<JavaFileObject> collection) throws IOException List all the file objects that match the given criteria in this group.- Parameters:
packageName- the package name to look in.kinds- the kinds of file to look for.recurse-trueto recurse subpackages,falseto only consider the given package.collection- the collection to fill.- Throws:
IOException- if the file lookup fails due to an IO exception.
-