17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.util.jar;
27
28 import java.io.DataOutputStream;
29 import java.io.IOException;
30 import java.util.Collection;
31 import java.util.HashMap;
32 import java.util.LinkedHashMap;
33 import java.util.Map;
34 import java.util.Objects;
35 import java.util.Set;
36
37 import sun.util.logging.PlatformLogger;
38
39 /**
40 * The Attributes class maps Manifest attribute names to associated string
41 * values. Valid attribute names are case-insensitive, are restricted to
42 * the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
43 * characters in length. There must be a colon and a SPACE after the name;
44 * the combined length will not exceed 72 characters.
45 * Attribute values can contain any characters and
46 * will be UTF8-encoded when written to the output stream. See the
47 * <a href="{@docRoot}/../specs/jar/jar.html">JAR File Specification</a>
48 * for more information about valid attribute names and values.
49 *
50 * <p>This map and its views have a predictable iteration order, namely the
51 * order that keys were inserted into the map, as with {@link LinkedHashMap}.
52 *
53 * @author David Connelly
54 * @see Manifest
55 * @since 1.2
56 */
449 }
450 return lineNumber;
451 }
452
453 /**
454 * The Attributes.Name class represents an attribute name stored in
455 * this Map. Valid attribute names are case-insensitive, are restricted
456 * to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed
457 * 70 characters in length. Attribute values can contain any characters
458 * and will be UTF8-encoded when written to the output stream. See the
459 * <a href="{@docRoot}/../specs/jar/jar.html">JAR File Specification</a>
460 * for more information about valid attribute names and values.
461 */
462 public static class Name {
463 private final String name;
464 private final int hashCode;
465
466 /**
467 * Avoid allocation for common Names
468 */
469 private static final Map<String, Name> KNOWN_NAMES;
470
471 static final Name of(String name) {
472 Name n = KNOWN_NAMES.get(name);
473 if (n != null) {
474 return n;
475 }
476 return new Name(name);
477 }
478
479 /**
480 * Constructs a new attribute name using the given string name.
481 *
482 * @param name the attribute string name
483 * @exception IllegalArgumentException if the attribute name was
484 * invalid
485 * @exception NullPointerException if the attribute name was null
486 */
487 public Name(String name) {
488 this.hashCode = hash(name);
489 this.name = name.intern();
536 * Computes the hash value for this attribute name.
537 */
538 public int hashCode() {
539 return hashCode;
540 }
541
542 /**
543 * Returns the attribute name as a String.
544 */
545 public String toString() {
546 return name;
547 }
548
549 /**
550 * {@code Name} object for {@code Manifest-Version}
551 * manifest attribute. This attribute indicates the version number
552 * of the manifest standard to which a JAR file's manifest conforms.
553 * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
554 * Manifest and Signature Specification</a>
555 */
556 public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
557
558 /**
559 * {@code Name} object for {@code Signature-Version}
560 * manifest attribute used when signing JAR files.
561 * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
562 * Manifest and Signature Specification</a>
563 */
564 public static final Name SIGNATURE_VERSION = new Name("Signature-Version");
565
566 /**
567 * {@code Name} object for {@code Content-Type}
568 * manifest attribute.
569 */
570 public static final Name CONTENT_TYPE = new Name("Content-Type");
571
572 /**
573 * {@code Name} object for {@code Class-Path}
574 * manifest attribute.
575 * @see <a href="{@docRoot}/../specs/jar/jar.html#class-path-attribute">
576 * JAR file specification</a>
577 */
578 public static final Name CLASS_PATH = new Name("Class-Path");
579
580 /**
581 * {@code Name} object for {@code Main-Class} manifest
582 * attribute used for launching applications packaged in JAR files.
583 * The {@code Main-Class} attribute is used in conjunction
584 * with the {@code -jar} command-line option of the
585 * {@code java} application launcher.
586 */
587 public static final Name MAIN_CLASS = new Name("Main-Class");
588
589 /**
590 * {@code Name} object for {@code Sealed} manifest attribute
591 * used for sealing.
592 * @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
593 * Package Sealing</a>
594 */
595 public static final Name SEALED = new Name("Sealed");
596
597 /**
598 * {@code Name} object for {@code Extension-List} manifest attribute
599 * used for the extension mechanism that is no longer supported.
600 */
601 public static final Name EXTENSION_LIST = new Name("Extension-List");
602
603 /**
604 * {@code Name} object for {@code Extension-Name} manifest attribute.
605 * used for the extension mechanism that is no longer supported.
606 */
607 public static final Name EXTENSION_NAME = new Name("Extension-Name");
608
609 /**
610 * {@code Name} object for {@code Extension-Installation} manifest attribute.
611 *
612 * @deprecated Extension mechanism is no longer supported.
613 */
614 @Deprecated
615 public static final Name EXTENSION_INSTALLATION = new Name("Extension-Installation");
616
617 /**
618 * {@code Name} object for {@code Implementation-Title}
619 * manifest attribute used for package versioning.
620 */
621 public static final Name IMPLEMENTATION_TITLE = new Name("Implementation-Title");
622
623 /**
624 * {@code Name} object for {@code Implementation-Version}
625 * manifest attribute used for package versioning.
626 */
627 public static final Name IMPLEMENTATION_VERSION = new Name("Implementation-Version");
628
629 /**
630 * {@code Name} object for {@code Implementation-Vendor}
631 * manifest attribute used for package versioning.
632 */
633 public static final Name IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor");
634
635 /**
636 * {@code Name} object for {@code Implementation-Vendor-Id}
637 * manifest attribute.
638 *
639 * @deprecated Extension mechanism is no longer supported.
640 */
641 @Deprecated
642 public static final Name IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");
643
644 /**
645 * {@code Name} object for {@code Implementation-URL}
646 * manifest attribute.
647 *
648 * @deprecated Extension mechanism is no longer supported.
649 */
650 @Deprecated
651 public static final Name IMPLEMENTATION_URL = new Name("Implementation-URL");
652
653 /**
654 * {@code Name} object for {@code Specification-Title}
655 * manifest attribute used for package versioning.
656 */
657 public static final Name SPECIFICATION_TITLE = new Name("Specification-Title");
658
659 /**
660 * {@code Name} object for {@code Specification-Version}
661 * manifest attribute used for package versioning.
662 */
663 public static final Name SPECIFICATION_VERSION = new Name("Specification-Version");
664
665 /**
666 * {@code Name} object for {@code Specification-Vendor}
667 * manifest attribute used for package versioning.
668 */
669 public static final Name SPECIFICATION_VENDOR = new Name("Specification-Vendor");
670
671 /**
672 * {@code Name} object for {@code Multi-Release}
673 * manifest attribute that indicates this is a multi-release JAR file.
674 *
675 * @since 9
676 */
677 public static final Name MULTI_RELEASE = new Name("Multi-Release");
678
679 private static void addName(Map<String, Name> names, Name name) {
680 names.put(name.name, name);
681 }
682
683 static {
684 var names = new HashMap<String, Name>(64);
685 addName(names, MANIFEST_VERSION);
686 addName(names, SIGNATURE_VERSION);
687 addName(names, CONTENT_TYPE);
688 addName(names, CLASS_PATH);
689 addName(names, MAIN_CLASS);
690 addName(names, SEALED);
691 addName(names, EXTENSION_LIST);
692 addName(names, EXTENSION_NAME);
693 addName(names, IMPLEMENTATION_TITLE);
694 addName(names, IMPLEMENTATION_VERSION);
695 addName(names, IMPLEMENTATION_VENDOR);
696 addName(names, SPECIFICATION_TITLE);
697 addName(names, SPECIFICATION_VERSION);
698 addName(names, SPECIFICATION_VENDOR);
699 addName(names, MULTI_RELEASE);
700
701 // Common attributes used in MANIFEST.MF et.al; adding these has a
702 // small footprint cost, but is likely to be quickly paid for by
703 // reducing allocation when reading and parsing typical manifests
706 addName(names, new Name("Ant-Version"));
707 addName(names, new Name("Archiver-Version"));
708 addName(names, new Name("Build-Jdk"));
709 addName(names, new Name("Built-By"));
710 addName(names, new Name("Bnd-LastModified"));
711 addName(names, new Name("Bundle-Description"));
712 addName(names, new Name("Bundle-DocURL"));
713 addName(names, new Name("Bundle-License"));
714 addName(names, new Name("Bundle-ManifestVersion"));
715 addName(names, new Name("Bundle-Name"));
716 addName(names, new Name("Bundle-Vendor"));
717 addName(names, new Name("Bundle-Version"));
718 addName(names, new Name("Bundle-SymbolicName"));
719 addName(names, new Name("Created-By"));
720 addName(names, new Name("Export-Package"));
721 addName(names, new Name("Import-Package"));
722 addName(names, new Name("Name"));
723 addName(names, new Name("SHA1-Digest"));
724 addName(names, new Name("X-Compile-Source-JDK"));
725 addName(names, new Name("X-Compile-Target-JDK"));
726 KNOWN_NAMES = names;
727 }
728 }
729 }
|
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.util.jar;
27
28 import java.io.DataOutputStream;
29 import java.io.IOException;
30 import java.util.Collection;
31 import java.util.HashMap;
32 import java.util.LinkedHashMap;
33 import java.util.Map;
34 import java.util.Objects;
35 import java.util.Set;
36
37 import jdk.internal.misc.VM;
38 import jdk.internal.vm.annotation.Stable;
39 import sun.util.logging.PlatformLogger;
40
41 /**
42 * The Attributes class maps Manifest attribute names to associated string
43 * values. Valid attribute names are case-insensitive, are restricted to
44 * the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
45 * characters in length. There must be a colon and a SPACE after the name;
46 * the combined length will not exceed 72 characters.
47 * Attribute values can contain any characters and
48 * will be UTF8-encoded when written to the output stream. See the
49 * <a href="{@docRoot}/../specs/jar/jar.html">JAR File Specification</a>
50 * for more information about valid attribute names and values.
51 *
52 * <p>This map and its views have a predictable iteration order, namely the
53 * order that keys were inserted into the map, as with {@link LinkedHashMap}.
54 *
55 * @author David Connelly
56 * @see Manifest
57 * @since 1.2
58 */
451 }
452 return lineNumber;
453 }
454
455 /**
456 * The Attributes.Name class represents an attribute name stored in
457 * this Map. Valid attribute names are case-insensitive, are restricted
458 * to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed
459 * 70 characters in length. Attribute values can contain any characters
460 * and will be UTF8-encoded when written to the output stream. See the
461 * <a href="{@docRoot}/../specs/jar/jar.html">JAR File Specification</a>
462 * for more information about valid attribute names and values.
463 */
464 public static class Name {
465 private final String name;
466 private final int hashCode;
467
468 /**
469 * Avoid allocation for common Names
470 */
471 private static @Stable Map<String, Name> KNOWN_NAMES;
472
473 static final Name of(String name) {
474 Name n = KNOWN_NAMES.get(name);
475 if (n != null) {
476 return n;
477 }
478 return new Name(name);
479 }
480
481 /**
482 * Constructs a new attribute name using the given string name.
483 *
484 * @param name the attribute string name
485 * @exception IllegalArgumentException if the attribute name was
486 * invalid
487 * @exception NullPointerException if the attribute name was null
488 */
489 public Name(String name) {
490 this.hashCode = hash(name);
491 this.name = name.intern();
538 * Computes the hash value for this attribute name.
539 */
540 public int hashCode() {
541 return hashCode;
542 }
543
544 /**
545 * Returns the attribute name as a String.
546 */
547 public String toString() {
548 return name;
549 }
550
551 /**
552 * {@code Name} object for {@code Manifest-Version}
553 * manifest attribute. This attribute indicates the version number
554 * of the manifest standard to which a JAR file's manifest conforms.
555 * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
556 * Manifest and Signature Specification</a>
557 */
558 public static final Name MANIFEST_VERSION;
559
560 /**
561 * {@code Name} object for {@code Signature-Version}
562 * manifest attribute used when signing JAR files.
563 * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
564 * Manifest and Signature Specification</a>
565 */
566 public static final Name SIGNATURE_VERSION;
567
568 /**
569 * {@code Name} object for {@code Content-Type}
570 * manifest attribute.
571 */
572 public static final Name CONTENT_TYPE;
573
574 /**
575 * {@code Name} object for {@code Class-Path}
576 * manifest attribute.
577 * @see <a href="{@docRoot}/../specs/jar/jar.html#class-path-attribute">
578 * JAR file specification</a>
579 */
580 public static final Name CLASS_PATH;
581
582 /**
583 * {@code Name} object for {@code Main-Class} manifest
584 * attribute used for launching applications packaged in JAR files.
585 * The {@code Main-Class} attribute is used in conjunction
586 * with the {@code -jar} command-line option of the
587 * {@code java} application launcher.
588 */
589 public static final Name MAIN_CLASS;
590
591 /**
592 * {@code Name} object for {@code Sealed} manifest attribute
593 * used for sealing.
594 * @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
595 * Package Sealing</a>
596 */
597 public static final Name SEALED;
598
599 /**
600 * {@code Name} object for {@code Extension-List} manifest attribute
601 * used for the extension mechanism that is no longer supported.
602 */
603 public static final Name EXTENSION_LIST;
604
605 /**
606 * {@code Name} object for {@code Extension-Name} manifest attribute.
607 * used for the extension mechanism that is no longer supported.
608 */
609 public static final Name EXTENSION_NAME;
610
611 /**
612 * {@code Name} object for {@code Extension-Installation} manifest attribute.
613 *
614 * @deprecated Extension mechanism is no longer supported.
615 */
616 @Deprecated
617 public static final Name EXTENSION_INSTALLATION;
618
619 /**
620 * {@code Name} object for {@code Implementation-Title}
621 * manifest attribute used for package versioning.
622 */
623 public static final Name IMPLEMENTATION_TITLE;
624
625 /**
626 * {@code Name} object for {@code Implementation-Version}
627 * manifest attribute used for package versioning.
628 */
629 public static final Name IMPLEMENTATION_VERSION;
630
631 /**
632 * {@code Name} object for {@code Implementation-Vendor}
633 * manifest attribute used for package versioning.
634 */
635 public static final Name IMPLEMENTATION_VENDOR;
636
637 /**
638 * {@code Name} object for {@code Implementation-Vendor-Id}
639 * manifest attribute.
640 *
641 * @deprecated Extension mechanism is no longer supported.
642 */
643 @Deprecated
644 public static final Name IMPLEMENTATION_VENDOR_ID;
645
646 /**
647 * {@code Name} object for {@code Implementation-URL}
648 * manifest attribute.
649 *
650 * @deprecated Extension mechanism is no longer supported.
651 */
652 @Deprecated
653 public static final Name IMPLEMENTATION_URL;
654
655 /**
656 * {@code Name} object for {@code Specification-Title}
657 * manifest attribute used for package versioning.
658 */
659 public static final Name SPECIFICATION_TITLE;
660
661 /**
662 * {@code Name} object for {@code Specification-Version}
663 * manifest attribute used for package versioning.
664 */
665 public static final Name SPECIFICATION_VERSION;
666
667 /**
668 * {@code Name} object for {@code Specification-Vendor}
669 * manifest attribute used for package versioning.
670 */
671 public static final Name SPECIFICATION_VENDOR;
672
673 /**
674 * {@code Name} object for {@code Multi-Release}
675 * manifest attribute that indicates this is a multi-release JAR file.
676 *
677 * @since 9
678 */
679 public static final Name MULTI_RELEASE;
680
681 private static void addName(Map<String, Name> names, Name name) {
682 names.put(name.name, name);
683 }
684
685 static {
686
687 VM.initializeFromArchive(Attributes.Name.class);
688
689 if (KNOWN_NAMES == null) {
690 MANIFEST_VERSION = new Name("Manifest-Version");
691 SIGNATURE_VERSION = new Name("Signature-Version");
692 CONTENT_TYPE = new Name("Content-Type");
693 CLASS_PATH = new Name("Class-Path");
694 MAIN_CLASS = new Name("Main-Class");
695 SEALED = new Name("Sealed");
696 EXTENSION_LIST = new Name("Extension-List");
697 EXTENSION_NAME = new Name("Extension-Name");
698 EXTENSION_INSTALLATION = new Name("Extension-Installation");
699 IMPLEMENTATION_TITLE = new Name("Implementation-Title");
700 IMPLEMENTATION_VERSION = new Name("Implementation-Version");
701 IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor");
702 IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");
703 IMPLEMENTATION_URL = new Name("Implementation-URL");
704 SPECIFICATION_TITLE = new Name("Specification-Title");
705 SPECIFICATION_VERSION = new Name("Specification-Version");
706 SPECIFICATION_VENDOR = new Name("Specification-Vendor");
707 MULTI_RELEASE = new Name("Multi-Release");
708
709 var names = new HashMap<String, Name>(64);
710 addName(names, MANIFEST_VERSION);
711 addName(names, SIGNATURE_VERSION);
712 addName(names, CONTENT_TYPE);
713 addName(names, CLASS_PATH);
714 addName(names, MAIN_CLASS);
715 addName(names, SEALED);
716 addName(names, EXTENSION_LIST);
717 addName(names, EXTENSION_NAME);
718 addName(names, IMPLEMENTATION_TITLE);
719 addName(names, IMPLEMENTATION_VERSION);
720 addName(names, IMPLEMENTATION_VENDOR);
721 addName(names, SPECIFICATION_TITLE);
722 addName(names, SPECIFICATION_VERSION);
723 addName(names, SPECIFICATION_VENDOR);
724 addName(names, MULTI_RELEASE);
725
726 // Common attributes used in MANIFEST.MF et.al; adding these has a
727 // small footprint cost, but is likely to be quickly paid for by
728 // reducing allocation when reading and parsing typical manifests
731 addName(names, new Name("Ant-Version"));
732 addName(names, new Name("Archiver-Version"));
733 addName(names, new Name("Build-Jdk"));
734 addName(names, new Name("Built-By"));
735 addName(names, new Name("Bnd-LastModified"));
736 addName(names, new Name("Bundle-Description"));
737 addName(names, new Name("Bundle-DocURL"));
738 addName(names, new Name("Bundle-License"));
739 addName(names, new Name("Bundle-ManifestVersion"));
740 addName(names, new Name("Bundle-Name"));
741 addName(names, new Name("Bundle-Vendor"));
742 addName(names, new Name("Bundle-Version"));
743 addName(names, new Name("Bundle-SymbolicName"));
744 addName(names, new Name("Created-By"));
745 addName(names, new Name("Export-Package"));
746 addName(names, new Name("Import-Package"));
747 addName(names, new Name("Name"));
748 addName(names, new Name("SHA1-Digest"));
749 addName(names, new Name("X-Compile-Source-JDK"));
750 addName(names, new Name("X-Compile-Target-JDK"));
751 KNOWN_NAMES = Map.copyOf(names);
752 } else {
753 // Even if KNOWN_NAMES was read from archive, we still need
754 // to initialize the public constants
755 MANIFEST_VERSION = KNOWN_NAMES.get("Manifest-Version");
756 SIGNATURE_VERSION = KNOWN_NAMES.get("Signature-Version");
757 CONTENT_TYPE = KNOWN_NAMES.get("Content-Type");
758 CLASS_PATH = KNOWN_NAMES.get("Class-Path");
759 MAIN_CLASS = KNOWN_NAMES.get("Main-Class");
760 SEALED = KNOWN_NAMES.get("Sealed");
761 EXTENSION_LIST = KNOWN_NAMES.get("Extension-List");
762 EXTENSION_NAME = KNOWN_NAMES.get("Extension-Name");
763 EXTENSION_INSTALLATION = KNOWN_NAMES.get("Extension-Installation");
764 IMPLEMENTATION_TITLE = KNOWN_NAMES.get("Implementation-Title");
765 IMPLEMENTATION_VERSION = KNOWN_NAMES.get("Implementation-Version");
766 IMPLEMENTATION_VENDOR = KNOWN_NAMES.get("Implementation-Vendor");
767 IMPLEMENTATION_VENDOR_ID = KNOWN_NAMES.get("Implementation-Vendor-Id");
768 IMPLEMENTATION_URL = KNOWN_NAMES.get("Implementation-URL");
769 SPECIFICATION_TITLE = KNOWN_NAMES.get("Specification-Title");
770 SPECIFICATION_VERSION = KNOWN_NAMES.get("Specification-Version");
771 SPECIFICATION_VENDOR = KNOWN_NAMES.get("Specification-Vendor");
772 MULTI_RELEASE = KNOWN_NAMES.get("Multi-Release");
773 }
774 }
775 }
776 }
|