Search in sources :

Example 11 with Repository

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

the class Aries1523Test method createRepositoryXml.

private URL createRepositoryXml(DataModelHelper helper) throws Exception {
    File dir;
    String cwd = new File("").getAbsolutePath();
    if (cwd.endsWith(File.separator + "target")) {
        dir = new File("test-classes/aries1523");
    } else {
        dir = new File("target/test-classes/aries1523");
    }
    File jar = new File(dir, "aries1523host.jar");
    assertTrue("The host jar does not exist: " + jar.getAbsolutePath(), jar.exists());
    Resource resource = helper.createResource(jar.toURI().toURL());
    Repository repository = helper.repository(new Resource[] { resource });
    File file = new File(dir, "repository.xml");
    FileWriter fw = new FileWriter(file);
    try {
        helper.writeRepository(repository, fw);
        return file.toURI().toURL();
    } finally {
        fw.close();
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) FileWriter(java.io.FileWriter) Resource(org.apache.felix.bundlerepository.Resource) File(java.io.File)

Example 12 with Repository

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

the class OBRAriesResolver method getConfiguredObrResolver.

private Resolver getConfiguredObrResolver(String appName, String appVersion, Collection<ModelledResource> byValueBundles, boolean noExtraRepositories) throws ResolverException {
    log.debug(LOG_ENTRY, "getConfiguredObrResolver", new Object[] { appName, appVersion, byValueBundles });
    DataModelHelper helper = repositoryAdmin.getHelper();
    Repository appRepo;
    try {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        RepositoryGeneratorImpl.generateRepository(repositoryAdmin, appName + "_" + appVersion, byValueBundles, bytesOut);
        appRepo = helper.readRepository(new InputStreamReader(new ByteArrayInputStream(bytesOut.toByteArray())));
    } catch (Exception e) {
        throw new ResolverException(e);
    }
    List<Repository> resolveRepos = new ArrayList<Repository>();
    // add system repository
    resolveRepos.add(repositoryAdmin.getSystemRepository());
    // add application repository
    resolveRepos.add(appRepo);
    if (!!!noExtraRepositories) {
        // add local repository if configured
        if (!(excludeLocalRuntime())) {
            resolveRepos.add(getLocalRepository(repositoryAdmin));
        }
        // Need to refresh the repositories added to repository admin 
        // add user-defined repositories
        Repository[] repos = repositoryAdmin.listRepositories();
        for (Repository r : repos) {
            resolveRepos.add(r);
        }
    }
    Resolver obrResolver = repositoryAdmin.resolver(resolveRepos.toArray(new Repository[resolveRepos.size()]));
    addPlatformRepositories(obrResolver, appName, platformRepository);
    log.debug(LOG_EXIT, "getConfiguredObrResolver", obrResolver);
    return obrResolver;
}
Also used : PlatformRepository(org.apache.aries.application.management.spi.repository.PlatformRepository) Repository(org.apache.felix.bundlerepository.Repository) ResolverException(org.apache.aries.application.management.ResolverException) InputStreamReader(java.io.InputStreamReader) Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResolverException(org.apache.aries.application.management.ResolverException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException)

Example 13 with Repository

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

the class ObrCommandSupport method persistRepositoryList.

protected void persistRepositoryList(RepositoryAdmin admin) {
    try {
        StringBuilder sb = new StringBuilder();
        for (Repository repo : admin.listRepositories()) {
            if (sb.length() > 0) {
                sb.append(" ");
            }
            sb.append(repo.getURI());
        }
        File etc = new File(System.getProperty("karaf.etc"));
        File sys = new File(etc, "config.properties");
        File sysTmp = new File(etc, "config.properties.tmp");
        boolean modified = false;
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sysTmp)))) {
            if (sys.exists()) {
                try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(sys)))) {
                    String line = reader.readLine();
                    while (line != null) {
                        if (line.matches("obr\\.repository\\.url[:= ].*")) {
                            modified = true;
                            line = "obr.repository.url = " + sb.toString();
                        }
                        writer.write(line);
                        writer.newLine();
                        line = reader.readLine();
                    }
                }
            }
            if (!modified) {
                writer.newLine();
                writer.write("# ");
                writer.newLine();
                writer.write("# OBR Repository list");
                writer.newLine();
                writer.write("# ");
                writer.newLine();
                writer.write("obr.repository.url = " + sb.toString());
                writer.newLine();
                writer.newLine();
            }
        }
        sys.delete();
        sysTmp.renameTo(sys);
    } catch (Exception e) {
        System.err.println("Error while persisting repository list");
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BufferedWriter(java.io.BufferedWriter)

Example 14 with Repository

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

the class MinimumImportsTest method testAppUsingAriesApplicationManager.

@Test
public void testAppUsingAriesApplicationManager() throws Exception {
    // Register a BlueprintListener to listen for the events from the BlueprintContainer for the bundle in the appmgrclienttest.eba
    AppMgrClientBlueprintListener acbl = new AppMgrClientBlueprintListener();
    ServiceRegistration sr = bundleContext.registerService("org.osgi.service.blueprint.container.BlueprintListener", acbl, null);
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("appmgrclienttest.eba")));
    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());
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    int sleepfor = 3000;
    while ((acbl.success == null || acbl.success == false) && sleepfor > 0) {
        Thread.sleep(100);
        sleepfor -= 100;
    }
    assertNotNull("Timed out - didn't receive Blueprint CREATED or FAILURE event", acbl.success);
    assertTrue("Received Blueprint FAILURE event", acbl.success);
    ctx.stop();
    manager.uninstall(ctx);
    sr.unregister();
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 15 with Repository

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

the class OBRAppManagerTest method testAppWithApplicationManifest.

@Test
public void testAppWithApplicationManifest() throws Exception {
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        Resource[] resources = repo.getResources();
        for (Resource r : resources) {
            Capability[] cs = r.getCapabilities();
            for (Capability c : cs) {
                System.out.println(c.getName() + " : " + c.getProperties());
            }
        }
    }
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
    app = manager.resolve(app);
    //installing requires a valid url for the bundle in repository.xml.
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    HelloWorld hw = context().getService(HelloWorld.class);
    String result = hw.getMessage();
    assertEquals(result, "hello world");
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Capability(org.apache.felix.bundlerepository.Capability) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) Resource(org.apache.felix.bundlerepository.Resource) AriesApplication(org.apache.aries.application.management.AriesApplication) HelloWorld(org.apache.aries.sample.HelloWorld) Repository(org.apache.felix.bundlerepository.Repository) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) File(java.io.File) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Aggregations

Repository (org.apache.felix.bundlerepository.Repository)24 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)13 File (java.io.File)12 Resource (org.apache.felix.bundlerepository.Resource)10 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 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)5 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)5 ArrayList (java.util.ArrayList)4 FileWriter (java.io.FileWriter)3 InputStreamReader (java.io.InputStreamReader)3 PlatformRepository (org.apache.aries.application.management.spi.repository.PlatformRepository)3 BundleContext (org.osgi.framework.BundleContext)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Content (org.apache.aries.application.Content)2 DeploymentContent (org.apache.aries.application.DeploymentContent)2 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)2