java.util.jar.Attributes.Name Java Examples

The following examples show how to use java.util.jar.Attributes.Name. 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: WebappClassLoaderBase.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
protected boolean isPackageSealed(String name, Manifest man) {

    String path = name.replace('.', '/') + '/';
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);

}
 
Example #2
Source File: URLClassPath.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        Manifest man = jar.getManifest();
        if (man != null) {
            Attributes attr = man.getMainAttributes();
            if (attr != null) {
                String value = attr.getValue(Name.CLASS_PATH);
                if (value != null) {
                    return parseClassPath(csu, value);
                }
            }
        }
    }
    return null;
}
 
Example #3
Source File: URLClassPath.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();
    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        Manifest man = jar.getManifest();
        if (man != null) {
            Attributes attr = man.getMainAttributes();
            if (attr != null) {
                String value = attr.getValue(Name.CLASS_PATH);
                if (value != null) {
                    return parseClassPath(csu, value);
                }
            }
        }
    }
    return null;
}
 
Example #4
Source File: Metadata.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
    * Public main method, used solely for allowing customers to
    * print version and other metadata information from the enclosing
    * JAR file's manifest. This information is printed to stdout;
    * errors are printed to stderr.
    * 
    * @since 2011.1
    * @param args not used.
    */
public static void main(String[] args) {
	try {
		Manifest manifest = getManifest();
		Attributes attr = manifest.getMainAttributes();
		System.out.println(attr.getValue(Name.IMPLEMENTATION_TITLE));
		StringBuilder version = new StringBuilder(
				attr.getValue(Name.IMPLEMENTATION_VERSION));
		String changelist = attr.getValue("Build-Changelist");
		if (changelist != null) {
			version.append('/').append(changelist);
		}
		String type = attr.getValue("Build-Type");
		if (type != null) {
			version.append('/').append(type);
		}
		System.out.println(version);
	} catch (Exception exception) {
		System.err.println(exception.getLocalizedMessage());
	}
}
 
Example #5
Source File: URLClassPath.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        Manifest man = jar.getManifest();
        if (man != null) {
            Attributes attr = man.getMainAttributes();
            if (attr != null) {
                String value = attr.getValue(Name.CLASS_PATH);
                if (value != null) {
                    return parseClassPath(csu, value);
                }
            }
        }
    }
    return null;
}
 
Example #6
Source File: URLClassPath.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
URL[] getClassPath() throws IOException {
    if (index != null) {
        return null;
    }

    if (metaIndex != null) {
        return null;
    }

    ensureOpen();
    parseExtensionsDependencies();

    if (SharedSecrets.javaUtilJarAccess().jarFileHasClassPathAttribute(jar)) { // Only get manifest when necessary
        Manifest man = jar.getManifest();
        if (man != null) {
            Attributes attr = man.getMainAttributes();
            if (attr != null) {
                String value = attr.getValue(Name.CLASS_PATH);
                if (value != null) {
                    return parseClassPath(csu, value);
                }
            }
        }
    }
    return null;
}
 
Example #7
Source File: Metadata.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
    * Public main method, used solely for allowing customers to
    * print version and other metadata information from the enclosing
    * JAR file's manifest. This information is printed to stdout;
    * errors are printed to stderr.
    * 
    * @since 2011.1
    * @param args not used.
    */
public static void main(String[] args) {
	try {
		Manifest manifest = getManifest();
		Attributes attr = manifest.getMainAttributes();
		System.out.println(attr.getValue(Name.IMPLEMENTATION_TITLE));
		StringBuilder version = new StringBuilder(
				attr.getValue(Name.IMPLEMENTATION_VERSION));
		String changelist = attr.getValue("Build-Changelist");
		if (changelist != null) {
			version.append('/').append(changelist);
		}
		String type = attr.getValue("Build-Type");
		if (type != null) {
			version.append('/').append(type);
		}
		System.out.println(version);
	} catch (Exception exception) {
		System.err.println(exception.getLocalizedMessage());
	}
}
 
