Search in sources :

Example 26 with HttpClient

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

the class BndrunResolveContext method findAdditionalAugmentsFromResource.

private void findAdditionalAugmentsFromResource(Processor augments, Capability capability) {
    Resource resource = capability.getResource();
    Map<URI, String> locations = ResourceUtils.getLocations(resource);
    if (locations == null || locations.isEmpty())
        return;
    Object pathObject = capability.getAttributes().get("path");
    if (pathObject == null)
        pathObject = "augments.bnd";
    if (pathObject instanceof String) {
        String path = (String) pathObject;
        HttpClient http = registry.getPlugin(HttpClient.class);
        for (URI uri : locations.keySet()) try {
            logger.debug("loading augments from {}", uri);
            File file = http.build().age(24, TimeUnit.HOURS).useCache().go(uri);
            try (Jar jar = new Jar(file)) {
                aQute.bnd.osgi.Resource rs = jar.getResource(path);
                try (InputStream in = rs.openInputStream()) {
                    UTF8Properties p = new UTF8Properties();
                    p.load(in, file, project);
                    augments.getProperties().putAll(p);
                    return;
                }
            }
        } catch (Exception e) {
            project.warning("Failed to handle augment resource from repo %s", uri);
        }
    }
}
Also used : InputStream(java.io.InputStream) HttpClient(aQute.bnd.http.HttpClient) Resource(org.osgi.resource.Resource) Jar(aQute.bnd.osgi.Jar) URI(java.net.URI) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 27 with HttpClient

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

the class RemoteRepoTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    tmpName = "generated/tmp/test/" + getName();
    local = IO.getFile(tmpName + "/local");
    remote = IO.getFile(tmpName + "/remote");
    Config config = new Config();
    fnx = new FakeNexus(config, remote);
    fnx.start();
    IO.delete(remote);
    IO.delete(local);
    remote.mkdirs();
    local.mkdirs();
    reporter.setTrace(true);
    repo = new MavenRemoteRepository(local, new HttpClient(), fnx.getBaseURI() + "/repo/", reporter);
}
Also used : Config(aQute.http.testservers.HttpTestServer.Config) HttpClient(aQute.bnd.http.HttpClient)

Example 28 with HttpClient

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

the class OSGiRepositoryTest method testPollingWithFile.

public void testPollingWithFile() throws Exception {
    try (OSGiRepository r = new OSGiRepository()) {
        Map<String, String> map = new HashMap<>();
        map.put("locations", IO.getFile(remote, "minir5.xml").toURI().toString());
        map.put("cache", cache.getPath());
        map.put("max.stale", "10000");
        map.put("name", "test");
        map.put("poll.time", "1");
        r.setProperties(map);
        Processor p = new Processor();
        HttpClient httpClient = new HttpClient();
        httpClient.setCache(cache);
        httpClient.setRegistry(p);
        p.addBasicPlugin(httpClient);
        p.setBase(ws);
        p.addBasicPlugin(Workspace.createStandaloneWorkspace(p, ws.toURI()));
        r.setRegistry(p);
        final AtomicReference<RepositoryPlugin> refreshed = new AtomicReference<>();
        p.addBasicPlugin(new RepositoryListenerPlugin() {

            @Override
            public void repositoryRefreshed(RepositoryPlugin repository) {
                refreshed.set(repository);
            }

            @Override
            public void repositoriesRefreshed() {
            // TODO Auto-generated method stub
            }

            @Override
            public void bundleRemoved(RepositoryPlugin repository, Jar jar, File file) {
            // TODO Auto-generated method stub
            }

            @Override
            public void bundleAdded(RepositoryPlugin repository, Jar jar, File file) {
            // TODO Auto-generated method stub
            }
        });
        File file = r.get("dummybundle", new Version("0"), null);
        assertNotNull(file);
        Thread.sleep(3000);
        assertEquals(null, refreshed.get());
        System.out.println("1");
        // update the index file
        File index = IO.getFile(remote, "minir5.xml");
        long time = index.lastModified();
        do {
            Thread.sleep(1000);
            String s = IO.collect(index);
            // change the sha
            s += " ";
            IO.store(s, index);
            System.out.println(index.lastModified());
        } while (index.lastModified() == time);
        System.out.println("2 ");
        // give the poller a chance
        Thread.sleep(3000);
        System.out.println("3 ");
        assertEquals(r, refreshed.get());
        assertEquals("test [stale]", r.title(new Object[0]));
        System.out.println(r.tooltip(new Object[0]));
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) RepositoryListenerPlugin(aQute.bnd.service.RepositoryListenerPlugin) HashMap(java.util.HashMap) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) AtomicReference(java.util.concurrent.atomic.AtomicReference) Version(aQute.bnd.version.Version) HttpClient(aQute.bnd.http.HttpClient) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 29 with HttpClient

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

the class OSGiRepositoryTest method testBndRepo.

public void testBndRepo() throws Exception {
    try (OSGiRepository r = new OSGiRepository()) {
        Map<String, String> map = new HashMap<>();
        map.put("locations", "https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessfulBuild/artifact/dist/bundles/index.xml.gz");
        map.put("cache", cache.getPath());
        map.put("max.stale", "10000");
        r.setProperties(map);
        Processor p = new Processor();
        HttpClient httpClient = new HttpClient();
        httpClient.setCache(cache);
        httpClient.setRegistry(p);
        p.addBasicPlugin(httpClient);
        p.setBase(ws);
        p.addBasicPlugin(Workspace.createStandaloneWorkspace(p, ws.toURI()));
        r.setRegistry(p);
        final AtomicInteger tasks = new AtomicInteger();
        p.addBasicPlugin(new ProgressPlugin() {

            @Override
            public Task startTask(final String name, int size) {
                System.out.println("Starting " + name);
                tasks.incrementAndGet();
                return new Task() {

                    @Override
                    public void worked(int units) {
                        System.out.println("Worked " + name + " " + units);
                    }

                    @Override
                    public void done(String message, Throwable e) {
                        System.out.println("Done " + name + " " + message);
                    }

                    @Override
                    public boolean isCanceled() {
                        return false;
                    }
                };
            }
        });
        assertEquals(0, tasks.get());
        List<String> list = r.list(null);
        assertFalse(list.isEmpty());
        SortedSet<Version> versions = r.versions("aQute.libg");
        assertFalse(versions.isEmpty());
        File f1 = r.get("aQute.libg", versions.first(), null);
        assertNotNull(f1);
        // index + bundle
        assertEquals(2, tasks.get());
        File f2 = r.get("aQute.libg", versions.first(), null);
        // should use cache
        assertEquals(2, tasks.get());
        r.getIndex(true);
        File f3 = r.get("aQute.libg", versions.first(), null);
        // should fetch again
        assertEquals(4, tasks.get());
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Version(aQute.bnd.version.Version) HttpClient(aQute.bnd.http.HttpClient) File(java.io.File)

Example 30 with HttpClient

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

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