Search in sources :

Example 31 with HttpClient

use of aQute.bnd.http.HttpClient 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 HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class AgainstNexusTest method config.

void config(Map<String, String> config) throws Exception {
    if (config == null)
        config = new HashMap<>();
    config.put("local", tmpName + "/local");
    config.put("index", tmpName + "/index");
    config.put("releaseUrl", HTTP_LOCALHOST_8081);
    Processor reporter = new Processor();
    HttpClient client = new HttpClient();
    BasicAuthentication ba = new BasicAuthentication("admin", "admin123", reporter);
    client.addURLConnectionHandler(ba);
    Executor executor = Executors.newCachedThreadPool();
    reporter.addBasicPlugin(client);
    reporter.setTrace(true);
    repo = new MavenBndRepository();
    repo.setReporter(reporter);
    repo.setRegistry(reporter);
    repo.setProperties(config);
}
Also used : Processor(aQute.bnd.osgi.Processor) Executor(java.util.concurrent.Executor) HashMap(java.util.HashMap) HttpClient(aQute.bnd.http.HttpClient) BasicAuthentication(aQute.bnd.url.BasicAuthentication)

Example 33 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class PomRepositoryTest method setUp.

protected void setUp() {
    IO.delete(tmp);
    tmp.mkdirs();
    client = new HttpClient();
}
Also used : HttpClient(aQute.bnd.http.HttpClient)

Example 34 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class PomRepositoryTest method testPomTransitive.

public void testPomTransitive() throws Exception {
    MavenRepository mr = getRepo();
    Revision revision = Program.valueOf("org.apache.aries.blueprint", "org.apache.aries.blueprint.cm").version("1.0.8");
    Traverser t = new Traverser(mr, new HttpClient(), Processor.getExecutor(), true).revision(revision);
    Map<Archive, Resource> value = t.getResources().getValue();
    assertEquals(8, value.size());
    assertAllBndCap(value);
}
Also used : Archive(aQute.maven.api.Archive) MavenRepository(aQute.maven.provider.MavenRepository) Revision(aQute.maven.api.Revision) HttpClient(aQute.bnd.http.HttpClient) Resource(org.osgi.resource.Resource)

Example 35 with HttpClient

use of aQute.bnd.http.HttpClient in project bnd by bndtools.

the class PomRepositoryTest method testPomNotTransitive.

public void testPomNotTransitive() throws Exception {
    MavenRepository mr = getRepo();
    Revision revision = Program.valueOf("org.apache.aries.blueprint", "org.apache.aries.blueprint.cm").version("1.0.8");
    Traverser t = new Traverser(mr, new HttpClient(), Processor.getExecutor(), false).revision(revision);
    Map<Archive, Resource> value = t.getResources().getValue();
    assertEquals(1, value.size());
    assertAllBndCap(value);
}
Also used : Archive(aQute.maven.api.Archive) MavenRepository(aQute.maven.provider.MavenRepository) Revision(aQute.maven.api.Revision) HttpClient(aQute.bnd.http.HttpClient) Resource(org.osgi.resource.Resource)

Aggregations

HttpClient (aQute.bnd.http.HttpClient)46 TaggedData (aQute.bnd.service.url.TaggedData)18 File (java.io.File)14 Processor (aQute.bnd.osgi.Processor)13 URI (java.net.URI)9 ProgressPlugin (aQute.bnd.service.progress.ProgressPlugin)6 Version (aQute.bnd.version.Version)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HashMap (java.util.HashMap)6 ConnectionSettings (aQute.bnd.connection.settings.ConnectionSettings)5 Workspace (aQute.bnd.build.Workspace)4 ServerDTO (aQute.bnd.connection.settings.ServerDTO)4 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)4 Config (aQute.http.testservers.HttpTestServer.Config)4 Resource (org.osgi.resource.Resource)4 Jar (aQute.bnd.osgi.Jar)3 Slf4jReporter (aQute.libg.reporter.slf4j.Slf4jReporter)3 MavenRepository (aQute.maven.provider.MavenRepository)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3