use of java.io.Closeable in project sling by apache.
the class JcrResourceProvider method unregisterListeners.
/**
* Unregister all observation listeners.
*/
private void unregisterListeners() {
logger.debug("Unregistering resource listeners...");
for (final Closeable c : this.listeners.values()) {
try {
logger.debug("Removing listener for {}", ((JcrResourceListener) c).getConfig().getPaths());
c.close();
} catch (final IOException e) {
// ignore this as the method above does not throw it
}
}
this.listeners.clear();
if (this.listenerConfig != null) {
try {
this.listenerConfig.close();
} catch (final IOException e) {
// ignore this as the method above does not throw it
}
this.listenerConfig = null;
}
logger.debug("Unregistered resource listeners");
}
use of java.io.Closeable in project wildfly by wildfly.
the class ScannerTest method testZippedJar.
@Test
public void testZippedJar() throws Exception {
File defaultPar = buildDefaultPar();
addPackageToClasspath(defaultPar);
final VirtualFile virtualFile = VFS.getChild(defaultPar.getAbsolutePath());
Closeable closeable = VFS.mountZip(virtualFile, virtualFile, tempFileProvider);
try {
ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(virtualFile.toURL());
AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
validateResults(resultCollector, ApplicationServer.class, Version.class);
} finally {
closeable.close();
}
}
use of java.io.Closeable in project wildfly by wildfly.
the class ScannerTest method testNestedJarProtocol.
@Test
public void testNestedJarProtocol() throws Exception {
File defaultPar = buildDefaultPar();
File nestedEar = buildNestedEar(defaultPar);
addPackageToClasspath(nestedEar);
final VirtualFile nestedEarVirtualFile = VFS.getChild(nestedEar.getAbsolutePath());
Closeable closeable = VFS.mountZip(nestedEarVirtualFile, nestedEarVirtualFile, tempFileProvider);
try {
VirtualFile parVirtualFile = nestedEarVirtualFile.getChild("defaultpar.par");
Closeable closeable2 = VFS.mountZip(parVirtualFile, parVirtualFile, tempFileProvider);
try {
ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(parVirtualFile.toURL());
AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
validateResults(resultCollector, ApplicationServer.class, Version.class);
} finally {
closeable2.close();
}
} finally {
closeable.close();
}
File nestedEarDir = buildNestedEarDir(defaultPar);
final VirtualFile nestedEarDirVirtualFile = VFS.getChild(nestedEarDir.getAbsolutePath());
try {
VirtualFile parVirtualFile = nestedEarDirVirtualFile.getChild("defaultpar.par");
closeable = VFS.mountZip(parVirtualFile, parVirtualFile, tempFileProvider);
try {
ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(parVirtualFile.toURL());
AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
validateResults(resultCollector, ApplicationServer.class, Version.class);
} finally {
closeable.close();
}
} finally {
closeable.close();
}
}
use of java.io.Closeable in project wildfly by wildfly.
the class WarStructureDeploymentProcessor method createResourceRoots.
/**
* Create the resource roots for a .war deployment
*
*
* @param deploymentRoot the deployment root
* @return the resource roots
* @throws java.io.IOException for any error
*/
private List<ResourceRoot> createResourceRoots(final VirtualFile deploymentRoot, final DeploymentUnit deploymentUnit) throws IOException, DeploymentUnitProcessingException {
final List<ResourceRoot> entries = new ArrayList<ResourceRoot>();
// WEB-INF classes
final VirtualFile webinfClasses = deploymentRoot.getChild(WEB_INF_CLASSES);
if (webinfClasses.exists()) {
final ResourceRoot webInfClassesRoot = new ResourceRoot(webinfClasses.getName(), webinfClasses, null);
ModuleRootMarker.mark(webInfClassesRoot);
entries.add(webInfClassesRoot);
}
// WEB-INF lib
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
final VirtualFile webinfLib = deploymentRoot.getChild(WEB_INF_LIB);
if (webinfLib.exists()) {
final List<VirtualFile> archives = webinfLib.getChildren(DEFAULT_WEB_INF_LIB_FILTER);
for (final VirtualFile archive : archives) {
try {
String relativeName = archive.getPathNameRelativeTo(deploymentRoot);
MountedDeploymentOverlay overlay = overlays.get(relativeName);
Closeable closable = null;
if (overlay != null) {
overlay.remountAsZip(false);
} else if (archive.isFile()) {
closable = VFS.mountZip(archive, archive, TempFileProviderService.provider());
} else {
closable = null;
}
final ResourceRoot webInfArchiveRoot = new ResourceRoot(archive.getName(), archive, new MountHandle(closable));
ModuleRootMarker.mark(webInfArchiveRoot);
entries.add(webInfArchiveRoot);
} catch (IOException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToProcessWebInfLib(archive), e);
}
}
}
return entries;
}
use of java.io.Closeable in project heron by twitter.
the class SysUtilsTest method testCloseIgnoringException.
@Test
public void testCloseIgnoringException() throws Exception {
Closeable closeable = new Closeable() {
@Override
public void close() throws IOException {
throw new RuntimeException("Deliberate exception to be ignored.");
}
};
// This invocation should not throw any exceptions
// Otherwise, the test will automatically fail
SysUtils.closeIgnoringExceptions(closeable);
Assert.assertTrue(true);
}
Aggregations