Search in sources :

Example 26 with Content

use of org.apache.aries.application.Content in project aries by apache.

the class EquinoxFrameworkUtils method calculateSystemPackagesToFlow.

/**
   * Calculates which system packages should be flowed 
   * to a child framework based on what packages the 
   * child framework imports. Equinox will require anything imported by the 
   * child framework which is available from the system bundle 
   * in the parent framework to come from the system bundle 
   * in the child framework. However, we don't want to flow 
   * all the extra system packages by default since we want CBAs 
   * which use them to explicitly import them.
   * @param importPackage
   * @return
   * @throws CompositeBundleCalculateException 
   */
public static String calculateSystemPackagesToFlow(final Collection<Content> systemExports, final Collection<Content> imports) {
    // Let's always set javax.transaction as system extra packages because of the split package. 
    // It is reasonable to do so because we always flow userTransaction service into child framework anyway.
    Map<String, String> map = new HashMap<String, String>();
    map.put(EquinoxFrameworkConstants.TRANSACTION_BUNDLE, EquinoxFrameworkConstants.TRANSACTION_BUNDLE_VERSION);
    Map<String, Map<String, String>> resultMap = new HashMap<String, Map<String, String>>();
    resultMap.put(EquinoxFrameworkConstants.TRANSACTION_BUNDLE, map);
    // let's go through the import list to build the resultMap
    for (Content nvp : imports) {
        String name = nvp.getContentName().trim();
        // if it exist in the list of packages exported by the system, we need to add it to the result
        if (existInExports(name, nvp.getNameValueMap(), systemExports)) {
            for (Content nvpp : systemExports) {
                if (nvpp.getContentName().trim().equals(name)) {
                    Map<String, String> frameworkVersion = nvpp.getNameValueMap();
                    resultMap.put(name, frameworkVersion);
                // We don't break here since we're too lazy to check the version
                // again and so we might end up flowing multiple statements for the 
                // same package (but with different versions). Better this than 
                // accidentally flowing the wrong version if we hit it first.
                }
            }
        }
    }
    StringBuffer result = new StringBuffer();
    for (String key : resultMap.keySet()) {
        result.append(getString(key, resultMap) + ",");
    }
    String toReturn = trimEndString(result.toString().trim(), ",");
    return toReturn;
}
Also used : HashMap(java.util.HashMap) Content(org.apache.aries.application.Content) HashMap(java.util.HashMap) Map(java.util.Map)

Example 27 with Content

use of org.apache.aries.application.Content in project aries by apache.

the class EquinoxFrameworkUtils method getExportPackages.

public static Collection<Content> getExportPackages(BundleContext isolatedBundleContext) {
    Set<Content> exports = new HashSet<Content>();
    Bundle sysBundle = isolatedBundleContext.getBundle(0);
    if (sysBundle != null && sysBundle.getHeaders() != null) {
        String exportString = (String) sysBundle.getHeaders().get(Constants.EXPORT_PACKAGE);
        if (exportString != null) {
            for (NameValuePair nvp : ManifestHeaderProcessor.parseExportString(exportString)) exports.add(ContentFactory.parseContent(nvp.getName(), nvp.getAttributes()));
        }
    }
    return Collections.unmodifiableSet(exports);
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair) Content(org.apache.aries.application.Content) Bundle(org.osgi.framework.Bundle) HashSet(java.util.HashSet)

Aggregations

Content (org.apache.aries.application.Content)27 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 ModelledResource (org.apache.aries.application.modelling.ModelledResource)9 AriesApplication (org.apache.aries.application.management.AriesApplication)8 ResolverException (org.apache.aries.application.management.ResolverException)8 Version (org.osgi.framework.Version)8 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)7 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 DeploymentContent (org.apache.aries.application.DeploymentContent)5 HashMap (java.util.HashMap)4 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4 VersionRange (org.apache.aries.util.VersionRange)4 List (java.util.List)3 Map (java.util.Map)3 Manifest (java.util.jar.Manifest)3 ApplicationMetadataFactoryImpl (org.apache.aries.application.impl.ApplicationMetadataFactoryImpl)3