All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dm.gradle.plugins.bundle.ManifestSubstitute.groovy Maven / Gradle / Ivy

There is a newer version: 0.10.0
Show newest version
package org.dm.gradle.plugins.bundle

import org.gradle.api.java.archives.Attributes
import org.gradle.api.java.archives.Manifest
import org.gradle.api.java.archives.ManifestException
import org.gradle.api.java.archives.internal.DefaultManifest

import java.nio.charset.Charset

import static aQute.bnd.osgi.Constants.BND_LASTMODIFIED
import static org.dm.gradle.plugins.bundle.Objects.requireNonNull

class ManifestSubstitute implements Manifest {
    // With accordance to manifest specification
    private static final Charset CHARSET = Charset.forName('UTF-8')

    private final org.gradle.internal.Factory jarBuilderFactory
    private final Manifest wrapped

    ManifestSubstitute(org.gradle.internal.Factory jarBuilderFactory, Manifest wrapped) {
        this.jarBuilderFactory = requireNonNull(jarBuilderFactory)
        this.wrapped = wrapped ?: new DefaultManifest(null)
    }

    @Override
    Manifest writeTo(Writer writer) {
        jarBuilderFactory.create().writeManifestTo(new WriterToOutputStreamAdapter(writer, CHARSET)) { manifest ->
            manifest.mainAttributes.remove(new java.util.jar.Attributes.Name(BND_LASTMODIFIED))
        }
        return this
    }

    /* Delegates */

    @Override
    Attributes getAttributes() {
        return wrapped.attributes
    }

    @Override
    Map getSections() {
        return wrapped.sections
    }

    @Override
    Manifest attributes(Map attributes) throws ManifestException {
        return wrapped.attributes(attributes)
    }

    @Override
    Manifest attributes(Map attributes, String sectionName) throws ManifestException {
        return wrapped.attributes(attributes, sectionName)
    }

    @Override
    Manifest getEffectiveManifest() {
        return wrapped.effectiveManifest
    }

    @Override
    Manifest writeTo(Object path) {
        return wrapped.writeTo(path)
    }

    @Override
    Manifest from(Object... mergePath) {
        return wrapped.from(mergePath)
    }

    @Override
    Manifest from(Object mergePath, Closure closure) {
        return wrapped.from(mergePath, closure)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy