use of org.osgi.service.repository.Repository 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");
}
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class JpmRepoTest method testScr.
public void testScr() {
Repository repo = ws.getPlugin(Repository.class);
BndEditModel model = new BndEditModel();
model.setRunFw("org.apache.felix.framework");
List<Requirement> requires = new ArrayList<Requirement>();
CapReqBuilder capReq = CapReqBuilder.createSimpleRequirement("osgi.extender", "osgi.component", "[1.1,2)");
requires.add(capReq.buildSyntheticRequirement());
Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
assertNotNull(shell);
assertEquals(1, shell.size());
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class StandaloneTest method testMacroExpansion.
public void testMacroExpansion() throws Exception {
File f = IO.getFile("testdata/standalone/macro.bndrun");
Run run = Run.createRun(null, f);
List<Repository> repositories = run.getWorkspace().getPlugins(Repository.class);
assertEquals(1, repositories.size());
assertTrue(repositories.get(0) instanceof OSGiRepository);
OSGiRepository f0 = (OSGiRepository) repositories.get(0);
assertEquals(System.getProperty("user.name") + " M2", f0.getName());
File indexFile = IO.getFile(System.getProperty("user.home") + "/.m2/repository/repository.xml");
assertEquals(indexFile.toURI().toString(), f0.getLocation());
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class StandaloneTest method testRelativeUrl.
public void testRelativeUrl() throws Exception {
File f = IO.getFile("testdata/standalone/relative_url.bndrun");
Run run = Run.createRun(null, f);
List<Repository> repositories = run.getWorkspace().getPlugins(Repository.class);
assertEquals(2, repositories.size());
assertTrue(repositories.get(0) instanceof OSGiRepository);
assertTrue(repositories.get(1) instanceof OSGiRepository);
OSGiRepository f0 = (OSGiRepository) repositories.get(0);
assertEquals("repo01", f0.getName());
String resolvedUrl = IO.getFile("testdata/larger-repo.xml").toURI().toString();
assertEquals(resolvedUrl, f0.getLocation());
OSGiRepository f1 = (OSGiRepository) repositories.get(1);
assertEquals("repo02", f1.getName());
assertEquals("http://example.org/index2.xml", f1.getLocation());
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class StandaloneTest method testMultipleUrls.
public void testMultipleUrls() throws Exception {
File f = IO.getFile("testdata/standalone/multi.bndrun");
Run run = Run.createRun(null, f);
List<Repository> repositories = run.getWorkspace().getPlugins(Repository.class);
assertEquals(2, repositories.size());
assertTrue(repositories.get(0) instanceof OSGiRepository);
assertTrue(repositories.get(1) instanceof OSGiRepository);
OSGiRepository f0 = (OSGiRepository) repositories.get(0);
assertEquals("repo01", f0.getName());
assertEquals("http://example.org/index1.xml", f0.getLocation());
OSGiRepository f1 = (OSGiRepository) repositories.get(1);
assertEquals("second", f1.getName());
assertEquals("http://example.org/index2.xml", f1.getLocation());
}
Aggregations