本文整理匯總了Java中java.util.jar.Attributes類的典型用法代碼示例。如果您正苦於以下問題:Java Attributes類的具體用法?Java Attributes怎麽用?Java Attributes使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Attributes類屬於java.util.jar包,在下文中一共展示了Attributes類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getVersion
import java.util.jar.Attributes; //導入依賴的package包/類
public String[] getVersion() throws Exception {
Enumeration<URL> resources = CommandLine.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
try {
Manifest manifest = new Manifest(url.openStream());
if (isApplicableManifest(manifest)) {
Attributes attributes = manifest.getMainAttributes();
return new String[] { attributes.get(key("Implementation-Title")) + " version \"" + attributes.get(key("Implementation-Version")) + "\"" };
}
} catch (IOException ex) {
return new String[] { "Unable to read from " + url + ": " + ex };
}
}
return new String[0];
}
示例2: getEntriesWithAttribute
import java.util.jar.Attributes; //導入依賴的package包/類
private Map<String, String> getEntriesWithAttribute(String attributeName) throws ContentException {
Map<String, String> result = new HashMap<>();
for (Map.Entry<String, Attributes> entry : manifest.getEntries().entrySet()) {
String attributeValue = entry.getValue().getValue(attributeName);
if (attributeValue == null) {
continue;
}
String fileName = entry.getKey();
MtaPathValidator.validatePath(fileName);
if (attributeName.equals(ATTR_MTA_MODULE)) {
Arrays.asList(attributeValue.split(Constants.MODULE_SEPARATOR)).forEach(module -> result.put(module.trim(), fileName));
} else {
result.put(attributeValue, fileName);
}
}
return result;
}
示例3: writeMainSection
import java.util.jar.Attributes; //導入依賴的package包/類
public static void writeMainSection(OutputStream out, Attributes attributes)
throws IOException {
// Main section must start with the Manifest-Version attribute.
// See https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File.
String manifestVersion = attributes.getValue(Attributes.Name.MANIFEST_VERSION);
if (manifestVersion == null) {
throw new IllegalArgumentException(
"Mandatory " + Attributes.Name.MANIFEST_VERSION + " attribute missing");
}
writeAttribute(out, Attributes.Name.MANIFEST_VERSION, manifestVersion);
if (attributes.size() > 1) {
SortedMap<String, String> namedAttributes = getAttributesSortedByName(attributes);
namedAttributes.remove(Attributes.Name.MANIFEST_VERSION.toString());
writeAttributes(out, namedAttributes);
}
writeSectionDelimiter(out);
}
示例4: isPackageSealed
import java.util.jar.Attributes; //導入依賴的package包/類
/**
* 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);
}
示例5: writeMainSection
import java.util.jar.Attributes; //導入依賴的package包/類
public static void writeMainSection(OutputStream out, Attributes attributes)
throws IOException {
// Main section must start with the Signature-Version attribute.
// See https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File.
String signatureVersion = attributes.getValue(Attributes.Name.SIGNATURE_VERSION);
if (signatureVersion == null) {
throw new IllegalArgumentException(
"Mandatory " + Attributes.Name.SIGNATURE_VERSION + " attribute missing");
}
ManifestWriter.writeAttribute(out, Attributes.Name.SIGNATURE_VERSION, signatureVersion);
if (attributes.size() > 1) {
SortedMap<String, String> namedAttributes =
ManifestWriter.getAttributesSortedByName(attributes);
namedAttributes.remove(Attributes.Name.SIGNATURE_VERSION.toString());
ManifestWriter.writeAttributes(out, namedAttributes);
}
writeSectionDelimiter(out);
}
示例6: getVersionInfo
import java.util.jar.Attributes; //導入依賴的package包/類
/**
* Reads version information from the MANIFEST.MF file of the JAR file from
* which this class was loaded.
*
* @return A string with the version information.
* The string "UNKNOWN" is returned if the class was not loaded from a JAR file or if
* the version information could not be determined.
*/
public static String getVersionInfo() {
Manifest mf = FileUtils.getJarManifest(Info.class);
if (mf == null) {
return "UNKNOWN";
}
//IJ.log("listing attributes");
Attributes attr = mf.getMainAttributes();
String version = null;
String buildDate = null;
try {
version = attr.getValue("Implementation-Version");
buildDate = attr.getValue("Build-Date");
} catch (IllegalArgumentException e) { }
return version + " (" + buildDate + ")";
}
示例7: testMainClass
import java.util.jar.Attributes; //導入依賴的package包/類
/**
* Test that a JAR file with a Main-Class attribute results
* in a module with a main class.
*/
public void testMainClass() throws IOException {
String mainClass = "p.Main";
Manifest man = new Manifest();
Attributes attrs = man.getMainAttributes();
attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
attrs.put(Attributes.Name.MAIN_CLASS, mainClass);
Path dir = Files.createTempDirectory(USER_DIR, "mods");
String entry = mainClass.replace('.', '/') + ".class";
createDummyJarFile(dir.resolve("m.jar"), man, entry);
ModuleFinder finder = ModuleFinder.of(dir);
Configuration parent = ModuleLayer.boot().configuration();
Configuration cf = resolve(parent, finder, "m");
ModuleDescriptor descriptor = findDescriptor(cf, "m");
assertTrue(descriptor.mainClass().isPresent());
assertEquals(descriptor.mainClass().get(), mainClass);
}
示例8: getClassPath
import java.util.jar.Attributes; //導入依賴的package包/類
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;
}
示例9: testWithAddExportsInManifest
import java.util.jar.Attributes; //導入依賴的package包/類
/**
* Specify Add-Exports in JAR file manifest
*/
public void testWithAddExportsInManifest() throws Exception {
Manifest man = new Manifest();
Attributes attrs = man.getMainAttributes();
attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
attrs.put(Attributes.Name.MAIN_CLASS, "TryAccess");
attrs.put(new Attributes.Name("Add-Exports"), "java.base/sun.security.x509");
Path jarfile = Paths.get("x.jar");
Path classes = Paths.get(TEST_CLASSES);
JarUtils.createJarFile(jarfile, man, classes, Paths.get("TryAccess.class"));
run(jarfile, "reflectPublicMemberNonExportedPackage", successNoWarning());
run(jarfile, "setAccessibleNonPublicMemberExportedPackage", successWithWarning());
// attempt two illegal accesses, one allowed by Add-Exports
run(jarfile, "reflectPublicMemberNonExportedPackage,"
+ "setAccessibleNonPublicMemberExportedPackage",
successWithWarning());
}
示例10: getClassPath
import java.util.jar.Attributes; //導入依賴的package包/類
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;
}
示例11: loadManifest
import java.util.jar.Attributes; //導入依賴的package包/類
private void loadManifest(Manifest manifest) {
Attributes attributes = manifest.getMainAttributes();
this.key = attributes.getValue(KEY_ATTRIBUTE);
this.mainClass = attributes.getValue(MAIN_CLASS_ATTRIBUTE);
this.name = attributes.getValue(NAME_ATTRIBUTE);
this.version = attributes.getValue(VERSION_ATTRIBUTE);
this.useChildFirstClassLoader = StringUtils.equalsIgnoreCase(attributes.getValue(USE_CHILD_FIRST_CLASSLOADER), "true");
String slSupported = attributes.getValue(SONARLINT_SUPPORTED);
this.sonarLintSupported = slSupported != null ? StringUtils.equalsIgnoreCase(slSupported, "true") : null;
this.basePlugin = attributes.getValue(BASE_PLUGIN);
this.implementationBuild = attributes.getValue(IMPLEMENTATION_BUILD);
String deps = attributes.getValue(DEPENDENCIES_ATTRIBUTE);
this.dependencies = StringUtils.split(StringUtils.defaultString(deps), ' ');
String requires = attributes.getValue(REQUIRE_PLUGINS_ATTRIBUTE);
this.requirePlugins = StringUtils.split(StringUtils.defaultString(requires), ',');
}
示例12: writeSelfReferencingJarFile
import java.util.jar.Attributes; //導入依賴的package包/類
private static void writeSelfReferencingJarFile(File jarFile, String... entries)
throws IOException {
Manifest manifest = new Manifest();
// Without version, the manifest is silently ignored. Ugh!
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
manifest.getMainAttributes().put(Attributes.Name.CLASS_PATH, jarFile.getName());
Closer closer = Closer.create();
try {
FileOutputStream fileOut = closer.register(new FileOutputStream(jarFile));
JarOutputStream jarOut = closer.register(new JarOutputStream(fileOut));
for (String entry : entries) {
jarOut.putNextEntry(new ZipEntry(entry));
Resources.copy(ClassPathTest.class.getResource(entry), jarOut);
jarOut.closeEntry();
}
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
示例13: getVersion
import java.util.jar.Attributes; //導入依賴的package包/類
private static String getVersion()
{
try
{
String path = VDMJC.class.getName().replaceAll("\\.", "/");
URL url = VDMJC.class.getResource("/" + path + ".class");
JarURLConnection conn = (JarURLConnection)url.openConnection();
JarFile jar = conn.getJarFile();
Manifest mf = jar.getManifest();
String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
return version;
}
catch (Exception e)
{
return null;
}
}
示例14: isPackageSealed
import java.util.jar.Attributes; //導入依賴的package包/類
/**
* Returns true if the specified package name is sealed according to the
* given manifest.
*/
protected boolean isPackageSealed(String name, Manifest man) {
String path = name + "/";
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);
}
示例15: getMeta
import java.util.jar.Attributes; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
protected Manifest getMeta() {
Manifest retManifest = new Manifest();
Attributes main = retManifest.getMainAttributes();
main.putValue("Manifest-Version", "1.0");
main.putValue("Created-By", "1.0 (ApkPatch)");
main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
main.putValue("Patch-Name", name);
try {
fillManifest(main);
} catch (IOException e) {
e.printStackTrace();
return null;
}
return retManifest;
}