Search in sources :

Example 1 with NameValuePair

use of org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair in project aries by apache.

the class DeployedBundlesTest method parseEntries.

/**
   * Parse manifest entries into a set of values and associated attributes, which can
   * be directly compared for equality regardless of ordering.
   * <p>
   * Example manifest entry format: value1;attrName1=attrValue1;attrName2=attrValue2,value2;attrName1=attrValue1
   * @param entries a manifest header entry.
   * @return a set of parsed entries.
   */
private static Map<NameValuePair, Integer> parseEntries(String entries) {
    Map<NameValuePair, Integer> result = new HashMap<NameValuePair, Integer>();
    for (NameValuePair entry : ManifestHeaderProcessor.parseExportString(entries)) {
        Integer count = result.get(entry);
        if (count != null) {
            // This entry already exists to increment the count.
            count++;
        } else {
            count = 1;
        }
        result.put(entry, count);
    }
    return result;
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair) HashMap(java.util.HashMap)

Example 2 with NameValuePair

use of org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair in project aries by apache.

the class EquinoxFrameworkUtils method getSystemExtraPkgs.

public static Collection<Content> getSystemExtraPkgs(BundleContext context) {
    Set<Content> extraPkgs = new HashSet<Content>();
    String exportString = context.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
    if (exportString != null) {
        for (NameValuePair nvp : ManifestHeaderProcessor.parseExportString(exportString)) extraPkgs.add(ContentFactory.parseContent(nvp.getName(), nvp.getAttributes()));
    }
    return Collections.unmodifiableSet(extraPkgs);
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair) Content(org.apache.aries.application.Content) HashSet(java.util.HashSet)

Example 3 with NameValuePair

use of org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair in project aries by apache.

the class OpenEJBLocator method getClassPathLocations.

/**
   * Find the classpath entries for our bundle
   * 
   * @param manifest
   * @param bundle
   * @return
   */
private List<IDirectory> getClassPathLocations(BundleManifest manifest, IDirectory bundle) {
    List<IDirectory> result = new ArrayList<IDirectory>();
    String rawCp = manifest.getRawAttributes().getValue(Constants.BUNDLE_CLASSPATH);
    logger.debug("Classpath is " + rawCp);
    if (rawCp == null || rawCp.trim() == "")
        result.add(bundle);
    else {
        List<NameValuePair> splitCp = ManifestHeaderProcessor.parseExportString(rawCp);
        List<IFile> allFiles = null;
        for (NameValuePair nvp : splitCp) {
            String name = nvp.getName().trim();
            if (".".equals(name)) {
                result.add(bundle);
            } else {
                IFile f = bundle.getFile(name);
                if (f == null) {
                    //Zip. Check to make sure
                    if (allFiles == null)
                        allFiles = bundle.listAllFiles();
                    for (IFile file : allFiles) {
                        if (file.getName().startsWith(name)) {
                            result.add(new ClasspathIDirectory(bundle, name));
                            break;
                        }
                    }
                } else {
                    IDirectory converted = f.convertNested();
                    if (converted != null)
                        result.add(converted);
                }
            }
        }
    }
    return result;
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair) IFile(org.apache.aries.util.filesystem.IFile) IDirectory(org.apache.aries.util.filesystem.IDirectory) ArrayList(java.util.ArrayList)

Example 4 with NameValuePair

use of org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair in project aries by apache.

the class BundleManifest method getSymbolicName.

public String getSymbolicName() {
    String rawSymName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
    String result = null;
    if (rawSymName != null) {
        NameValuePair info = ManifestHeaderProcessor.parseBundleSymbolicName(rawSymName);
        result = info.getName();
    }
    return result;
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair)

Example 5 with NameValuePair

use of org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair in project aries by apache.

the class ManifestHeaderProcessorTest method testExportMandatoryAttributes.

@Test
public void testExportMandatoryAttributes() {
    String exportPackage = "com.acme.foo,com.acme.bar;version=2;company=dodo;security=false;mandatory:=\"security,company\"";
    List<NameValuePair> exportPackageReturn = ManifestHeaderProcessor.parseExportString(exportPackage);
    int i = 0;
    assertEquals("The number of the packages is wrong.", 2, exportPackageReturn.size());
    for (NameValuePair nvp : exportPackageReturn) {
        if (nvp.getName().equals("com.acme.foo")) {
            i++;
            assertTrue("The directive or attribute should not be set.", nvp.getAttributes().isEmpty());
        } else if ((nvp.getName().equals("com.acme.bar")) && ("2".equals(nvp.getAttributes().get("version")))) {
            i++;
            assertEquals("The directive is wrong.", "dodo", nvp.getAttributes().get("company"));
            assertEquals("The directive is wrong.", "false", nvp.getAttributes().get("security"));
            assertEquals("The directive is wrong.", "security,company", nvp.getAttributes().get("mandatory:"));
        }
    }
    // make sure all three packages stored
    assertEquals("The names of the packages are wrong.", 2, i);
}
Also used : NameValuePair(org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair) Test(org.junit.Test)

Aggregations

NameValuePair (org.apache.aries.util.manifest.ManifestHeaderProcessor.NameValuePair)10 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Content (org.apache.aries.application.Content)2 Hashtable (java.util.Hashtable)1 IDirectory (org.apache.aries.util.filesystem.IDirectory)1 IFile (org.apache.aries.util.filesystem.IFile)1 BeanContext (org.apache.openejb.BeanContext)1 ContainerType (org.apache.openejb.ContainerType)1 Bundle (org.osgi.framework.Bundle)1