List of usage examples for java.util.jar Manifest Manifest
public Manifest(Manifest man)
From source file:org.echocat.jomon.runtime.ManifestInformationFactory.java
@Nonnull public Manifest getManifest() { if (_manifest == null) { final URL manifestUrl = findManifestUrl(); if (manifestUrl != null) { try (final InputStream is = manifestUrl.openStream()) { _manifest = new Manifest(is); } catch (final IOException e) { throw new RuntimeException("Could not read manifest from " + manifestUrl + ".", e); }/* w w w . j a va2s . c om*/ } else { _manifest = new Manifest(); } } return _manifest; }
From source file:org.rhq.core.clientapi.descriptor.PluginTransformer.java
private String getVersionFromPluginJarManifest(URL pluginJarUrl) throws IOException { JarInputStream jarInputStream = new JarInputStream(pluginJarUrl.openStream()); Manifest manifest = jarInputStream.getManifest(); if (manifest == null) { // BZ 682116 (ips, 03/25/11): The manifest file is not in the standard place as the 2nd entry of the JAR, // but we want to be flexible and support JARs that have a manifest file somewhere else, so scan the entire // JAR for one. JarEntry jarEntry;// w w w . java2 s .c om while ((jarEntry = jarInputStream.getNextJarEntry()) != null) { if (JarFile.MANIFEST_NAME.equalsIgnoreCase(jarEntry.getName())) { manifest = new Manifest(jarInputStream); break; } } } try { jarInputStream.close(); } catch (IOException e) { LOG.error("Failed to close plugin jar input stream for plugin jar [" + pluginJarUrl + "].", e); } if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); } else { return null; } }
From source file:com.github.lindenb.jvarkit.util.command.Command.java
private void loadManifest() { try {// w ww . j a va2s . c o m Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");//not '/META-INF' while (resources.hasMoreElements()) { URL url = resources.nextElement(); InputStream in = url.openStream(); if (in == null) { continue; } Manifest m = new Manifest(in); in.close(); in = null; java.util.jar.Attributes attrs = m.getMainAttributes(); if (attrs == null) { continue; } String s = attrs.getValue("Git-Hash"); if (s != null && !s.isEmpty() && !s.contains("$")) //ant failed { this.gitHash = s; } s = attrs.getValue("Compile-Date"); if (s != null && !s.isEmpty()) //ant failed { this.compileDate = s; } } } catch (Exception err) { } }
From source file:eu.chocolatejar.eclipse.plugin.cleaner.Main.java
/** * Read version from jar manifest, if it fails the exception is swallow and * empty string is returned//from w w w.ja v a2 s .c om */ private String getImplementationVersion() { try { URLClassLoader cl = (URLClassLoader) Main.class.getClassLoader(); URL url = cl.findResource("META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(url.openStream()); Attributes mainAttribs = manifest.getMainAttributes(); String version = mainAttribs.getValue("Implementation-Version"); if (version != null) { return version; } } catch (Exception e) { logger.trace("Unable to read a manifest version of this program.", e); } return "X.X.X.X"; }
From source file:com.lwr.software.reporter.utils.Q2RContextListener.java
@Override public void contextInitialized(ServletContextEvent contextEvent) { logger.info("Creating directories if already created"); logger.info("Creating config directory tree " + DashboardConstants.CONFIG_PATH); File dir = new File(DashboardConstants.CONFIG_PATH); if (dir.exists()) { logger.info("Config directory tree already exists"); } else {/* w ww. j a va 2s .c om*/ boolean dirCreated = dir.mkdirs(); if (dirCreated) { logger.info("Config directory tree created successfully"); } else { logger.error("Config directory tree creation failed, please check for file permission on " + DashboardConstants.CONFIG_PATH); } } logger.info("Creating public report directory tree " + DashboardConstants.PUBLIC_REPORT_DIR); dir = new File(DashboardConstants.PUBLIC_REPORT_DIR); if (dir.exists()) { logger.info("Public report directory tree already exists"); } else { boolean dirCreated = dir.mkdirs(); if (dirCreated) { logger.info("Public report directory tree created successfully"); } else { logger.error("Public report directory tree creation failed, please check for file permission on " + DashboardConstants.PUBLIC_REPORT_DIR); } } logger.info("Creating private report directory tree " + DashboardConstants.PRIVATE_REPORT_DIR); dir = new File(DashboardConstants.PRIVATE_REPORT_DIR); if (dir.exists()) { logger.info("Private report directory tree already exists"); } else { boolean dirCreated = dir.mkdirs(); if (dirCreated) { logger.info("Private report directory tree created successfully"); } else { logger.error("Private report directory tree creation failed, please check for file permission on " + DashboardConstants.PRIVATE_REPORT_DIR); } } logger.info("Creating private report directory tree " + DashboardConstants.APPLN_TEMP_DIR); dir = new File(DashboardConstants.APPLN_TEMP_DIR); if (dir.exists()) { logger.info("Private report directory tree already exists"); } else { boolean dirCreated = dir.mkdirs(); if (dirCreated) { logger.info("Private report directory tree created successfully"); } else { logger.error("Private report directory tree creation failed, please check for file permission on " + DashboardConstants.APPLN_TEMP_DIR); } } File logoFile = new File(DashboardConstants.APPLN_LOGO_FILE); if (logoFile.exists()) { String appLogo = contextEvent.getServletContext().getRealPath("/") + File.separatorChar + "images" + File.separatorChar + "q2r.png"; File appLogoFile = new File(appLogo); logger.info("Coping of custom logo file " + logoFile.getAbsolutePath() + " to folder " + appLogoFile.getAbsolutePath()); try { Files.copy(logoFile, appLogoFile); logger.info("Coping of custom logo file " + logoFile.getAbsolutePath() + " to folder " + appLogoFile.getAbsolutePath() + " -- Copied"); } catch (IOException e) { logger.error("Coping of custom logo file " + logoFile.getAbsolutePath() + " to folder " + appLogoFile.getAbsolutePath() + " -- Failed", e); } } Q2RProperties.getInstance(); logger.info("Loading build time from manifest file"); try { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(inputStream); String buildTime = manifest.getMainAttributes().getValue("Build-Time"); logger.info("Build time is " + buildTime); if (buildTime != null) Q2RProperties.getInstance().put("buildTime", buildTime); } catch (IOException e) { logger.error("Error loading manifest file", e); } }
From source file:org.jasig.ssp.service.impl.ServerServiceImpl.java
private void cacheVersionProfile() throws IOException { InputStream mfStream = null;// w w w . ja v a2 s .c om try { mfStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF"); Manifest mf = new Manifest(mfStream); final Attributes mainAttributes = mf.getMainAttributes(); final Map<String, Object> tmpVersionProfile = new HashMap<String, Object>(); tmpVersionProfile.put(NAME_API_FIELD_NAME, SSP_VERSION_PROFILE_NAME); // For SSP itself the entry format is: // SSP-<EntryName> // e.g.: // SSP-Artifact-Version // // For "extensions" the entry format is: // SSP-Ext-<ExtensionName>-<EntryName> // e.g.: // SSP-Ext-UPOverlay-Artifact-Version // // We do not want to accidentally expose any sensitive config // placed into the manifest. So we only output values from recognized // <EntryName> values. Map<String, Object> extensions = null; for (Map.Entry<Object, Object> entry : mainAttributes.entrySet()) { String rawEntryName = entry.getKey().toString(); if (rawEntryName.startsWith(SSP_EXTENSION_ENTRY_PREFIX)) { String[] parsedEntryName = rawEntryName.split(SSP_EXTENSION_ENTRY_DELIM); if (parsedEntryName.length < 4) { continue; } String unqualifiedEntryName = StringUtils.join(parsedEntryName, SSP_EXTENSION_ENTRY_DELIM, 3, parsedEntryName.length); if (!(isWellKnownEntryName(unqualifiedEntryName))) { continue; } String extName = parsedEntryName[2]; if (extensions == null) { extensions = new HashMap<String, Object>(); } Map<String, Object> thisExtension = (Map<String, Object>) extensions.get(extName); if (thisExtension == null) { thisExtension = new HashMap<String, Object>(); thisExtension.put(NAME_API_FIELD_NAME, extName); extensions.put(extName, thisExtension); } mapWellKnownEntryName(unqualifiedEntryName, (String) entry.getValue(), thisExtension); } else if (rawEntryName.startsWith(SSP_ENTRY_PREFIX)) { String unqualifiedEntryName = rawEntryName.substring(SSP_ENTRY_PREFIX.length()); if (isWellKnownEntryName(unqualifiedEntryName)) { mapWellKnownEntryName(unqualifiedEntryName, (String) entry.getValue(), tmpVersionProfile); } } } if (extensions == null) { tmpVersionProfile.put(EXTENSIONS_API_FIELD_NAME, Collections.EMPTY_MAP); } else { tmpVersionProfile.put(EXTENSIONS_API_FIELD_NAME, Lists.newArrayList(extensions.values())); } this.versionProfile = tmpVersionProfile; // lets not cache it until we're sure we loaded everything } finally { if (mfStream != null) { try { mfStream.close(); } catch (Exception e) { } } } }
From source file:org.cleverbus.core.common.version.impl.ManifestVersionInfoSource.java
private Collection<VersionInfo> getVersionData(String location, @Nullable VersionInfo filter) throws IOException, PatternSyntaxException { Collection<VersionInfo> result = new ArrayList<VersionInfo>(); Resource[] resources = applicationContext.getResources(location); for (Resource resource : resources) { try {//from www . j a va2 s. c o m InputStream is = resource.getInputStream(); if (is != null) { Manifest manifest = new Manifest(is); VersionInfo info = createVersionInfo(manifest); // Log.debug(location + ": " + info); // Version entries may be empty or incomplete. // Return only entries that match the specified filter. if (info.matches(filter)) { result.add(info); } } } catch (IOException e) { Log.error("Unable to process manifest resource '{}'", e, resource.getURL()); throw e; } catch (PatternSyntaxException e) { Log.error("Unable to process version data, invalid filter '{}'", e, filter.toString()); } } return result; }
From source file:org.eclipse.mdht.dita.ui.util.DitaUtil.java
public static ILaunch publish(IFile ditaMapFile, String antTargets, String ditavalFileName) throws IOException, CoreException, URISyntaxException { IProject ditaProject = ditaMapFile.getProject(); IFolder ditaFolder = ditaProject.getFolder(new Path("dita")); IFile ditaValFile = ditaFolder.getFile(ditavalFileName); StringBuffer jvmArguments = new StringBuffer(); for (String arg : ManagementFactory.getRuntimeMXBean().getInputArguments()) { if (arg.startsWith("-X")) { jvmArguments.append(arg);/*from ww w . j a v a 2 s . co m*/ jvmArguments.append(" "); } } jvmArguments.append("-Dfile.encoding=UTF-8 "); String[] segments = ditaMapFile.getName().split("\\."); String ditaMapFileRoot = segments[0]; Bundle bundle = Platform.getBundle("org.eclipse.mdht.dita.ui"); Path path = new Path("META-INF/MANIFEST.MF"); URL fileURL = FileLocator.find(bundle, path, null); Path ditadirPath = new Path("DITA-OT"); URL ditadirURL = FileLocator.find(bundle, ditadirPath, null); if (ditadirURL == null) { return null; } ditadirURL = FileLocator.toFileURL(ditadirURL); InputStream in = fileURL.openStream(); Manifest ditaPluginManifest = new Manifest(in); Attributes attributes = ditaPluginManifest.getMainAttributes(); String ditaClassPath = attributes.getValue("Bundle-ClassPath"); List<String> classpath = new ArrayList<String>(); String ditaRequiredBundles = attributes.getValue("Require-Bundle"); for (String requiredBundleSymbolicName : ditaRequiredBundles.split(",")) { // get before ; Bundle requiredBundle = Platform.getBundle(requiredBundleSymbolicName.split(";")[0]); // Assume the bundle is optional if null if (requiredBundle != null) { File file = FileLocator.getBundleFile(requiredBundle); IRuntimeClasspathEntry requiredBundleEntry = JavaRuntime .newArchiveRuntimeClasspathEntry(new Path(file.getPath())); requiredBundleEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); classpath.add(requiredBundleEntry.getMemento()); } } for (String classPath : ditaClassPath.split(",")) { if (".".equals(classPath)) { URL url = FileLocator.find(bundle, new Path(""), null); url = FileLocator.toFileURL(url); IRuntimeClasspathEntry pluginEntry = JavaRuntime.newRuntimeContainerClasspathEntry( new Path(url.getPath()), IRuntimeClasspathEntry.USER_CLASSES); classpath.add(pluginEntry.getMemento()); } else { URL url = FileLocator.find(bundle, new Path(classPath), null); url = FileLocator.toFileURL(url); IRuntimeClasspathEntry toolsEntry = JavaRuntime .newArchiveRuntimeClasspathEntry(new Path(url.getPath())); toolsEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); classpath.add(toolsEntry.getMemento()); } } ContributedClasspathEntriesEntry ccee = new ContributedClasspathEntriesEntry(); AntHomeClasspathEntry ace = new AntHomeClasspathEntry(); classpath.add(ace.getMemento()); classpath.add(ccee.getMemento()); ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = launchManager .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE); URL ditaPublishBuildFileURL = fileURL = FileLocator.find(bundle, new Path("dita-publish.xml"), null); ditaPublishBuildFileURL = FileLocator.toFileURL(ditaPublishBuildFileURL); String name = launchManager.generateLaunchConfigurationName("Publish DITA"); ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name); workingCopy.setAttribute("org.eclipse.ui.externaltools.ATTR_LOCATION", ditaPublishBuildFileURL.getPath()); IVMInstall jre = JavaRuntime.getDefaultVMInstall(); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jre.getName()); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "-Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl"); Map<String, String> antProperties = new HashMap<String, String>(); antProperties.put("dita.dir", ditadirURL.getPath()); antProperties.put("ditaMapFile", ditaMapFile.getLocation().toOSString()); if (ditaValFile != null) { antProperties.put("args.filter", ditaValFile.getLocation().toOSString()); } antProperties.put("ditaMapFileName", ditaMapFile.getName().substring(0, ditaMapFile.getName().length() - ditaMapFile.getFileExtension().length())); // antProperties.put("outputLocation", ditaProject.getLocation().toOSString()); antProperties.put("dita.output", ditaProject.getLocation().append(antTargets).toOSString()); antProperties.put("ditaMapFileRoot", ditaMapFileRoot); String fileName = getFileNameFromMap(ditaMapFile.getLocation().toOSString()); if (StringUtils.isEmpty(fileName)) { fileName = ditaMapFile.getName().replace("." + ditaMapFile.getFileExtension(), ""); } antProperties.put("fileName", fileName); antProperties.put("args.debug", "no"); antProperties.put("ditaFilePath", ditaFolder.getLocation().toOSString()); antProperties.put("tempFilePath", org.eclipse.mdht.dita.ui.internal.Activator.getDefault() .getStateLocation().append("temp").toOSString()); antProperties.put("docProject", ditaProject.getLocation().toOSString()); String pdfFileLocation = ditaMapFile.getName(); pdfFileLocation = pdfFileLocation.replaceFirst(".ditamap", ".pdf"); antProperties.put("pdflocation", pdfFileLocation); workingCopy.setAttribute("process_factory_id", "org.eclipse.ant.ui.remoteAntProcessFactory"); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.ant.internal.ui.antsupport.InternalAntRunner"); workingCopy.setAttribute( org.eclipse.core.externaltools.internal.IExternalToolConstants.ATTR_WORKING_DIRECTORY, ditaProject.getLocation().toOSString()); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, jvmArguments.toString()); workingCopy.setAttribute(org.eclipse.ant.launching.IAntLaunchConstants.ATTR_ANT_TARGETS, antTargets); workingCopy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, antProperties); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); workingCopy.setAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS, false); workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); workingCopy.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, "UTF-8"); workingCopy.migrate(); return workingCopy.launch(ILaunchManager.RUN_MODE, null, false, true); }
From source file:org.jboss.pnc.buildagent.server.BootstrapUndertowBuildAgentHandlers.java
private String getManifestInformation() { String result = ""; try {/*from ww w.j av a2s.co m*/ final Enumeration<URL> resources = Welcome.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { final URL jarUrl = resources.nextElement(); log.trace("Processing jar resource " + jarUrl); if (jarUrl.getFile().contains("build-agent")) { final Manifest manifest = new Manifest(jarUrl.openStream()); result = manifest.getMainAttributes().getValue("Implementation-Version"); result += " ( SHA: " + manifest.getMainAttributes().getValue("Scm-Revision") + " ) "; break; } } } catch (final IOException e) { log.trace("Error retrieving information from manifest", e); } return result; }
From source file:org.apache.axiom.util.stax.dialect.StAXDialectDetector.java
private static StAXDialect detectDialectFromJarManifest(URL rootUrl) { Manifest manifest;/*from www .ja va 2 s. c o m*/ try { URL metaInfUrl = new URL(rootUrl, "META-INF/MANIFEST.MF"); InputStream is = metaInfUrl.openStream(); try { manifest = new Manifest(is); } finally { is.close(); } } catch (IOException ex) { log.warn("Unable to load manifest for StAX implementation at " + rootUrl); return UnknownStAXDialect.INSTANCE; } Attributes attrs = manifest.getMainAttributes(); String title = attrs.getValue(IMPLEMENTATION_TITLE); String symbolicName = attrs.getValue(BUNDLE_SYMBOLIC_NAME); if (symbolicName != null) { int i = symbolicName.indexOf(';'); if (i != -1) { symbolicName = symbolicName.substring(0, i); } } String vendor = attrs.getValue(IMPLEMENTATION_VENDOR); if (vendor == null) { vendor = attrs.getValue(BUNDLE_VENDOR); } String version = attrs.getValue(IMPLEMENTATION_VERSION); if (version == null) { version = attrs.getValue(BUNDLE_VERSION); } if (log.isDebugEnabled()) { log.debug("StAX implementation at " + rootUrl + " is:\n" + " Title: " + title + "\n" + " Symbolic name: " + symbolicName + "\n" + " Vendor: " + vendor + "\n" + " Version: " + version); } // For the moment, the dialect detection is quite simple, but in the future we will probably // have to differentiate by version number if (vendor != null && vendor.toLowerCase().indexOf("woodstox") != -1) { return WoodstoxDialect.INSTANCE; } else if (title != null && title.indexOf("SJSXP") != -1) { return new SJSXPDialect(false); } else if ("com.bea.core.weblogic.stax".equals(symbolicName)) { // Weblogic's StAX implementation doesn't support CDATA section reporting and there are // a couple of additional test cases (with respect to BEA's reference implementation) // that fail. log.warn("Weblogic's StAX implementation is unsupported and some Axiom features will not work " + "as expected! Please use Woodstox instead."); // This is the best match we can return in this case. return BEADialect.INSTANCE; } else if ("BEA".equals(vendor)) { return BEADialect.INSTANCE; } else if ("com.ibm.ws.prereq.banshee".equals(symbolicName)) { return XLXP2Dialect.INSTANCE; } else { return null; } }