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 }
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();
/** * Cleans up any resources held by this classloader. Any open archive * files are closed. */ public synchronized void cleanup() { for (Enumeration e = jarFiles.elements(); e.hasMoreElements();) { JarFile jarFile = (JarFile) e.nextElement(); try { jarFile.close(); } catch (IOException ioe) { // ignore } } jarFiles = new Hashtable(); if (project != null) { project.removeBuildListener(this); } project = null; }
@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); }
File dir = new File(outputPath); if (!dir.exists()) { dir.mkdirs(); jf = new JarFile(fileName); for (Enumeration<JarEntry> e = jf.entries(); e.hasMoreElements(); ) { JarEntry je = e.nextElement(); String outFileName = outputPath + je.getName(); File f = new File(outFileName); if (je.isDirectory()) { if (!f.exists()) { if (jf != null) { try { jf.close(); } catch (IOException e) { e.printStackTrace();
/** * 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); }
public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try { Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); ensureDirectory(file.getParentFile()); OutputStream out = new FileOutputStream(file); try { copyBytes(in, out, 8192); } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }
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);
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); }
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) { } } }
jarFileUrl = jarCon.getJarFileURL().toExternalForm(); JarEntry jarEntry = jarCon.getJarEntry(); rootEntryPath = (jarEntry != null ? jarEntry.getName() : ""); closeJarFile = !jarCon.getUseCaches(); jarFile = new JarFile(urlFile); jarFileUrl = urlFile; rootEntryPath = ""; for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = entries.nextElement(); String entryPath = entry.getName(); if (entryPath.startsWith(rootEntryPath)) { String relativePath = entryPath.substring(rootEntryPath.length()); jarFile.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);
public static boolean containsDebugInfo(final String filename) throws IOException { if (!filename.endsWith(".jar") || !new File(filename).exists()) return false; final JarFile jar = new JarFile(filename); for (final JarEntry file : Collections.list(jar.entries())) { if (!file.getName().endsWith(".class")) continue; final InputStream input = jar.getInputStream(file); final byte[] code = UpdaterUtil.readStreamAsBytes(input); final ByteCodeAnalyzer analyzer = new ByteCodeAnalyzer(code, Mode.METHODS); if (analyzer.containsDebugInfo()) return true; } jar.close(); return false; }
public static void unJar(File jarFile, File toDir) throws IOException { if (jarFile == null) return; JarFile jar = new JarFile(jarFile); try { Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory() && isOk(entry.getName())) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); file.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(file); jar.close();
public static void fillMetadataFromJar(final FileObject object, final File file) throws ParserConfigurationException, IOException, SAXException { final JarFile jar = new JarFile(file); for (final JarEntry entry : UpdaterUtil.iterate(jar.entries())) { if (entry.getName().matches("META-INF/maven/.*/pom.xml")) { new POMParser(object).read(jar.getInputStream(entry)); break; } } jar.close(); }