use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class DebugReporter method doRepos.
private void doRepos() {
header("OSGi REPOSITORIES");
for (Repository repo : context.getRepositories()) {
out.printf("%s%n", repo.toString());
}
nl();
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class XMLResourceGeneratorTest method testBasic.
public void testBasic() throws URISyntaxException, Exception {
Repository repository = getTestRepository();
File location = new File(tmp, "index.xml");
new XMLResourceGenerator().name("test").repository(repository).save(location);
Repository other = getRepository(location.toURI());
Map<Requirement, Collection<Capability>> findProviders = other.findProviders(Collections.singleton(WILDCARD));
Set<Resource> resources = ResourceUtils.getResources(findProviders.get(WILDCARD));
assertEquals(1, resources.size());
Resource r = resources.iterator().next();
assertEquals("http://macbadge-updates.s3.amazonaws.com/plugins/name.njbartlett.eclipse.macbadge_1.0.0.201110100042.jar", ResourceUtils.getContentCapability(r).url().toString());
}
use of org.osgi.service.repository.Repository in project bndtools by bndtools.
the class RepositoryTreeContentProvider method getRepositoryBundles.
Object[] getRepositoryBundles(final RepositoryPlugin repoPlugin) {
Object[] result = null;
if (requirementFilter != null) {
if (repoPlugin instanceof Repository) {
result = searchR5Repository(repoPlugin, (Repository) repoPlugin);
} else if (repoPlugin instanceof WorkspaceRepository) {
try {
WorkspaceR5Repository workspaceRepo = Central.getWorkspaceR5Repository();
result = searchR5Repository(repoPlugin, workspaceRepo);
} catch (Exception e) {
logger.logError("Error querying workspace repository", e);
}
}
return result;
}
/*
* We can't directly call repoPlugin.list() since we are on the UI thread
* so the plan is to first check to see if we have cached the list results
* already from a previous job, if so, return those results directly
* If not, then we need to create a background job that will call list()
* and once it is finished, we tell the Viewer to refresh this node and the
* next time this method gets called the 'results' will be available in the cache
*/
Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
if (listResults == null) {
listResults = new HashMap<>();
repoPluginListResults.put(repoPlugin, listResults);
}
result = listResults.get(wildcardFilter);
if (result == null) {
Job job = new Job("Loading " + repoPlugin.getName() + " content...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
Object[] jobresult;
List<String> bsns = null;
try {
bsns = repoPlugin.list(wildcardFilter);
} catch (Exception e) {
String message = MessageFormat.format("Error querying repository {0}.", repoPlugin.getName());
logger.logError(message, e);
status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, message, e);
}
if (bsns != null) {
Collections.sort(bsns);
jobresult = new RepositoryBundle[bsns.size()];
int i = 0;
for (String bsn : bsns) {
jobresult[i++] = new RepositoryBundle(repoPlugin, bsn);
}
Map<String, Object[]> listResults = repoPluginListResults.get(repoPlugin);
listResults.put(wildcardFilter, jobresult);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
structuredViewer.refresh(repoPlugin, true);
}
});
}
return status;
}
};
job.schedule();
// wait 100 ms and see if the job will complete fast (likely already cached)
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
IStatus status = job.getResult();
if (status != null && status.isOK()) {
Map<String, Object[]> fastResults = repoPluginListResults.get(repoPlugin);
result = fastResults.get(wildcardFilter);
} else {
Object[] loading = new Object[] { new LoadingContentElement() };
listResults.put(wildcardFilter, loading);
result = loading;
}
}
return result;
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class JpmRepoTest method testSimpleResolve.
// public void testResolveProviderWithRunpath() throws Exception {
// try {
// Project provider = ws.getProject("provider");
// provider.build();
// assertTrue(provider.check());
//
// Project requirer = ws.getProject("requirer");
// requirer.build();
// assertTrue(requirer.check());
//
// BndEditModel model = new BndEditModel();
// model.setProject(requirer);
// BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
//
// Resolver resolver = new ResolverImpl(new
// org.apache.felix.resolver.Logger(4), null);
//
// Map<Resource,List<Wire>> resolved = resolver.resolve(context);
// Set<Resource> resources = resolved.keySet();
// Resource resource = getResource(resources, "requirer", "0");
// assertNotNull(resource);
// }
// catch (ResolutionException e) {
// fail("Resolve failed " + e);
// }
// }
public void testSimpleResolve() {
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.createBundleRequirement("org.apache.felix.gogo.shell", "[0,1)");
requires.add(capReq.buildSyntheticRequirement());
Map<Requirement, Collection<Capability>> shell = repo.findProviders(requires);
assertNotNull(shell);
assertEquals(1, shell.size());
model.setRunRequires(requires);
BndrunResolveContext context = new BndrunResolveContext(model, ws, log);
Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
try {
Map<Resource, List<Wire>> resolved = resolver.resolve(context);
Set<Resource> resources = resolved.keySet();
Resource resource = getResource(resources, "org.apache.felix.gogo.runtime", "0.12");
assertNotNull(resource);
} catch (ResolutionException e) {
fail("Resolve failed");
}
}
use of org.osgi.service.repository.Repository in project aries by apache.
the class RepositoryServiceRepository method findProviders.
@SuppressWarnings("unchecked")
public Collection<Capability> findProviders(Requirement requirement) {
Set<Capability> result = new HashSet<Capability>();
ServiceReference<?>[] references;
try {
references = context.getAllServiceReferences("org.osgi.service.repository.Repository", null);
if (references == null)
return result;
} catch (InvalidSyntaxException e) {
throw new IllegalStateException(e);
}
for (ServiceReference<?> reference : references) {
Object repository = context.getService(reference);
if (repository == null)
continue;
try {
// Reflection is used here to allow the service to work with a mixture of
// Repository services implementing different versions of the API.
Class<?> clazz = repository.getClass();
Class<?> repoInterface = null;
while (clazz != null && repoInterface == null) {
for (Class<?> intf : clazz.getInterfaces()) {
if (Repository.class.getName().equals(intf.getName())) {
// Compare interfaces by name so that we can work with different versions of the
// interface.
repoInterface = intf;
break;
}
}
clazz = clazz.getSuperclass();
}
if (repoInterface == null) {
continue;
}
Map<Requirement, Collection<Capability>> map;
try {
Method method = repoInterface.getMethod("findProviders", Collection.class);
map = (Map<Requirement, Collection<Capability>>) method.invoke(repository, Collections.singleton(requirement));
} catch (Exception e) {
throw new SubsystemException(e);
}
Collection<Capability> capabilities = map.get(requirement);
if (capabilities == null)
continue;
result.addAll(capabilities);
} finally {
context.ungetService(reference);
}
}
return result;
}
Aggregations