private void addManifest(ZipOutputStream destination, Collection<File> dexFiles) throws IOException { final Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Created-By"), "Soot Dex Printer"); if (dexFiles != null && !dexFiles.isEmpty()) { manifest.getMainAttributes().put(new Attributes.Name("Dex-Location"), dexFiles.stream().map(File::getName).collect(Collectors.joining(" "))); } final ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); destination.putNextEntry(manifestEntry); manifest.write(new BufferedOutputStream(destination)); destination.closeEntry(); }
try (InputStream in = Files.newInputStream(file)) { Manifest mf = new Manifest(in); mf.getMainAttributes().put(new Name("X-NOTICE"), "Modified"); mf.getEntries().clear();
private void readName() throws IOException { int mark = pos; while (pos < buf.length) { if (buf[pos++] != ':') { continue; } String nameString = new String(buf, mark, pos - mark - 1, StandardCharsets.US_ASCII); if (buf[pos++] != ' ') { throw new IOException(String.format("Invalid value for attribute '%s'", nameString)); } try { name = attributeNameCache.get(nameString); if (name == null) { name = new Attributes.Name(nameString); attributeNameCache.put(nameString, name); } } catch (IllegalArgumentException e) { // new Attributes.Name() throws IllegalArgumentException but we declare IOException throw new IOException(e.getMessage()); } return; } }
static File createDelegatingJavaagentJarFile(File dir) throws Exception { File jarFile = File.createTempFile("glowroot-", ".jar", dir); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Premain-Class"), DelegatingJavaagent.class.getName()); manifest.getMainAttributes().put(new Attributes.Name("Can-Redefine-Classes"), "true"); manifest.getMainAttributes().put(new Attributes.Name("Can-Retransform-Classes"), "true"); String resourceName = ClassNames.toInternalName(DelegatingJavaagent.class.getName()) + ".class"; JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile), manifest); try { out.putNextEntry(new JarEntry(resourceName)); Resources.asByteSource(Resources.getResource(resourceName)).copyTo(out); out.closeEntry(); } finally { out.close(); } return jarFile; } }
public void removeAttribute( String attributeName ) { backingAttributes.remove( new Attributes.Name( attributeName ) ); }
public ExistingAttribute getAttribute( String attributeName ) { Attributes.Name name = new Attributes.Name( attributeName ); return backingAttributes.containsKey( name ) ? new ExistingAttribute( backingAttributes, attributeName ) : null; }
Attributes global = manifest.getMainAttributes(); global.put(Attributes.Name.MANIFEST_VERSION, "1.0.0"); global.put(new Attributes.Name("Class-Path"), String.join(" ", manifestEntries));
final String now = (new Date()).toString(); final java.util.jar.Attributes.Name dateAttr = new java.util.jar.Attributes.Name("Date"); while (classes.hasMoreElements()) { final JavaClass clazz = (JavaClass)classes.nextElement();
final Manifest manifest = myJar.getManifest(); if (manifest != null) { final String classPath = manifest.getMainAttributes().getValue(new Attributes.Name("Class-Path")); if (classPath != null) { for (String jar : classPath.split(" ")) {
private static File createJarFile(File jar) throws IOException, CannotCompileException, NotFoundException { Manifest manifest = new Manifest(); Attributes attrs = manifest.getMainAttributes(); attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); attrs.put(new Attributes.Name("Premain-Class"), HotSwapAgent.class.getName()); attrs.put(new Attributes.Name("Agent-Class"), HotSwapAgent.class.getName()); attrs.put(new Attributes.Name("Can-Retransform-Classes"), "true"); attrs.put(new Attributes.Name("Can-Redefine-Classes"), "true"); JarOutputStream jos = null; try { jos = new JarOutputStream(new FileOutputStream(jar), manifest); String cname = HotSwapAgent.class.getName(); JarEntry e = new JarEntry(cname.replace('.', '/') + ".class"); jos.putNextEntry(e); ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.get(cname); jos.write(clazz.toBytecode()); jos.closeEntry(); } finally { if (jos != null) jos.close(); } return jar; } }
final Manifest manifest = myJar.getManifest(); if (manifest != null) { final String classPath = manifest.getMainAttributes().getValue(new Attributes.Name("Class-Path")); if (classPath != null) { for (String jar : classPath.split(" ")) {
private static File createJarFile(File jar) throws IOException, CannotCompileException, NotFoundException { Manifest manifest = new Manifest(); Attributes attrs = manifest.getMainAttributes(); attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); attrs.put(new Attributes.Name("Premain-Class"), HotSwapAgent.class.getName()); attrs.put(new Attributes.Name("Agent-Class"), HotSwapAgent.class.getName()); attrs.put(new Attributes.Name("Can-Retransform-Classes"), "true"); attrs.put(new Attributes.Name("Can-Redefine-Classes"), "true"); JarOutputStream jos = null; try { jos = new JarOutputStream(new FileOutputStream(jar), manifest); String cname = HotSwapAgent.class.getName(); JarEntry e = new JarEntry(cname.replace('.', '/') + ".class"); jos.putNextEntry(e); ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.get(cname); jos.write(clazz.toBytecode()); jos.closeEntry(); } finally { if (jos != null) jos.close(); } return jar; } }
public @Override String get(Object _k) { if (!(_k instanceof String)) { return null; } String k = (String) _k; Attributes.Name an; try { an = new Attributes.Name(k); } catch (IllegalArgumentException iae) { // Robustness, and workaround for reported MRJ locale bug: LOG.log(Level.FINE, null, iae); return null; } return attrs.getValue(an); } }
private static Attributes.Name key(String key) { return new Attributes.Name(key); } }
private static Object get(Attributes attributes, String key) { return attributes.get(new Attributes.Name(key)); } }
/** * Stores the value {@code value} associated with the key {@code name} in this * {@code Attributes}. * * @return the value being stored. */ public String putValue(String name, String value) { return (String) map.put(new Attributes.Name(name), value); } }
/** * Returns the string associated with the parameter name. * * @param name * the key to obtain the value for. * @return the string associated with name, or {@code null} if name is not a * valid key. */ public String getValue(String name) { return getValue(new Attributes.Name(name)); }
private void updateManifest(String symbolicName, String classPath, String bundleActivator) throws IOException { try (FileInputStream manifestInputStream = new FileInputStream(manifestLocation)) { Manifest manifest = new Manifest(manifestInputStream); Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes.containsKey(new Attributes.Name(BUNDLE_SYMBOLICNAME))) { descriptor.markAsInvalid(Arrays.asList("Plugin JAR is invalid. MANIFEST.MF already contains header: " + BUNDLE_SYMBOLICNAME), null); return; } mainAttributes.put(new Attributes.Name(BUNDLE_SYMBOLICNAME), symbolicName); mainAttributes.put(new Attributes.Name(BUNDLE_CLASSPATH), classPath); mainAttributes.put(new Attributes.Name(BUNDLE_ACTIVATOR), bundleActivator); descriptor.updateBundleInformation(symbolicName, classPath, bundleActivator); try (FileOutputStream manifestOutputStream = new FileOutputStream(manifestLocation)) { manifest.write(manifestOutputStream); } } }
private void addHeaderToManifest(String header, String value) throws IOException { FileInputStream manifestInputStream = new FileInputStream(manifestFile); Manifest manifest = new Manifest(manifestInputStream); Attributes entries = manifest.getMainAttributes(); entries.put(new Attributes.Name(header), value); FileOutputStream manifestOutputStream = new FileOutputStream(manifestFile, false); manifest.write(manifestOutputStream); manifestOutputStream.close(); manifestInputStream.close(); }
String getManifestAttribute(String name, String defaultValue) { if (manifest == null) { return defaultValue; } Name attrName = new Name(name); Object value = manifest.getMainAttributes().get(attrName); return value == null ? defaultValue : value.toString(); }