Search in sources :

Example 11 with IDirectory

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

the class OBRResolverAdvancedTest method generateOBRRepoXML.

private void generateOBRRepoXML(boolean nullURI, String... bundleFiles) throws Exception {
    Set<ModelledResource> mrs = new HashSet<ModelledResource>();
    FileOutputStream fout = new FileOutputStream("repository.xml");
    RepositoryGenerator repositoryGenerator = context().getService(RepositoryGenerator.class);
    ModelledResourceManager modelledResourceManager = context().getService(ModelledResourceManager.class);
    for (String fileName : bundleFiles) {
        File bundleFile = new File(fileName);
        IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
        String uri = "";
        if (!!!nullURI) {
            uri = bundleFile.toURI().toString();
        }
        if ("delete.jar".equals(fileName)) {
            jarDir = null;
        }
        mrs.add(modelledResourceManager.getModelledResource(uri, jarDir));
    }
    repositoryGenerator.generateRepository("Test repo description", mrs, fout);
    fout.close();
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) ModelledResourceManager(org.apache.aries.application.modelling.ModelledResourceManager) File(java.io.File) ModelledResource(org.apache.aries.application.modelling.ModelledResource) HashSet(java.util.HashSet)

Example 12 with IDirectory

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

the class AriesApplicationManagerImpl method createApplication.

/**
 * Create an application from a URL.
 * The first version of this method isn't smart enough to check whether
 * the input URL is file://
 */
public AriesApplication createApplication(URL url) throws ManagementException {
    OutputStream os = null;
    AriesApplication app = null;
    try {
        File tempFile = _localPlatform.getTemporaryFile();
        InputStream is = url.openStream();
        os = new FileOutputStream(tempFile);
        IOUtils.copy(is, os);
        IDirectory downloadedSource = FileSystem.getFSRoot(tempFile);
        app = createApplication(downloadedSource);
    } catch (IOException iox) {
        throw new ManagementException(iox);
    } finally {
        IOUtils.close(os);
    }
    return app;
}
Also used : ManagementException(org.apache.aries.application.management.ManagementException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) AriesApplication(org.apache.aries.application.management.AriesApplication) IOException(java.io.IOException) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File)

Example 13 with IDirectory

use of org.apache.aries.util.filesystem.IDirectory 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)

Example 14 with IDirectory

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

the class InstallTest method createCompositeDirEsa.

private void createCompositeDirEsa() throws IOException, FileNotFoundException {
    ZipFixture feature = ArchiveFixture.newZip().binary("OSGI-INF/SUBSYSTEM.MF", getResourceAsStream("compositeDir" + "/OSGI-INF/SUBSYSTEM.MF")).binary("a.jar/META-INF/MANIFEST.MF", getResourceAsStream("compositeDir" + "/a.jar/META-INF/MANIFEST.MF")).binary("a.jar/a/A.class", getResourceAsStream("a/A.class")).binary("applicationDir.esa/OSGI-INF/SUBSYSTEM.MF", getResourceAsStream("compositeDir" + "/applicationDir/OSGI-INF/SUBSYSTEM.MF")).binary("applicationDir.esa/b.jar/META-INF/MANIFEST.MF", getResourceAsStream("compositeDir" + "/applicationDir/b.jar/META-INF/MANIFEST.MF")).binary("applicationDir.esa/b.jar/b/B.class", getResourceAsStream("b/B.class")).binary("applicationDir.esa/featureDir.esa/OSGI-INF/SUBSYSTEM.MF", getResourceAsStream("compositeDir" + "/applicationDir/featureDir/OSGI-INF/SUBSYSTEM.MF")).binary("applicationDir.esa/featureDir.esa/a.jar/META-INF/MANIFEST.MF", getResourceAsStream("compositeDir" + "/applicationDir/featureDir/a.jar/META-INF/MANIFEST.MF")).binary("applicationDir.esa/featureDir.esa/a.jar/a/A.class", getResourceAsStream("a/A.class")).binary("applicationDir.esa/featureDir.esa/b.jar/META-INF/MANIFEST.MF", getResourceAsStream("compositeDir" + "/applicationDir/featureDir/b.jar/META-INF/MANIFEST.MF")).binary("applicationDir.esa/featureDir.esa/b.jar/b/B.class", getResourceAsStream("b/B.class"));
    feature.end();
    FileOutputStream fos = new FileOutputStream("compositeDir" + ".esa");
    try {
        feature.writeOut(fos);
    } finally {
        Utils.closeQuietly(fos);
    }
    File userDir = new File(System.getProperty("user.dir"));
    IDirectory idir = FileSystem.getFSRoot(userDir);
    File compositeDir = new File(userDir, "compositeDir");
    compositeDir.mkdir();
    IOUtils.unpackZip(idir.getFile("compositeDir.esa"), compositeDir);
}
Also used : ZipFixture(org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) File(java.io.File)

Aggregations

IDirectory (org.apache.aries.util.filesystem.IDirectory)14 File (java.io.File)11 IFile (org.apache.aries.util.filesystem.IFile)7 FileOutputStream (java.io.FileOutputStream)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 AriesApplication (org.apache.aries.application.management.AriesApplication)3 ModelledResource (org.apache.aries.application.modelling.ModelledResource)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 RepositoryGenerator (org.apache.aries.application.management.spi.repository.RepositoryGenerator)2 ModelledResourceManager (org.apache.aries.application.modelling.ModelledResourceManager)2 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1 HashMap (java.util.HashMap)1