Example usage for java.util.jar Attributes putValue

List of usage examples for java.util.jar Attributes putValue

Introduction

In this page you can find the example usage for java.util.jar Attributes putValue.

Prototype

public String putValue(String name, String value) 

Source Link

Document

Associates the specified value with the specified attribute name, specified as a String.

Usage

From source file:org.wso2.carbon.server.util.Utils.java

/**
 * Create an OSGi bundle out of a JAR file
 *
 * @param jarFile         The jarfile to be bundled
 * @param targetDir       The directory into which the created OSGi bundle needs to be placed into.
 * @param mf              The bundle manifest file
 * @param extensionPrefix Prefix, if any, for the bundle
 * @throws java.io.IOException If an error occurs while reading the jar or creating the bundle
 *//*w  ww .  java  2s  . c om*/
public static void createBundle(File jarFile, File targetDir, Manifest mf, String extensionPrefix)
        throws IOException {
    if (mf == null) {
        mf = new Manifest();
    }
    String exportedPackages = Utils.parseJar(jarFile);

    String fileName = jarFile.getName();
    fileName = fileName.replaceAll("-", "_");
    if (fileName.endsWith(".jar")) {
        fileName = fileName.substring(0, fileName.length() - 4);
    }
    String symbolicName = extensionPrefix + fileName;
    String pluginName = extensionPrefix + fileName + "_1.0.0.jar";
    File extensionBundle = new File(targetDir, pluginName);

    Attributes attribs = mf.getMainAttributes();
    attribs.putValue(LauncherConstants.MANIFEST_VERSION, "1.0");
    attribs.putValue(LauncherConstants.BUNDLE_MANIFEST_VERSION, "2");
    attribs.putValue(LauncherConstants.BUNDLE_NAME, fileName);
    attribs.putValue(LauncherConstants.BUNDLE_SYMBOLIC_NAME, symbolicName);
    attribs.putValue(LauncherConstants.BUNDLE_VERSION, "1.0.0");
    attribs.putValue(LauncherConstants.EXPORT_PACKAGE, exportedPackages);
    attribs.putValue(LauncherConstants.BUNDLE_CLASSPATH, ".," + jarFile.getName());

    Utils.createBundle(jarFile, extensionBundle, mf);
}

From source file:pxb.android.tinysign.TinySign.java

private static void doFile(String name, File f, ZipOutputStream zos, DigestOutputStream dos, Manifest m)
        throws IOException {
    zos.putNextEntry(new ZipEntry(name));
    FileInputStream fis = FileUtils.openInputStream(f);
    IOUtils.copy(fis, dos);/*from ww w  .jav a2 s.  c  o m*/
    IOUtils.closeQuietly(fis);
    byte[] digets = dos.getMessageDigest().digest();
    zos.closeEntry();
    Attributes attr = new Attributes();
    attr.putValue("SHA1-Digest", eBase64(digets));
    m.getEntries().put(name, attr);
}

From source file:pxb.android.tinysign.TinySign.java

private static Manifest generateSF(Manifest manifest)
        throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    PrintStream print = new PrintStream(new DigestOutputStream(new OutputStream() {

        @Override/*  w w w  .j  av a 2  s  .  c om*/
        public void write(byte[] arg0) throws IOException {
        }

        @Override
        public void write(byte[] arg0, int arg1, int arg2) throws IOException {
        }

        @Override
        public void write(int arg0) throws IOException {
        }
    }, md), true, "UTF-8");
    Manifest sf = new Manifest();
    Map<String, Attributes> entries = manifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        // Digest of the manifest stanza for this entry.
        print.print("Name: " + entry.getKey() + "\r\n");
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        Attributes sfAttr = new Attributes();
        sfAttr.putValue("SHA1-Digest", eBase64(md.digest()));
        sf.getEntries().put(entry.getKey(), sfAttr);
    }
    return sf;
}

From source file:pxb.android.tinysign.TinySign.java

private static String writeMF(File dir, Manifest manifest, ZipOutputStream zos)
        throws NoSuchAlgorithmException, IOException {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    DigestOutputStream dos = new DigestOutputStream(zos, md);
    zipAndSha1(dir, zos, dos, manifest);
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("Created-By", "tiny-sign-" + TinySign.class.getPackage().getImplementationVersion());
    zos.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
    manifest.write(dos);//from w ww  . j  ava  2  s  . c om
    zos.closeEntry();
    return eBase64(md.digest());
}