< prev index next >
src/jdk.jartool/share/classes/sun/tools/jar/Main.java
Print this page
*** 25,34 ****
--- 25,35 ----
package sun.tools.jar;
import java.io.*;
import java.lang.module.Configuration;
+ import java.lang.module.FindException;
import java.lang.module.InvalidModuleDescriptorException;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Provides;
import java.lang.module.ModuleDescriptor.Opens;
*** 405,419 ****
genIndex(rootjar, files);
} else if (dflag) {
boolean found;
if (fname != null) {
try (ZipFile zf = new ZipFile(fname)) {
! found = printModuleDescriptor(zf);
}
} else {
try (FileInputStream fin = new FileInputStream(FileDescriptor.in)) {
! found = printModuleDescriptor(fin);
}
}
if (!found)
error(getMsg("error.module.descriptor.not.found"));
}
--- 406,420 ----
genIndex(rootjar, files);
} else if (dflag) {
boolean found;
if (fname != null) {
try (ZipFile zf = new ZipFile(fname)) {
! found = describeModule(zf);
}
} else {
try (FileInputStream fin = new FileInputStream(FileDescriptor.in)) {
! found = describeModule(fin);
}
}
if (!found)
error(getMsg("error.module.descriptor.not.found"));
}
*** 601,611 ****
/* parse file arguments */
int n = args.length - count;
if (n > 0) {
if (dflag) {
! // "--print-module-descriptor/-d" does not require file argument(s)
usageError(formatMsg("error.bad.dflag", args[count]));
return false;
}
int version = BASE_VERSION;
int k = 0;
--- 602,612 ----
/* parse file arguments */
int n = args.length - count;
if (n > 0) {
if (dflag) {
! // "--describe-module/-d" does not require file argument(s)
usageError(formatMsg("error.bad.dflag", args[count]));
return false;
}
int version = BASE_VERSION;
int k = 0;
*** 1726,1753 ****
return "";
return c.stream().map(e -> e.toString())
.collect(joining(", ", prefix, suffix));
}
! private boolean printModuleDescriptor(ZipFile zipFile)
! throws IOException
! {
ZipEntry[] zes = zipFile.stream()
.filter(e -> isModuleInfoEntry(e.getName()))
.sorted(Validator.ENTRY_COMPARATOR)
.toArray(ZipEntry[]::new);
! if (zes.length == 0)
! return false;
for (ZipEntry ze : zes) {
try (InputStream is = zipFile.getInputStream(ze)) {
! printModuleDescriptor(is, ze.getName());
}
}
return true;
}
! private boolean printModuleDescriptor(FileInputStream fis)
throws IOException
{
try (BufferedInputStream bis = new BufferedInputStream(fis);
ZipInputStream zis = new ZipInputStream(bis)) {
ZipEntry e;
--- 1727,1773 ----
return "";
return c.stream().map(e -> e.toString())
.collect(joining(", ", prefix, suffix));
}
! private boolean describeModule(ZipFile zipFile) throws IOException {
ZipEntry[] zes = zipFile.stream()
.filter(e -> isModuleInfoEntry(e.getName()))
.sorted(Validator.ENTRY_COMPARATOR)
.toArray(ZipEntry[]::new);
!
! if (zes.length == 0) {
! // No module descriptor found, derive the automatic module name
! String fn = zipFile.getName();
! ModuleFinder mf = ModuleFinder.of(Paths.get(fn));
! try {
! Set<ModuleReference> mref = mf.findAll();
! if (mref.isEmpty()) {
! output(formatMsg("error.unable.derive.automodule", fn));
! return true;
! }
! ModuleDescriptor md = mref.iterator().next().descriptor();
! output(getMsg("out.automodule"));
! describeModule(md, null, "automatic");
! } catch (FindException e) {
! String msg = formatMsg("error.unable.derive.automodule", fn);
! Throwable t = e.getCause();
! if (t != null)
! msg = msg + "\n" + t.getMessage();
! output(msg);
! }
! } else {
for (ZipEntry ze : zes) {
try (InputStream is = zipFile.getInputStream(ze)) {
! describeModule(is, ze.getName());
! }
}
}
return true;
}
! private boolean describeModule(FileInputStream fis)
throws IOException
{
try (BufferedInputStream bis = new BufferedInputStream(fis);
ZipInputStream zis = new ZipInputStream(bis)) {
ZipEntry e;
*** 1762,1789 ****
return false;
String[] names = moduleInfos.keySet().stream()
.sorted(Validator.ENTRYNAME_COMPARATOR)
.toArray(String[]::new);
for (String name : names) {
! printModuleDescriptor(new ByteArrayInputStream(moduleInfos.get(name)), name);
}
return true;
}
static <T> String toString(Collection<T> set) {
if (set.isEmpty()) { return ""; }
return set.stream().map(e -> e.toString().toLowerCase(Locale.ROOT))
.collect(joining(" "));
}
! private void printModuleDescriptor(InputStream entryInputStream, String ename)
throws IOException
{
ModuleInfo.Attributes attrs = ModuleInfo.read(entryInputStream, null);
ModuleDescriptor md = attrs.descriptor();
ModuleHashes hashes = attrs.recordedHashes();
StringBuilder sb = new StringBuilder();
sb.append("\nmodule ")
.append(md.toNameAndVersion())
.append(" (").append(ename).append(")");
--- 1782,1817 ----
return false;
String[] names = moduleInfos.keySet().stream()
.sorted(Validator.ENTRYNAME_COMPARATOR)
.toArray(String[]::new);
for (String name : names) {
! describeModule(new ByteArrayInputStream(moduleInfos.get(name)), name);
}
return true;
}
static <T> String toString(Collection<T> set) {
if (set.isEmpty()) { return ""; }
return set.stream().map(e -> e.toString().toLowerCase(Locale.ROOT))
.collect(joining(" "));
}
! private void describeModule(InputStream entryInputStream, String ename)
throws IOException
{
ModuleInfo.Attributes attrs = ModuleInfo.read(entryInputStream, null);
ModuleDescriptor md = attrs.descriptor();
ModuleHashes hashes = attrs.recordedHashes();
+ describeModule(md, hashes, ename);
+ }
+
+ private void describeModule(ModuleDescriptor md,
+ ModuleHashes hashes,
+ String ename)
+ throws IOException
+ {
StringBuilder sb = new StringBuilder();
sb.append("\nmodule ")
.append(md.toNameAndVersion())
.append(" (").append(ename).append(")");
< prev index next >