Search in sources :

Example 16 with Repository

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;
}
Also used : Deferred(org.osgi.util.promise.Deferred) ArrayList(java.util.ArrayList) Success(org.osgi.util.promise.Success) Template(org.bndtools.templating.Template) TemplateEngine(org.bndtools.templating.TemplateEngine) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Requirement(org.osgi.resource.Requirement) Promise(org.osgi.util.promise.Promise) Repository(org.osgi.service.repository.Repository) Collection(java.util.Collection) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 17 with Repository

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;
}
Also used : Parameters(aQute.bnd.header.Parameters) Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) AggregateRepository(aQute.bnd.osgi.repository.AggregateRepository) AggregateRepository(aQute.bnd.osgi.repository.AggregateRepository) Repository(org.osgi.service.repository.Repository) AugmentRepository(aQute.bnd.osgi.repository.AugmentRepository) AugmentRepository(aQute.bnd.osgi.repository.AugmentRepository) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Example 18 with Repository

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;
}
Also used : Requirement(org.osgi.resource.Requirement) AggregateRepository(aQute.bnd.osgi.repository.AggregateRepository) Repository(org.osgi.service.repository.Repository) AugmentRepository(aQute.bnd.osgi.repository.AugmentRepository) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Collection(java.util.Collection) RequirementBuilder(aQute.bnd.osgi.resource.RequirementBuilder)

Example 19 with Repository

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;
}
Also used : Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList)

Example 20 with Repository

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);
}
Also used : Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) HostedCapability(org.osgi.service.resolver.HostedCapability) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Repository (org.osgi.service.repository.Repository)35 Requirement (org.osgi.resource.Requirement)18 Capability (org.osgi.resource.Capability)16 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)11 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)9 File (java.io.File)9 Resource (org.osgi.resource.Resource)8 Run (aQute.bnd.build.Run)5 OSGiRepository (aQute.bnd.repository.osgi.OSGiRepository)5 List (java.util.List)5 Resolver (org.osgi.service.resolver.Resolver)5 BndEditModel (aQute.bnd.build.model.BndEditModel)4 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)4 Processor (aQute.bnd.osgi.Processor)3 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 InfoRepository (aQute.bnd.service.repository.InfoRepository)3 WorkspaceR5Repository (bndtools.central.WorkspaceR5Repository)3 Map (java.util.Map)3