List of usage examples for java.util.jar JarFile entries
public Enumeration<JarEntry> entries()
From source file:org.rhq.enterprise.server.plugin.pc.perspective.PerspectiveServerPluginManager.java
private void deployEmbeddedWars(ServerPluginEnvironment env) { String name = null;/* ww w . java 2 s .c om*/ try { JarFile pluginJarFile = new JarFile(env.getPluginUrl().getFile()); try { for (JarEntry entry : Collections.list(pluginJarFile.entries())) { name = entry.getName(); if (name.toLowerCase().endsWith(".war")) { deployWar(env, entry.getName(), pluginJarFile.getInputStream(entry)); } } } finally { pluginJarFile.close(); } } catch (Exception e) { Throwable t = (e instanceof MBeanException) ? e.getCause() : e; log.error("Failed to deploy " + env.getPluginKey().getPluginName() + "#" + name, t); } }
From source file:org.spoutcraft.launcher.launch.MinecraftClassLoader.java
private void index(File file) throws IOException { JarFile jar = null; try {/*from w w w . jav a 2s .co m*/ jar = new JarFile(file); Enumeration<JarEntry> i = jar.entries(); while (i.hasMoreElements()) { JarEntry entry = i.nextElement(); if (entry.getName().endsWith(".class")) { String name = entry.getName(); name = name.replace("/", ".").substring(0, name.length() - 6); classLocations.put(name, file); } } } catch (IOException e) { throw e; } finally { if (jar != null) { try { jar.close(); } catch (IOException ignore) { } } } }
From source file:com.netflix.nicobar.core.archive.JarScriptArchive.java
protected JarScriptArchive(ScriptModuleSpec moduleSpec, Path jarPath, String moduleSpecEntry, long createTime) throws IOException { this.createTime = createTime; this.moduleSpec = Objects.requireNonNull(moduleSpec, "moduleSpec"); Objects.requireNonNull(jarPath, "jarFile"); if (!jarPath.isAbsolute()) throw new IllegalArgumentException("jarPath must be absolute."); // initialize the index JarFile jarFile = new JarFile(jarPath.toFile()); Set<String> indexBuilder; try {// ww w . j a v a 2 s. c o m Enumeration<JarEntry> jarEntries = jarFile.entries(); indexBuilder = new HashSet<String>(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); // Skip adding moduleSpec to archive entries if (jarEntry.getName().equals(moduleSpecEntry)) { continue; } if (!jarEntry.isDirectory()) { indexBuilder.add(jarEntry.getName()); } } } finally { jarFile.close(); } entryNames = Collections.unmodifiableSet(indexBuilder); rootUrl = jarPath.toUri().toURL(); }
From source file:org.lnicholls.galleon.app.AppDescriptor.java
public AppDescriptor(File jar) throws IOException, AppException { mJar = jar;/*from w w w . j a v a 2 s. c om*/ JarFile zipFile = new JarFile(jar); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String name = entry.getName(); if (name.toUpperCase().equals(JarFile.MANIFEST_NAME)) { InputStream in = null; try { in = zipFile.getInputStream(entry); Manifest manifest = new Manifest(in); Attributes attributes = manifest.getMainAttributes(); if (attributes.getValue("Main-Class") != null) { mClassName = (String) attributes.getValue("Main-Class"); if (attributes.getValue("HME-Arguments") != null) mArguments = (String) attributes.getValue("HME-Arguments"); if (attributes.getValue(TITLE) != null) mTitle = (String) attributes.getValue(TITLE); if (attributes.getValue(RELEASE_DATE) != null) mReleaseDate = (String) attributes.getValue(RELEASE_DATE); if (attributes.getValue(DESCRIPTION) != null) mDescription = (String) attributes.getValue(DESCRIPTION); if (attributes.getValue(DOCUMENTATION) != null) mDocumentation = (String) attributes.getValue(DOCUMENTATION); if (attributes.getValue(AUTHOR_NAME) != null) mAuthorName = (String) attributes.getValue(AUTHOR_NAME); if (attributes.getValue(AUTHOR_EMAIL) != null) mAuthorEmail = (String) attributes.getValue(AUTHOR_EMAIL); if (attributes.getValue(AUTHOR_HOMEPAGE) != null) mAuthorHomepage = (String) attributes.getValue(AUTHOR_HOMEPAGE); if (attributes.getValue(VERSION) != null) mVersion = (String) attributes.getValue(VERSION); if (attributes.getValue(CONFIGURATION) != null) mConfiguration = (String) attributes.getValue(CONFIGURATION); if (attributes.getValue(CONFIGURATION_PANEL) != null) mConfigurationPanel = (String) attributes.getValue(CONFIGURATION_PANEL); if (attributes.getValue(TAGS) != null) mTags = (String) attributes.getValue(TAGS); } if (mTitle == null) { mTitle = jar.getName().substring(0, jar.getName().indexOf('.')); } } catch (Exception ex) { Tools.logException(AppDescriptor.class, ex, "Cannot get descriptor: " + jar.getAbsolutePath()); } finally { if (in != null) { try { in.close(); in = null; } catch (Exception ex) { } } } break; } } zipFile.close(); }
From source file:javadepchecker.Main.java
/** * Scan jar for classes to be processed by ASM * * @param jar jar file to be processed// ww w .j av a2 s . c om * @throws IOException */ public void processJar(JarFile jar) throws IOException { Collections.list(jar.entries()).stream() .filter((JarEntry entry) -> (!entry.isDirectory() && entry.getName().endsWith("class"))) .forEach((JarEntry entry) -> { InputStream is = null; try { Main.this.mCurrent.add(entry.getName()); is = jar.getInputStream(entry); new ClassReader(is).accept(Main.this, 0); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (is != null) is.close(); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:de.knurt.fam.plugin.DefaultPluginResolver.java
private void initPlugins() { File pluginDirectory = new File(FamConnector.me().getPluginDirectory()); if (pluginDirectory.exists() && pluginDirectory.isDirectory() && pluginDirectory.canRead()) { File[] files = pluginDirectory.listFiles(); ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader(); for (File file : files) { if (file.isFile() && file.getName().toLowerCase().endsWith("jar")) { JarFile jar = null; try { jar = new JarFile(file.getAbsoluteFile().toString()); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry entry = jarEntries.nextElement(); if (entry.getName().toLowerCase().endsWith("class")) { String className = entry.getName().replaceAll("/", ".").replaceAll("\\.class$", ""); // @SuppressWarnings("resource") // classLoader must not be closed, getting an "IllegalStateException: zip file closed" otherwise URLClassLoader classLoader = new URLClassLoader(new URL[] { file.toURI().toURL() }, currentThreadClassLoader); Class<?> cl = classLoader.loadClass(className); if (this.isPlugin(cl)) { Plugin plugin = (Plugin) cl.newInstance(); this.plugins.add(plugin); }/*from w w w .ja v a 2 s . c o m*/ } } } catch (IllegalAccessException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091426l); } catch (InstantiationException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091424l); } catch (ClassNotFoundException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091425l); } catch (IOException e) { e.printStackTrace(); FamLog.logException(this.getClass(), e, "failed to load plugin", 201010091351l); } finally { try { jar.close(); } catch (Exception e) { } } } } for (Plugin plugin : this.plugins) { boolean found = false; if (this.implementz(plugin.getClass(), RegisterSubmission.class)) { if (found == true) { throw new PluginConfigurationException("Found more than one RegisterSubmission classes"); // TODO #19 supply a solution Ticket } this.registerSubmission = (RegisterSubmission) plugin; found = true; } } for (Plugin plugin : this.plugins) { plugin.start(); } } // search plugin if (this.registerSubmission == null) { this.registerSubmission = new DefaultRegisterSubmission(); } }
From source file:org.wisdom.resources.WebJarDeployer.java
private FileWebJarLib expand(DetectedWebJar lib, JarFile jar) { File out = new File(cache, lib.id); Enumeration<? extends ZipEntry> entries = jar.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().startsWith(WebJarController.WEBJAR_LOCATION) && !entry.isDirectory()) { // Compute destination. File output = new File(out, entry.getName().substring(WebJarController.WEBJAR_LOCATION.length())); InputStream stream = null; try { stream = jar.getInputStream(entry); boolean made = output.getParentFile().mkdirs(); LOGGER.debug("{} directory created : {} ", output.getParentFile().getAbsolutePath(), made); FileUtils.copyInputStreamToFile(stream, output); } catch (IOException e) { LOGGER.error("Cannot unpack " + entry.getName() + " from " + lib.file.getName(), e); return null; } finally { IOUtils.closeQuietly(stream); }//from www .j ava2s .co m } } File root = new File(out, lib.name + "/" + lib.version); return new FileWebJarLib(lib.name, lib.version, root, lib.file.getName()); }
From source file:org.hyperic.hq.plugin.activemq.EmbeddedActiveMQServerDetector.java
@Override protected File findVersionFile(File dir, Pattern pattern) { File res = null;//from ww w. j ava2 s . co m log.debug("[findVersionFile] dir=" + dir + " pattern=" + pattern); if (!dir.exists()) { log.debug("File '" + dir + "' Not Found"); return null; } // In an Embedded ActiveMQ instance, we know we are starting with // CATALINA_BASE // Give preferential search treatment to webapps/*/WEB-INF/lib for // performance gains File libDir = new File(dir, "lib"); if (libDir.exists()) { File versionFile = super.findVersionFile(libDir, pattern); if (versionFile != null) { res = versionFile; } } if (res == null) { File webappsDir = new File(dir, "webapps"); if (webappsDir.exists()) { for (File app : webappsDir.listFiles()) { if (app.isDirectory()) { File wlibDir = new File(app, "WEB-INF" + File.separator + "lib"); if (wlibDir.exists()) { File versionFile = super.findVersionFile(wlibDir, pattern); if (versionFile != null) { res = versionFile; } } } else if (app.getName().endsWith(".war")) { JarFile war = null; try { war = new JarFile(app); Enumeration<JarEntry> files = war.entries(); while (files.hasMoreElements()) { final String fileName = files.nextElement().toString(); if (pattern.matcher(fileName).find()) { res = new File(app + "!" + fileName); break; } } } catch (IOException ex) { log.debug("Error: '" + app + "': " + ex.getMessage(), ex); } finally { if (war != null) { try { war.close(); } catch (IOException e) { log.debug("Unable to close war file: " + e.getMessage(), e); } } } } } } } if ((res == null) && recursive) { res = super.findVersionFile(dir, pattern); } log.debug("[findVersionFile] res=" + res); return res; }
From source file:io.fabric8.insight.log.support.LogQuerySupport.java
protected String jarIndex(JarFile jarFile) { StringBuilder buffer = new StringBuilder(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); addJarEntryToIndex(entry, buffer); }//from www.j a v a 2s. c o m return buffer.toString(); }
From source file:net.sf.mavenjython.JythonMojo.java
public Collection<File> extractJarToDirectory(File jar, File outputDirectory) throws MojoExecutionException { getLog().info("extracting " + jar); JarFile ja = openJarFile(jar); Enumeration<JarEntry> en = ja.entries(); Collection<File> files = extractAllFiles(outputDirectory, ja, en); closeFile(ja);//from ww w. j av a 2s. co m return files; }