List of usage examples for java.util.jar Attributes putValue
public String putValue(String name, String value)
From source file:Main.java
private static Manifest getCompositeManifest(Map compositeManifest) { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); //$NON-NLS-1$//$NON-NLS-2$ // get the common headers Bundle-ManifestVersion, Bundle-SymbolicName and Bundle-Version // get the manifest version from the map String manifestVersion = (String) compositeManifest.remove(Constants.BUNDLE_MANIFESTVERSION); // here we assume the validation got the correct version for us attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, manifestVersion); // Ignore the Equinox composite bundle header compositeManifest.remove(BaseStorageHook.COMPOSITE_HEADER); attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.COMPOSITE_BUNDLE); for (Iterator entries = compositeManifest.entrySet().iterator(); entries.hasNext();) { Map.Entry entry = (Entry) entries.next(); if (entry.getKey() instanceof String && entry.getValue() instanceof String) attributes.putValue((String) entry.getKey(), (String) entry.getValue()); }//from w w w. j a v a 2s .c om return manifest; }
From source file:Main.java
private static Manifest getSurrogateManifest(Dictionary compositeManifest, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports) { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); //$NON-NLS-1$//$NON-NLS-2$ // Ignore the manifest version from the map // always use bundle manifest version 2 attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$ // Ignore the Equinox composite bundle header attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.SURROGATE_BUNDLE); if (compositeDesc != null && matchingExports != null) { // convert the exports from the composite into imports addImports(attributes, compositeDesc, matchingExports); // convert the matchingExports from the composite into exports addExports(attributes, compositeDesc, matchingExports); }/*from w ww . j a v a 2s.c om*/ // add the rest for (Enumeration keys = compositeManifest.keys(); keys.hasMoreElements();) { Object header = keys.nextElement(); if (Constants.BUNDLE_MANIFESTVERSION.equals(header) || BaseStorageHook.COMPOSITE_HEADER.equals(header) || Constants.IMPORT_PACKAGE.equals(header) || Constants.EXPORT_PACKAGE.equals(header)) continue; if (header instanceof String && compositeManifest.get(header) instanceof String) attributes.putValue((String) header, (String) compositeManifest.get(header)); } return manifest; }
From source file:com.jrummyapps.busybox.signing.ZipSigner.java
/** * Write a .SF file with a digest the specified manifest. *//*w w w . j av a 2 s.c om*/ private static byte[] writeSignatureFile(Manifest manifest, OutputStream out) throws IOException, GeneralSecurityException { final Manifest sf = new Manifest(); final Attributes main = sf.getMainAttributes(); main.putValue("Manifest-Version", MANIFEST_VERSION); main.putValue("Created-By", CREATED_BY); final MessageDigest md = MessageDigest.getInstance("SHA1"); final PrintStream print = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true, "UTF-8"); // Digest of the entire manifest manifest.write(print); print.flush(); main.putValue("SHA1-Digest-Manifest", base64encode(md.digest())); final Map<String, Attributes> entries = manifest.getEntries(); for (final Map.Entry<String, Attributes> entry : entries.entrySet()) { // Digest of the manifest stanza for this entry. print.print("Name: " + entry.getKey() + "\r\n"); for (final Map.Entry<Object, Object> att : entry.getValue().entrySet()) { print.print(att.getKey() + ": " + att.getValue() + "\r\n"); } print.print("\r\n"); print.flush(); final Attributes sfAttr = new Attributes(); sfAttr.putValue("SHA1-Digest", base64encode(md.digest())); sf.getEntries().put(entry.getKey(), sfAttr); } final ByteArrayOutputStream sos = new ByteArrayOutputStream(); sf.write(sos); String value = sos.toString(); String done = value.replace("Manifest-Version", "Signature-Version"); out.write(done.getBytes()); print.close(); sos.close(); return done.getBytes(); }
From source file:com.jrummyapps.busybox.signing.ZipSigner.java
/** Add the SHA1 of every file to the manifest, creating it if necessary. */ private static Manifest addDigestsToManifest(final JarFile jar) throws IOException, GeneralSecurityException { final Manifest input = jar.getManifest(); final Manifest output = new Manifest(); final Attributes main = output.getMainAttributes(); main.putValue("Manifest-Version", MANIFEST_VERSION); main.putValue("Created-By", CREATED_BY); // We sort the input entries by name, and add them to the output manifest in sorted order. // We expect that the output map will be deterministic. final TreeMap<String, JarEntry> byName = new TreeMap<>(); for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) { JarEntry entry = e.nextElement(); byName.put(entry.getName(), entry); }/* www.j av a2 s. c o m*/ final MessageDigest md = MessageDigest.getInstance("SHA1"); final byte[] buffer = new byte[4096]; int num; for (JarEntry entry : byName.values()) { final String name = entry.getName(); if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) && !name.equals(CERT_SF_NAME) && !name.equals(CERT_RSA_NAME)) { InputStream data = jar.getInputStream(entry); while ((num = data.read(buffer)) > 0) { md.update(buffer, 0, num); } Attributes attr = null; if (input != null) { attr = input.getAttributes(name); } attr = attr != null ? new Attributes(attr) : new Attributes(); attr.putValue("SHA1-Digest", base64encode(md.digest())); output.getEntries().put(name, attr); } } return output; }
From source file:Main.java
private static void addExports(Attributes attributes, BundleDescription compositeDesc, ExportPackageDescription[] matchingExports) { if (matchingExports.length == 0) return;// w ww. j ava 2 s . com StringBuffer exportStatement = new StringBuffer(); for (int i = 0; i < matchingExports.length; i++) { if (matchingExports[i].getExporter() == compositeDesc) { // the matching export from outside is the composite bundle itself // this must be one of our own substitutable exports, it must be ignored (bug 345640) continue; } if (exportStatement.length() > 0) exportStatement.append(','); getExportFrom(matchingExports[i], exportStatement); } if (exportStatement.length() > 0) attributes.putValue(Constants.EXPORT_PACKAGE, exportStatement.toString()); }
From source file:org.eclipse.gemini.blueprint.test.internal.util.ManifestUtilsTest.java
public void testExportEntries() throws Exception { Manifest mf = new Manifest(); Attributes attrs = mf.getMainAttributes(); String[] packages = new String[] { "foo.bar; version:=1", "bar.foo", "hop.trop" }; attrs.putValue(Constants.EXPORT_PACKAGE, StringUtils.arrayToCommaDelimitedString(packages)); createJar(mf);/* ww w. j a v a 2s . c o m*/ String[] entries = ManifestUtils .determineImportPackages(new Resource[] { storage.getResource(), storage.getResource() }); assertEquals(3, entries.length); ObjectUtils.nullSafeEquals(packages, entries); }
From source file:com.xebialabs.deployit.maven.packager.ManifestPackager.java
public ManifestPackager(String artifactId, String version, File targetDirectory) { this.targetDirectory = new File(targetDirectory, DEPLOYMENT_PACKAGE_DIR + File.separator + artifactId + File.separator + version); this.targetDirectory.mkdirs(); this.deploymentPackageName = artifactId + "/" + version; final Attributes mainAttributes = manifest.getMainAttributes(); mainAttributes.putValue("Manifest-Version", "1.0"); mainAttributes.putValue("Deployit-Package-Format-Version", "1.1"); mainAttributes.putValue("CI-Application", artifactId); mainAttributes.putValue("CI-Version", version); }
From source file:com.xebialabs.deployit.maven.packager.ManifestPackager.java
public void addDeployableArtifact(DeployableArtifactItem item) { if ("Dar".equals(item.getType())) return;//from w ww . j av a 2s.co m if ("Pom".equals(item.getType())) return; final Map<String, Attributes> entries = manifest.getEntries(); final Attributes attributes = new Attributes(); final String type = item.getType(); final File location = new File(item.getLocation()); attributes.putValue("CI-Type", type); if (item.hasName()) attributes.putValue("CI-Name", item.getName()); String darLocation = (item.getDarLocation() == null ? type : item.getDarLocation()); if (item.isFolder()) { entries.put(darLocation, attributes); } else { if (location.isAbsolute()) entries.put(darLocation + "/" + location.getName(), attributes); else entries.put(darLocation + "/" + item.getLocation(), attributes); } final File targetDir = new File(targetDirectory, darLocation); if (generateManifestOnly) { System.out.println("Skip copying artifact " + item.getName() + " to " + targetDir); return; } targetDir.mkdirs(); File locationTargetDirs; //do not create missing directories is there are no parents or if the file is absolute if (location.isAbsolute() || location.getParent() == null) { locationTargetDirs = targetDir; } else { locationTargetDirs = new File(targetDir, location.getParent()); locationTargetDirs.mkdirs(); } try { if (location.isDirectory()) { FileUtils.copyDirectoryToDirectory(location, locationTargetDirs); } else { FileUtils.copyFileToDirectory(location, locationTargetDirs); } } catch (IOException e) { throw new RuntimeException("Fail to copy of " + location + " to " + targetDir, e); } }
From source file:com.taobao.android.apatch.FastBuild.java
@Override protected Manifest getMeta() { Manifest manifest = new Manifest(); Attributes main = manifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (ApkPatch)"); main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString()); main.putValue("Patch-Name", name); main.putValue(name + "-Patch-Classes", Formater.dotStringList(classes)); main.putValue(name + "-Prepare-Classes", Formater.dotStringList(prepareClasses)); main.putValue(name + "-Used-Methods", Formater.dotStringList(usedMethods)); main.putValue(name + "-Modified-Classes", Formater.dotStringList(modifiedClasses)); main.putValue(name + "-Used-Classes", Formater.dotStringList(usedClasses)); main.putValue(name + "-add-classes", Formater.dotStringList(addClasses)); return manifest; }
From source file:com.taobao.android.apatch.MergePatch.java
@SuppressWarnings("deprecation") @Override/* w ww . ja va2s . c om*/ protected Manifest getMeta() { Manifest retManifest = new Manifest(); Attributes main = retManifest.getMainAttributes(); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.0 (ApkPatch)"); main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString()); main.putValue("Patch-Name", name); try { fillManifest(main); } catch (IOException e) { e.printStackTrace(); return null; } return retManifest; }