java.util.jar.Attributes.containsKey()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中java.util.jar.Attributes.containsKey()方法的一些代码示例,展示了Attributes.containsKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Attributes.containsKey()方法的具体详情如下:
包路径:java.util.jar.Attributes
类名称:Attributes
方法名:containsKey

Attributes.containsKey介绍

[英]Determines whether this Attributes contains the specified key.
[中]确定此属性是否包含指定的键。

代码示例

代码示例来源:origin: gocd/gocd

private void updateManifest(String symbolicName, String classPath, String bundleActivator) throws IOException {
  try (FileInputStream manifestInputStream = new FileInputStream(manifestLocation)) {
    Manifest manifest = new Manifest(manifestInputStream);
    Attributes mainAttributes = manifest.getMainAttributes();
    if (mainAttributes.containsKey(new Attributes.Name(BUNDLE_SYMBOLICNAME))) {
      descriptor.markAsInvalid(Arrays.asList("Plugin JAR is invalid. MANIFEST.MF already contains header: " + BUNDLE_SYMBOLICNAME), null);
      return;
    }
    mainAttributes.put(new Attributes.Name(BUNDLE_SYMBOLICNAME), symbolicName);
    mainAttributes.put(new Attributes.Name(BUNDLE_CLASSPATH), classPath);
    mainAttributes.put(new Attributes.Name(BUNDLE_ACTIVATOR), bundleActivator);
    descriptor.updateBundleInformation(symbolicName, classPath, bundleActivator);
    try (FileOutputStream manifestOutputStream = new FileOutputStream(manifestLocation)) {
      manifest.write(manifestOutputStream);
    }
  }
}

代码示例来源:origin: robovm/robovm

if (temp != null && temp.containsKey("hidden")) {
  return;

代码示例来源:origin: org.codehaus.plexus/plexus-archiver

public ExistingAttribute getAttribute( String attributeName )
{
  Attributes.Name name = new Attributes.Name( attributeName );
  return backingAttributes.containsKey( name )
        ? new ExistingAttribute( backingAttributes, attributeName )
        : null;
}

代码示例来源:origin: org.ceylon-lang/com.redhat.ceylon.model

private boolean isJavaCapabilityRequired(Attributes main) {
  return main.containsKey(Bundle_RequiredExecutionEnvironment) || main.containsKey(Require_Capability);
}

代码示例来源:origin: stackoverflow.com

Attributes mainAtts = mf.getMainAttributes();
   if(mainAtts.containsKey(Attributes.Name.MAIN_CLASS)){
     String mainClass = mainAtts.getValue(Attributes.Name.MAIN_CLASS);
     System.out.println(mainClass);
     String mainVer = mainAtts.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
     System.out.println(mainVer);
   }

代码示例来源:origin: senbox-org/snap-desktop

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;
}

代码示例来源:origin: senbox-org/snap-desktop

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;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2me-common-ant

