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"); } }
/** * 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(); } }
try (JarFile jf = new JarFile(new File(new URI(loc)), false)) { Manifest mf = jf.getManifest(); if (mf != null) { if (isPluginManifest(mf)) { File manifestFile = new File(new URI(m.group(1) + "META-INF/MANIFEST.MF")); if (manifestFile.isFile()) { try (InputStream is = new FileInputStream(manifestFile)) {
private static Manifest getClassLoaderForExtraModule(String filepath) throws IOException { File jar = new File(filepath); JarFile jf = new JarFile(jar); Manifest mf = jf.getManifest(); jf.close(); return mf; }
private void scanJar(File file, ClassLoader classloader) throws IOException { JarFile jarFile; try { jarFile = new JarFile(file); } catch (IOException e) { // Not a jar file return; } try { for (File path : getClassPathFromManifest(file, jarFile.getManifest())) { scan(path, classloader); } scanJarFile(classloader, jarFile); } finally { try { jarFile.close(); } catch (IOException ignored) { } } }
@Override public String getShortName(File archive) throws IOException { Manifest manifest; if (!archive.exists()) { throw new FileNotFoundException("Failed to load " + archive + ". The file does not exist"); } else if (!archive.isFile()) { throw new FileNotFoundException("Failed to load " + archive + ". It is not a file"); } if (isLinked(archive)) { manifest = loadLinkedManifest(archive); } else { try (JarFile jf = new JarFile(archive, false)) { manifest = jf.getManifest(); } catch (IOException ex) { // Mention file name in the exception throw new IOException("Failed to load " + archive, ex); } } return PluginWrapper.computeShortName(manifest, archive.getName()); }
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; }
try { fis = new FileInputStream(classpathItem); JarFile jar = new JarFile(classpathItem); manifest = jar.getManifest(); } catch (IOException ignore) { File metaDir = new File(classpathItem, "META-INF"); File manifestFile = null; if (metaDir.isDirectory()) { for (String m : MANIFESTS) { File mFile = new File(metaDir, m); if (mFile.isFile()) { manifestFile = mFile;
protected boolean isJar(URL url) { JarFile jarFile = null; try { File file = new File(url.getPath()); jarFile = new JarFile(file); jarFile.getManifest(); return true; } catch (IOException e) { return false; } finally { if (jarFile != null) { try { jarFile.close(); } catch (IOException e) { } } } }
private void scanJar(File file, ClassLoader classloader) throws IOException { JarFile jarFile; try { jarFile = new JarFile(file); } catch (IOException e) { // Not a jar file return; } try { for (File path : getClassPathFromManifest(file, jarFile.getManifest())) { scan(path, classloader); } scanJarFile(classloader, jarFile); } finally { try { jarFile.close(); } catch (IOException ignored) { } } }
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; }
/** * Retrieve manifest for specified file. * * @param file the file * @return the manifest * @throws BuildException if error occurs (file doesn't exist, * file not a jar, manifest doesn't exist in file) */ static Manifest getManifest(final File file) throws BuildException { try (JarFile jarFile = new JarFile(file)) { Manifest m = jarFile.getManifest(); if (m == null) { throw new BuildException("%s doesn't have a MANIFEST", file); } return m; } catch (final IOException ioe) { throw new BuildException(ioe.getMessage(), ioe); } }
Manifest input = jar.getManifest(); Manifest output = new Manifest(); Attributes main = output.getMainAttributes(); if (input != null) { main.putAll(input.getMainAttributes());
/** Useful for {@code JenkinsRule.createSlave}, {@code hudson-dev:run}, etc. */ private @CheckForNull URL findExecutableJar(File notActuallyJAR, Class<?> mainClass) throws IOException { if (notActuallyJAR.getName().equals("classes")) { File[] siblings = notActuallyJAR.getParentFile().listFiles(); if (siblings != null) { for (File actualJar : siblings) { if (actualJar.getName().endsWith(".jar")) { try (JarFile jf = new JarFile(actualJar, false)) { Manifest mf = jf.getManifest(); if (mf != null && mainClass.getName().equals(mf.getMainAttributes().getValue("Main-Class"))) { LOGGER.log(Level.FINE, "found {0}", actualJar); return actualJar.toURI().toURL(); } } } } } } return null; }
try { fis = new FileInputStream(classpathItem); JarFile jar = new JarFile(classpathItem); manifest = jar.getManifest(); } catch (IOException ignore) { File metaDir = new File(classpathItem, "META-INF"); File manifestFile = null; if (metaDir.isDirectory()) { for (String m : MANIFESTS) { File mFile = new File(metaDir, m); if (mFile.isFile()) { manifestFile = mFile;
private void scanJar(File file, ClassLoader classloader) throws IOException { JarFile jarFile; try { jarFile = new JarFile(file); } catch (IOException e) { // Not a jar file return; } try { for (File path : getClassPathFromManifest(file, jarFile.getManifest())) { scan(path, classloader); } scanJarFile(classloader, jarFile); } finally { try { jarFile.close(); } catch (IOException ignored) { } } }
private static String getImplementationVersion(JarFile jarFile) throws IOException { return jarFile.getManifest().getMainAttributes() .getValue(Attributes.Name.IMPLEMENTATION_VERSION); }
/** * Load list of available extensions from specified file. * * @param file the file * @param extensionList the list to add available extensions to * @throws BuildException if there is an error */ private static void loadExtensions(final File file, final List<Extension> extensionList, final boolean includeImpl, final boolean includeURL) throws BuildException { try (JarFile jarFile = new JarFile(file)) { for (Extension extension : Extension .getAvailable(jarFile.getManifest())) { addExtension(extensionList, extension, includeImpl, includeURL); } } catch (final Exception e) { throw new BuildException(e.getMessage(), e); } }
/** * Returns String with version of backup .war file, * if the file does not exists returns null */ public String getBackupVersion() { try { try (JarFile backupWar = new JarFile(new File(Lifecycle.get().getHudsonWar() + ".bak"))) { Attributes attrs = backupWar.getManifest().getMainAttributes(); String v = attrs.getValue("Jenkins-Version"); if (v == null) v = attrs.getValue("Hudson-Version"); return v; } } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to read backup version ", e); return null;} }