Java Code Examples for java.util.jar.Attributes#containsKey()
The following examples show how to use
java.util.jar.Attributes#containsKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JarManifestEntriesTestIT.java From jgitver with Apache License 2.0 | 6 votes |
private Manifest jgitverManifestOrEmpty() { try { Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { URL url = resources.nextElement(); Manifest manifest = new Manifest(url.openStream()); Attributes mfAttrs = manifest.getMainAttributes(); Attributes.Name attributeName = new Attributes.Name(X_MAVEN_COORDINATES); if (mfAttrs.containsKey(attributeName) && mfAttrs.getValue(attributeName).startsWith("fr.brouillard.oss:jgitver")) { return manifest; } } } catch (IOException ignore) { // expected } return new Manifest(); }
Example 2
Source File: LauncherHelper.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 3
Source File: JkManifest.java From jeka with Apache License 2.0 | 5 votes |
/** * Returns <code>true</code> if this manifest has no entry or has only * "Manifest-Version" entry. */ public boolean isEmpty() { final Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes.size() > 1) { return false; } if (mainAttributes.size() == 1 && !mainAttributes.containsKey(Attributes.Name.MANIFEST_VERSION)) { return false; } return manifest.getEntries().size() == 0; }
Example 4
Source File: LauncherHelper.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 5
Source File: LauncherHelper.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 6
Source File: LibraryUtil.java From jeddict with Apache License 2.0 | 5 votes |
public static String getLibrary(ClassPath classPath, String resource) { // Find as resource as a class String classNameAsPath = resource.replace('.', '/') + ".class"; FileObject classResource = classPath.findResource(classNameAsPath); if (classResource == null) { // Find as resource as a package classNameAsPath = resource.replace('.', '/'); classResource = classPath.findResource(classNameAsPath); } if (classResource != null) { FileObject archiveFile = FileUtil.getArchiveFile(classResource); if (archiveFile != null && FileUtil.isArchiveFile(archiveFile)) { File toFile = FileUtil.toFile(archiveFile); try { JarFile jf = new JarFile(toFile); Manifest manifest = jf.getManifest(); Attributes mainAttributes = manifest.getMainAttributes(); // Find library version by Bundle information (Eclipse/OSGi) if (mainAttributes.containsKey(BUNDLE_NAME) && mainAttributes.containsKey(BUNDLE_VERSION)) { if (!mainAttributes.getValue(BUNDLE_NAME).isEmpty()) { return mainAttributes.getValue(BUNDLE_NAME); } } // If unsuccessful, try by default Manifest Headers if (mainAttributes.containsKey(Name.IMPLEMENTATION_TITLE) && mainAttributes.containsKey(Name.IMPLEMENTATION_VERSION)) { if (!mainAttributes.getValue(Name.IMPLEMENTATION_TITLE).isEmpty()) { return mainAttributes.getValue(Name.IMPLEMENTATION_TITLE); } } } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } return null; }
Example 7
Source File: LauncherHelper.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 8
Source File: LauncherHelper.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 9
Source File: ModulePackager.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
public static String getAdapterAlias(File jarFile) throws IOException { String version = null; JarFile jar = new JarFile(jarFile); Attributes attributes = jar.getManifest().getMainAttributes(); if (attributes.containsKey(ATTR_MODULE_ALIAS)) { version = attributes.getValue(ATTR_MODULE_ALIAS); } jar.close(); return version; }
Example 10
Source File: LauncherHelper.java From hottub with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 11
Source File: LauncherHelper.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 12
Source File: LauncherHelper.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 13
Source File: ModulePackager.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
public static String getAdapterVersion(File jarFile) throws IOException { String version = null; JarFile jar = new JarFile(jarFile); Attributes attributes = jar.getManifest().getMainAttributes(); if (attributes.containsKey(ATTR_MODULE_IMPLEMENTATION)) { version = attributes.getValue(ATTR_MODULE_IMPLEMENTATION); } jar.close(); return version; }
Example 14
Source File: LauncherHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 15
Source File: LauncherHelper.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 16
Source File: LauncherHelper.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
static String getMainClassFromJar(String jarname) { String mainValue = null; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(FXHelper.JAVAFX_APPLICATION_MARKER))) { return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 17
Source File: LauncherHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static String getMainClassFromJar(String jarname) { String mainValue; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } // Main-Class mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } // Launcher-Agent-Class (only check for this when Main-Class present) String agentClass = mainAttrs.getValue(LAUNCHER_AGENT_CLASS); if (agentClass != null) { ModuleLayer.boot().findModule("java.instrument").ifPresent(m -> { try { String cn = "sun.instrument.InstrumentationImpl"; Class<?> clazz = Class.forName(cn, false, null); Method loadAgent = clazz.getMethod("loadAgent", String.class); loadAgent.invoke(null, jarname); } catch (Throwable e) { if (e instanceof InvocationTargetException) e = e.getCause(); abort(e, "java.launcher.jar.error4", jarname); } }); } // Add-Exports and Add-Opens String exports = mainAttrs.getValue(ADD_EXPORTS); if (exports != null) { addExportsOrOpens(exports, false); } String opens = mainAttrs.getValue(ADD_OPENS); if (opens != null) { addExportsOrOpens(opens, true); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(JAVAFX_APPLICATION_MARKER))) { FXHelper.setFXLaunchParameters(jarname, LM_JAR); return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 18
Source File: MCRRuntimeComponentDetector.java From mycore with GNU General Public License v3.0 | 4 votes |
private static MCRComponent buildComponent(Manifest manifest, URL manifestURL) throws IOException { Attributes mainAttributes = manifest.getMainAttributes(); String artifactId = mainAttributes.getValue(ATT_MCR_ARTIFACT_ID); String pomPropertiesPath = mainAttributes.getValue(ATT_POM); boolean usePomProperties = false; if (artifactId == null) { if (!mainAttributes.containsKey(ATT_POM)) { return null; } if (pomPropertiesPath == null) { return null; } try (InputStream pi = MCRClassTools.getClassLoader().getResourceAsStream( pomPropertiesPath)) { if (pi == null) { LOGGER.warn("Manifest entry {} set to \"{}\", but resource could not be loaded.", ATT_POM, pomPropertiesPath); return null; } Properties pomProperties = new Properties(); pomProperties.load(pi); artifactId = (String) pomProperties.get("artifactId"); usePomProperties = true; } } if (artifactId != null && artifactId.startsWith("mycore-") || mainAttributes.containsKey(ATT_MCR_APPLICATION_MODULE)) { if (usePomProperties) { LOGGER.warn("No Attribute \"{}\" in Manifest of {}.", ATT_MCR_ARTIFACT_ID, mainAttributes.getValue(ATT_MCR_APPLICATION_MODULE)); LOGGER.warn("Change this in the future, pom.properties path definition is deprecated."); LOGGER.info("Using artifactId in {}.", pomPropertiesPath); } return new MCRComponent(artifactId, manifest, extractJarFile(manifestURL)); } return null; }
Example 19
Source File: LauncherHelper.java From Bytecoder with Apache License 2.0 | 4 votes |
static String getMainClassFromJar(String jarname) { String mainValue; try (JarFile jarFile = new JarFile(jarname)) { Manifest manifest = jarFile.getManifest(); if (manifest == null) { abort(null, "java.launcher.jar.error2", jarname); } Attributes mainAttrs = manifest.getMainAttributes(); if (mainAttrs == null) { abort(null, "java.launcher.jar.error3", jarname); } // Main-Class mainValue = mainAttrs.getValue(MAIN_CLASS); if (mainValue == null) { abort(null, "java.launcher.jar.error3", jarname); } // Launcher-Agent-Class (only check for this when Main-Class present) String agentClass = mainAttrs.getValue(LAUNCHER_AGENT_CLASS); if (agentClass != null) { ModuleLayer.boot().findModule("java.instrument").ifPresent(m -> { try { String cn = "sun.instrument.InstrumentationImpl"; Class<?> clazz = Class.forName(cn, false, null); Method loadAgent = clazz.getMethod("loadAgent", String.class); loadAgent.invoke(null, jarname); } catch (Throwable e) { if (e instanceof InvocationTargetException) e = e.getCause(); abort(e, "java.launcher.jar.error4", jarname); } }); } // Add-Exports and Add-Opens String exports = mainAttrs.getValue(ADD_EXPORTS); if (exports != null) { addExportsOrOpens(exports, false); } String opens = mainAttrs.getValue(ADD_OPENS); if (opens != null) { addExportsOrOpens(opens, true); } /* * Hand off to FXHelper if it detects a JavaFX application * This must be done after ensuring a Main-Class entry * exists to enforce compliance with the jar specification */ if (mainAttrs.containsKey( new Attributes.Name(JAVAFX_APPLICATION_MARKER))) { FXHelper.setFXLaunchParameters(jarname, LM_JAR); return FXHelper.class.getName(); } return mainValue.trim(); } catch (IOException ioe) { abort(ioe, "java.launcher.jar.error1", jarname); } return null; }
Example 20
Source File: EmbeddedFelixFramework.java From brooklyn-server with Apache License 2.0 | 4 votes |
private static boolean isValidBundle(Manifest manifest) { Attributes atts = manifest.getMainAttributes(); return atts.containsKey(new Attributes.Name(Constants.BUNDLE_MANIFESTVERSION)); }