Example #8
Source File: VFSClassLoader.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Reads attributes for the package and defines it.
 */
private Package definePackage(final String name, final Resource res) throws FileSystemException {
    // TODO - check for MANIFEST_ATTRIBUTES capability first
    final String specTitle = res.getPackageAttribute(Name.SPECIFICATION_TITLE);
    final String specVendor = res.getPackageAttribute(Attributes.Name.SPECIFICATION_VENDOR);
    final String specVersion = res.getPackageAttribute(Name.SPECIFICATION_VERSION);
    final String implTitle = res.getPackageAttribute(Name.IMPLEMENTATION_TITLE);
    final String implVendor = res.getPackageAttribute(Name.IMPLEMENTATION_VENDOR);
    final String implVersion = res.getPackageAttribute(Name.IMPLEMENTATION_VERSION);

    final URL sealBase;
    if (isSealed(res)) {
        sealBase = res.getCodeSourceURL();
    } else {
        sealBase = null;
    }

    return definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase);
}
 
Example #9
Source File: URLClassLoader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    String path = name.replace('.', '/').concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #10
Source File: URLClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    String path = name.replace('.', '/').concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #11
Source File: ExtCheck.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
URL[] getClassPath() throws IOException {
    Manifest man = jar.getManifest();
    if (man != null) {
        Attributes attr = man.getMainAttributes();
        if (attr != null) {
            String value = attr.getValue(Name.CLASS_PATH);
            if (value != null) {
                return parseClassPath(csu, value);
            }
        }
    }
    return null;
}
 
Example #12
Source File: URLClassLoader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    Attributes attr = SharedSecrets.javaUtilJarAccess()
            .getTrustedAttributes(man, name.replace('.', '/').concat("/"));
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #13
Source File: ExtCheck.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
URL[] getClassPath() throws IOException {
    Manifest man = jar.getManifest();
    if (man != null) {
        Attributes attr = man.getMainAttributes();
        if (attr != null) {
            String value = attr.getValue(Name.CLASS_PATH);
            if (value != null) {
                return parseClassPath(csu, value);
            }
        }
    }
    return null;
}
 
Example #14
Source File: URLClassLoader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    String path = name.replace('.', '/').concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #15
Source File: URLClassLoader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    String path = name.replace('.', '/').concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #16
Source File: Metadata.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Return the P4Java version string associated with this instance
 * as contained in the enclosing JAR file's manifest IMPLEMENTATION_TITLE
 * attribute. If this information is not available, DEFAULT_VERSION_STRING
 * is returned.<p>
 * 
 * The format and semantics of this string are not specified here.
 * 
 * @return non-null version string
 */

public static String getP4JVersionString() {
	if (p4jVersionString != null) {
		return p4jVersionString;
	} else {
		p4jVersionString = DEFAULT_VERSION_STRING;
		
		// try to get this information from the JAR manifest
		try {
			if (manifest == null) {
					manifest = getManifest();
			}
			// manifest is non-null or we got an exception...
			Attributes attr = manifest.getMainAttributes();
			String version = attr.getValue(Name.IMPLEMENTATION_VERSION);
			if (version != null) {
				p4jVersionString = version;
			}
		} catch (Exception exc) {
			Log.warn("unable to get manifest version attribute: "
								+ exc.getLocalizedMessage());
		}
	}
	
	return p4jVersionString;
}
 
Example #17
Source File: URLClassLoader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    String path = name.replace('.', '/').concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #18
Source File: Metadata.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * Return the P4Java version string associated with this instance
 * as contained in the enclosing JAR file's manifest IMPLEMENTATION_TITLE
 * attribute. If this information is not available, DEFAULT_VERSION_STRING
 * is returned.<p>
 * 
 * The format and semantics of this string are not specified here.
 * 
 * @return non-null version string
 */

