ArchUnit
ArchUnit copied to clipboard
If origin file could be deleted when importLocations called
Normally I don't need to delete origin jars when call ClassFileImporter().importLocations(androidJarLocation); But there is an occation, when input is aar file, I would unzip it before feed to importLocations; So there would generate temp jars when unzip aar file, and I have no wish to keep it when check is over; But I try many way to delete those temp jars when checking process is over So my question is: is there any way to detete those temp jars; Hoping for your reply , thanks very much !
Maybe you can use Runtime.getRuntime().addShutdownHook(deleteTempJars);
with a suitable Thread deleteTempJars
?
For example: JavaClasses dependencyClasses = new ClassFileImporter().importLocations(dependencyLocation); This is how I import jars, is there any way to get the Thread object of the process? Thanks very much!
The idea of the shutdown hook is to define your own Thread
that does the necessary cleanup. It will be started when the JVM begins its shutdown sequence. (But note that all of this is entirely unrelated to ArchUnit
.)
I'm not sure I fully understand your constraints, but what about just creating your own utility around the ClassFileImporter
?
Like
class ImportUtils {
static JavaClasses importAar(aarFile) {
try {
Path location = unpack(aarFile);
return new ClassFileImporter().importPath(location);
} finally {
delete(aarFile);
}
}
}