Java Code Examples for java.util.jar.Attributes#Name
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: StrictJarManifest.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static void writeEntry(OutputStream os, Attributes.Name name, String value, CharsetEncoder encoder, ByteBuffer bBuf) throws IOException { String nameString = name.toString(); os.write(nameString.getBytes(StandardCharsets.US_ASCII)); os.write(VALUE_SEPARATOR); encoder.reset(); bBuf.clear().limit(LINE_LENGTH_LIMIT - nameString.length() - 2); CharBuffer cBuf = CharBuffer.wrap(value); while (true) { CoderResult r = encoder.encode(cBuf, bBuf, true); if (CoderResult.UNDERFLOW == r) { r = encoder.flush(bBuf); } os.write(bBuf.array(), bBuf.arrayOffset(), bBuf.position()); os.write(LINE_SEPARATOR); if (CoderResult.UNDERFLOW == r) { break; } os.write(' '); bBuf.clear().limit(LINE_LENGTH_LIMIT - 1); } }
Example 2
Source File: JavacTurbine.java From bazel with Apache License 2.0 | 6 votes |
private static byte[] manifestContent(TurbineOptions turbineOptions) throws IOException { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); Attributes.Name createdBy = new Attributes.Name("Created-By"); if (attributes.getValue(createdBy) == null) { attributes.put(createdBy, "bazel"); } if (turbineOptions.targetLabel().isPresent()) { attributes.put(TARGET_LABEL, turbineOptions.targetLabel().get()); } if (turbineOptions.injectingRuleKind().isPresent()) { attributes.put(INJECTING_RULE_KIND, turbineOptions.injectingRuleKind().get()); } ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); return out.toByteArray(); }
Example 3
Source File: AndroidResourceOutputs.java From bazel with Apache License 2.0 | 6 votes |
private byte[] manifestContent(@Nullable String targetLabel, @Nullable String injectingRuleKind) throws IOException { Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); Attributes.Name createdBy = new Attributes.Name("Created-By"); if (attributes.getValue(createdBy) == null) { attributes.put(createdBy, "bazel"); } if (targetLabel != null) { // Enable add_deps support. add_deps expects this attribute in the jar manifest. attributes.putValue("Target-Label", targetLabel); } if (injectingRuleKind != null) { // add_deps support for aspects. Usually null. attributes.putValue("Injecting-Rule-Kind", injectingRuleKind); } ByteArrayOutputStream out = new ByteArrayOutputStream(); manifest.write(out); return out.toByteArray(); }
Example 4
Source File: ContentComparator.java From netbeans with Apache License 2.0 | 5 votes |
/** * Compares two manifest files. First check is for number of attributes, * next one is comparing name-value pairs. * *@param mf1, mf2 manifests to compare *@param ignoredEntries array of manifest entries to ignore *@return true if files contains the same entries/values in manifest */ public static boolean equalsManifest(File mf1, File mf2, String[] ignoredEntries) { if (ignoredEntries == null) { ignoredEntries = new String[] {}; } try { Manifest m1 = new Manifest(new FileInputStream(mf1)); Manifest m2 = new Manifest(new FileInputStream(mf2)); Attributes a1 = m1.getMainAttributes(); Attributes a2 = m2.getMainAttributes(); if (a1.size() != a2.size()) { return false; } for (Iterator<Object> i = a1.keySet().iterator(); i.hasNext();) { Attributes.Name a = (Attributes.Name) i.next(); boolean b = true; for (int j = 0; j < ignoredEntries.length; j++) { if (a.toString().equals(ignoredEntries[j])) { a2.remove(a); b = false; break; } } if (b && (a1.get(a).equals(a2.get(a)))) { a2.remove(a); } } return a2.isEmpty(); } catch (FileNotFoundException fnfe) { LOGGER.log(Level.WARNING, "Exception from test - comparing manifests", fnfe); //NOI18N } catch (IOException ioe) { LOGGER.log(Level.WARNING, "Exception from test - comparing manifests", ioe); //NOI18N } return false; }
Example 5
Source File: BuildParameterBuilder.java From smithy with Apache License 2.0 | 5 votes |
@Override public Set<String> findJarsWithMatchingTags(Set<String> classpath, Set<String> tagsToFind) { Set<String> tagSourceJars = new LinkedHashSet<>(); for (String jar : classpath) { if (!Files.exists(Paths.get(jar))) { LOGGER.severe("Classpath entry not found: " + jar); continue; } try (JarFile jarFile = new JarFile(jar)) { Manifest manifest = jarFile.getManifest(); Attributes.Name name = new Attributes.Name(SMITHY_TAG_PROPERTY); if (manifest == null || !manifest.getMainAttributes().containsKey(name)) { continue; } Set<String> jarTags = loadTags((String) manifest.getMainAttributes().get(name)); LOGGER.info("Found Smithy-Tags in JAR dependency `" + jar + "`: " + jarTags); for (String needle : tagsToFind) { if (jarTags.contains(needle)) { tagSourceJars.add(jar); break; } } } catch (IOException e) { throw new SmithyBuildException( "Error reading manifest from JAR in build dependencies: " + e.getMessage(), e); } } return tagSourceJars; }
Example 6
Source File: Name.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { try { Attributes.Name name = new Attributes.Name(""); throw new Exception("empty string should be rejected"); } catch (IllegalArgumentException e) { } }
Example 7
Source File: AttributesTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * java.util.jar.Attributes#equals(java.lang.Object) */ public void test_equalsLjava_lang_Object() { Attributes.Name n1 = new Attributes.Name("name"), n2 = new Attributes.Name("Name"); assertEquals(n1, n2); Attributes a1 = new Attributes(); a1.putValue("one", "1"); a1.putValue("two", "2"); Attributes a2 = new Attributes(); a2.putValue("One", "1"); a2.putValue("TWO", "2"); assertEquals(a1, a2); assertEquals(a1, a1); a2 = null; assertFalse(a1.equals(a2)); }
Example 8
Source File: Name.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { try { Attributes.Name name = new Attributes.Name(""); throw new Exception("empty string should be rejected"); } catch (IllegalArgumentException e) { } }
Example 9
Source File: Utils.java From samoa with Apache License 2.0 | 5 votes |
public static Manifest createManifest() { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_URL, "http://samoa.yahoo.com"); manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VERSION, "0.1"); manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VENDOR, "Yahoo"); manifest.getMainAttributes().put(Attributes.Name.IMPLEMENTATION_VENDOR_ID, "SAMOA"); Attributes s4Attributes = new Attributes(); s4Attributes.putValue("S4-App-Class", "path.to.Class"); Attributes.Name name = new Attributes.Name("S4-App-Class"); Attributes.Name S4Version = new Attributes.Name("S4-Version"); manifest.getMainAttributes().put(name, "samoa.topology.impl.DoTaskApp"); manifest.getMainAttributes().put(S4Version, "0.6.0-incubating"); return manifest; }
Example 10
Source File: DeterministicManifest.java From buck with Apache License 2.0 | 5 votes |
private void writeAttributes(Attributes attributes, OutputStream out) throws IOException { List<Attributes.Name> sortedNames = attributes.keySet().stream() .map(a -> (Attributes.Name) a) .sorted(Comparator.comparing(Attributes.Name::toString)) .collect(Collectors.toList()); for (Attributes.Name name : sortedNames) { writeKeyValue(name.toString(), attributes.getValue(name), out); } writeLine(out); }
Example 11
Source File: Name.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { try { Attributes.Name name = new Attributes.Name(""); throw new Exception("empty string should be rejected"); } catch (IllegalArgumentException e) { } }
Example 12
Source File: IterationOrder.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Attributes.Name k0 = Name.MANIFEST_VERSION; Attributes.Name k1 = Name.MAIN_CLASS; Attributes.Name k2 = Name.SEALED; String v0 = "42.0"; String v1 = "com.google.Hello"; String v2 = "yes"; checkOrder(k0, v0, k1, v1, k2, v2); checkOrder(k1, v1, k0, v0, k2, v2); checkOrder(k2, v2, k1, v1, k0, v0); }
Example 13
Source File: OutputConsumerPath.java From tiny-remapper with GNU Lesser General Public License v3.0 | 5 votes |
private static void fixManifest(Manifest manifest, TinyRemapper remapper) { Attributes mainAttrs = manifest.getMainAttributes(); if (remapper != null) { String val = mainAttrs.getValue(Attributes.Name.MAIN_CLASS); if (val != null) mainAttrs.put(Attributes.Name.MAIN_CLASS, mapFullyQualifiedClassName(val, remapper)); val = mainAttrs.getValue("Launcher-Agent-Class"); if (val != null) mainAttrs.put("Launcher-Agent-Class", mapFullyQualifiedClassName(val, remapper)); } mainAttrs.remove(Attributes.Name.SIGNATURE_VERSION); for (Iterator<Attributes> it = manifest.getEntries().values().iterator(); it.hasNext(); ) { Attributes attrs = it.next(); for (Iterator<Object> it2 = attrs.keySet().iterator(); it2.hasNext(); ) { Attributes.Name attrName = (Attributes.Name) it2.next(); String name = attrName.toString(); if (name.endsWith("-Digest") || name.contains("-Digest-") || name.equals("Magic")) { it2.remove(); } } if (attrs.isEmpty()) it.remove(); } }
Example 14
Source File: JarUtil.java From consulo with Apache License 2.0 | 4 votes |
/** * Returns attribute value from a manifest main section, * or null if missing or a file does not contain a manifest. */ @Nullable public static String getJarAttribute(@Nonnull File file, @Nonnull Attributes.Name attribute) { return getJarAttributeImpl(file, null, attribute); }
Example 15
Source File: FileUtil.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
public static Attributes getAttribute(String name, String value) { Attributes a = new Attributes(); Attributes.Name attribName = new Attributes.Name(name); a.put(attribName, value); return a; }
Example 16
Source File: ManifestWriter.java From Xpatch with Apache License 2.0 | 4 votes |
static void writeAttribute(OutputStream out, Attributes.Name name, String value) throws IOException { writeAttribute(out, name.toString(), value); }
Example 17
Source File: ServerLogger.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@LogMessage(level = WARN) @Message(id = 45, value = "Extension %s is missing the required manifest attribute %s-%s (skipping extension)") void extensionMissingManifestAttribute(String item, String again, Attributes.Name suffix);
Example 18
Source File: PackageAttrsCache.java From netbeans with Apache License 2.0 | 4 votes |
private static String getAttr(Attributes spec, Attributes main, Attributes.Name name) { String val = null; if (spec != null) val = spec.getValue (name); if (val == null && main != null) val = main.getValue (name); return val; }
Example 19
Source File: Resource.java From commons-vfs with Apache License 2.0 | 4 votes |
/** * Returns an attribute of the package containing the resource. */ public String getPackageAttribute(final Attributes.Name attrName) throws FileSystemException { return (String) packageFolder.getContent().getAttribute(attrName.toString()); }
Example 20
Source File: NbBundle.java From netbeans with Apache License 2.0 | 2 votes |
/** * Find a localized and/or branded value in a JAR manifest. * @param attr the manifest attributes * @param key the key to look for (case-insensitive) * @param locale the locale to use * @return the value if found, else <code>null</code> */ public static String getLocalizedValue(Attributes attr, Attributes.Name key, Locale locale) { return getLocalizedValue(attr2Map(attr), key.toString().toLowerCase(Locale.US), locale); }