当前位置: 首页>>代码示例>>Java>>正文


Java Attributes类代码示例

本文整理汇总了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];
}
 
开发者ID:remkop,项目名称:picocli,代码行数:17,代码来源:Demo.java

示例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;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:18,代码来源:MtaArchiveHelper.java

示例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);
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:20,代码来源:ManifestWriter.java

示例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);

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:21,代码来源:WebappClassLoaderBase.java

示例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);
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:21,代码来源:SignatureFileWriter.java

示例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 + ")";
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:24,代码来源:Info.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:AutomaticModulesTest.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:URLClassPath.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:IllegalAccessTest.java

示例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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:URLClassPath.java

示例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), ',');
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:19,代码来源:PluginManifest.java

示例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();
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:23,代码来源:ClassPathTest.java

示例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;
	}
}
 
开发者ID:nickbattle,项目名称:FJ-VDMJ,代码行数:18,代码来源:VDMJC.java

示例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);

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:21,代码来源:WebappClassLoader.java

示例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;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:19,代码来源:MergePatch.java


注:本文中的java.util.jar.Attributes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。