Search in sources :

Example 1 with RepositoryAdmin

use of org.apache.felix.bundlerepository.RepositoryAdmin in project karaf by apache.

the class Activator method doStart.

@Override
protected void doStart() throws Exception {
    RepositoryAdmin admin = getTrackedService(RepositoryAdmin.class);
    ObrMBeanImpl mbean = new ObrMBeanImpl(bundleContext, admin);
    registerMBean(mbean, "type=obr");
}
Also used : RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) ObrMBeanImpl(org.apache.karaf.obr.core.internal.ObrMBeanImpl)

Example 2 with RepositoryAdmin

use of org.apache.felix.bundlerepository.RepositoryAdmin in project felix by apache.

the class Activator method handleRepositoryXML.

private void handleRepositoryXML(ServiceReference<String> reference, String xml) throws Exception {
    File tempXMLFile = bundleContext.getDataFile("repo-" + reference.getProperty("repository-xml") + ".xml");
    writeXMLToFile(tempXMLFile, xml);
    repoTracker = new ServiceTracker<RepositoryAdmin, RepositoryAdmin>(bundleContext, RepositoryAdmin.class, null);
    repoTracker.open();
    RepositoryAdmin repo = repoTracker.waitForService(30000);
    repo.addRepository(tempXMLFile.toURI().toURL());
    tempXMLFile.delete();
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("repository-populated", reference.getProperty("repository-xml"));
    bundleContext.registerService(String.class, "", props);
}
Also used : RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Hashtable(java.util.Hashtable) File(java.io.File)

Example 3 with RepositoryAdmin

use of org.apache.felix.bundlerepository.RepositoryAdmin in project aries by apache.

the class OBRResolverAdvancedTest method testDemoApp.

@Test
public void testDemoApp() throws Exception {
    // do not provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
    generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar", USE_BUNDLE_BY_REFERENCE + ".jar");
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        repositoryAdmin.removeRepository(repo.getURI());
    }
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
    // installing requires a valid url for the bundle in repository.xml.
    app = manager.resolve(app);
    DeploymentMetadata depMeta = app.getDeploymentMetadata();
    List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
    Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
    Collection<Content> importPackages = depMeta.getImportPackage();
    assertEquals(provision.toString(), 2, provision.size());
    assertEquals(useBundles.toString(), 1, useBundles.size());
    assertEquals(importPackages.toString(), 4, importPackages.size());
    List<String> bundleSymbolicNames = new ArrayList<String>();
    for (DeploymentContent dep : provision) {
        bundleSymbolicNames.add(dep.getContentName());
    }
    assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_REFERENCE));
    assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_VALUE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_VALUE));
    bundleSymbolicNames.clear();
    for (DeploymentContent dep : useBundles) {
        bundleSymbolicNames.add(dep.getContentName());
    }
    assertTrue("Bundle " + USE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(USE_BUNDLE_BY_REFERENCE));
    Collection<String> packages = new ArrayList<String>();
    Map<String, String> maps = new HashMap<String, String>();
    maps.put("version", "0.0.0");
    maps.put("bundle-symbolic-name", "use.bundle.by.reference");
    maps.put("bundle-version", "[1.0.0,1.0.0]");
    Content useContent = ContentFactory.parseContent("a.b.c", maps);
    assertTrue("Use Bundle not found in import packags", importPackages.contains(useContent));
    for (Content c : importPackages) {
        packages.add(c.getContentName());
    }
    assertTrue("package javax.naming not found", packages.contains("javax.naming"));
    assertTrue("package p.q.r not found", packages.contains("p.q.r"));
    assertTrue("package x.y.z not found", packages.contains("x.y.z"));
    assertTrue("package a.b.c not found", packages.contains("a.b.c"));
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    Set<Bundle> bundles = ctx.getApplicationContent();
    assertEquals("Number of bundles provisioned in the app", 5, bundles.size());
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) ArrayList(java.util.ArrayList) DeploymentContent(org.apache.aries.application.DeploymentContent) Repository(org.apache.felix.bundlerepository.Repository) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) File(java.io.File) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with RepositoryAdmin

use of org.apache.felix.bundlerepository.RepositoryAdmin in project aries by apache.

the class OBRResolverAdvancedTest method clearRepository.

@After
public void clearRepository() {
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    Repository[] repos = repositoryAdmin.listRepositories();
    if ((repos != null) && (repos.length > 0)) {
        for (Repository repo : repos) {
            repositoryAdmin.removeRepository(repo.getURI());
        }
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) After(org.junit.After)

Example 5 with RepositoryAdmin

use of org.apache.felix.bundlerepository.RepositoryAdmin in project aries by apache.

the class OBRResolverAdvancedTest method testDemoAppResolveFail.

@Test(expected = ResolverException.class)
public void testDemoAppResolveFail() throws ResolverException, Exception {
    // do not provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
    generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + "_0.0.0.jar", USE_BUNDLE_BY_REFERENCE + ".jar");
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        repositoryAdmin.removeRepository(repo.getURI());
    }
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
    app = manager.resolve(app);
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)19 Repository (org.apache.felix.bundlerepository.Repository)15 File (java.io.File)9 AriesApplication (org.apache.aries.application.management.AriesApplication)8 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)8 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)8 Test (org.junit.Test)8 Resource (org.apache.felix.bundlerepository.Resource)7 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)5 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)3 BundleContext (org.osgi.framework.BundleContext)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ServletException (javax.servlet.ServletException)2 DeploymentContent (org.apache.aries.application.DeploymentContent)2 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)2 HelloWorld (org.apache.aries.sample.HelloWorld)2 Capability (org.apache.felix.bundlerepository.Capability)2 Resolver (org.apache.felix.bundlerepository.Resolver)2