Search in sources :

Example 1 with IDirectory

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

the class OBRResolverTest method generateOBRRepoXML.

private void generateOBRRepoXML(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);
        mrs.add(modelledResourceManager.getModelledResource(bundleFile.toURI().toString(), 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 2 with IDirectory

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

the class AriesApplicationManagerImplTest method testStoreAndReload.

@Test
public void testStoreAndReload() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    File dest = new File("ariesApplicationManagerImplTest/stored.eba");
    app.store(dest);
    /* Dest should be a zip file with four entries:
     *  /foo.bar.widgets.jar
     *  /my.business.logic.jar
     *  /META-INF/APPLICATION.MF
     *  /META-INF/DEPLOYMENT.MF
     */
    IDirectory storedEba = FileSystem.getFSRoot(dest);
    assertNotNull(storedEba);
    assertEquals(storedEba.listFiles().size(), 3);
    IFile ifile = storedEba.getFile("META-INF/APPLICATION.MF");
    assertNotNull(ifile);
    ifile = storedEba.getFile("META-INF/DEPLOYMENT.MF");
    assertNotNull(ifile);
    ifile = storedEba.getFile("foo.bar.widgets.jar");
    assertNotNull(ifile);
    ifile = storedEba.getFile("my.business.logic.jar");
    assertNotNull(ifile);
    AriesApplication newApp = _appMgr.createApplication(storedEba);
    DeploymentMetadata dm = newApp.getDeploymentMetadata();
    assertEquals(2, dm.getApplicationDeploymentContents().size());
    assertEquals(1, dm.getApplicationProvisionBundles().size());
    assertEquals(dm.getApplicationSymbolicName(), app.getApplicationMetadata().getApplicationSymbolicName());
    assertEquals(dm.getApplicationVersion(), app.getApplicationMetadata().getApplicationVersion());
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) IFile(org.apache.aries.util.filesystem.IFile) IDirectory(org.apache.aries.util.filesystem.IDirectory) AriesApplication(org.apache.aries.application.management.AriesApplication) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File) Test(org.junit.Test)

Example 3 with IDirectory

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

the class AriesApplicationManagerImplTest method createApplication.

private AriesApplication createApplication(String fileName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ManagementException, ResolverException {
    // This next block is a very long winded way of constructing a BundleInfoImpl
    // against the existing (BundleManifest bm, String location) constructor. If we
    // find we need a String-based BundleInfoImpl constructor for other reasons,
    // we could change to using it here.
    Set<BundleInfo> nextResolverResult = new HashSet<BundleInfo>();
    String persistenceLibraryLocation = "../src/test/resources/bundles/repository/a.handy.persistence.library.jar";
    File persistenceLibrary = new File(persistenceLibraryLocation);
    BundleManifest mf = BundleManifest.fromBundle(persistenceLibrary);
    BundleInfo resolvedPersistenceLibrary = new SimpleBundleInfo(mf, persistenceLibraryLocation);
    Field v = SimpleBundleInfo.class.getDeclaredField("_version");
    v.setAccessible(true);
    v.set(resolvedPersistenceLibrary, new Version("1.1.0"));
    nextResolverResult.add(resolvedPersistenceLibrary);
    _resolver.setNextResult(nextResolverResult);
    IDirectory testEba = FileSystem.getFSRoot(new File(fileName));
    AriesApplication app = _appMgr.createApplication(testEba);
    app = _appMgr.resolve(app);
    return app;
}
Also used : Field(java.lang.reflect.Field) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) Version(org.osgi.framework.Version) IDirectory(org.apache.aries.util.filesystem.IDirectory) BundleManifest(org.apache.aries.util.manifest.BundleManifest) AriesApplication(org.apache.aries.application.management.AriesApplication) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) IFile(org.apache.aries.util.filesystem.IFile) File(java.io.File) HashSet(java.util.HashSet)

Example 4 with IDirectory

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

the class OpenEJBLocator method getClassPathLocations.

/**
 * Find the classpath entries for our bundle
 *
 * @param manifest
 * @param bundle
 * @return
 */
private List<IDirectory> getClassPathLocations(BundleManifest manifest, IDirectory bundle) {
    List<IDirectory> result = new ArrayList<IDirectory>();
    String rawCp = manifest.getRawAttributes().getValue(Constants.BUNDLE_CLASSPATH);
    logger.debug("Classpath is " + rawCp);
    if (rawCp == null || rawCp.trim() == "")
        result.add(bundle);
    else {
        List<NameValuePair> splitCp = ManifestHeaderProcessor.parseExportString(rawCp);
        List<IFile> allFiles = null;
        for (NameValuePair nvp : splitCp) {
            String name = nvp.getName().trim();
            if (".".equals(name)) {
                result.add(bundle);
            } else {
                IFile f = bundle.getFile(name);
                if (f == null) {
                    // Zip. Check to make sure
                    if (allFiles == null)
                        allFiles = bundle.listAllFiles();
                    for (IFile file : allFiles) {
                        if (file.getName().startsWith(name)) {
                            result.add(new ClasspathIDirectory(bundle, name));
                            break;
                        }
                    }
                } else {
                    IDirectory converted = f.convertNested();
                    if (converted != null)
                        result.add(converted);
                }
            }
        }
    }
    return result;
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair) IFile(org.apache.aries.util.filesystem.IFile) IDirectory(org.apache.aries.util.filesystem.IDirectory) ArrayList(java.util.ArrayList)

Example 5 with IDirectory

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

the class FileSystemImpl method getFSRoot.

public static ICloseableDirectory getFSRoot(InputStream is) {
    File tempFile = null;
    try {
        tempFile = File.createTempFile("inputStreamExtract", ".zip");
    } catch (IOException e1) {
        throw new IORuntimeException("IOException in IDirectory.getFSRoot", e1);
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(tempFile);
        IOUtils.copy(is, fos);
    } catch (IOException e) {
        return null;
    } finally {
        IOUtils.close(fos);
    }
    IDirectory dir = getFSRoot(tempFile, null);
    if (dir == null)
        return null;
    else
        return new InputStreamClosableDirectory(dir, tempFile);
}
Also used : IORuntimeException(org.apache.aries.util.IORuntimeException) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) IOException(java.io.IOException) IFile(org.apache.aries.util.filesystem.IFile) ZipFile(java.util.zip.ZipFile) 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