Search in sources :

Example 1 with ICloseableDirectory

use of org.apache.aries.util.filesystem.ICloseableDirectory in project aries by apache.

the class ModelledResourceManagerImpl method getServiceElements.

public ParsedServiceElements getServiceElements(InputStreamProvider archive) throws ModellerException {
    ICloseableDirectory dir = null;
    try {
        dir = FileSystem.getFSRoot(archive.open());
        BundleManifest bm = BundleManifest.fromBundle(dir);
        return getServiceElements(bm, dir);
    } catch (IOException e) {
        throw new ModellerException(e);
    } finally {
        IOUtils.close(dir);
    }
}
Also used : ICloseableDirectory(org.apache.aries.util.filesystem.ICloseableDirectory) BundleManifest(org.apache.aries.util.manifest.BundleManifest) ModellerException(org.apache.aries.application.modelling.ModellerException) IOException(java.io.IOException)

Example 2 with ICloseableDirectory

use of org.apache.aries.util.filesystem.ICloseableDirectory in project aries by apache.

the class EJBLocatorTest method runTest.

private void runTest(byte[] zip, String manifest) throws ModellerException, IOException {
    ICloseableDirectory icd = FileSystem.getFSRoot(new ByteArrayInputStream(zip));
    new OpenEJBLocator().findEJBs(new BundleManifest(getClass().getClassLoader().getResourceAsStream(manifest)), icd, registry);
    icd.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ICloseableDirectory(org.apache.aries.util.filesystem.ICloseableDirectory) BundleManifest(org.apache.aries.util.manifest.BundleManifest)

Example 3 with ICloseableDirectory

use of org.apache.aries.util.filesystem.ICloseableDirectory in project aries by apache.

the class BasicSubsystem method install.

@Override
public AriesSubsystem install(String location, final InputStream content, InputStream deploymentManifest) {
    AriesSubsystem result = null;
    IDirectory directory = null;
    try {
        directory = content == null ? null : AccessController.doPrivileged(new PrivilegedAction<IDirectory>() {

            @Override
            public IDirectory run() {
                return FileSystem.getFSRoot(content);
            }
        });
        result = install(location, directory, deploymentManifest);
        return result;
    } finally {
        // This method must guarantee the content input stream was closed.
        // TODO Not sure closing the content is necessary. The content will
        // either be null of will have been closed while copying the data
        // to the temporary file.
        IOUtils.close(content);
        // at start time if it contains any dependencies.
        if (directory instanceof ICloseableDirectory) {
            if (result == null || Utils.isProvisionDependenciesInstall((BasicSubsystem) result) || !wasInstalledWithChildrenHavingProvisionDependenciesResolve()) {
                final IDirectory toClose = directory;
                AccessController.doPrivileged(new PrivilegedAction<Void>() {

                    @Override
                    public Void run() {
                        try {
                            ((ICloseableDirectory) toClose).close();
                        } catch (IOException ioex) {
                            logger.info("Exception calling close for content {}. Exception {}", content, ioex);
                        }
                        return null;
                    }
                });
            }
        }
    }
}
Also used : IDirectory(org.apache.aries.util.filesystem.IDirectory) ICloseableDirectory(org.apache.aries.util.filesystem.ICloseableDirectory) IOException(java.io.IOException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem)

Aggregations

ICloseableDirectory (org.apache.aries.util.filesystem.ICloseableDirectory)3 IOException (java.io.IOException)2 BundleManifest (org.apache.aries.util.manifest.BundleManifest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ModellerException (org.apache.aries.application.modelling.ModellerException)1 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)1 IDirectory (org.apache.aries.util.filesystem.IDirectory)1