void expand(File jar, File dir) throws IOException { JarFile jarFile = new JarFile(jar); try { Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry je = entries.nextElement(); if (!je.isDirectory()) { copy(jarFile.getInputStream(je), new File(dir, je.getName())); } } } finally { jarFile.close(); } }
public GLBootstrap() throws Exception { System.setProperty("jogamp.gluegen.UseTempJarCache", "false"); log.info( "Initializing native JOGL jar dependencies for platform [{}]. Temp jar cache disabled.", PlatformPropsImpl.os_and_arch); String nativeJarName = String.format("%s-%s", NATIVES, PlatformPropsImpl.os_and_arch); String[] classpathEntries = System.getProperty(JAVA_CLASSPATH).split(System.getProperty(JAVA_SEPARATOR)); for (String jarPath : classpathEntries) { if (jarPath.contains(nativeJarName)) { if (log.isDebugEnabled()) { log.debug("Applicable platform jar: [{}]", jarPath); } JarFile jf = new JarFile(jarPath); try { Enumeration<JarEntry> jarEntries = jf.entries(); while (jarEntries.hasMoreElements()) { JarEntry je = jarEntries.nextElement(); if (!je.isDirectory() && !je.getName().contains(JAVA_META_INF)) { if (log.isDebugEnabled()) { log.debug("Mapping jar entry [{}] -> [{}]", je.getName(), jarPath); } if (log.isDebugEnabled() && platformNativeIndex.containsKey(je.getName())) { log.debug("Duplicate jar entry: [{}]", je.getName()); log.debug("Mapped at: [{}]", platformNativeIndex.get(je.getName())); log.debug("Also at: [{}]", jarPath); } platformNativeIndex.put(je.getName(), jarPath); } } } finally { closeJar(jf); } } } }
/** * Enables to get the name of an object in the spoken language thanks to the jar file * * @param jarName the file that contains the object classes * @return the object name in the spoken language */ private String getLangName(File jarName) { String name = null; try { URL url = jarName.toURI().toURL(); JarInputStream jarFile = new JarInputStream(url.openStream()); JarEntry jarEntry = jarFile.getNextJarEntry(); while (jarEntry != null) { if (!jarEntry.isDirectory() && jarEntry.getName().contains(Configuration.instance().getLanguage())) { int lang_index = jarEntry.getName().lastIndexOf(Configuration.instance().getLanguage()); name = jarEntry.getName().substring(lang_index + 3, jarEntry.getName().length() - 6); } jarEntry = jarFile.getNextJarEntry(); } } catch (Exception e) { LOG.error("Error getLangName " + jarName + " " + e); } return name; }
/** * This method scans to see which entry we're parsing and keeps various state information * depending on what type of file is being parsed. */ public void beginEntry(JarEntry je, ManifestEntryVerifier mev) throws IOException { if (je == null) return; if (debug != null) { debug.println("beginEntry " + je.getName()); } String name = je.getName(); /* * Assumptions: * 1. The manifest should be the first entry in the META-INF directory. * 2. The .SF/.DSA/.EC files follow the manifest, before any normal entries * 3. Any of the following will throw a SecurityException: * a. digest mismatch between a manifest section and * the SF section. * b. digest mismatch between the actual jar entry and the manifest */ if (parsingMeta) { String uname = name.toUpperCase(Locale.ENGLISH); if ((uname.startsWith("META-INF/") || uname.startsWith("/META-INF/"))) { if (je.isDirectory()) { mev.setEntry(null, je); return; } if (uname.equals(JarFile.MANIFEST_NAME) || uname.equals(JarIndex.INDEX_NAME)) { return; } if (SignatureFileVerifier.isBlockOrSF(uname)) { /* We parse only DSA, RSA or EC PKCS7 blocks. */ parsingBlockOrSF = true; baos.reset(); mev.setEntry(null, je); return; } // If a META-INF entry is not MF or block or SF, they should // be normal entries. According to 2 above, no more block or // SF will appear. Let's doneWithMeta. } } if (parsingMeta) { doneWithMeta(); } if (je.isDirectory()) { mev.setEntry(null, je); return; } // be liberal in what you accept. If the name starts with ./, remove // it as we internally canonicalize it with out the ./. if (name.startsWith("./")) name = name.substring(2); // be liberal in what you accept. If the name starts with /, remove // it as we internally canonicalize it with out the /. if (name.startsWith("/")) name = name.substring(1); // only set the jev object for entries that have a signature // (either verified or not) if (sigFileSigners.get(name) != null || verifiedSigners.get(name) != null) { mev.setEntry(name, je); return; } // don't compute the digest for this entry mev.setEntry(null, je); return; }