本文整理汇总了Java中java.util.jar.Attributes.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Attributes.getValue方法的具体用法?Java Attributes.getValue怎么用?Java Attributes.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.Attributes
的用法示例。
在下文中一共展示了Attributes.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readManifestJars
import java.util.jar.Attributes; //导入方法依赖的package包/类
private static String[] readManifestJars(InputStream in) throws IOException
{
Manifest manifest = new Manifest(in);
Attributes attributes = manifest.getMainAttributes();
String classpath = attributes.getValue(Attributes.Name.CLASS_PATH);
if(classpath == null)
return ArrayUtils.EMPTY_STRING_ARRAY;
System.out.println("Manifest jars: " + classpath);
return classpath.split(" ");
}
示例2: getJarClassPath
import java.util.jar.Attributes; //导入方法依赖的package包/类
public List<Path> getJarClassPath(Path file) throws IOException {
Path parent = file.getParent();
try (JarFile jarFile = new JarFile(file.toFile())) {
Manifest man = jarFile.getManifest();
if (man == null)
return Collections.emptyList();
Attributes attr = man.getMainAttributes();
if (attr == null)
return Collections.emptyList();
String path = attr.getValue(Attributes.Name.CLASS_PATH);
if (path == null)
return Collections.emptyList();
List<Path> list = new ArrayList<>();
for (StringTokenizer st = new StringTokenizer(path);
st.hasMoreTokens(); ) {
String elt = st.nextToken();
Path f = FileSystems.getDefault().getPath(elt);
if (!f.isAbsolute() && parent != null)
f = parent.resolve(f).toAbsolutePath();
list.add(f);
}
return list;
}
}
示例3: processManifest
import java.util.jar.Attributes; //导入方法依赖的package包/类
private static void processManifest(final List<VersionLine> components, final URL url) {
try (InputStream is = url.openStream()) {
final Manifest manifest = new Manifest(is);
final Attributes attributes = manifest.getMainAttributes();
final String artifact = attributes.getValue(ARTIFACT_ATTRIBUTE);
if (artifact != null && !artifact.isEmpty()) {
components.add(maakVersionLine(attributes));
}
} catch (final IOException e) {
LOGGER.warn("Could not read manifest: {} ", url, e);
}
}
示例4: getAvailableExtensions
import java.util.jar.Attributes; //导入方法依赖的package包/类
/**
* Return the set of <code>Extension</code> objects representing optional
* packages that are bundled with the application associated with the
* specified <code>Manifest</code>.
*
* @param manifest Manifest to be parsed
*
* @return List of available extensions, or null if the web application
* does not bundle any extensions
*/
private ArrayList getAvailableExtensions(Manifest manifest) {
Attributes attributes = manifest.getMainAttributes();
String name = attributes.getValue("Extension-Name");
if (name == null)
return null;
ArrayList extensionList = new ArrayList();
Extension extension = new Extension();
extension.setExtensionName(name);
extension.setImplementationURL(
attributes.getValue("Implementation-URL"));
extension.setImplementationVendor(
attributes.getValue("Implementation-Vendor"));
extension.setImplementationVendorId(
attributes.getValue("Implementation-Vendor-Id"));
extension.setImplementationVersion(
attributes.getValue("Implementation-Version"));
extension.setSpecificationVersion(
attributes.getValue("Specification-Version"));
extensionList.add(extension);
return extensionList;
}
示例5: addJarClassPath
import java.util.jar.Attributes; //导入方法依赖的package包/类
private void addJarClassPath(String jarFileName, boolean warn) {
try {
String jarParent = new File(jarFileName).getParent();
JarFile jar = new JarFile(jarFileName);
try {
Manifest man = jar.getManifest();
if (man == null) return;
Attributes attr = man.getMainAttributes();
if (attr == null) return;
String path = attr.getValue(Attributes.Name.CLASS_PATH);
if (path == null) return;
for (StringTokenizer st = new StringTokenizer(path);
st.hasMoreTokens();) {
String elt = st.nextToken();
if (jarParent != null)
elt = new File(jarParent, elt).getCanonicalPath();
addFile(elt, warn);
}
} finally {
jar.close();
}
} catch (IOException e) {
// log.error(Position.NOPOS,
// "error.reading.file", jarFileName,
// e.getLocalizedMessage());
}
}
示例6: readAttribute
import java.util.jar.Attributes; //导入方法依赖的package包/类
protected Object readAttribute(String name, String attrName) {
if ("java.io.File".equals(attrName)) {
return null;
}
Attributes attr1 = getManifest().getAttributes(name);
try {
return (attr1 == null) ? null : attr1.getValue(attrName);
} catch (IllegalArgumentException iax) {
return null;
}
}
示例7: getMainClassFromJar
import java.util.jar.Attributes; //导入方法依赖的package包/类
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;
}
示例8: isSealed
import java.util.jar.Attributes; //导入方法依赖的package包/类
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);
}
示例9: readProperty
import java.util.jar.Attributes; //导入方法依赖的package包/类
/**
* read a property from the manifest attributes.
*
* @param attrs the attributes.
* @param property the name of the property to read.
* @return the values.
* @throws BundleException if the manifest has an empty value for the key.
*/
private static String[] readProperty(final Attributes attrs, final String property) throws BundleException {
final String values = attrs.getValue(property);
if (values != null && values.equals("")) {
// throw new BundleException("Broken manifest, " + property + " is empty.");
return new String[0];
}
return splitString(values);
}
示例10: checkExtensions
import java.util.jar.Attributes; //导入方法依赖的package包/类
protected boolean checkExtensions(JarFile jar)
throws ExtensionInstallationException
{
Manifest man;
try {
man = jar.getManifest();
} catch (IOException e) {
return false;
}
if (man == null) {
// The applet does not define a manifest file, so
// we just assume all dependencies are satisfied.
return true;
}
boolean result = true;
Attributes attr = man.getMainAttributes();
if (attr != null) {
// Let's get the list of declared dependencies
String value = attr.getValue(Name.EXTENSION_LIST);
if (value != null) {
StringTokenizer st = new StringTokenizer(value);
// Iterate over all declared dependencies
while (st.hasMoreTokens()) {
String extensionName = st.nextToken();
debug("The file " + jar.getName() +
" appears to depend on " + extensionName);
// Sanity Check
String extName = extensionName + "-" +
Name.EXTENSION_NAME.toString();
if (attr.getValue(extName) == null) {
debug("The jar file " + jar.getName() +
" appers to depend on "
+ extensionName + " but does not define the " +
extName + " attribute in its manifest ");
} else {
if (!checkExtension(extensionName, attr)) {
debug("Failed installing " + extensionName);
result = false;
}
}
}
} else {
debug("No dependencies for " + jar.getName());
}
}
return result;
}
示例11: add
import java.util.jar.Attributes; //导入方法依赖的package包/类
public void add(String packageName) throws BundleException, IOException, CoreException {
final String exportPackageHeader = "Export-Package";
boolean foundHeader = false;
boolean hasValuesForPackageName = false;
StringBuilder strBuilder = new StringBuilder();
Attributes mainAttrs = getManifest().getMainAttributes();
for (Object entryName : mainAttrs.keySet()) {
String values;
String header;
// Get the values safely
if (entryName instanceof String) {
header = (String) entryName;
values = mainAttrs.getValue(header);
} else if (entryName instanceof Attributes.Name) {
header = (String) ((Attributes.Name) entryName).toString();
values = mainAttrs.getValue((Attributes.Name) entryName);
} else {
throw new BundleException("Unknown Main Attribute Key type: "
+ entryName.getClass() + " (" + entryName + ")");
}
// loop to the next header if we don't find ours
if (!exportPackageHeader.equals(header))
continue;
// found it
foundHeader = true;
// process the components of the value for this element see
// ManifestElement javadocs for spec
if (values != null) {
ManifestElement[] elements = ManifestElement.parseHeader(
header, values);
for (int i = 0; i < elements.length; i++) {
ManifestElement manifestElement = elements[i];
boolean lastElement = i >= elements.length - 1;
if(packageName.equals(manifestElement.getValueComponents()[0])){
hasValuesForPackageName = true;
break;
}
strBuilder.append(manifestElement.getValue());
if (!lastElement) {
strBuilder.append(",\n");
}
}
}
break;
}
if (!foundHeader) {
// Add a new one with this package
getManifest().getMainAttributes().putValue(
exportPackageHeader,
packageName);
} else {
// found it and wish to edit it...
if (!hasValuesForPackageName) {
// There are no values for the package we wish to add.
// ...create a fresh entry
String existingValues = strBuilder.toString();
boolean areExistingValues = existingValues.trim().length() != 0;
String newValue = packageName ;
newValue = (areExistingValues) ? (existingValues + ",\n " + newValue)
: newValue;
getManifest().getMainAttributes().putValue(exportPackageHeader,
newValue);
}
}
}
示例12: definePackage
import java.util.jar.Attributes; //导入方法依赖的package包/类
/**
* Defines a new package by name in this ClassLoader. The attributes
* contained in the specified Manifest will be used to obtain package
* version and sealing information. For sealed packages, the additional
* URL specifies the code source URL from which the package was loaded.
*
* @param name the package name
* @param man the Manifest containing package version and sealing
* information
* @param url the code source url for the package, or null if none
* @exception IllegalArgumentException if the package name duplicates
* an existing package either in this class loader or one
* of its ancestors
* @return the newly defined Package object
*/
protected Package definePackage(String name, Manifest man, URL url)
throws IllegalArgumentException
{
String path = name.replace('.', '/').concat("/");
String specTitle = null, specVersion = null, specVendor = null;
String implTitle = null, implVersion = null, implVendor = null;
String sealed = null;
URL sealBase = null;
Attributes attr = man.getAttributes(path);
if (attr != null) {
specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
sealed = attr.getValue(Name.SEALED);
}
attr = man.getMainAttributes();
if (attr != null) {
if (specTitle == null) {
specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
}
if (specVersion == null) {
specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
}
if (specVendor == null) {
specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
}
if (implTitle == null) {
implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
}
if (implVersion == null) {
implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
}
if (implVendor == null) {
implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
}
if (sealed == null) {
sealed = attr.getValue(Name.SEALED);
}
}
if ("true".equalsIgnoreCase(sealed)) {
sealBase = url;
}
return definePackage(name, specTitle, specVersion, specVendor,
implTitle, implVersion, implVendor, sealBase);
}
示例13: maakVersionLine
import java.util.jar.Attributes; //导入方法依赖的package包/类
private static VersionLine maakVersionLine(final Attributes attributes) {
return new VersionLine(attributes.getValue(GROUP_ATTRIBUTE), attributes.getValue(ARTIFACT_ATTRIBUTE), attributes.getValue(NAME_ATTRIBUTE),
attributes.getValue(VERSION_ATTRIBUTE));
}
示例14: definePackage
import java.util.jar.Attributes; //导入方法依赖的package包/类
/**
* Defines a new package by name in this {@code URLClassLoader}.
* The attributes contained in the specified {@code Manifest}
* will be used to obtain package version and sealing information.
* For sealed packages, the additional URL specifies the code source URL
* from which the package was loaded.
*
* @param name the package name
* @param man the {@code Manifest} containing package version and sealing
* information
* @param url the code source url for the package, or null if none
* @throws IllegalArgumentException if the package name is
* already defined by this class loader
* @return the newly defined {@code Package} object
*
* @revised 9
* @spec JPMS
*/
protected Package definePackage(String name, Manifest man, URL url) {
String path = name.replace('.', '/').concat("/");
String specTitle = null, specVersion = null, specVendor = null;
String implTitle = null, implVersion = null, implVendor = null;
String sealed = null;
URL sealBase = null;
Attributes attr = man.getAttributes(path);
if (attr != null) {
specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
sealed = attr.getValue(Name.SEALED);
}
attr = man.getMainAttributes();
if (attr != null) {
if (specTitle == null) {
specTitle = attr.getValue(Name.SPECIFICATION_TITLE);
}
if (specVersion == null) {
specVersion = attr.getValue(Name.SPECIFICATION_VERSION);
}
if (specVendor == null) {
specVendor = attr.getValue(Name.SPECIFICATION_VENDOR);
}
if (implTitle == null) {
implTitle = attr.getValue(Name.IMPLEMENTATION_TITLE);
}
if (implVersion == null) {
implVersion = attr.getValue(Name.IMPLEMENTATION_VERSION);
}
if (implVendor == null) {
implVendor = attr.getValue(Name.IMPLEMENTATION_VENDOR);
}
if (sealed == null) {
sealed = attr.getValue(Name.SEALED);
}
}
if ("true".equalsIgnoreCase(sealed)) {
sealBase = url;
}
return definePackage(name, specTitle, specVersion, specVendor,
implTitle, implVersion, implVendor, sealBase);
}
示例15: getMainClassFromJar
import java.util.jar.Attributes; //导入方法依赖的package包/类
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;
}