Search in sources :

Example 1 with Slf4jReporter

use of aQute.libg.reporter.slf4j.Slf4jReporter in project bnd by bndtools.

the class P2IndexerTest method testRefresh.

public void testRefresh() throws Exception {
    HttpClient client = new HttpClient();
    client.setCache(IO.getFile(tmp, "cache"));
    try (P2Indexer p2 = new P2Indexer(new Slf4jReporter(P2IndexerTest.class), tmp, client, new URI("http://macbadge-updates.s3.amazonaws.com"), "test")) {
        assertEquals(1, p2.versions("name.njbartlett.eclipse.macbadge").size());
        p2.refresh();
        assertEquals(1, p2.versions("name.njbartlett.eclipse.macbadge").size());
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) Slf4jReporter(aQute.libg.reporter.slf4j.Slf4jReporter) URI(java.net.URI)

Example 2 with Slf4jReporter

use of aQute.libg.reporter.slf4j.Slf4jReporter in project bnd by bndtools.

the class P2IndexerTest method testURI.

public void testURI() throws Exception {
    HttpClient client = new HttpClient();
    client.setCache(IO.getFile(tmp, "cache"));
    try (P2Indexer p2 = new P2Indexer(new Slf4jReporter(P2IndexerTest.class), tmp, client, new URI("http://macbadge-updates.s3.amazonaws.com"), "test")) {
        assertEquals("[name.njbartlett.eclipse.macbadge]", p2.list(null).toString());
        System.out.println(p2.list(null));
    }
}
Also used : HttpClient(aQute.bnd.http.HttpClient) Slf4jReporter(aQute.libg.reporter.slf4j.Slf4jReporter) URI(java.net.URI)

Example 3 with Slf4jReporter

use of aQute.libg.reporter.slf4j.Slf4jReporter 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)

Aggregations

HttpClient (aQute.bnd.http.HttpClient)3 Slf4jReporter (aQute.libg.reporter.slf4j.Slf4jReporter)3 URI (java.net.URI)2 RequirementBuilder (aQute.bnd.osgi.resource.RequirementBuilder)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 Version (aQute.bnd.version.Version)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Capability (org.osgi.resource.Capability)1 Requirement (org.osgi.resource.Requirement)1 Resource (org.osgi.resource.Resource)1 Repository (org.osgi.service.repository.Repository)1