Search in sources :

Example 21 with Version

use of org.osgi.framework.Version in project aries by apache.

the class Main method extendImportPackage.

private static void extendImportPackage(Manifest manifest) throws IOException {
    String utilPkgVersion = getPackageVersion(Util.class);
    Version osgiVersion = Version.parseVersion(utilPkgVersion);
    Version minVersion = new Version(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro());
    Version maxVersion = new Version(osgiVersion.getMajor(), osgiVersion.getMinor() + 1, 0);
    String ip = manifest.getMainAttributes().getValue(IMPORT_PACKAGE);
    if (ip == null)
        ip = "";
    StringBuilder sb = new StringBuilder(ip);
    if (ip.length() > 0)
        sb.append(",");
    sb.append(Util.class.getPackage().getName());
    sb.append(";version=\"[");
    sb.append(minVersion);
    sb.append(",");
    sb.append(maxVersion);
    sb.append(")\"");
    manifest.getMainAttributes().putValue(IMPORT_PACKAGE, sb.toString());
}
Also used : Version(org.osgi.framework.Version)

Example 22 with Version

use of org.osgi.framework.Version in project aries by apache.

the class RepositoryGenerator method find.

/**
     * the format of resource is like bundlesymbolicname;version=1.0.0, for example com.ibm.ws.eba.example.blog.api;version=1.0.0,
     */
@SuppressWarnings({ "rawtypes", "unused" })
public Resource find(String resource) throws SubsystemException {
    generateOBR();
    Content content = new ContentImpl(resource);
    String symbolicName = content.getContentName();
    // this version could possibly be a range
    String version = content.getVersion().toString();
    StringBuilder filterString = new StringBuilder();
    filterString.append("(&(name" + "=" + symbolicName + "))");
    filterString.append("(version" + "=" + version + "))");
    //org.apache.felix.bundlerepository.Resource[] res = this.repositoryAdmin.discoverResources(filterString.toString());
    Repository[] repos = this.repositoryAdmin.listRepositories();
    org.apache.felix.bundlerepository.Resource res = null;
    for (Repository repo : repos) {
        org.apache.felix.bundlerepository.Resource[] resources = repo.getResources();
        for (int i = 0; i < resources.length; i++) {
            if (resources[i].getSymbolicName().equals(symbolicName)) {
                if (resources[i].getVersion().compareTo(new Version(version)) == 0) {
                    res = resources[i];
                    break;
                }
            }
        }
    }
    if (res == null) {
        //            throw new SubsystemException("unable to find the resource " + resource);
        return null;
    }
    Map props = res.getProperties();
    Object type = props.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
    return new FelixResourceAdapter(res);
}
Also used : Resource(org.osgi.resource.Resource) FelixResourceAdapter(org.apache.aries.subsystem.util.felix.FelixResourceAdapter) Repository(org.apache.felix.bundlerepository.Repository) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) Map(java.util.Map)

Example 23 with Version

use of org.osgi.framework.Version 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)

Example 24 with Version

use of org.osgi.framework.Version in project aries by apache.

the class BundleRepositoryManagerImpl method getBundleSuggestions.

