Search in sources :

Example 11 with Resource

use of org.apache.felix.bundlerepository.Resource in project felix by apache.

the class RepositoryAdminImpl method discoverResources.

public synchronized Resource[] discoverResources(Requirement[] requirements) {
    initialize();
    Resource[] resources = null;
    Repository[] repos = listRepositories();
    List matchList = new ArrayList();
    for (int repoIdx = 0; (repos != null) && (repoIdx < repos.length); repoIdx++) {
        resources = repos[repoIdx].getResources();
        for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
            boolean match = true;
            for (int reqIdx = 0; (requirements != null) && (reqIdx < requirements.length); reqIdx++) {
                boolean reqMatch = false;
                Capability[] caps = resources[resIdx].getCapabilities();
                for (int capIdx = 0; (caps != null) && (capIdx < caps.length); capIdx++) {
                    if (requirements[reqIdx].isSatisfied(caps[capIdx])) {
                        reqMatch = true;
                        break;
                    }
                }
                match &= reqMatch;
                if (!match) {
                    break;
                }
            }
            if (match) {
                matchList.add(resources[resIdx]);
            }
        }
    }
    // Convert matching resources to an array an sort them by name.
    resources = (Resource[]) matchList.toArray(new Resource[matchList.size()]);
    Arrays.sort(resources, m_nameComparator);
    return resources;
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Capability(org.apache.felix.bundlerepository.Capability) Resource(org.apache.felix.bundlerepository.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with Resource

use of org.apache.felix.bundlerepository.Resource in project felix by apache.

the class RepositoryAdminImpl method discoverResources.

public synchronized Resource[] discoverResources(String filterExpr) throws InvalidSyntaxException {
    initialize();
    Filter filter = filterExpr != null ? m_helper.filter(filterExpr) : null;
    Resource[] resources;
    MapToDictionary dict = new MapToDictionary(null);
    Repository[] repos = listRepositories();
    List matchList = new ArrayList();
    for (int repoIdx = 0; (repos != null) && (repoIdx < repos.length); repoIdx++) {
        resources = repos[repoIdx].getResources();
        for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
            dict.setSourceMap(resources[resIdx].getProperties());
            if (filter == null || filter.match(dict)) {
                matchList.add(resources[resIdx]);
            }
        }
    }
    // Convert matching resources to an array an sort them by name.
    resources = (Resource[]) matchList.toArray(new Resource[matchList.size()]);
    Arrays.sort(resources, m_nameComparator);
    return resources;
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Filter(org.osgi.framework.Filter) Resource(org.apache.felix.bundlerepository.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MapToDictionary(org.apache.felix.utils.collections.MapToDictionary)

Example 13 with Resource

use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.

the class ObrAddonSearchOperationsImpl method populateBundleCache.

/**
 * Method to populate current Bundles on installed repositories
 */
private void populateBundleCache() {
    // Refreshing Repositories
    populateRepositories();
    // Cleaning Bundle Cache
    bundleCache.clear();
    for (Repository repo : repositories) {
        Resource[] repoResources = repo.getResources();
        for (Resource repoResource : repoResources) {
            // Creating bundle of current resource
            ObrBundle bundle = new ObrBundle(repoResource.getSymbolicName(), repoResource.getPresentationName(), repoResource.getSize(), repoResource.getVersion(), repoResource.getURI());
            // Getting Resource Capabilites
            Capability[] resourceCapabilities = repoResource.getCapabilities();
            for (Capability capability : resourceCapabilities) {
                // Getting resource commands
                if (capability.getName().equals(CAPABILITY_COMMANDS_NAME) || capability.getName().equals(CAPABILITY_JDBCDRIVER_NAME) || capability.getName().equals(CAPABILITY_LIBRARY_NAME)) {
                    // Getting all resource properties
                    Map<String, Object> capabilityProperties = capability.getPropertiesAsMap();
                    for (Entry capabilityProperty : capabilityProperties.entrySet()) {
                        String capabilityCommand = (String) capabilityProperty.getValue();
                        bundle.addCommand(capabilityCommand);
                    }
                    bundleCache.put(bundle.getSymbolicName(), bundle);
                }
            }
        }
    }
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Entry(java.util.Map.Entry) Capability(org.apache.felix.bundlerepository.Capability) Resource(org.apache.felix.bundlerepository.Resource) ObrBundle(org.springframework.roo.obr.addon.search.model.ObrBundle)

Example 14 with Resource

use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.

the class ObrRepositoryOperationsImpl method introspectRepos.

@Override
public void introspectRepos() throws Exception {
    LOGGER.log(Level.INFO, "Getting available bundles on installed repositories...");
    // Populating repositories
    populateRepositories();
    LOGGER.log(Level.INFO, "");
    // Getting all names of installed bundles
    List<String> installedBundles = getNamesOfInstalledBundles();
    // Getting all addons installed on repositories
    int totalAddons = 0;
    LOGGER.log(Level.INFO, "Status               Bundle Description and version");
    LOGGER.log(Level.INFO, "-------------------------------------------------------------------------------");
    for (Repository repo : repositories) {
        Resource[] allResources = repo.getResources();
        // Getting all resources for repo
        for (Resource resource : allResources) {
            String status = "";
            // Checking if resource is installed or not
            if (installedBundles.indexOf(resource.getSymbolicName()) != -1) {
                status = "Installed    ";
            } else {
                status = "Not Installed";
            }
            // Printing all resources
            LOGGER.log(Level.INFO, status + "        " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
            totalAddons++;
        }
    }
    LOGGER.log(Level.INFO, "");
    LOGGER.log(Level.INFO, String.format("%s available bundles on installed repositories were found", totalAddons));
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) Resource(org.apache.felix.bundlerepository.Resource)

Example 15 with Resource

use of org.apache.felix.bundlerepository.Resource in project aries by apache.

the class OBRAriesResolver method resolve.

@Deprecated
@Override
public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
    log.trace("resolving {}", app);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    String appName = appMeta.getApplicationSymbolicName();
    Version appVersion = appMeta.getApplicationVersion();
    List<Content> appContent = appMeta.getApplicationContents();
    Collection<Content> useBundleContent = appMeta.getUseBundles();
    List<Content> contents = new ArrayList<Content>();
    contents.addAll(appContent);
    contents.addAll(useBundleContent);
    if ((constraints != null) && (constraints.length > 0)) {
        for (ResolveConstraint con : constraints) {
            contents.add(ContentFactory.parseContent(con.getBundleName(), con.getVersionRange().toString()));
        }
    }
    Resolver obrResolver = getConfiguredObrResolver(appName, appVersion.toString(), toModelledResource(app.getBundleInfo()), false);
    // add a resource describing the requirements of the application metadata.
    obrResolver.add(createApplicationResource(appName, appVersion, contents));
    if (obrResolver.resolve()) {
        Set<BundleInfo> result = new HashSet<BundleInfo>();
        List<Resource> requiredResources = retrieveRequiredResources(obrResolver);
        for (Resource resource : requiredResources) {
            BundleInfo bundleInfo = toBundleInfo(resource, false);
            result.add(bundleInfo);
        }
        if (returnOptionalResources) {
            for (Resource resource : obrResolver.getOptionalResources()) {
                BundleInfo bundleInfo = toBundleInfo(resource, true);
                result.add(bundleInfo);
            }
        }
        return result;
    } else {
        Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
        // refine the list by removing the indirect unsatisfied bundles that are caused by unsatisfied packages or other bundles
        Map<String, Set<String>> refinedReqs = refineUnsatisfiedRequirements(obrResolver, reasons);
        StringBuffer reqList = new StringBuffer();
        Map<String, String> unsatisfiedRequirements = extractConsumableMessageInfo(refinedReqs);
        for (String reason : unsatisfiedRequirements.keySet()) {
            reqList.append('\n');
            reqList.append(reason);
        }
        ResolverException re = new ResolverException(MessageUtil.getMessage("RESOLVER_UNABLE_TO_RESOLVE", new Object[] { app.getApplicationMetadata().getApplicationName(), reqList }));
        re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
        log.debug(LOG_EXIT, "resolve", re);
        throw re;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ResolverException(org.apache.aries.application.management.ResolverException) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) Resolver(org.apache.felix.bundlerepository.Resolver) AriesApplicationResolver(org.apache.aries.application.management.spi.resolve.AriesApplicationResolver) ArrayList(java.util.ArrayList) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) BundleInfo(org.apache.aries.application.management.BundleInfo) OBRBundleInfo(org.apache.aries.application.resolver.obr.impl.OBRBundleInfo) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) HashSet(java.util.HashSet)

Aggregations

Resource (org.apache.felix.bundlerepository.Resource)45 Repository (org.apache.felix.bundlerepository.Repository)19 Capability (org.apache.felix.bundlerepository.Capability)9 Resolver (org.apache.felix.bundlerepository.Resolver)9 ArrayList (java.util.ArrayList)8 ModelledResource (org.apache.aries.application.modelling.ModelledResource)8 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)8 Reason (org.apache.felix.bundlerepository.Reason)7 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)7 HashMap (java.util.HashMap)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)6 URL (java.net.URL)5 File (java.io.File)4 DataModelHelper (org.apache.felix.bundlerepository.DataModelHelper)4 FileWriter (java.io.FileWriter)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Requirement (org.apache.felix.bundlerepository.Requirement)3 BundleContext (org.osgi.framework.BundleContext)3