private boolean isJarLiblet(String path) {
    try {
      JarFile jar = new JarFile(path);
      Attributes manifestAttributes = jar.getManifest().getMainAttributes();
      return manifestAttributes.containsKey(new Attributes.Name("LIBlet-Name")); //NOI18N
    } catch (IOException ex) {
      Logger.getLogger(ExtractTask.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
  }
}

代码示例来源:origin: com.atlassian.plugins/atlassian-plugins-osgi

private boolean manifestDoesntHaveRequiredOsgiHeader(final Manifest mf, final Entry<String, String> entry) {
  if (mf.getMainAttributes().containsKey(new Attributes.Name(entry.getKey()))) {
    return !entry.getValue().equals(mf.getMainAttributes().getValue(entry.getKey()));
  }
  return true;
}

代码示例来源:origin: nz.ac.auckland.common/common-configuration

/**
 * {@inheritDoc} Triggers lazy-loading of the manifest.
 */
public boolean hasValue(String key) {
  return loadManifest() && manifest.getMainAttributes().containsKey(key);
}

代码示例来源:origin: works.lmz.common/common-configuration

/**
 * {@inheritDoc} Triggers lazy-loading of the manifest.
 */
public boolean hasValue(String key) {
  return loadManifest() && manifest.getMainAttributes().containsKey(key);
}

代码示例来源:origin: ops4j/org.ops4j.pax.exam2

public static boolean isBundle(Manifest manifest) {
  if (manifest != null) {
    Attributes attributes = manifest.getMainAttributes();
    return attributes.containsKey(new Attributes.Name(Constants.BUNDLE_SYMBOLICNAME))
      && attributes.containsKey(new Attributes.Name(Constants.BUNDLE_VERSION));
  }
  return false;
}

代码示例来源:origin: fstab/promagent

InputStream transform(InputStream inputStream) throws MojoExecutionException {
  try (InputStream in = inputStream) { // No need for new variable in Java 9.
    Manifest manifest = new Manifest(in);
    Attributes attributes = manifest.getMainAttributes();
    if (!attributes.containsKey(PREMAIN_CLASS)) {
      throw new MojoExecutionException(PREMAIN_CLASS + " not found in MANIFEST.MF. This is a bug in promagent-maven-plugin.");
    }
    attributes.put(CREATED_BY, pluginArtifactId + ":" + pluginVersion);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    manifest.write(out);
    return new ByteArrayInputStream(out.toByteArray());
  } catch (IOException e) {
    throw new MojoExecutionException("Failed to transform MANIFEST.MF: " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-rt-felix

private static boolean isValidBundle(Manifest manifest) {
  Attributes atts = manifest.getMainAttributes();
  return atts.containsKey(new Attributes.Name(Constants.BUNDLE_MANIFESTVERSION));
}

代码示例来源:origin: tntim96/JSCover

public void checkDependantClasses(List<String> dependantClasses, String manifestName) throws IOException {
    try {
      for (String dependantClass : dependantClasses) {
        Class.forName(dependantClass);
      }
    } catch (ClassNotFoundException e) {
      Manifest mf = new Manifest(getClass().getResourceAsStream("/META-INF/" + manifestName));
      Attributes mainAttributes = mf.getMainAttributes();
      String name = mainAttributes.get(Attributes.Name.IMPLEMENTATION_TITLE).toString();
      if (mainAttributes.containsKey(Attributes.Name.CLASS_PATH)) {
        String classPathJARs = mainAttributes.get(Attributes.Name.CLASS_PATH).toString();
        String message = "%nEnsure these JARs are in the same directory as %s.jar:%n%s";
        throw new IllegalStateException(format(message, name , classPathJARs), e);
      } else {
        String message = "Could not find the '%s' attribute in the manifest '%s'";
        throw new IllegalStateException(format(message, Attributes.Name.CLASS_PATH, manifestName), e);
      }
    }
  }
}

代码示例来源:origin: org.glassfish.hk2/hk2-core

private void merge(Attributes target, Attributes source) {
  for (Object o : source.keySet()) {
    if (target.containsKey(o)) {
      String sep = mappings.containsKey(o.toString())?mappings.get(o.toString()):",";
      String newValue = target.get(o) + sep
          + source.get(o);
      target.put(o, newValue);
    } else {
      target.put(o, source.get(o));
    }
  }
}

代码示例来源:origin: org.glassfish.hk2/core

private void merge(Attributes target, Attributes source) {
  for (Object o : source.keySet()) {
    if (target.containsKey(o)) {
      String sep = mappings.containsKey(o.toString())?mappings.get(o.toString()):",";
      String newValue = target.get(o) + sep
          + source.get(o);
      target.put(o, newValue);
    } else {
      target.put(o, source.get(o));
    }
  }
}

代码示例来源:origin: org.jboss.shrinkwrap.descriptors/shrinkwrap-descriptors-impl-base

public ManifestAppletDefImpl(String descriptorName, ManifestModel manifest, String appletName) {
  super(descriptorName, manifest);
  this.appletName = appletName;
  Attributes mainAttributes = manifest.getMainAttributes();
  String extensionListValue = (mainAttributes.containsKey(Name.EXTENSION_LIST) ? String.valueOf(mainAttributes
    .get(Name.EXTENSION_LIST)) + " " + appletName : appletName);
  manifest.getMainAttributes().put(Name.EXTENSION_LIST, extensionListValue);
}

代码示例来源:origin: org.projectodd.shrinkwrap.descriptors/shrinkwrap-descriptors-impl-base

public ManifestAppletDefImpl(String descriptorName, ManifestModel manifest, String appletName) {
  super(descriptorName, manifest);
  this.appletName = appletName;
  Attributes mainAttributes = manifest.getMainAttributes();
  String extensionListValue = (mainAttributes.containsKey(Name.EXTENSION_LIST) ? String.valueOf(mainAttributes
    .get(Name.EXTENSION_LIST)) + " " + appletName : appletName);
  manifest.getMainAttributes().put(Name.EXTENSION_LIST, extensionListValue);
}

代码示例来源:origin: org.ceylon-lang/com.redhat.ceylon.model

private void appendOriginalManifest(Manifest manifest, Attributes main) {
  if (originalManifest != null) {
    Attributes attributes = originalManifest.getMainAttributes();
    for (Object key : attributes.keySet()) {
      if (!main.containsKey(key)) {
        main.put(key, attributes.get(key));
      } else if (log != null) {
        Object oldValue = main.get(key);
        Object newValue = attributes.get(key);
        if(!Objects.equals(oldValue, newValue))
          log.warning("manifest attribute provided by compiler: ignoring value from '"+key+"' for module '" + module.getNameAsString() +"'");
      }
    }
    manifest.getEntries().putAll(originalManifest.getEntries());
  }
}

相关文章