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 Map<String, SQLCase> loadSQLCasesFromJar(final String path, final File file) throws IOException, JAXBException { Map<String, SQLCase> result = new TreeMap<>(); try (JarFile jar = new JarFile(file)) { Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.startsWith(path + "/") && name.endsWith(".xml")) { fillSQLMap(result, SQLCasesLoader.class.getClassLoader().getResourceAsStream(name)); } } } return result; }
@Override public String call() throws IOException { File[] jars = new File(getHomeDir(), "lib").listFiles(); if (jars != null) { // be defensive for (File jar : jars) { if (jar.getName().startsWith("maven-")) { JarFile jf = null; try { jf = new JarFile(jar); Manifest manifest = jf.getManifest(); String version = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION); if (version != null) { return version; } } finally { if (jf != null) { jf.close(); } } } } } return ""; } }
JarClassPath(String pathname) throws NotFoundException { JarFile jarfile = null; try { jarfile = new JarFile(pathname); jarfileEntries = new ArrayList<String>(); for (JarEntry je:Collections.list(jarfile.entries())) if (je.getName().endsWith(".class")) jarfileEntries.add(je.getName()); jarfileURL = new File(pathname).getCanonicalFile() .toURI().toURL().toString(); return; } catch (IOException e) {} finally { if (null != jarfile) try { jarfile.close(); } catch (IOException e) {} } throw new NotFoundException(pathname); }
public static List<File> extractFilesInLibDirAndReturnFiles(File aJarFile, Predicate<JarEntry> extractFilter, File outputTmpDir) { List<File> newClassPath = new ArrayList<>(); try (JarFile jarFile = new JarFile(aJarFile)) { List<File> extractedJars = jarFile.stream() .filter(extractFilter) .map(jarEntry -> { String jarFileBaseName = FilenameUtils.getName(jarEntry.getName()); File targetFile = new File(outputTmpDir, jarFileBaseName); return extractJarEntry(jarFile, jarEntry, targetFile); }) .collect(Collectors.toList()); // add deps in dir specified by `libDirManifestKey` newClassPath.addAll(extractedJars); } catch (IOException e) { throw new RuntimeException(e); } return newClassPath; }
private static long jarComparisonKeyFunction(File file) { try { return new JarFile(file).entries().nextElement().getTime(); } catch (IOException e) { throw new RuntimeException(e); } }
JarFile jarFile = new JarFile(jarFilePath); try { for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = entries.nextElement(); String entryPath = entry.getName(); if (getPathMatcher().match(entryPattern, entryPath)) { result.add(new UrlResource( jarFile.close();
public void addClassPathEntry(String classPathEntry) { if (classPathEntry.endsWith(".jar")) { try { JarFile jarFile = new JarFile(classPathEntry); jarFiles.add(jarFile); } catch (IOException e) { throw new IllegalStateException("Failed to register classPath entry: " + classPathEntry, e); } } else { File classDirectory = new File(classPathEntry); classDirectories.add(classDirectory); } }
/** * find jar file * * @param filePath 文件路径 * @param packageName 包名 * @return list * @throws IOException 文件读取异常 */ private Set<String> findJarFiles(String filePath, String packageName) throws IOException { JarFile localJarFile = new JarFile(new File(filePath)); Set<String> inJarFiles = findInJarFiles(localJarFile, packageName); localJarFile.close(); return inJarFiles; }
JarClassPath(String pathname) throws NotFoundException { JarFile jarfile = null; try { jarfile = new JarFile(pathname); jarfileEntries = new ArrayList<String>(); for (JarEntry je:Collections.list(jarfile.entries())) if (je.getName().endsWith(".class")) jarfileEntries.add(je.getName()); jarfileURL = new File(pathname).getCanonicalFile() .toURI().toURL().toString(); return; } catch (IOException e) {} finally { if (null != jarfile) try { jarfile.close(); } catch (IOException e) {} } throw new NotFoundException(pathname); }
JarFile jarFile = new JarFile(pathToJar); Enumeration<JarEntry> e = jarFile.entries(); URL[] urls = { new URL("jar:file:" + pathToJar+"!/") }; URLClassLoader cl = URLClassLoader.newInstance(urls); while (e.hasMoreElements()) { JarEntry je = e.nextElement(); if(je.isDirectory() || !je.getName().endsWith(".class")){ continue; } // -6 because of .class String className = je.getName().substring(0,je.getName().length()-6); className = className.replace('/', '.'); Class c = cl.loadClass(className); }
/** * 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;} }
JarFile jarFile = null; try { jarFile = new JarFile(pathComponent); Manifest manifest = jarFile.getManifest(); if (manifest == null) { } finally { if (jarFile != null) { jarFile.close(); File libraryFile = new File(decodedPath); if (libraryFile.exists() && !isInPath(libraryFile)) { addPathFile(libraryFile);
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) { } } }
java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile); java.util.Enumeration enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement(); java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName()); if (file.isDirectory()) { // if its a directory, create it f.mkdir(); continue; } java.io.InputStream is = jar.getInputStream(file); // get the input stream java.io.FileOutputStream fos = new java.io.FileOutputStream(f); while (is.available() > 0) { // write contents of 'is' to 'fos' fos.write(is.read()); } fos.close(); is.close(); }
jar = new JarFile(new File(jarFile.toURI())); } catch (URISyntaxException use) { throw new ProgramInvocationException("Invalid file path '" + jarFile.getPath() + "'", use); jar.close(); } catch (Throwable t) { throw new ProgramInvocationException("Could not close the JAR file: " + t.getMessage(), t);