1163 private boolean isAmbiguousMainClass(Manifest m) {
1164 if (ename != null) {
1165 Attributes global = m.getMainAttributes();
1166 if ((global.get(Attributes.Name.MAIN_CLASS) != null)) {
1167 usageError(getMsg("error.bad.eflag"));
1168 return true;
1169 }
1170 }
1171 return false;
1172 }
1173
1174 /**
1175 * Adds a new file entry to the ZIP output stream.
1176 */
1177 void addFile(ZipOutputStream zos, Entry entry) throws IOException {
1178
1179 File file = entry.file;
1180 String name = entry.name;
1181 boolean isDir = entry.isDir;
1182
1183 if (name.equals("") || name.equals(".") || name.equals(zname)) {
1184 return;
1185 } else if ((name.equals(MANIFEST_DIR) || name.equals(MANIFEST_NAME))
1186 && !Mflag) {
1187 if (vflag) {
1188 output(formatMsg("out.ignore.entry", name));
1189 }
1190 return;
1191 } else if (name.equals(MODULE_INFO)) {
1192 throw new Error("Unexpected module info: " + name);
1193 }
1194
1195 long size = isDir ? 0 : file.length();
1196
1197 if (vflag) {
1198 out.print(formatMsg("out.adding", name));
1199 }
1200 ZipEntry e = new ZipEntry(name);
1201 e.setTime(file.lastModified());
1202 if (size == 0) {
1203 e.setMethod(ZipEntry.STORED);
1869 s = s.substring(0, s.indexOf('/'));
1870 return Integer.valueOf(s);
1871 }
1872
1873 /**
1874 * Describes a single module descriptor, determined by the specified
1875 * --release, if any, from the given ordered entries.
1876 * The given infos must be ordered as per ENTRY_COMPARATOR.
1877 */
1878 private boolean describeModuleFromEntries(ModuleInfoEntry[] infos)
1879 throws IOException
1880 {
1881 assert infos.length > 0;
1882
1883 // Informative: output all non-root descriptors, if any
1884 String releases = Arrays.stream(infos)
1885 .filter(e -> !e.name().equals(MODULE_INFO))
1886 .map(ModuleInfoEntry::name)
1887 .map(Main::versionFromEntryName)
1888 .collect(joining(" "));
1889 if (!releases.equals(""))
1890 output("releases: " + releases + "\n");
1891
1892 // Describe the operative descriptor for the specified --release, if any
1893 if (releaseValue != -1) {
1894 ModuleInfoEntry entry = null;
1895 int i = 0;
1896 while (i < infos.length && lessThanEqualReleaseValue(infos[i])) {
1897 entry = infos[i];
1898 i++;
1899 }
1900
1901 if (entry == null) {
1902 output(formatMsg("error.no.operative.descriptor",
1903 String.valueOf(releaseValue)));
1904 return false;
1905 }
1906
1907 String uriString = entry.uriString().orElse("");
1908 try (InputStream is = entry.bytes()) {
1909 describeModule(is, uriString);
1938 throws IOException
1939 {
1940 ModuleInfo.Attributes attrs = ModuleInfo.read(entryInputStream, null);
1941 ModuleDescriptor md = attrs.descriptor();
1942 ModuleTarget target = attrs.target();
1943 ModuleHashes hashes = attrs.recordedHashes();
1944
1945 describeModule(md, target, hashes, uriString);
1946 }
1947
1948 private void describeModule(ModuleDescriptor md,
1949 ModuleTarget target,
1950 ModuleHashes hashes,
1951 String uriString)
1952 throws IOException
1953 {
1954 StringBuilder sb = new StringBuilder();
1955
1956 sb.append(md.toNameAndVersion());
1957
1958 if (!uriString.equals(""))
1959 sb.append(" ").append(uriString);
1960 if (md.isOpen())
1961 sb.append(" open");
1962 if (md.isAutomatic())
1963 sb.append(" automatic");
1964 sb.append("\n");
1965
1966 // unqualified exports (sorted by package)
1967 md.exports().stream()
1968 .sorted(Comparator.comparing(Exports::source))
1969 .filter(e -> !e.isQualified())
1970 .forEach(e -> sb.append("exports ").append(e.source())
1971 .append(toLowerCaseString(e.modifiers()))
1972 .append("\n"));
1973
1974 // dependences
1975 md.requires().stream().sorted()
1976 .forEach(r -> sb.append("requires ").append(r.name())
1977 .append(toLowerCaseString(r.modifiers()))
1978 .append("\n"));
|
1163 private boolean isAmbiguousMainClass(Manifest m) {
1164 if (ename != null) {
1165 Attributes global = m.getMainAttributes();
1166 if ((global.get(Attributes.Name.MAIN_CLASS) != null)) {
1167 usageError(getMsg("error.bad.eflag"));
1168 return true;
1169 }
1170 }
1171 return false;
1172 }
1173
1174 /**
1175 * Adds a new file entry to the ZIP output stream.
1176 */
1177 void addFile(ZipOutputStream zos, Entry entry) throws IOException {
1178
1179 File file = entry.file;
1180 String name = entry.name;
1181 boolean isDir = entry.isDir;
1182
1183 if (name.isEmpty() || name.equals(".") || name.equals(zname)) {
1184 return;
1185 } else if ((name.equals(MANIFEST_DIR) || name.equals(MANIFEST_NAME))
1186 && !Mflag) {
1187 if (vflag) {
1188 output(formatMsg("out.ignore.entry", name));
1189 }
1190 return;
1191 } else if (name.equals(MODULE_INFO)) {
1192 throw new Error("Unexpected module info: " + name);
1193 }
1194
1195 long size = isDir ? 0 : file.length();
1196
1197 if (vflag) {
1198 out.print(formatMsg("out.adding", name));
1199 }
1200 ZipEntry e = new ZipEntry(name);
1201 e.setTime(file.lastModified());
1202 if (size == 0) {
1203 e.setMethod(ZipEntry.STORED);
1869 s = s.substring(0, s.indexOf('/'));
1870 return Integer.valueOf(s);
1871 }
1872
1873 /**
1874 * Describes a single module descriptor, determined by the specified
1875 * --release, if any, from the given ordered entries.
1876 * The given infos must be ordered as per ENTRY_COMPARATOR.
1877 */
1878 private boolean describeModuleFromEntries(ModuleInfoEntry[] infos)
1879 throws IOException
1880 {
1881 assert infos.length > 0;
1882
1883 // Informative: output all non-root descriptors, if any
1884 String releases = Arrays.stream(infos)
1885 .filter(e -> !e.name().equals(MODULE_INFO))
1886 .map(ModuleInfoEntry::name)
1887 .map(Main::versionFromEntryName)
1888 .collect(joining(" "));
1889 if (!releases.isEmpty())
1890 output("releases: " + releases + "\n");
1891
1892 // Describe the operative descriptor for the specified --release, if any
1893 if (releaseValue != -1) {
1894 ModuleInfoEntry entry = null;
1895 int i = 0;
1896 while (i < infos.length && lessThanEqualReleaseValue(infos[i])) {
1897 entry = infos[i];
1898 i++;
1899 }
1900
1901 if (entry == null) {
1902 output(formatMsg("error.no.operative.descriptor",
1903 String.valueOf(releaseValue)));
1904 return false;
1905 }
1906
1907 String uriString = entry.uriString().orElse("");
1908 try (InputStream is = entry.bytes()) {
1909 describeModule(is, uriString);
1938 throws IOException
1939 {
1940 ModuleInfo.Attributes attrs = ModuleInfo.read(entryInputStream, null);
1941 ModuleDescriptor md = attrs.descriptor();
1942 ModuleTarget target = attrs.target();
1943 ModuleHashes hashes = attrs.recordedHashes();
1944
1945 describeModule(md, target, hashes, uriString);
1946 }
1947
1948 private void describeModule(ModuleDescriptor md,
1949 ModuleTarget target,
1950 ModuleHashes hashes,
1951 String uriString)
1952 throws IOException
1953 {
1954 StringBuilder sb = new StringBuilder();
1955
1956 sb.append(md.toNameAndVersion());
1957
1958 if (!uriString.isEmpty())
1959 sb.append(" ").append(uriString);
1960 if (md.isOpen())
1961 sb.append(" open");
1962 if (md.isAutomatic())
1963 sb.append(" automatic");
1964 sb.append("\n");
1965
1966 // unqualified exports (sorted by package)
1967 md.exports().stream()
1968 .sorted(Comparator.comparing(Exports::source))
1969 .filter(e -> !e.isQualified())
1970 .forEach(e -> sb.append("exports ").append(e.source())
1971 .append(toLowerCaseString(e.modifiers()))
1972 .append("\n"));
1973
1974 // dependences
1975 md.requires().stream().sorted()
1976 .forEach(r -> sb.append("requires ").append(r.name())
1977 .append(toLowerCaseString(r.modifiers()))
1978 .append("\n"));
|