Search in sources :

Example 6 with Repository

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

the class OBRResolverTest method testProvisionExcludeLocalRepo.

/**
     * Test the resolution should fail because the required package org.apache.aries.util is provided by the local runtime,
     * which is not included when provisioning.
     *
     * @throws Exception
     */
@Test(expected = ResolverException.class)
public void testProvisionExcludeLocalRepo() throws Exception {
    // do not provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
    generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_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("blog.eba")));
    //installing requires a valid url for the bundle in repository.xml.
    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) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 7 with Repository

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

the class OBRResolverTest method testBlogAppResolveFail.

@Test(expected = ResolverException.class)
public void testBlogAppResolveFail() throws ResolverException, Exception {
    //  provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
    generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + "_0.0.0.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("blog.eba")));
    //installing requires a valid url for the bundle in repository.xml.
    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) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 8 with Repository

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

the class OBRResolverTest 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 9 with Repository

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

the class RepositoryGenerator method find.

/**
     * the format of resource is like bundlesymbolicname;version=1.0.0, for example com.ibm.ws.eba.example.blog.api;version=1.0.0,
     */
@SuppressWarnings({ "rawtypes", "unused" })
public Resource find(String resource) throws SubsystemException {
    generateOBR();
    Content content = new ContentImpl(resource);
    String symbolicName = content.getContentName();
    // this version could possibly be a range
    String version = content.getVersion().toString();
    StringBuilder filterString = new StringBuilder();
    filterString.append("(&(name" + "=" + symbolicName + "))");
    filterString.append("(version" + "=" + version + "))");
    //org.apache.felix.bundlerepository.Resource[] res = this.repositoryAdmin.discoverResources(filterString.toString());
    Repository[] repos = this.repositoryAdmin.listRepositories();
    org.apache.felix.bundlerepository.Resource res = null;
    for (Repository repo : repos) {
        org.apache.felix.bundlerepository.Resource[] resources = repo.getResources();
        for (int i = 0; i < resources.length; i++) {
            if (resources[i].getSymbolicName().equals(symbolicName)) {
                if (resources[i].getVersion().compareTo(new Version(version)) == 0) {
                    res = resources[i];
                    break;
                }
            }
        }
    }
    if (res == null) {
        //            throw new SubsystemException("unable to find the resource " + resource);
        return null;
    }
    Map props = res.getProperties();
    Object type = props.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
    return new FelixResourceAdapter(res);
}
Also used : Resource(org.osgi.resource.Resource) FelixResourceAdapter(org.apache.aries.subsystem.util.felix.FelixResourceAdapter) Repository(org.apache.felix.bundlerepository.Repository) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) Map(java.util.Map)

Example 10 with Repository

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

the class Aries1608Test 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/aries1608");
    } else {
        dir = new File("target/test-classes/aries1608");
    }
    File jar = new File(dir, "aries1608provider.jar");
    assertTrue("The bundle 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)

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