private static Manifest loadManifest(String jarUrl) throws Exception { InputStream is = new URL(jarUrl + "!/META-INF/MANIFEST.MF").openStream(); try { return new Manifest(is); } finally { is.close(); } }
public static String getVersion() { try { ClassLoader classLoader = Jadx.class.getClassLoader(); if (classLoader != null) { Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { Manifest manifest = new Manifest(resources.nextElement().openStream()); String ver = manifest.getMainAttributes().getValue("jadx-version"); if (ver != null) { return ver; } } } } catch (Exception e) { LOG.error("Can't get manifest file", e); } return "dev"; } }
/** * {@inheritDoc} */ public Manifest getManifest() throws IOException { File file = new File(folder, JarFile.MANIFEST_NAME); if (file.exists()) { InputStream inputStream = new FileInputStream(file); try { return new Manifest(inputStream); } finally { inputStream.close(); } } else { return NO_MANIFEST; } }
public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException { Preconditions.checkNotNull(relativePath, "relativePath"); Preconditions.checkNotNull(zos, "zos"); // by JAR spec, if there is a manifest, it must be the first entry in // the // ZIP. File manifestFile = new File(dir, JarFile.MANIFEST_NAME); ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); if (!manifestFile.exists()) { zos.putNextEntry(manifestEntry); new Manifest().write(new BufferedOutputStream(zos)); zos.closeEntry(); } else { InputStream is = new FileInputStream(manifestFile); copyToZipStream(is, manifestEntry, zos); } zos.closeEntry(); zipDir(dir, relativePath, zos, true); zos.close(); }
Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); JarOutputStream target = new JarOutputStream(new FileOutputStream("output.jar"), manifest); add(new File("inputDirectory"), target); target.close();
File f = new File(url.getPath()); jis = new JarInputStream(url.openStream()); mf = jis.getManifest(); } catch (IOException ioe) { try { is = new FileInputStream(manifest); mf = new Manifest(is); } catch (IOException e) { throw new PluginException("Failed loading manifest for plugin jar: " + url, e);
/** * Loads the manifest attributes from the jar. * * @throws java.net.MalformedURLException * @throws IOException */ private static synchronized void loadManifestAttributes() throws IOException { if (manifestAttributes != null) { return; } Class<?> clazz = HiveDriver.class; String classContainer = clazz.getProtectionDomain().getCodeSource() .getLocation().toString(); URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(manifestUrl.openStream()); manifestAttributes = manifest.getMainAttributes(); }
Enumeration<URL> resources = getClass().getClassLoader() .getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { try { Manifest manifest = new Manifest(resources.nextElement().openStream()); // check that this is your manifest and do what you need or get the next one ... } catch (IOException E) { // handle } }
private static Manifest getManifest(final URI uri) throws IOException { String content = IOUtils.toString(uri, StandardCharsets.UTF_8); InputStream istream = new ByteArrayInputStream(content.getBytes("UTF8")); try { Manifest manifest = new Manifest(istream); manifest.read(istream); manifest.getMainAttributes().putValue(MANIFEST_URI, uri.toString()); return manifest; } finally { istream.close(); } }
public static void print() throws IOException { InputStream manifestStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream("META-INF/MANIFEST.MF"); try { Manifest manifest = new Manifest(manifestStream); Attributes attributes = manifest.getMainAttributes(); String impVersion = attributes.getValue("Implementation-Version"); System.out.println(attributes); } catch (IOException ex) { ex.printStackTrace(); } }
/** * {@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); }
Class clazz = MyClass.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); if (!classPath.startsWith("jar")) { // Class not from JAR return; } String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; Manifest manifest = new Manifest(new URL(manifestPath).openStream()); Attributes attr = manifest.getMainAttributes(); String value = attr.getValue("Manifest-Version");
try (JarFile jf = new JarFile(new File(new URI(loc)), false)) { Manifest mf = jf.getManifest(); if (mf != null) { File manifestFile = new File(new URI(m.group(1) + "META-INF/MANIFEST.MF")); if (manifestFile.isFile()) { try (InputStream is = new FileInputStream(manifestFile)) { if (isPluginManifest(new Manifest(is))) { LOGGER.log(Level.FINE, "{0} looks like a Jenkins plugin based on {1}, OK", new Object[] {loc, manifestFile}); return true;
Path locationPath = new File(location).getCanonicalFile().toPath(); Files.createDirectories(locationPath); Manifest manifest = new Manifest(); Attributes global = manifest.getMainAttributes(); global.put(Attributes.Name.MANIFEST_VERSION, "1.0.0"); global.put(new Attributes.Name("Class-Path"), String.join(" ", manifestEntries));
private static Manifest loadManifest(String jarUrl) throws Exception { InputStream is = new URL(jarUrl + "!/META-INF/MANIFEST.MF").openStream(); try { return new Manifest(is); } finally { is.close(); } }
/** * Returns Manifest-Attributes for MANIFEST.MF, if running for a .jar file * * @return Manifest Attributes (may be empty but never null) * @throws IOException If something went wrong finding the MANIFEST file * @see <a href="http://stackoverflow.com/a/1273432">stackoverflow article</a> */ private static Attributes getAttributes() throws IOException { Class clazz = BuildInfoReader.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); if (!classPath.startsWith("jar")) { // Class not from JAR return new Attributes(0); } String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + FILE_NAME; Manifest manifest = new Manifest(new URL(manifestPath).openStream()); return manifest.getMainAttributes(); }
URLClassLoader cl = (URLClassLoader) getClass().getClassLoader(); try { URL url = cl.findResource("META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(url.openStream()); // do stuff with it ... } catch (IOException E) { // handle }