Search in sources :

Example 6 with ProgressPlugin

use of aQute.bnd.service.progress.ProgressPlugin in project bnd by bndtools.

the class OSGiRepositoryTest method testSimple.

public void testSimple() throws Exception {
    try (OSGiRepository r = new OSGiRepository()) {
        Map<String, String> map = new HashMap<>();
        map.put("locations", fnx.getBaseURI("/repo/minir5.xml").toString());
        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());
        File file = r.get("dummybundle", new Version("0"), null);
        assertNotNull(file);
        // 2 = index + file
        assertEquals(2, tasks.get());
        File file2 = r.get("dummybundle", new Version("0"), null);
        assertNotNull(file2);
        // second one should not have downloaded
        assertEquals(2, tasks.get());
        r.refresh();
        File file3 = r.get("dummybundle", new Version("0"), null);
        assertNotNull(file3);
        // second one should not have downloaded
        assertEquals(2, 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 7 with ProgressPlugin

use of aQute.bnd.service.progress.ProgressPlugin in project bnd by bndtools.

the class HttpClientTest method testPut.

public void testPut() throws URISyntaxException, Exception {
    try (Processor p = new Processor()) {
        final AtomicBoolean done = new AtomicBoolean();
        p.addBasicPlugin(new ProgressPlugin() {

            @Override
            public Task startTask(final String name, int size) {
                System.out.println("start " + name);
                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 + " " + e);
                        done.set(true);
                    }

                    @Override
                    public boolean isCanceled() {
                        return false;
                    }
                };
            }
        });
        try (HttpClient c = new HttpClient()) {
            c.setRegistry(p);
            TaggedData go = c.build().verb("PUT").upload("hello").asTag().go(httpServer.getBaseURI("put"));
            go.getInputStream().close();
            assertEquals(200, go.getResponseCode());
            assertTrue(done.get());
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Processor(aQute.bnd.osgi.Processor) ProgressPlugin(aQute.bnd.service.progress.ProgressPlugin) HttpClient(aQute.bnd.http.HttpClient) TaggedData(aQute.bnd.service.url.TaggedData)

Aggregations

ProgressPlugin (aQute.bnd.service.progress.ProgressPlugin)7 HttpClient (aQute.bnd.http.HttpClient)6 Processor (aQute.bnd.osgi.Processor)6 HashMap (java.util.HashMap)3 TaggedData (aQute.bnd.service.url.TaggedData)2 Version (aQute.bnd.version.Version)2 File (java.io.File)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Task (aQute.bnd.service.progress.ProgressPlugin.Task)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1