Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ClassLoaderResourceAccessor implement Closable #2308

Merged
merged 4 commits into from Jan 26, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,7 +24,7 @@
*
* @see OSGiResourceAccessor for OSGi-based classloaders
*/
public class ClassLoaderResourceAccessor extends AbstractResourceAccessor {
public class ClassLoaderResourceAccessor extends AbstractResourceAccessor implements AutoCloseable {

private ClassLoader classLoader;
protected List<FileSystem> rootPaths;
Expand Down Expand Up @@ -270,7 +270,7 @@ protected SortedSet<String> listFromClassLoader(String path, boolean recursive,
try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name()))) {
String comparePath = path;
if (comparePath.startsWith("/")) {
comparePath = "/"+comparePath;
comparePath = "/" + comparePath;
}
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
Expand Down Expand Up @@ -355,4 +355,17 @@ public SortedSet<String> describeLocations() {

return description;
}

@Override
public void close() throws Exception {
if (rootPaths != null) {
for (final FileSystem rootPath : rootPaths) {
try {
rootPath.close();
} catch (final Exception e) {
Scope.getCurrentScope().getLog(getClass()).fine("Cannot close path " + e.getMessage(), e);
}
}
}
}
}