List of usage examples for java.util.jar Manifest Manifest
public Manifest(Manifest man)
From source file:org.jcurl.core.helpers.Version.java
static final Manifest findManifest(final ClassLoader clz, final String marker) throws IOException { for (final Enumeration<URL> enu = clz.getResources("META-INF/MANIFEST.MF"); enu.hasMoreElements();) { final URL url = enu.nextElement(); if (url.getPath().indexOf(marker) >= 0) return new Manifest(url.openStream()); }/* w w w. j a v a 2 s. c o m*/ log.info("Manifest not found in"); for (final Enumeration<URL> enu = clz.getResources("META-INF/MANIFEST.MF"); enu.hasMoreElements();) log.info("url=" + enu.nextElement()); return new Manifest(new File("config/jcurl.jar/" + "META-INF/MANIFEST.MF").toURL().openStream()); }
From source file:org.nosphere.honker.deptree.DepTreeManifestLoader.java
private DepTreeData.Manifest loadFromManifest(File manifestFile) throws IOException { InputStream manifestStream = null; try {//from w ww . j a v a2 s . c o m manifestStream = new FileInputStream(manifestFile); return loadData(new Manifest(manifestStream)); } finally { IOUtils.closeQuietly(manifestStream); } }
From source file:org.kuali.student.common.util.ManifestInspector.java
/** * Return a Manifest object/*from w ww . j a va 2 s.c o m*/ */ protected Manifest getManifest(ServletContext servletContext) throws IOException { InputStream in = null; try { in = servletContext.getResourceAsStream(MANIFEST_LOCATION); if (in == null) { return null; } else { return new Manifest(in); } } catch (IOException e) { throw e; } finally { closeQuietly(in); } }
From source file:csiro.pidsvc.core.Settings.java
private Settings(HttpServlet servlet) throws NullPointerException, IOException { // Retrieve manifest. if ((_servlet = servlet) != null) { ServletConfig config = _servlet.getServletConfig(); if (config != null) { ServletContext application = config.getServletContext(); _manifest = new Manifest(application.getResourceAsStream("/META-INF/MANIFEST.MF")); }/*from w w w. j a v a2s. c o m*/ } // Retrieve settings. FileInputStream fis = null; try { InitialContext context = new InitialContext(); String settingsFile = (String) context.lookup("java:comp/env/" + SETTINGS_OPT); fis = new FileInputStream(settingsFile); _properties = new PropertyResourceBundle(fis); } catch (NamingException ex) { _logger.debug("Using default pidsvc.properties file."); _properties = ResourceBundle.getBundle("pidsvc"); } finally { if (fis != null) fis.close(); } // Get additional system properties. _serverProperties.put("serverJavaVersion", System.getProperty("java.version")); _serverProperties.put("serverJavaVendor", System.getProperty("java.vendor")); _serverProperties.put("javaHome", System.getProperty("java.home")); _serverProperties.put("serverOsArch", System.getProperty("os.arch")); _serverProperties.put("serverOsName", System.getProperty("os.name")); _serverProperties.put("serverOsVersion", System.getProperty("os.version")); }
From source file:org.jumpmind.util.AbstractVersion.java
protected Attributes findManifestAttributes() { InputStream is = null;/*ww w .j a va 2 s . c om*/ try { Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { is = resources.nextElement().openStream(); Manifest manifest = new Manifest(is); Attributes attributes = manifest.getMainAttributes(); if (getArtifactName().equals(attributes.getValue("Project-Artifact"))) { return attributes; } } } catch (IOException e) { // nothing to do, really } finally { IOUtils.closeQuietly(is); } return null; }
From source file:com.headwire.aem.tooling.intellij.eclipse.stub.JarBuilder.java
public InputStream buildJar(final IFolder sourceDir) throws CoreException { ByteArrayOutputStream store = new ByteArrayOutputStream(); JarOutputStream zos = null;//from w w w .j a va 2 s . co m InputStream manifestInput = null; try { IResource manifestResource = sourceDir.findMember(JarFile.MANIFEST_NAME); if (manifestResource == null || manifestResource.getType() != IResource.FILE) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No file named " + JarFile.MANIFEST_NAME + " found under " + sourceDir)); } manifestInput = ((IFile) manifestResource).getContents(); Manifest manifest = new Manifest(manifestInput); zos = new JarOutputStream(store); zos.setLevel(Deflater.NO_COMPRESSION); // manifest first final ZipEntry anEntry = new ZipEntry(JarFile.MANIFEST_NAME); zos.putNextEntry(anEntry); manifest.write(zos); zos.closeEntry(); zipDir(sourceDir, zos, ""); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); } finally { IOUtils.closeQuietly(zos); IOUtils.closeQuietly(manifestInput); } return new ByteArrayInputStream(store.toByteArray()); }
From source file:com.ikon.util.cl.FilesystemClassLoader.java
/** * Get main class name/*from ww w . jav a2s .com*/ */ @Override public String getMainClassName() throws IOException { log.debug("getMainClassName()"); File mf = new File(file, "META-INF/MANIFEST.MF"); FileInputStream fis = null; try { if (mf.exists() && mf.canRead()) { fis = new FileInputStream(mf); Manifest manif = new Manifest(fis); Attributes attr = manif.getMainAttributes(); return attr != null ? attr.getValue(Attributes.Name.MAIN_CLASS) : null; } } finally { IOUtils.closeQuietly(fis); } return null; }
From source file:net.hillsdon.reviki.wiki.plugin.PluginClassLoader.java
public PluginClassLoader(final URL jarUrl, final ClassLoader parent) throws InvalidPluginException { super(new URL[] { jarUrl }, parent); InputStream manifestInputStream = null; try {/* www . j a v a 2s.c o m*/ final URL manifestUrl = getManifestURL(jarUrl); try { manifestInputStream = manifestUrl.openStream(); } catch (IOException ex) { throw new InvalidPluginException("Could not open META-INF/MANIFEST.MF in plugin jar."); } final Manifest manifest = new Manifest(manifestInputStream); final Attributes attrs = manifest.getMainAttributes(); String classPath = attrs.getValue("Class-Path"); if (classPath != null && classPath.length() > 0) { cacheClassPathEntries(jarUrl, classPath); } String pluginContributions = attrs.getValue("Plugin-Contributions"); if (pluginContributions != null && pluginContributions.length() > 0) { _contributedClasses = unmodifiableList(loadPluginContributionClasses(pluginContributions)); } else { _contributedClasses = Collections.emptyList(); } } catch (URISyntaxException ex) { throw new InvalidPluginException(ex); } catch (IOException ex) { throw new InvalidPluginException(ex); } catch (ClassNotFoundException ex) { throw new InvalidPluginException(ex); } finally { IOUtils.closeQuietly(manifestInputStream); } }
From source file:org.springframework.boot.ManifestReader.java
public Map<String, String> getVersions() { Map<String, String> result = new TreeMap<String, String>(); try {//from w w w. j a va 2 s .c om Enumeration<URL> resources = getClass().getClassLoader().getResources(META_INF_MANIFEST_MF); while (resources.hasMoreElements()) { String urlName = null; try { URL url = resources.nextElement(); urlName = url.toString(); if (!urlName.contains("org/springframework/")) { continue; } if (urlName.contains("org/springframework/boot/")) { // skipping since starter versions are usually same (as SpringBoot) continue; } Manifest manifest = new Manifest(url.openStream()); String title = manifest.getMainAttributes().getValue(IMPLEMENTATION_TITLE); if (title == null) { title = parseLibraryNameFromUrl(urlName); if (title == null) { // when version is not even in the URL if (log.isTraceEnabled()) { log.trace(String.format("Version is not parsable from this URL: ", urlName)); } continue; } result.put(title, title); } else { String version = manifest.getMainAttributes().getValue(IMPLEMENTATION_VERSION); result.put(title, String.format("%s %s", title, getValue(version))); } } catch (IOException ioEx) { log.warn(String.format("Manifest is not readable (%s)!", urlName)); } } } catch (IOException ex) { log.error("MANIFEST.MF reading error: " + ex.getMessage()); return result; } return result; }
From source file:com.bluexml.side.build.tools.reader.PluginReader.java
public Plugin read(File project) throws Exception { logger.debug("Read plugin :" + project.getName()); // chemin vers le MANIFEST.MF File filePluginPath = new File( project.getAbsoluteFile() + File.separator + "META-INF" + File.separator + "MANIFEST.MF"); FileInputStream fileInputStream; fileInputStream = new FileInputStream(filePluginPath); Manifest m = new Manifest(fileInputStream); String id = ""; String version = ""; String name = ""; List<String> requiredBundle = new ArrayList<String>(); for (Entry<Object, Object> ent : m.getMainAttributes().entrySet()) { String key = ent.getKey().toString(); logger.debug("key :" + key); Object value = ent.getValue(); logger.debug("* value :" + value); String string = value.toString(); if (key.equals("Bundle-Version")) { version = string;/* w w w. j a v a2s .c om*/ } else if (key.equals("Bundle-SymbolicName")) { if (string.indexOf(";") == -1) { id = string; } else { id = string.substring(0, string.indexOf(";")); } } else if (key.equals("Bundle-Name")) { name = string; } else if (key.equals("Require-Bundle")) { String[] split = string.split(","); CollectionUtils.addAll(requiredBundle, split); } } logger.debug("Plugin ID :" + id); if (name.equals("%pluginName")) { // must read plugin.properties logger.debug("plugin name must be read from properties file"); } else { logger.debug("Plugin Name :" + name); } logger.debug("Plugin Version :" + version); logger.debug("Required Bundles :" + requiredBundle); fileInputStream.close(); Plugin p = new Plugin(); p.setId(id); p.setVersion(version); p.setName(name); if (registries.pluginsRegister.containsKey(p.getId())) { logger.debug("this plugin exist in registry so we stop reading now"); // stop to prevent loops between PluginReader -> extPReader -> constraints -> plugin return registries.pluginsRegister.get(p.getId()); } if (addExtensions) { // extension // search plugin.xml if any File filePluginXMLPath = new File(project, "plugin.xml"); if (filePluginXMLPath.exists()) { logger.debug("extension found :" + filePluginXMLPath); BlxExtensionPointReader extR = new BlxExtensionPointReader(registries, props); List<LinkedWithModule> lext = extR.read(filePluginXMLPath, p.getId()); p.setExtensions(lext); for (LinkedWithModule extension : lext) { Utils.add(registries.tree, p, extension); } } else { logger.debug("Plugin do not have extension :" + filePluginXMLPath); } } if (addRequiredBundle) { // add dependencies for (String reqIdString : requiredBundle) { String reqId = reqIdString; String reqVersion = null; int indexOfSep = reqIdString.indexOf(";"); if (indexOfSep != -1) { reqId = reqIdString.substring(0, indexOfSep); reqVersion = reqIdString.substring(indexOfSep); } // get the Object Plugin reqP = null; boolean side = true; if (registries.pluginsRegister.containsKey(p.getId())) { logger.debug("this plugin exist in registry so we stop reading now"); reqP = registries.pluginsRegister.get(p.getId()); } else { // need to read from plugin definition if source are available logger.debug("requeried Bundle " + reqId + " is not in register, try to read from FS"); File featureFolder = registries.getProjectFolder(reqId, id); if (featureFolder != null) { reqP = read(featureFolder); } else { // not found in repository, not SIDE side = false; reqP = new Plugin(); reqP.setId(reqId); if (reqVersion != null) { reqP.setVersion(reqVersion); } } } if (side || addAll) { registries.pluginsRegister.put(reqId, reqP); Utils.add(registries.tree, p, reqP); p.getDependecies().add(reqP); } } } return p; }