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());
}
}
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());
}
}
}
Aggregations