< 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;
*** 406,416 ****
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);
}
--- 407,417 ----
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 = printModuleDescriptor(fin);
}
*** 602,612 ****
/* 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;
--- 603,613 ----
/* 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;
*** 1727,1750 ****
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
--- 1728,1769 ----
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;
! }
! String nv = mref.iterator().next().descriptor().toNameAndVersion();
! output(formatMsg("out.automodule.name", nv));
! } 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)) {
printModuleDescriptor(is, ze.getName());
}
}
+ }
return true;
}
private boolean printModuleDescriptor(FileInputStream fis)
throws IOException
< prev index next >