/** * {@inheritDoc} */ public File toJar(File file) throws IOException { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION); return toJar(file, manifest); }
public void addManifestV0(final String embulkPluginMainClass) { final Attributes attributes = this.manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); attributes.putValue(MANIFEST_PLUGIN_SPI_VERSION, "0"); attributes.putValue(MANIFEST_PLUGIN_MAIN_CLASS, embulkPluginMainClass); }
Manifest sf = new Manifest(); Attributes mainAttrs = sf.getMainAttributes(); mainAttrs.put(Attributes.Name.SIGNATURE_VERSION, ATTRIBUTE_VALUE_SIGNATURE_VERSION); mainAttrs.put(ATTRIBUTE_NAME_CREATED_BY, ATTRIBUTE_DEFALT_VALUE_CREATED_BY); if (!apkSignatureSchemeIds.isEmpty()) { mainAttrs.put( SF_ATTRIBUTE_NAME_ANDROID_APK_SIGNED_NAME, attrValue.toString());
public ManifestReader(byte[] buf, Attributes main) throws IOException { this.buf = buf; while (readHeader()) { main.put(name, value); } this.endOfMainSection = pos; }
private void enqueueDownload(String pluginKey, String pluginHash) throws IOException { File jar = temp.newFile(); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().putValue("Plugin-Key", pluginKey); try (JarOutputStream output = new JarOutputStream(FileUtils.openOutputStream(jar), manifest)) { } doReturn(Optional.of(jar)).when(pluginFiles).get(argThat(p -> pluginKey.equals(p.key) && pluginHash.equals(p.hash))); }
/** * Append an attribute such as "Extension-List: lib0 lib1 lib2" * using specified prefix and counting up to specified size. * Also use specified extensionKey so that can generate list of * optional dependencies as well. * * @param size the number of libraries to list * @param listPrefix the prefix for all libraries * @param attributes the attributes to add key-value to * @param extensionKey the key to use */ private void appendExtensionList(final Attributes attributes, final Attributes.Name extensionKey, final String listPrefix, final int size) { //add in something like //"Extension-List: javahelp java3d" attributes.put(extensionKey, IntStream.range(0, size) .mapToObj(i -> listPrefix + i).collect(Collectors.joining(" "))); }
final Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION); attributes.putValue(CREATED_BY, "Apache Ant " + getProject().getProperty(MagicNames.ANT_VERSION));
private void packageTopology(Path jar, AbstractStreamsProcessor processor) throws IOException { Manifest manifest = new Manifest(); Attributes attr = manifest.getMainAttributes(); attr.put(Attributes.Name.MANIFEST_VERSION, "1.0"); attr.put(Attributes.Name.MAIN_CLASS, processor.getClass().getCanonicalName()); try (JarOutputStream out = new JarOutputStream( new BufferedOutputStream(new FileOutputStream(jar.toFile())), manifest)) { List<CompilingClassLoader> classLoaders = processor.getClassLoaders(); if (classLoaders != null && !classLoaders.isEmpty()) { for (CompilingClassLoader classLoader : classLoaders) { for (Map.Entry<String, ByteArrayOutputStream> e : classLoader.getClasses().entrySet()) { out.putNextEntry(new ZipEntry(e.getKey().replace(".", "/") + ".class")); out.write(e.getValue().toByteArray()); out.closeEntry(); } } } } } }
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(); }
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); } } }
try (InputStream in = Files.newInputStream(file)) { Manifest mf = new Manifest(in); mf.getMainAttributes().put(new Name("X-NOTICE"), "Modified"); mf.getEntries().clear();
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; } }
private static void writeSelfReferencingJarFile(File jarFile, String... entries) throws IOException { Manifest manifest = new Manifest(); // Without version, the manifest is silently ignored. Ugh! manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, jarFile.getName()); Closer closer = Closer.create(); try { FileOutputStream fileOut = closer.register(new FileOutputStream(jarFile)); JarOutputStream jarOut = closer.register(new JarOutputStream(fileOut)); for (String entry : entries) { jarOut.putNextEntry(new ZipEntry(entry)); Resources.copy(ClassPathTest.class.getResource(entry), jarOut); jarOut.closeEntry(); } } catch (Throwable e) { throw closer.rethrow(e); } finally { closer.close(); } }
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; } }
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); JarOutputStream target = new JarOutputStream(new FileOutputStream("output.jar"), manifest); add(new File("inputDirectory"), target);
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(); }
private File createJar(Manifest mf, String name) throws Exception { mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); File file = tempDir.newFile(name); OutputStream out = new JarOutputStream(new FileOutputStream(file), mf); out.flush(); IOUtils.closeQuietly(out); return file; } }
@Before public void run() throws IOException { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); tempJarPath = Files.createTempFile("test", ".jar"); JarOutputStream target = new JarOutputStream(new FileOutputStream(tempJarPath.toFile()), manifest); File startingDirectory = Paths.get(System.getProperty("user.dir"), "src", "test", "java").toFile(); addFileToJar(startingDirectory, startingDirectory, target); target.close(); }
public void readEntries(Map<String, Attributes> entries, Map<String, Manifest.Chunk> chunks) throws IOException { int mark = pos; while (readHeader()) { if (!Attributes.Name.NAME.equals(name)) { throw new IOException("Entry is not named"); } String entryNameValue = value; Attributes entry = entries.get(entryNameValue); if (entry == null) { entry = new Attributes(12); } while (readHeader()) { entry.put(name, value); } if (chunks != null) { if (chunks.get(entryNameValue) != null) { // TODO A bug: there might be several verification chunks for // the same name. I believe they should be used to update // signature in order of appearance; there are two ways to fix // this: either use a list of chunks, or decide on used // signature algorithm in advance and reread the chunks while // updating the signature; for now a defensive error is thrown throw new IOException("A jar verifier does not support more than one entry with the same name"); } chunks.put(entryNameValue, new Manifest.Chunk(mark, pos)); mark = pos; } entries.put(entryNameValue, entry); } }