Search in sources :

Example 31 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class P2IndexerTest method testFile.

public void testFile() throws Throwable {
    HttpClient client = new HttpClient();
    client.setCache(IO.getFile(tmp, "cache"));
    File input = IO.getFile("testdata/p2/macbadge");
    assertTrue("File must be dir", input.isDirectory());
    try (P2Indexer p2 = new P2Indexer(new Slf4jReporter(P2IndexerTest.class), tmp, client, input.toURI(), "test")) {
        assertEquals("[name.njbartlett.eclipse.macbadge]", p2.list(null).toString());
        System.out.println(p2.list(null));
        assertEquals("[1.0.0.201110100042]", p2.versions("name.njbartlett.eclipse.macbadge").toString());
        File f = p2.get("name.njbartlett.eclipse.macbadge", new Version("1.0.0.201110100042"), null);
        assertNotNull(f);
        assertEquals(4672, f.length());
        assertEquals(f.getName(), "name.njbartlett.eclipse.macbadge-1.0.0.201110100042.jar");
        String sha256 = SHA256.digest(f).asHex();
        Repository repository = p2.getBridge().getRepository();
        RequirementBuilder rb = new RequirementBuilder("osgi.content");
        rb.addDirective("filter", "(osgi.content~=" + sha256.toLowerCase() + ")");
        Requirement req = rb.synthetic();
        Collection<Capability> collection = repository.findProviders(Collections.singleton(req)).get(req);
        Set<Resource> resources = ResourceUtils.getResources(collection);
        assertEquals(1, resources.size());
        final AtomicReference<Throwable> result = new AtomicReference<>();
        final Semaphore sem = new Semaphore(0);
        p2.get("name.njbartlett.eclipse.macbadge", new Version("1.0.0.201110100042"), null, new RepositoryPlugin.DownloadListener() {

            @Override
            public void success(File file) throws Exception {
                try {
                } catch (Throwable e) {
                    result.set(e);
                } finally {
                    sem.release();
                }
            }

            @Override
            public void failure(File file, String reason) throws Exception {
                try {
                    fail(reason);
                } catch (Throwable e) {
                    result.set(e);
                } finally {
                    sem.release();
                }
            }

            @Override
            public boolean progress(File file, int percentage) throws Exception {
                return true;
            }
        });
        sem.acquire();
        if (result.get() != null)
            throw result.get();
    } catch (InvocationTargetException ite) {
        ite.getTargetException().printStackTrace();
        throw ite.getTargetException();
    }
    try (P2Indexer p3 = new P2Indexer(new Slf4jReporter(P2IndexerTest.class), tmp, client, input.toURI(), "test")) {
        File f = p3.get("name.njbartlett.eclipse.macbadge", new Version("1.0.0.201110100042"), null);
        assertNotNull(f);
        assertEquals(4672, f.length());
        assertEquals(f.getName(), "name.njbartlett.eclipse.macbadge-1.0.0.201110100042.jar");
    }
}
Also used : Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) Version(aQute.bnd.version.Version) HttpClient(aQute.bnd.http.HttpClient) Slf4jReporter(aQute.libg.reporter.slf4j.Slf4jReporter) File(java.io.File)

Example 32 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class JpmRepoTest method testScr.

public void testScr() {
    Repository repo = ws.getPlugin(Repository.class);
    BndEditModel model = new BndEditModel();
    model.setRunFw("org.apache.felix.framework");
    List<Requirement> requires = new ArrayList<Requirement>();
    CapReqBuilder capReq = CapReqBuilder.createSimpleRequirement("osgi.extender", "osgi.component", "[1.1,2)");
    requires.add(capReq.buildSyntheticRequirement());
    Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
    assertNotNull(shell);
    assertEquals(1, shell.size());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) InfoRepository(aQute.bnd.service.repository.InfoRepository) Repository(org.osgi.service.repository.Repository) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 33 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class StandaloneTest method testMacroExpansion.

public void testMacroExpansion() throws Exception {
    File f = IO.getFile("testdata/standalone/macro.bndrun");
    Run run = Run.createRun(null, f);
    List<Repository> repositories = run.getWorkspace().getPlugins(Repository.class);
    assertEquals(1, repositories.size());
    assertTrue(repositories.get(0) instanceof OSGiRepository);
    OSGiRepository f0 = (OSGiRepository) repositories.get(0);
    assertEquals(System.getProperty("user.name") + " M2", f0.getName());
    File indexFile = IO.getFile(System.getProperty("user.home") + "/.m2/repository/repository.xml");
    assertEquals(indexFile.toURI().toString(), f0.getLocation());
}
Also used : OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Repository(org.osgi.service.repository.Repository) OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Run(aQute.bnd.build.Run) File(java.io.File)

Example 34 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class StandaloneTest method testRelativeUrl.

public void testRelativeUrl() throws Exception {
    File f = IO.getFile("testdata/standalone/relative_url.bndrun");
    Run run = Run.createRun(null, f);
    List<Repository> repositories = run.getWorkspace().getPlugins(Repository.class);
    assertEquals(2, repositories.size());
    assertTrue(repositories.get(0) instanceof OSGiRepository);
    assertTrue(repositories.get(1) instanceof OSGiRepository);
    OSGiRepository f0 = (OSGiRepository) repositories.get(0);
    assertEquals("repo01", f0.getName());
    String resolvedUrl = IO.getFile("testdata/larger-repo.xml").toURI().toString();
    assertEquals(resolvedUrl, f0.getLocation());
    OSGiRepository f1 = (OSGiRepository) repositories.get(1);
    assertEquals("repo02", f1.getName());
    assertEquals("http://example.org/index2.xml", f1.getLocation());
}
Also used : OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Repository(org.osgi.service.repository.Repository) OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Run(aQute.bnd.build.Run) File(java.io.File)

Example 35 with Repository

use of org.osgi.service.repository.Repository in project bnd by bndtools.

the class StandaloneTest method testMultipleUrls.

public void testMultipleUrls() throws Exception {
    File f = IO.getFile("testdata/standalone/multi.bndrun");
    Run run = Run.createRun(null, f);
    List<Repository> repositories = run.getWorkspace().getPlugins(Repository.class);
    assertEquals(2, repositories.size());
    assertTrue(repositories.get(0) instanceof OSGiRepository);
    assertTrue(repositories.get(1) instanceof OSGiRepository);
    OSGiRepository f0 = (OSGiRepository) repositories.get(0);
    assertEquals("repo01", f0.getName());
    assertEquals("http://example.org/index1.xml", f0.getLocation());
    OSGiRepository f1 = (OSGiRepository) repositories.get(1);
    assertEquals("second", f1.getName());
    assertEquals("http://example.org/index2.xml", f1.getLocation());
}
Also used : OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Repository(org.osgi.service.repository.Repository) OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Run(aQute.bnd.build.Run) File(java.io.File)

Aggregations

Repository (org.osgi.service.repository.Repository)35 Requirement (org.osgi.resource.Requirement)18 Capability (org.osgi.resource.Capability)16 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)11 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)9 File (java.io.File)9 Resource (org.osgi.resource.Resource)8 Run (aQute.bnd.build.Run)5 OSGiRepository (aQute.bnd.repository.osgi.OSGiRepository)5 List (java.util.List)5 Resolver (org.osgi.service.resolver.Resolver)5 BndEditModel (aQute.bnd.build.model.BndEditModel)4 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)4 Processor (aQute.bnd.osgi.Processor)3 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 InfoRepository (aQute.bnd.service.repository.InfoRepository)3 WorkspaceR5Repository (bndtools.central.WorkspaceR5Repository)3 Map (java.util.Map)3