1664 s.forEach(sv -> sb.append("\n ").append(sv));
1665 }
1666
1667 Set<Exports> exports = md.exports();
1668 if (!exports.isEmpty()) {
1669 sb.append("\nExports:");
1670 exports.forEach(sv -> sb.append("\n ").append(sv));
1671 }
1672
1673 Map<String,Provides> provides = md.provides();
1674 if (!provides.isEmpty()) {
1675 sb.append("\nProvides: ");
1676 provides.values().forEach(p ->
1677 sb.append("\n ").append(p.service())
1678 .append(" with ")
1679 .append(toString(p.providers(), "", "")));
1680 }
1681
1682 Optional<String> mc = md.mainClass();
1683 if (mc.isPresent())
1684 sb.append("\nMain class:\n " + mc.get());
1685
1686 s = md.conceals();
1687 if (!s.isEmpty()) {
1688 sb.append("\nConceals:");
1689 s.forEach(p -> sb.append("\n ").append(p));
1690 }
1691
1692 try {
1693 Method m = ModuleDescriptor.class.getDeclaredMethod("hashes");
1694 m.setAccessible(true);
1695 Optional<Hasher.DependencyHashes> optHashes =
1696 (Optional<Hasher.DependencyHashes>) m.invoke(md);
1697
1698 if (optHashes.isPresent()) {
1699 Hasher.DependencyHashes hashes = optHashes.get();
1700 sb.append("\nHashes:");
1701 sb.append("\n Algorithm: " + hashes.algorithm());
1702 hashes.names().stream().forEach(mod ->
1703 sb.append("\n ").append(mod)
1704 .append(": ").append(hashes.hashFor(mod)));
1705 }
1706 } catch (ReflectiveOperationException x) {
1707 throw new InternalError(x);
1708 }
1709 output(sb.toString());
1710 }
1711
1712 private static String toBinaryName(String classname) {
1713 return (classname.replace('.', '/')) + ".class";
1714 }
1715
1716 private boolean checkServices(byte[] moduleInfoBytes)
1717 throws IOException
1718 {
1719 ModuleDescriptor md;
1788 }
1789
1790 /**
1791 * Examines the module dependences of the given module and computes the
1792 * hash of any module that matches the pattern {@code dependenciesToHash}.
1793 */
1794 private Hasher.DependencyHashes
1795 hashDependences(String name,
1796 Set<ModuleDescriptor.Requires> moduleDependences)
1797 throws IOException
1798 {
1799 Map<String, Path> map = new HashMap<>();
1800 Matcher matcher = dependenciesToHash.matcher("");
1801 for (ModuleDescriptor.Requires md: moduleDependences) {
1802 String dn = md.name();
1803 if (matcher.reset(dn).find()) {
1804 Optional<ModuleReference> omref = moduleFinder.find(dn);
1805 if (!omref.isPresent()) {
1806 throw new IOException(formatMsg2("error.hash.dep", name , dn));
1807 }
1808 map.put(dn, modRefToPath(omref.get()));
1809 }
1810 }
1811
1812 if (map.size() == 0) {
1813 return null;
1814 } else {
1815 return Hasher.generate(map, "SHA-256");
1816 }
1817 }
1818
1819 private static Path modRefToPath(ModuleReference mref) {
1820 URI location = mref.location().get();
1821 return Paths.get(location);
1822 }
1823 }
|
1664 s.forEach(sv -> sb.append("\n ").append(sv));
1665 }
1666
1667 Set<Exports> exports = md.exports();
1668 if (!exports.isEmpty()) {
1669 sb.append("\nExports:");
1670 exports.forEach(sv -> sb.append("\n ").append(sv));
1671 }
1672
1673 Map<String,Provides> provides = md.provides();
1674 if (!provides.isEmpty()) {
1675 sb.append("\nProvides: ");
1676 provides.values().forEach(p ->
1677 sb.append("\n ").append(p.service())
1678 .append(" with ")
1679 .append(toString(p.providers(), "", "")));
1680 }
1681
1682 Optional<String> mc = md.mainClass();
1683 if (mc.isPresent())
1684 sb.append("\nMain class:\n " + mc.getWhenPresent());
1685
1686 s = md.conceals();
1687 if (!s.isEmpty()) {
1688 sb.append("\nConceals:");
1689 s.forEach(p -> sb.append("\n ").append(p));
1690 }
1691
1692 try {
1693 Method m = ModuleDescriptor.class.getDeclaredMethod("hashes");
1694 m.setAccessible(true);
1695 Optional<Hasher.DependencyHashes> optHashes =
1696 (Optional<Hasher.DependencyHashes>) m.invoke(md);
1697
1698 if (optHashes.isPresent()) {
1699 Hasher.DependencyHashes hashes = optHashes.getWhenPresent();
1700 sb.append("\nHashes:");
1701 sb.append("\n Algorithm: " + hashes.algorithm());
1702 hashes.names().stream().forEach(mod ->
1703 sb.append("\n ").append(mod)
1704 .append(": ").append(hashes.hashFor(mod)));
1705 }
1706 } catch (ReflectiveOperationException x) {
1707 throw new InternalError(x);
1708 }
1709 output(sb.toString());
1710 }
1711
1712 private static String toBinaryName(String classname) {
1713 return (classname.replace('.', '/')) + ".class";
1714 }
1715
1716 private boolean checkServices(byte[] moduleInfoBytes)
1717 throws IOException
1718 {
1719 ModuleDescriptor md;
1788 }
1789
1790 /**
1791 * Examines the module dependences of the given module and computes the
1792 * hash of any module that matches the pattern {@code dependenciesToHash}.
1793 */
1794 private Hasher.DependencyHashes
1795 hashDependences(String name,
1796 Set<ModuleDescriptor.Requires> moduleDependences)
1797 throws IOException
1798 {
1799 Map<String, Path> map = new HashMap<>();
1800 Matcher matcher = dependenciesToHash.matcher("");
1801 for (ModuleDescriptor.Requires md: moduleDependences) {
1802 String dn = md.name();
1803 if (matcher.reset(dn).find()) {
1804 Optional<ModuleReference> omref = moduleFinder.find(dn);
1805 if (!omref.isPresent()) {
1806 throw new IOException(formatMsg2("error.hash.dep", name , dn));
1807 }
1808 map.put(dn, modRefToPath(omref.getWhenPresent()));
1809 }
1810 }
1811
1812 if (map.size() == 0) {
1813 return null;
1814 } else {
1815 return Hasher.generate(map, "SHA-256");
1816 }
1817 }
1818
1819 private static Path modRefToPath(ModuleReference mref) {
1820 URI location = mref.location().getWhenPresent();
1821 return Paths.get(location);
1822 }
1823 }
|