Search in sources :

Example 51 with Attributes

use of java.util.jar.Attributes in project felix by apache.

the class DefaultManifestBuilder method build.

/**
 * Update the given manifest.
 * @param original original manifest to be modified
 * @return modified manifest
 */
public Manifest build(final Manifest original) {
    Attributes att = original.getMainAttributes();
    // Set the imports (add ipojo and handler namespaces
    setImports(att);
    // Add iPOJO-Component
    setPOJOMetadata(att);
    // Add iPOJO to the creators
    setCreatedBy(att);
    return original;
}
Also used : Attributes(java.util.jar.Attributes)

Example 52 with Attributes

use of java.util.jar.Attributes in project felix by apache.

the class DefaultManifestBuilderTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.putValue("Import-Package", ORG_OSGI_FRAMEWORK_VERSION_1_5);
    attributes.putValue("Created-By", "TestCase");
    builder = new DefaultManifestBuilder();
    builder.addReferredPackage(Collections.singleton("org.osgi.service.http"));
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) DefaultManifestBuilder(org.apache.felix.ipojo.manipulator.store.builder.DefaultManifestBuilder)

Example 53 with Attributes

use of java.util.jar.Attributes in project felix by apache.

the class BundlePlugin method mergeManifest.

protected static void mergeManifest(Instructions instructions, Manifest... manifests) throws IOException {
    for (int i = manifests.length - 2; i >= 0; i--) {
        Manifest mergedManifest = manifests[i];
        Manifest manifest = manifests[i + 1];
        Attributes mergedMainAttributes = mergedManifest.getMainAttributes();
        Attributes mainAttributes = manifest.getMainAttributes();
        Attributes filteredMainAttributes = filterAttributes(instructions, mainAttributes, null);
        if (!filteredMainAttributes.isEmpty()) {
            mergeAttributes(mergedMainAttributes, filteredMainAttributes);
        }
        Map<String, Attributes> mergedEntries = mergedManifest.getEntries();
        Map<String, Attributes> entries = manifest.getEntries();
        for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
            String name = entry.getKey();
            Attributes attributes = entry.getValue();
            Attributes filteredAttributes = filterAttributes(instructions, attributes, null);
            if (!filteredAttributes.isEmpty()) {
                Attributes mergedAttributes = mergedManifest.getAttributes(name);
                if (mergedAttributes != null) {
                    mergeAttributes(mergedAttributes, filteredAttributes);
                } else {
                    mergedEntries.put(name, filteredAttributes);
                }
            }
        }
    }
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 54 with Attributes

use of java.util.jar.Attributes in project felix by apache.

the class BundlePlugin method filterAttributes.

/**
 * @see Analyzer#filter
 */
private static Attributes filterAttributes(Instructions instructions, Attributes source, Set<Instruction> nomatch) {
    Attributes result = new Attributes();
    Map<String, Object> keys = new TreeMap<String, Object>();
    for (Object key : source.keySet()) {
        keys.put(key.toString(), key);
    }
    List<Instruction> filters = new ArrayList<Instruction>(instructions.keySet());
    if (nomatch == null) {
        nomatch = Create.set();
    }
    for (Instruction instruction : filters) {
        boolean match = false;
        for (Iterator<Map.Entry<String, Object>> i = keys.entrySet().iterator(); i.hasNext(); ) {
            Map.Entry<String, Object> entry = i.next();
            String key = entry.getKey();
            if (instruction.matches(key)) {
                match = true;
                if (!instruction.isNegated()) {
                    Object name = entry.getValue();
                    Object value = source.get(name);
                    result.put(name, value);
                }
                // Can never match again for another pattern
                i.remove();
            }
        }
        if (!match && !instruction.isAny())
            nomatch.add(instruction);
    }
    for (Iterator<Instruction> i = nomatch.iterator(); i.hasNext(); ) {
        Instruction instruction = i.next();
        // #252, we should not be negated to make it a constant
        if (instruction.isLiteral() && !instruction.isNegated()) {
            Object key = keys.get(instruction.getLiteral());
            if (key != null) {
                Object value = source.get(key);
                result.put(key, value);
            }
            i.remove();
            continue;
        }
        // the !package will never match anymore.
        if (instruction.isNegated()) {
            i.remove();
            continue;
        }
        // an error
        if (instruction.isOptional()) {
            i.remove();
            continue;
        }
    }
    return result;
}
Also used : Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Instruction(aQute.bnd.osgi.Instruction) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 55 with Attributes

use of java.util.jar.Attributes in project gocd by gocd.

the class MacAboutBox method getCruiseVersion.

public static String getCruiseVersion(String jar) {
    String version = null;
    try {
        JarFile jarFile = new JarFile(jar);
        Manifest manifest = jarFile.getManifest();
        if (manifest != null) {
            Attributes attributes = manifest.getMainAttributes();
            version = attributes.getValue("Go-Version");
        }
    } catch (IOException e) {
    }
    return version;
}
Also used : Attributes(java.util.jar.Attributes) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest)

Aggregations

Attributes (java.util.jar.Attributes)629 Manifest (java.util.jar.Manifest)356 IOException (java.io.IOException)152 File (java.io.File)143 JarFile (java.util.jar.JarFile)106 URL (java.net.URL)92 Map (java.util.Map)78 InputStream (java.io.InputStream)62 HashMap (java.util.HashMap)62 Jar (aQute.bnd.osgi.Jar)49 Builder (aQute.bnd.osgi.Builder)43 ArrayList (java.util.ArrayList)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 Test (org.junit.Test)41 ZipEntry (java.util.zip.ZipEntry)39 FileOutputStream (java.io.FileOutputStream)37 JarOutputStream (java.util.jar.JarOutputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 FileInputStream (java.io.FileInputStream)33 JarEntry (java.util.jar.JarEntry)32