public static String getP4JVersionString() {
	if (p4jVersionString != null) {
		return p4jVersionString;
	} else {
		p4jVersionString = DEFAULT_VERSION_STRING;
		
		// try to get this information from the JAR manifest
		try {
			if (manifest == null) {
					manifest = getManifest();
			}
			// manifest is non-null or we got an exception...
			Attributes attr = manifest.getMainAttributes();
			String version = attr.getValue(Name.IMPLEMENTATION_VERSION);
			if (version != null) {
				p4jVersionString = version;
			}
		} catch (Exception exc) {
			Log.warn("unable to get manifest version attribute: "
								+ exc.getLocalizedMessage());
		}
	}
	
	return p4jVersionString;
}
 
Example #19
Source File: PortablePipelineJarCreatorTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateManifest_withMainMethod() {
  Manifest manifest = jarCreator.createManifest(FakePipelineRunnner.class, "job");
  assertEquals(
      FakePipelineRunnner.class.getName(),
      manifest.getMainAttributes().getValue(Name.MAIN_CLASS));
}
 
Example #20
Source File: JkManifest.java    From jeka with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #21
Source File: URLClassLoader.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    Attributes attr = SharedSecrets.javaUtilJarAccess()
            .getTrustedAttributes(man, name.replace('.', '/').concat("/"));
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #22
Source File: URLClassLoader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    Attributes attr = SharedSecrets.javaUtilJarAccess()
            .getTrustedAttributes(man, name.replace('.', '/').concat("/"));
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #23
Source File: ExtCheck.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
URL[] getClassPath() throws IOException {
    Manifest man = jar.getManifest();
    if (man != null) {
        Attributes attr = man.getMainAttributes();
        if (attr != null) {
            String value = attr.getValue(Name.CLASS_PATH);
            if (value != null) {
                return parseClassPath(csu, value);
            }
        }
    }
    return null;
}
 
Example #24
Source File: ManifestInfo.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the value.
 *
 * @param name the name
 * @return the value
 */
public String getValue(Name... name) {
    if (name == null || isEmpty()) {
        return null;
    }
    return getAttribute(attr, main, entries, name);
}
 
Example #25
Source File: JarFileSystem.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
Name lookupName(final String attrName) {
    if (Name.CLASS_PATH.toString().equals(attrName)) {
        return Name.CLASS_PATH;
    } else if (Name.CONTENT_TYPE.toString().equals(attrName)) {
        return Name.CONTENT_TYPE;
    } else if (Name.EXTENSION_INSTALLATION.toString().equals(attrName)) {
        return Name.EXTENSION_INSTALLATION;
    } else if (Name.EXTENSION_LIST.toString().equals(attrName)) {
        return Name.EXTENSION_LIST;
    } else if (Name.EXTENSION_NAME.toString().equals(attrName)) {
        return Name.EXTENSION_NAME;
    } else if (Name.IMPLEMENTATION_TITLE.toString().equals(attrName)) {
        return Name.IMPLEMENTATION_TITLE;
    } else if (Name.IMPLEMENTATION_URL.toString().equals(attrName)) {
        return Name.IMPLEMENTATION_URL;
    } else if (Name.IMPLEMENTATION_VENDOR.toString().equals(attrName)) {
        return Name.IMPLEMENTATION_VENDOR;
    } else if (Name.IMPLEMENTATION_VENDOR_ID.toString().equals(attrName)) {
        return Name.IMPLEMENTATION_VENDOR_ID;
    } else if (Name.IMPLEMENTATION_VERSION.toString().equals(attrName)) {
        return Name.IMPLEMENTATION_VENDOR;
    } else if (Name.MAIN_CLASS.toString().equals(attrName)) {
        return Name.MAIN_CLASS;
    } else if (Name.MANIFEST_VERSION.toString().equals(attrName)) {
        return Name.MANIFEST_VERSION;
    } else if (Name.SEALED.toString().equals(attrName)) {
        return Name.SEALED;
    } else if (Name.SIGNATURE_VERSION.toString().equals(attrName)) {
        return Name.SIGNATURE_VERSION;
    } else if (Name.SPECIFICATION_TITLE.toString().equals(attrName)) {
        return Name.SPECIFICATION_TITLE;
    } else if (Name.SPECIFICATION_VENDOR.toString().equals(attrName)) {
        return Name.SPECIFICATION_VENDOR;
    } else if (Name.SPECIFICATION_VERSION.toString().equals(attrName)) {
        return Name.SPECIFICATION_VERSION;
    } else {
        return new Name(attrName);
    }
}
 
