List of usage examples for java.util.jar Attributes getValue
public String getValue(Name name)
From source file:com.tesora.dve.common.PELogUtils.java
private static Map<String, String> buildValues() { Attributes attributes = null; try {/*from w w w . j a va2 s .co m*/ attributes = readManifestFile(); } catch (Exception e) { Logger.getLogger(PELogUtils.class).warn("Unable to read manifest file", e); attributes = null; } Map<String, String> out = new HashMap<String, String>(); if (attributes != null) { for (String k : attributeKeys) { out.put(k, attributes.getValue(k)); } } return out; }
From source file:org.dita.dost.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 w w w .j a va2 s .com jvmArguments.append(" "); } } jvmArguments.append("-Dfile.encoding=UTF-8 "); String[] segments = ditaMapFile.getName().split("\\."); String ditaMapFileRoot = segments[0]; Bundle bundle = Platform.getBundle("org.dita.dost"); 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); 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.dita.dost.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:com.stacksync.desktop.util.FileUtil.java
public static String getPropertyFromManifest(String manifestPath, String property) { try {//from w ww. j a v a 2 s.c om URLClassLoader cl = (URLClassLoader) FileUtil.class.getClassLoader(); URL url = cl.findResource(manifestPath); Manifest manifest = new Manifest(url.openStream()); Attributes attr = manifest.getMainAttributes(); return attr.getValue(property); } catch (IOException ex) { logger.debug("Exception: ", ex); return null; } }
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 va2 s . com 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.jahia.services.modulemanager.util.ModuleUtils.java
/** * Modifies the manifest attributes for Provide-Capability and Require-Capability (if needed) based on the module dependencies. * * @param atts the manifest attributes to be modified * @return <code>true</code> if the manifest attributes were modified; <code>false</code> if nothing was touched *//*from w ww. ja v a 2 s . c om*/ static boolean addCapabilities(Attributes atts) { if (!requiresTransformation(atts)) { // the manifest already contains the required capabilities thus no modification is needed return false; } String moduleId = atts.getValue(ATTR_NAME_BUNDLE_SYMBOLIC_NAME); populateProvideCapabilities(moduleId, atts); populateRequireCapabilities(moduleId, atts); return true; }
From source file:adalid.util.info.JavaInfo.java
public static void printManifestInfo(String path, String name, boolean details, Manifest manifest) { Object object;//from w w w. j a va2 s.c o m String string; out.println(path); // out.println(StringUtils.leftPad(++fileCount + "", 4, '0') + ":" + name); out.println(name); Attributes attributes = manifest.getMainAttributes(); Map<String, Object> sortedAttributes; if (details) { sortedAttributes = sort(attributes); for (String key : sortedAttributes.keySet()) { object = sortedAttributes.get(key); if (object != null) { out.println("\t" + key + ": " + object); } } } else { for (Attributes.Name attribute : ATTRIBUTE_NAMES) { string = attributes.getValue(attribute); if (StringUtils.isNotBlank(string)) { out.println("\t" + attribute + ": " + string); } } } out.println(); }
From source file:org.orbisgis.framework.BundleTools.java
/** * Parse a Manifest in order to extract Exported Package * @param manifest Jar Manifest//from w ww . ja v a 2 s .c o m * @param packages package array or null * @throws IOException */ public static BundleReference parseManifest(Manifest manifest, List<PackageDeclaration> packages) throws IOException { Attributes attributes = manifest.getMainAttributes(); String exports = attributes.getValue(Constants.EXPORT_PACKAGE); String versionProperty = attributes.getValue(Constants.BUNDLE_VERSION_ATTRIBUTE); Version version = null; if (versionProperty != null) { version = new Version(versionProperty); } String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME); if (packages != null) { org.apache.felix.framework.Logger logger = new org.apache.felix.framework.Logger(); // Use Apache Felix to parse the Manifest Export header List<BundleCapability> exportsCapability = ManifestParser.parseExportHeader(logger, null, exports, "0", new Version(0, 0, 0)); for (BundleCapability bc : exportsCapability) { Map<String, Object> attr = bc.getAttributes(); // If the package contain a package name and a package version if (attr.containsKey(PACKAGE_NAMESPACE)) { Version packageVersion = new Version(0, 0, 0); if (attr.containsKey(Constants.VERSION_ATTRIBUTE)) { packageVersion = (Version) attr.get(Constants.VERSION_ATTRIBUTE); } if (packageVersion.getMajor() != 0 || packageVersion.getMinor() != 0 || packageVersion.getMicro() != 0) { packages.add(new PackageDeclaration((String) attr.get(PACKAGE_NAMESPACE), packageVersion)); } else { // No version, take the bundle version packages.add(new PackageDeclaration((String) attr.get(PACKAGE_NAMESPACE), version)); } } } } return new BundleReference(symbolicName, version); }
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. j a va 2s . com 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:ar.edu.taco.TacoMain.java
/** * // w w w . j av a 2 s . c o m */ private static String getManifestAttribute(Name name) { String manifestAttributeValue = "Undefined"; try { String jarFileName = System.getProperty("java.class.path") .split(System.getProperty("path.separator"))[0]; JarFile jar = new JarFile(jarFileName); Manifest manifest = jar.getManifest(); Attributes mainAttributes = manifest.getMainAttributes(); manifestAttributeValue = mainAttributes.getValue(name); jar.close(); } catch (IOException e) { } return manifestAttributeValue; }
From source file:org.apache.axis2.jaxws.description.builder.JAXWSRIWSDLGenerator.java
/** * Walk the classloader hierarchy and add to the classpath * * @param cl// w w w .ja v a2 s. c o m * @param classpath */ private static void fillClassPath(ClassLoader cl, HashSet classpath) { while (cl != null) { if (cl instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) cl).getURLs(); for (int i = 0; (urls != null) && i < urls.length; i++) { String path = urls[i].getPath(); //If it is a drive letter, adjust accordingly. if (path.length() >= 3 && path.charAt(0) == '/' && path.charAt(2) == ':') path = path.substring(1); addPath(classpath, URLDecoder.decode(path)); // if its a jar extract Class-Path entries from manifest File file = new File(urls[i].getFile()); if (file.isFile()) { FileInputStream fis = null; try { fis = new FileInputStream(file); if (isJar(fis)) { JarFile jar = new JarFile(file); Manifest manifest = jar.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); if (attributes != null) { String s = attributes.getValue(Attributes.Name.CLASS_PATH); String base = file.getParent(); if (s != null) { StringTokenizer st = new StringTokenizer(s, " "); while (st.hasMoreTokens()) { String t = st.nextToken(); addPath(classpath, base + File.separatorChar + t); } } } } } } catch (IOException ioe) { } finally { if (fis != null) { try { fis.close(); } catch (IOException ioe2) { } } } } } } cl = cl.getParent(); } }