private String getVersionOf(Manifest manifest) { String v = manifest.getMainAttributes().getValue("Plugin-Version"); if(v!=null) return v; // plugins generated before maven-hpi-plugin 1.3 should still have this attribute v = manifest.getMainAttributes().getValue("Implementation-Version"); if(v!=null) return v; return "???"; }
protected String identifyPluginShortName(File t) { try { JarFile j = new JarFile(t); try { String name = j.getManifest().getMainAttributes().getValue("Short-Name"); if (name!=null) return name; } finally { j.close(); } } catch (IOException e) { LOGGER.log(WARNING, "Failed to identify the short name from "+t,e); } return FilenameUtils.getBaseName(t.getName()); // fall back to the base name of what's uploaded }
private static String defaultMainClassName(JarFile jarFile) throws IOException { return jarFile.getManifest().getMainAttributes().getValue("GoCD-Main-Class"); } }
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"; } }
private static void parseClassPath(Manifest manifest, File archive, List<File> paths, String attributeName, String separator) throws IOException { String classPath = manifest.getMainAttributes().getValue(attributeName); if(classPath==null) return; // attribute not found for (String s : classPath.split(separator)) { File file = resolve(archive, s); if(file.getName().contains("*")) { // handle wildcard FileSet fs = new FileSet(); File dir = file.getParentFile(); fs.setDir(dir); fs.setIncludes(file.getName()); for( String included : fs.getDirectoryScanner(new Project()).getIncludedFiles() ) { paths.add(new File(dir,included)); } } else { if(!file.exists()) throw new IOException("No such file: "+file); paths.add(file); } } }
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();
/** * 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(); }
private static String kotlinVersionByJar() { StringBuilder kotlinVersion = new StringBuilder(""); JarInputStream kotlinJar = null; try { Class<?> kotlinUnit = Class.forName("kotlin.Unit"); kotlinVersion.append("kotlin"); kotlinJar = new JarInputStream(kotlinUnit.getProtectionDomain().getCodeSource().getLocation().openStream()); String version = kotlinJar.getManifest().getMainAttributes().getValue("Implementation-Version"); concat(kotlinVersion, version, "/"); } catch (ClassNotFoundException e) { //Ignore } catch (Exception e) { if (log.isTraceEnabled()) { log.trace("Exception attempting to get Kotlin version.", e); } } finally { closeQuietly(kotlinJar, log); } return kotlinVersion.toString(); }
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); }
Manifest input = jar.getManifest(); Manifest output = new Manifest(); Attributes main = output.getMainAttributes(); if (input != null) { main.putAll(input.getMainAttributes());
/** * Gets all attributes of the manifest file referenced by this {@code * JarURLConnection}. If this instance refers to a JAR-file rather than a * JAR-file entry, {@code null} will be returned. * * @return the attributes of the manifest file or {@code null}. * @throws IOException * if an I/O exception occurs while retrieving the {@code * JarFile}. */ public Attributes getMainAttributes() throws java.io.IOException { Manifest m = getJarFile().getManifest(); return (m == null) ? null : m.getMainAttributes(); } }
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");
public static String getCruiseVersion(String jar) { String version = null; try { JarFile jarFile = new JarFile(jar); Manifest manifest = jarFile.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); version = attributes.getValue("Go-Version"); } } catch (IOException e) { } return version; }
Attributes attributes = manifest.getMainAttributes(); if (attributes == null) { return; String s = attributes.getValue(Attributes.Name.CLASS_PATH); if (s == null) { return; file = new File(base, t); file = file.getCanonicalFile(); if (!file.exists()) { file = new File(t); file = file.getCanonicalFile(); if (!file.exists()) { URL url = new URL(t); file = new File(url.getFile()); file = file.getCanonicalFile(); if (!file.exists()) {
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));
/** * 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(); }
static String computeShortName(Manifest manifest, String fileName) { // use the name captured in the manifest, as often plugins // depend on the specific short name in its URLs. String n = manifest.getMainAttributes().getValue("Short-Name"); if(n!=null) return n; // maven seems to put this automatically, so good fallback to check. n = manifest.getMainAttributes().getValue("Extension-Name"); if(n!=null) return n; // otherwise infer from the file name, since older plugins don't have // this entry. return getBaseName(fileName); }
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(); } }
private static String getManifestKey(JarFile jarFile, String key) { try { Manifest manifest = jarFile.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); return attributes.getValue(key); } } catch (IOException e) { LOG.error("Exception while trying to read key {} from manifest of {}", key, jarFile.getName(), e); } return null; }