Search in sources :

Example 6 with Attributes

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

the class ManifestResource method getAvailableExtensions.

/**
     * Return the set of <code>Extension</code> objects representing optional
     * packages that are bundled with the application associated with the
     * specified <code>Manifest</code>.
     *
     * @param manifest Manifest to be parsed
     *
     * @return List of available extensions, or null if the web application
     * does not bundle any extensions
     */
private ArrayList<Extension> getAvailableExtensions(Manifest manifest) {
    Attributes attributes = manifest.getMainAttributes();
    String name = attributes.getValue("Extension-Name");
    if (name == null)
        return null;
    ArrayList<Extension> extensionList = new ArrayList<>();
    Extension extension = new Extension();
    extension.setExtensionName(name);
    extension.setImplementationURL(attributes.getValue("Implementation-URL"));
    extension.setImplementationVendor(attributes.getValue("Implementation-Vendor"));
    extension.setImplementationVendorId(attributes.getValue("Implementation-Vendor-Id"));
    extension.setImplementationVersion(attributes.getValue("Implementation-Version"));
    extension.setSpecificationVersion(attributes.getValue("Specification-Version"));
    extensionList.add(extension);
    return extensionList;
}
Also used : Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList)

Example 7 with Attributes

use of java.util.jar.Attributes in project buck by facebook.

the class JarContentHasher method getContentHashes.

public ImmutableMap<Path, HashCodeAndFileType> getContentHashes() throws IOException {
    Manifest manifest = filesystem.getJarManifest(jarRelativePath);
    if (manifest == null) {
        throw new UnsupportedOperationException("Cache does not know how to return hash codes for archive members except " + "when the archive contains a META-INF/MANIFEST.MF with " + HashingDeterministicJarWriter.DIGEST_ATTRIBUTE_NAME + " attributes for each file.");
    }
    ImmutableMap.Builder<Path, HashCodeAndFileType> builder = ImmutableMap.builder();
    for (Map.Entry<String, Attributes> nameAttributesEntry : manifest.getEntries().entrySet()) {
        Path memberPath = Paths.get(nameAttributesEntry.getKey());
        Attributes attributes = nameAttributesEntry.getValue();
        String hashStringValue = attributes.getValue(HashingDeterministicJarWriter.DIGEST_ATTRIBUTE_NAME);
        if (hashStringValue == null) {
            continue;
        }
        HashCode memberHash = HashCode.fromString(hashStringValue);
        HashCodeAndFileType memberHashCodeAndFileType = HashCodeAndFileType.ofFile(memberHash);
        builder.put(memberPath, memberHashCodeAndFileType);
    }
    return builder.build();
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 8 with Attributes

use of java.util.jar.Attributes in project atlas by alibaba.

the class BundleClassLoader method processManifest.

/**
     * process the bundle manifest.
     *
     * @param manifest the Manifest.
     * @throws BundleException in case of parse errors.
     */
private void processManifest(final Manifest manifest) throws BundleException {
    final Attributes attrs = (manifest != null) ? manifest.getMainAttributes() : new Attributes();
    checkEE(readProperty(attrs, Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT), splitString(System.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT)));
    // get the exports
    exports = readProperty(attrs, Constants.EXPORT_PACKAGE);
    if (exports != null) {
        int pos = 0;
        for (int x = 0; x < exports.length; x++) {
            if ((pos = exports[x].indexOf("*")) > -1) {
                exports[x] = exports[x].substring(0, pos);
            }
            Log.d("BundleClassLoader", String.format("%s dependency: %s", location, exports[x]));
        }
    }
    // set the bundle headers
    final Hashtable<String, String> headers = new Hashtable<String, String>(attrs.size());
    final Object[] entries = attrs.keySet().toArray(new Object[attrs.keySet().size()]);
    for (int i = 0; i < entries.length; i++) {
        headers.put(entries[i].toString(), attrs.get(entries[i]).toString());
    }
    bundle.headers = headers;
}
Also used : Hashtable(java.util.Hashtable) Attributes(java.util.jar.Attributes)

Example 9 with Attributes

use of java.util.jar.Attributes in project atlas by alibaba.

the class TPatchTool method createManifest.

/**
     * 创建tpatch的manifest信息
     *
     * @return
     */
private Manifest createManifest() {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "1.0 (DexPatch)");
    main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
    return manifest;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) Date(java.sql.Date)

Example 10 with Attributes

use of java.util.jar.Attributes in project buck by facebook.

the class DeterministicJarManifestWriterTest method testLinesSplitLikeJavaImpl.

@Test
public void testLinesSplitLikeJavaImpl() throws IOException {
    final String entryName = "test";
    final String key = "12345678";
    final String value = "138-char value + 8 char key + 2 char padding = 148 chars.  |" + "69-character second line                                            |" + "last line";
    manifestWriter.setEntryAttribute(entryName, key, value);
    manifestWriter.write();
    Manifest jdkManifest = new Manifest();
    Attributes attrs = new Attributes();
    attrs.putValue(key, value);
    jdkManifest.getEntries().put(entryName, attrs);
    ByteArrayOutputStream expected = new ByteArrayOutputStream();
    jdkManifest.write(expected);
    assertArrayEquals(expected.toByteArray(), outputStream.toByteArray());
}
Also used : Attributes(java.util.jar.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) Test(org.junit.Test)

Aggregations

Attributes (java.util.jar.Attributes)631 Manifest (java.util.jar.Manifest)358 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