Search in sources :

Example 11 with BundleInfo

use of org.apache.aries.application.management.BundleInfo in project aries by apache.

the class AriesApplicationImpl method storeInDirectory.

private void storeInDirectory(File dir) throws IOException, MalformedURLException {
    OutputStream out = null;
    InputStream in = null;
    try {
        out = IOUtils.getOutputStream(dir, AppConstants.APPLICATION_MF);
        _applicationMetadata.store(out);
    } finally {
        IOUtils.close(out);
    }
    if (_deploymentMetadata != null) {
        try {
            out = IOUtils.getOutputStream(dir, AppConstants.DEPLOYMENT_MF);
            _deploymentMetadata.store(out);
        } finally {
            IOUtils.close(out);
        }
    }
    // Write the by-value eba files out
    for (BundleInfo bi : _bundleInfo) {
        // bi.getLocation() will return a URL to the source bundle. It may be of the form
        // file:/path/to/my/file.jar, or
        // jar:file:/my/path/to/eba.jar!/myBundle.jar
        String bundleLocation = bi.getLocation();
        String bundleFileName = bundleLocation.substring(bundleLocation.lastIndexOf('/') + 1);
        try {
            out = IOUtils.getOutputStream(dir, bundleFileName);
            URL bundleURL = new URL(bundleLocation);
            InputStream is = bundleURL.openStream();
            IOUtils.copy(is, out);
        } finally {
            IOUtils.close(out);
            IOUtils.close(in);
        }
    }
    // Write the migrated bundles out
    if (_modifiedBundles != null) {
        for (Map.Entry<String, BundleConversion> modifiedBundle : _modifiedBundles.entrySet()) {
            try {
                out = IOUtils.getOutputStream(dir, modifiedBundle.getKey());
                IOUtils.copy(modifiedBundle.getValue().getInputStream(), out);
            } finally {
                IOUtils.close(out);
            }
        }
    }
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Map(java.util.Map) BundleConversion(org.apache.aries.application.management.spi.convert.BundleConversion) URL(java.net.URL)

Example 12 with BundleInfo

use of org.apache.aries.application.management.BundleInfo in project aries by apache.

the class AriesApplicationManagerImplTest method testCreateAndConversion.

@Test
public void testCreateAndConversion() throws Exception {
    AriesApplication app = createApplication(CONVERSION_EBA);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals(appMeta.getApplicationName(), "conversion.eba");
    assertEquals(appMeta.getApplicationSymbolicName(), "conversion.eba");
    assertEquals(appMeta.getApplicationVersion(), new Version("0.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals(2, appContent.size());
    Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
    Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
    assertTrue(appContent.contains(fbw));
    assertTrue(appContent.contains(mbl));
    DeploymentMetadata dm = app.getDeploymentMetadata();
    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
    assertEquals(2, dcList.size());
    DeploymentContent dc1 = new DeploymentContentImpl("hello.world.jar;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl("helloWorld.war;deployed-version=0.0.0");
    DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
    assertTrue(dcList.contains(dc1));
    assertTrue(dcList.contains(dc2));
    dcList = dm.getApplicationProvisionBundles();
    assertEquals(1, dcList.size());
    assertTrue(dcList.contains(dc3));
    assertEquals(2, app.getBundleInfo().size());
    BundleInfo info;
    info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
    assertNotNull(info);
    assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
    info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
    assertNotNull(info);
    assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
    assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplication(org.apache.aries.application.management.AriesApplication) ContentImpl(org.apache.aries.application.impl.ContentImpl) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test)

Example 13 with BundleInfo

use of org.apache.aries.application.management.BundleInfo in project aries by apache.

the class RepositoryGenerator method generateOBR.

public void generateOBR() {
    if (generated) {
        return;
    }
    synchronized (this) {
        if (obrPath == null) {
            // set to a default obr file which is local m2 repo
            String file = System.getProperty("user.home") + "/.m2/repository/";
            if (new File(file).exists()) {
                obrPath = file;
            }
        }
        // if repository.xml already exists, no need to generate it
        if (new File(obrPath + REPOSITORY_FILE).exists()) {
            registerOBR();
            generated = true;
            return;
        }
        File rootFile = new File(obrPath);
        if (!rootFile.exists() || !rootFile.isDirectory()) {
            throw new IllegalArgumentException("obr path " + obrPath + " is not valid");
        }
        Manve2Repository repo = new Manve2Repository(rootFile);
        SortedSet<String> ss = repo.listFiles();
        Set<BundleInfo> infos = new HashSet<BundleInfo>();
        for (String s : ss) {
            BundleInfo info = new BundleInfoImpl(s);
            infos.add(info);
        }
        Document doc;
        try {
            doc = RepositoryDescriptorGenerator.generateRepositoryDescriptor("Subsystem Repository description", infos);
            FileOutputStream fout = new FileOutputStream(obrPath + REPOSITORY_FILE);
            TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(fout));
            fout.close();
            TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(System.out));
        } catch (Exception e) {
            LOGGER.error("Exception occurred when generate obr", e);
            e.printStackTrace();
        }
        registerOBR();
        generated = true;
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) StreamResult(javax.xml.transform.stream.StreamResult) Document(org.w3c.dom.Document) SubsystemException(org.osgi.service.subsystem.SubsystemException) BundleInfo(org.apache.aries.application.management.BundleInfo) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

BundleInfo (org.apache.aries.application.management.BundleInfo)13 SimpleBundleInfo (org.apache.aries.application.utils.management.SimpleBundleInfo)5 HashSet (java.util.HashSet)4 Version (org.osgi.framework.Version)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)3 Content (org.apache.aries.application.Content)3 AriesApplication (org.apache.aries.application.management.AriesApplication)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)2 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)2 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)2 BundleConversion (org.apache.aries.application.management.spi.convert.BundleConversion)2