Example #26
Source File: URLClassLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSealed(String name, Manifest man) {
    Attributes attr = SharedSecrets.javaUtilJarAccess()
            .getTrustedAttributes(man, name.replace('.', '/').concat("/"));
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}
 
Example #27
Source File: ExtCheck.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
URL[] getClassPath() throws IOException {
    Manifest man = jar.getManifest();
    if (man != null) {
        Attributes attr = man.getMainAttributes();
        if (attr != null) {
            String value = attr.getValue(Name.CLASS_PATH);
            if (value != null) {
                return parseClassPath(csu, value);
            }
        }
    }
    return null;
}
 
Example #28
Source File: ManifestInfo.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the attribute.
 *
 * @param attr the attr
 * @param main the main
 * @param names the names
 * @return the attribute
 */
private static String getAttribute(Attributes attr, Attributes main, Map<String, Attributes> entries, Name... names) {
    if (names == null || names.length == 0) {
        return null;
    }

    String ret = getAttributeByName(main, names);

    if (ret != null) {
        return ret;
    }

    ret = getAttributeByName(attr, names);

    if (ret != null) {
        return ret;
    }

    if (entries != null) {
        for (Iterator<Map.Entry<String, Attributes>> it = entries.entrySet().iterator();it.hasNext();) {
            Map.Entry<String, Attributes> entry = it.next();
            ret = getAttributeByName(entry.getValue(), names);
            if (ret != null) {
                return ret;
            }

        }
    }

    return null;
}
 
Example #29
Source File: ShorterPaths.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String copyExtraLib(File file) throws IOException {
    if (extraLibsDir == null || !extraLibsDir.isDirectory() || !file.isFile()) {
        return null;
    }
    File copy = new File(extraLibsDir, file.getName());
    boolean wasCopied = copyMissing(file, copy);
    // copy Class-Path extensions if available
    if (wasCopied && file.getName().endsWith(".jar")) {
        String cp;
        try {
            try (JarFile jf = new JarFile(file)) {
                Manifest manifest = jf.getManifest();
                cp = manifest != null ? manifest.getMainAttributes().getValue(Name.CLASS_PATH) : null;
            }
        } catch (IOException x) {
            log("Could not parse " + file + " for Class-Path", Project.MSG_WARN);
            cp = null;
        }
        if (cp != null) {
            for (String ext : cp.split(" ")) {
                // copy CP extension with relative path to keep link dependency from manifest
                copyMissing(new File(file.getParentFile(), ext), new File(extraLibsDir, ext));
            }
        }
    }
    return copy.getName();
}
 
Example #30
Source File: URIClassLoader.java    From elasticsearch-gatherer with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the specified package name is sealed according to the
 * given manifest.
 */
private boolean isSealed(String name, Manifest man) {
    String path = name.replace('.', '/').concat("/");
    Attributes attr = man.getAttributes(path);
    String sealed = null;
    if (attr != null) {
        sealed = attr.getValue(Name.SEALED);
    }
    if (sealed == null) {
        if ((attr = man.getMainAttributes()) != null) {
            sealed = attr.getValue(Name.SEALED);
        }
    }
    return "true".equalsIgnoreCase(sealed);
}