public Map<DeploymentContent, BundleSuggestion> getBundleSuggestions(Collection<BundleRepository> providers, Collection<DeploymentContent> content) throws ContextException {
    LOGGER.debug(LOG_ENTRY, "getBundleSuggestions", new Object[] { content, providers });
    Map<DeploymentContent, BundleSuggestion> urlToBeInstalled = new HashMap<DeploymentContent, BundleSuggestion>();
    Iterator<DeploymentContent> it = content.iterator();
    while (it.hasNext()) {
        DeploymentContent bundleToFind = it.next();
        Map<Version, List<BundleSuggestion>> bundlesuggestions = new HashMap<Version, List<BundleSuggestion>>();
        for (BundleRepository obj : providers) {
            BundleSuggestion suggestion = obj.suggestBundleToUse(bundleToFind);
            if (suggestion != null) {
                List<BundleSuggestion> suggestions = bundlesuggestions.get(suggestion.getVersion());
                if (suggestions == null) {
                    suggestions = new ArrayList<BundleSuggestion>();
                    bundlesuggestions.put(suggestion.getVersion(), suggestions);
                }
                suggestions.add(suggestion);
            }
        }
        BundleSuggestion suggestion = null;
        if (!!!bundlesuggestions.isEmpty()) {
            List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
            if (thoughts != null) {
                Collections.sort(thoughts, new Comparator<BundleSuggestion>() {

                    public int compare(BundleSuggestion o1, BundleSuggestion o2) {
                        return o1.getCost() - o2.getCost();
                    }
                });
                suggestion = thoughts.get(0);
            }
        }
        // add the suggestion to the list
        if (suggestion != null) {
            urlToBeInstalled.put(bundleToFind, suggestion);
        } else {
            throw new ContextException("Unable to find bundle " + bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
        }
    }
    LOGGER.debug(LOG_EXIT, "getBundleSuggestions", new Object[] { urlToBeInstalled });
    return urlToBeInstalled;
}
Also used : HashMap(java.util.HashMap) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) ContextException(org.apache.aries.application.management.spi.repository.ContextException) DeploymentContent(org.apache.aries.application.DeploymentContent) Version(org.osgi.framework.Version) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) ArrayList(java.util.ArrayList) List(java.util.List) ArrayServiceList(org.apache.aries.application.utils.service.ArrayServiceList)

Example 25 with Version

use of org.osgi.framework.Version in project aries by apache.

the class EquinoxFrameworkUtils method existInExports.

/**
   * check if the value in nvm already exist in the exports
   * @param key
   * @param nvm
   * @param exports
   * @return boolean whether the value in nvm already exist in the exports
   */
private static boolean existInExports(String key, Map<String, String> nvm, final Collection<Content> exports) {
    boolean value = false;
    for (Content nvp : exports) {
        if (nvp.getContentName().trim().equals(key.trim())) {
            // ok key equal.  let's check the version
            // if version is higher, we still want to import, for example javax.transaction;version=1.1
            String vi = nvm.get(Constants.VERSION_ATTRIBUTE);
            String ve = nvp.getNameValueMap().get(Constants.VERSION_ATTRIBUTE);
            if (vi == null || vi.length() == 0) {
                vi = "0.0.0";
            }
            if (ve == null || ve.length() == 0) {
                ve = "0.0.0";
            }
            if (vi.indexOf(",") == -1) {
                if (new Version(vi).compareTo(new Version(ve)) <= 0) {
                    // we got it covered in our exports
                    value = true;
                }
            } else {
                // parse vi into version range.
                VersionRange vri = ManifestHeaderProcessor.parseVersionRange(vi);
                Version minV = vri.getMinimumVersion();
                Version maxV = vri.getMaximumVersion();
                if (minV.compareTo(new Version(ve)) < 0 && maxV.compareTo(new Version(ve)) > 0) {
                    value = true;
                } else if (minV.compareTo(new Version(ve)) == 0 && !!!vri.isMinimumExclusive()) {
                    value = true;
                } else if (maxV.compareTo(new Version(ve)) == 0 && !!!vri.isMaximumExclusive()) {
                    value = true;
                }
            }
        }
    }
    return value;
}
Also used : Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange)

Aggregations

Version (org.osgi.framework.Version)165 Test (org.junit.Test)30 Bundle (org.osgi.framework.Bundle)26 ArrayList (java.util.ArrayList)22 Capability (org.osgi.resource.Capability)19 File (java.io.File)17 HashMap (java.util.HashMap)16 Resource (org.osgi.resource.Resource)14 IOException (java.io.IOException)13 InputStream (java.io.InputStream)11 Manifest (java.util.jar.Manifest)11 Map (java.util.Map)9 HashSet (java.util.HashSet)8 Content (org.apache.aries.application.Content)8 AriesApplication (org.apache.aries.application.management.AriesApplication)8 VersionRange (org.apache.felix.utils.version.VersionRange)8 BundleRevision (org.osgi.framework.wiring.BundleRevision)8 List (java.util.List)7 BundleWiring (org.osgi.framework.wiring.BundleWiring)7 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)6