use of org.osgi.service.repository.Repository in project bndtools by bndtools.
the class ReposTemplateLoader method findTemplates.
@Override
public Promise<List<Template>> findTemplates(String templateType, final Reporter reporter) {
String filterStr = String.format("(%s=%s)", NS_TEMPLATE, templateType);
final Requirement requirement = new CapReqBuilder(NS_TEMPLATE).addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filterStr).buildSyntheticRequirement();
// Try to get the repositories and BundleLocator from the workspace
List<Repository> workspaceRepos;
BundleLocator tmpLocator;
try {
if (workspace == null)
workspace = Central.getWorkspace();
workspaceRepos = workspace.getPlugins(Repository.class);
tmpLocator = new RepoPluginsBundleLocator(workspace.getRepositories());
} catch (Exception e) {
workspaceRepos = Collections.emptyList();
tmpLocator = new DirectDownloadBundleLocator();
}
final BundleLocator locator = tmpLocator;
// Setup the repos
List<Repository> repos = new ArrayList<>(workspaceRepos.size() + 1);
repos.addAll(workspaceRepos);
addPreferenceConfiguredRepos(repos, reporter);
// Generate a Promise<List<Template>> for each repository and add to an accumulator
Promise<List<Template>> accumulator = Promises.resolved((List<Template>) new LinkedList<Template>());
for (final Repository repo : repos) {
final Deferred<List<Template>> deferred = new Deferred<>();
final Promise<List<Template>> current = deferred.getPromise();
accumulator = accumulator.then(new Success<List<Template>, List<Template>>() {
@Override
public Promise<List<Template>> call(Promise<List<Template>> resolved) throws Exception {
final List<Template> prefix = resolved.getValue();
return current.map(new Function<List<Template>, List<Template>>() {
@Override
public List<Template> apply(List<Template> t) {
return CollectionUtils.append(prefix, t);
}
});
}
});
executor.submit(new Runnable() {
@Override
public void run() {
List<Template> templates = new LinkedList<>();
Map<Requirement, Collection<Capability>> providerMap = repo.findProviders(Collections.singleton(requirement));
if (providerMap != null) {
Collection<Capability> candidates = providerMap.get(requirement);
if (candidates != null) {
for (Capability cap : candidates) {
IdentityCapability idcap = ResourceUtils.getIdentityCapability(cap.getResource());
Object id = idcap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
Object ver = idcap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
try {
String engineName = (String) cap.getAttributes().get("engine");
if (engineName == null)
engineName = "stringtemplate";
TemplateEngine engine = engines.get(engineName);
if (engine != null)
templates.add(new CapabilityBasedTemplate(cap, locator, engine));
else
reporter.error("Error loading template from resource '%s' version %s: no Template Engine available matching '%s'", id, ver, engineName);
} catch (Exception e) {
reporter.error("Error loading template from resource '%s' version %s: %s", id, ver, e.getMessage());
}
}
}
}
deferred.resolve(templates);
}
});
}
return accumulator;
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class BndrunResolveContext method loadRepositories.
/**
* Load all the OSGi repositories from our registry
* <p>
* TODO Use Instruction ...
*
* @return
* @throws Exception
*/
private Processor loadRepositories() throws Exception {
//
// Get all of the repositories from the plugin registry
//
List<Repository> allRepos = registry.getPlugins(Repository.class);
Collection<Repository> orderedRepositories;
String rn = properties.mergeProperties(Constants.RUNREPOS);
if (rn == null) {
//
// No filter set, so we use all
//
orderedRepositories = allRepos;
} else {
Parameters repoNames = new Parameters(rn, project);
// Map the repository names...
Map<String, Repository> repoNameMap = new HashMap<String, Repository>(allRepos.size());
for (Repository repo : allRepos) {
String name;
if (repo instanceof aQute.bnd.deployer.repository.wrapper.Plugin) {
@SuppressWarnings("resource") aQute.bnd.deployer.repository.wrapper.Plugin wrapper = (aQute.bnd.deployer.repository.wrapper.Plugin) repo;
wrapper.init();
name = wrapper.toString();
} else if (repo instanceof RepositoryPlugin) {
name = ((RepositoryPlugin) repo).getName();
} else {
name = repo.toString();
}
repoNameMap.put(name, repo);
}
// Create the result list
orderedRepositories = new ArrayList<>();
for (String repoName : repoNames.keySet()) {
Repository repo = repoNameMap.get(repoName);
if (repo != null)
orderedRepositories.add(repo);
}
}
Processor repositoryAugments = findRepositoryAugments(orderedRepositories);
Parameters augments = new Parameters(repositoryAugments.mergeProperties(Constants.AUGMENT), project);
augments.putAll(new Parameters(properties.mergeProperties(Constants.AUGMENT), project));
if (!augments.isEmpty()) {
AggregateRepository aggregate = new AggregateRepository(orderedRepositories);
AugmentRepository augment = new AugmentRepository(augments, aggregate);
orderedRepositories = Collections.singleton((Repository) augment);
}
for (Repository repository : orderedRepositories) {
super.addRepository(repository);
}
return repositoryAugments;
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class BndrunResolveContext method findRepositoryAugments.
private Processor findRepositoryAugments(Collection<Repository> orderedRepositories) {
Processor main = new Processor();
RequirementBuilder rb = new RequirementBuilder(BND_AUGMENT);
rb.filter("(path=*)");
Requirement req = rb.buildSyntheticRequirement();
for (Repository r : orderedRepositories) {
Map<Requirement, Collection<Capability>> found = r.findProviders(Collections.singleton(req));
Collection<Capability> capabilities = found.get(req);
if (capabilities != null) {
for (Capability capability : capabilities) {
findAdditionalAugmentsFromResource(main, capability);
}
}
}
return main;
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class AbstractResolveContext method findProvidersFromRepositories.
protected ArrayList<Capability> findProvidersFromRepositories(Requirement requirement, LinkedHashSet<Capability> existingWiredCapabilities) {
// Second stage results: repository contents; may be reordered.
ArrayList<Capability> secondStageResult = new ArrayList<Capability>();
// Iterate over the repos
int order = 0;
ArrayList<Capability> repoCapabilities = new ArrayList<Capability>();
for (Repository repo : repositories) {
repoCapabilities.clear();
Collection<Capability> capabilities = findProviders(repo, requirement);
if (capabilities != null && !capabilities.isEmpty()) {
repoCapabilities.ensureCapacity(capabilities.size());
for (Capability capability : capabilities) {
if (isPermitted(capability.getResource()) && isCorrectEffectiveness(requirement, capability)) {
repoCapabilities.add(capability);
setResourcePriority(order, capability.getResource());
}
}
secondStageResult.addAll(repoCapabilities);
}
order++;
}
Collections.sort(secondStageResult, capabilityComparator);
// Convert second-stage results to a list and post-process
ArrayList<Capability> secondStageList = new ArrayList<Capability>(secondStageResult);
// Post-processing second stage results
postProcessProviders(requirement, existingWiredCapabilities, secondStageList);
return secondStageList;
}
use of org.osgi.service.repository.Repository in project bnd by bndtools.
the class AbstractResolveContext method getResources.
public List<Resource> getResources(List<Repository> repos, Requirement req) {
Set<Resource> resources = new HashSet<Resource>();
for (Repository repo : repos) {
Collection<Capability> providers = findProviders(repo, req);
resources.addAll(ResourceUtils.getResources(providers));
}
return new ArrayList<>(resources);
}
Aggregations