List of usage examples for java.util.jar JarFile MANIFEST_NAME
String MANIFEST_NAME
To view the source code for java.util.jar JarFile MANIFEST_NAME.
Click Source Link
From source file:org.apache.hadoop.hive.ql.metadata.JarUtils.java
private static void zipDir(File dir, String relativePath, ZipOutputStream zos, boolean start) throws IOException { String[] dirList = dir.list(); for (String aDirList : dirList) { File f = new File(dir, aDirList); if (!f.isHidden()) { if (f.isDirectory()) { if (!start) { ZipEntry dirEntry = new ZipEntry(relativePath + f.getName() + "/"); zos.putNextEntry(dirEntry); zos.closeEntry();/*from w ww . ja va 2 s . c o m*/ } String filePath = f.getPath(); File file = new File(filePath); zipDir(file, relativePath + f.getName() + "/", zos, false); } else { String path = relativePath + f.getName(); if (!path.equals(JarFile.MANIFEST_NAME)) { ZipEntry anEntry = new ZipEntry(path); InputStream is = new FileInputStream(f); copyToZipStream(is, anEntry, zos); } } } } }
From source file:org.apache.sling.testing.mock.sling.NodeTypeDefinitionScanner.java
/** * Find all node type definition classpath paths by searching all MANIFEST.MF files in the classpath and reading * the paths from the "Sling-Nodetypes" entry. * The order of the paths from each entry is preserved, but the overall order when multiple bundles define such an entry * is not deterministic and may not be correct according to the dependencies between the node type definitions. * @return List of node type definition class paths *///from w ww.ja va2s . c o m private static List<String> findeNodeTypeDefinitions() { List<String> nodeTypeDefinitions = new ArrayList<String>(); try { Enumeration<URL> resEnum = NodeTypeDefinitionScanner.class.getClassLoader() .getResources(JarFile.MANIFEST_NAME); while (resEnum.hasMoreElements()) { try { URL url = (URL) resEnum.nextElement(); InputStream is = url.openStream(); if (is != null) { try { Manifest manifest = new Manifest(is); Attributes mainAttribs = manifest.getMainAttributes(); String nodeTypeDefinitionList = mainAttribs.getValue("Sling-Nodetypes"); String[] nodeTypeDefinitionArray = StringUtils.split(nodeTypeDefinitionList, ","); if (nodeTypeDefinitionArray != null) { for (String nodeTypeDefinition : nodeTypeDefinitionArray) { if (!StringUtils.isBlank(nodeTypeDefinition)) { nodeTypeDefinitions.add(StringUtils.trim(nodeTypeDefinition)); } } } } finally { is.close(); } } } catch (Throwable ex) { log.warn("Unable to read JAR manifest.", ex); } } } catch (IOException ex2) { log.warn("Unable to read JAR manifests.", ex2); } return nodeTypeDefinitions; }
From source file:org.apache.sling.tooling.support.install.impl.InstallServlet.java
private void installBasedOnDirectory(HttpServletResponse resp, final File dir) throws FileNotFoundException, IOException { InstallationResult result = null;/*from ww w . j a va 2s .c om*/ if (dir.exists() && dir.isDirectory()) { logger.info("Checking dir {} for bundle install", dir); final File manifestFile = new File(dir, JarFile.MANIFEST_NAME); if (manifestFile.exists()) { FileInputStream fis = null; try { fis = new FileInputStream(manifestFile); final Manifest mf = new Manifest(fis); final String symbolicName = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); if (symbolicName != null) { // search bundle Bundle found = getBundle(symbolicName); final File tempFile = File.createTempFile(dir.getName(), "bundle"); try { createJar(dir, tempFile, mf); final InputStream in = new FileInputStream(tempFile); try { String location = dir.getAbsolutePath(); installOrUpdateBundle(found, in, location); result = new InstallationResult(true, null); resp.setStatus(200); result.render(resp.getWriter()); return; } catch (final BundleException be) { logAndWriteError("Unable to install/update bundle from dir " + dir, be, resp); } } finally { tempFile.delete(); } } else { logAndWriteError("Manifest in " + dir + " does not have a symbolic name", resp); } } finally { IOUtils.closeQuietly(fis); } } else { result = new InstallationResult(false, "Dir " + dir + " does not have a manifest"); logAndWriteError("Dir " + dir + " does not have a manifest", resp); } } else { result = new InstallationResult(false, "Dir " + dir + " does not exist"); logAndWriteError("Dir " + dir + " does not exist", resp); } }
From source file:org.apache.sling.tooling.support.install.impl.InstallServlet.java
private static void createJar(final File sourceDir, final File jarFile, final Manifest mf) throws IOException { final JarOutputStream zos = new JarOutputStream(new FileOutputStream(jarFile)); try {// ww w.jav a 2 s . c om zos.setLevel(Deflater.NO_COMPRESSION); // manifest first final ZipEntry anEntry = new ZipEntry(JarFile.MANIFEST_NAME); zos.putNextEntry(anEntry); mf.write(zos); zos.closeEntry(); zipDir(sourceDir, zos, ""); } finally { try { zos.close(); } catch (final IOException ignore) { // ignore } } }
From source file:org.apache.sling.tooling.support.install.impl.InstallServlet.java
public static void zipDir(final File sourceDir, final ZipOutputStream zos, final String path) throws IOException { final byte[] readBuffer = new byte[8192]; int bytesIn = 0; for (final File f : sourceDir.listFiles()) { if (f.isDirectory()) { final String prefix = path + f.getName() + "/"; zos.putNextEntry(new ZipEntry(prefix)); zipDir(f, zos, prefix);// w ww.j av a 2 s . com } else { final String entry = path + f.getName(); if (!JarFile.MANIFEST_NAME.equals(entry)) { final FileInputStream fis = new FileInputStream(f); try { final ZipEntry anEntry = new ZipEntry(entry); zos.putNextEntry(anEntry); while ((bytesIn = fis.read(readBuffer)) != -1) { zos.write(readBuffer, 0, bytesIn); } } finally { fis.close(); } } } } }
From source file:org.dhatim.archive.Archive.java
private void writeEntriesToArchive(ZipOutputStream archiveStream) throws IOException { File manifestFile = entries.get(JarFile.MANIFEST_NAME); // Always write the jar manifest as the first entry, if it exists... if (manifestFile != null) { byte[] manifest = FileUtils.readFile(manifestFile); writeEntry(JarFile.MANIFEST_NAME, manifest, archiveStream); }//from w w w.ja v a 2s .c o m Set<Map.Entry<String, File>> entrySet = entries.entrySet(); for (Map.Entry<String, File> entry : entrySet) { if (!entry.getKey().equals(JarFile.MANIFEST_NAME)) { File file = entry.getValue(); if (file != null && !file.isDirectory()) { writeEntry(entry.getKey(), FileUtils.readFile(file), archiveStream); } else { writeEntry(entry.getKey(), null, archiveStream); } } } }
From source file:org.docx4j.jaxb.Context.java
public static void searchManifestsForJAXBImplementationInfo(ClassLoader loader) { Enumeration resEnum;/*from w w w .ja v a2 s . co m*/ try { resEnum = loader.getResources(JarFile.MANIFEST_NAME); while (resEnum.hasMoreElements()) { InputStream is = null; try { URL url = (URL) resEnum.nextElement(); // System.out.println("\n\n" + url); is = url.openStream(); if (is != null) { Manifest manifest = new Manifest(is); Attributes mainAttribs = manifest.getMainAttributes(); String impTitle = mainAttribs.getValue("Implementation-Title"); if (impTitle != null && impTitle.contains("JAXB Reference Implementation") || impTitle.contains("org.eclipse.persistence")) { log.info("\n" + url); for (Object key2 : mainAttribs.keySet()) { log.info(key2 + " : " + mainAttribs.getValue((java.util.jar.Attributes.Name) key2)); } } // In 2.1.3, it is in here for (String key : manifest.getEntries().keySet()) { //System.out.println(key); if (key.equals("com.sun.xml.bind.v2.runtime")) { log.info("Found JAXB reference implementation in " + url); mainAttribs = manifest.getAttributes((String) key); for (Object key2 : mainAttribs.keySet()) { log.info(key2 + " : " + mainAttribs.getValue((java.util.jar.Attributes.Name) key2)); } } } } } catch (Exception e) { // Silently ignore // log.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } } } catch (IOException e1) { // Silently ignore // log.error(e1); } }
From source file:org.eclipse.wb.internal.core.editor.palette.dialogs.ImportArchiveDialog.java
private List<PaletteElementInfo> extractElementsFromJarByManifest(JarInputStream jarStream) throws Exception { List<PaletteElementInfo> elements = Lists.newArrayList(); Manifest manifest = jarStream.getManifest(); // check manifest, if null find it if (manifest == null) { try {// w ww . j av a 2s . co m while (true) { JarEntry entry = jarStream.getNextJarEntry(); if (entry == null) { break; } if (JarFile.MANIFEST_NAME.equalsIgnoreCase(entry.getName())) { // read manifest data byte[] buffer = IOUtils.toByteArray(jarStream); jarStream.closeEntry(); // create manifest manifest = new Manifest(new ByteArrayInputStream(buffer)); break; } } } catch (Throwable e) { DesignerPlugin.log(e); manifest = null; } } if (manifest != null) { // extract all "Java-Bean: True" classes for (Iterator<Map.Entry<String, Attributes>> I = manifest.getEntries().entrySet().iterator(); I .hasNext();) { Map.Entry<String, Attributes> mapElement = I.next(); Attributes attributes = mapElement.getValue(); if (JAVA_BEAN_VALUE.equalsIgnoreCase(attributes.getValue(JAVA_BEAN_KEY))) { String beanClass = mapElement.getKey(); if (beanClass == null || beanClass.length() <= JAVA_BEAN_CLASS_SUFFIX.length()) { continue; } // convert 'aaa/bbb/ccc.class' to 'aaa.bbb.ccc' PaletteElementInfo element = new PaletteElementInfo(); element.className = StringUtils.substringBeforeLast(beanClass, JAVA_BEAN_CLASS_SUFFIX) .replace('/', '.'); element.name = CodeUtils.getShortClass(element.className); elements.add(element); } } } return elements; }
From source file:org.jahia.services.modulemanager.util.ModuleUtils.java
/** * Performs the transformation of the capability attributes in the MANIFEST.MF file of the supplied stream. * * @param sourceStream the source stream for the bundle, which manifest has to be adjusted w.r.t. module dependencies; the stream is * closed after returning from this method * @return the transformed stream for the bundle with adjusted manifest * @throws IOException in case of I/O errors *//*from ww w . j a v a 2s . c o m*/ public static InputStream addModuleDependencies(InputStream sourceStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try (ZipInputStream zis = new ZipInputStream(sourceStream); ZipOutputStream zos = new ZipOutputStream(out);) { ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { zos.putNextEntry(new ZipEntry(zipEntry.getName())); if (JarFile.MANIFEST_NAME.equals(zipEntry.getName())) { // we read the manifest from the source stream Manifest mf = new Manifest(); mf.read(zis); addCapabilities(mf.getMainAttributes()); // write the manifest entry into the target output stream mf.write(zos); } else { IOUtils.copy(zis, zos); } zis.closeEntry(); zipEntry = zis.getNextEntry(); } } return new ByteArrayInputStream(out.toByteArray()); }
From source file:org.kepler.gui.kar.KarManifestViewer.java
/** * Update the textfield and textarea to reflect the current LSID and LSID * referral list values.// w ww . j av a2 s . co m */ public void refreshValues() { KeplerLSID lsid = _karFile.getLSID(); StringBuilder manifest = new StringBuilder(); try { ZipEntry mane = _karFile.getEntry(JarFile.MANIFEST_NAME); final char[] buffer = new char[0x10000]; InputStream is = _karFile.getInputStream(mane); Reader in = null; try { in = new InputStreamReader(is); int read; do { read = in.read(buffer, 0, buffer.length); if (read > 0) { manifest.append(buffer, 0, read); } } while (read >= 0); } finally { if (in != null) { in.close(); } } } catch (Exception e) { e.printStackTrace(); } if (isDebugging) { log.debug(lsid.toString()); log.debug(manifest.toString()); } _lsidField.setText(lsid.toString()); _manifestField.setText(manifest.toString()); // not sure why this doesn't work // _manifestScrollPane.getVerticalScrollBar().setValue(0); }