doPrint(file, optionsi);
}
}
private void doPrint(File file, int options) throws ZipException, IOException, Exception {
Jar jar = new Jar(file.getName(), file);
try {
if ((options & VERIFY) != 0) {
Verifier verifier = new Verifier(jar);
verifier.setPedantic(isPedantic());
verifier.verify();
getInfo(verifier);
}
if ((options & MANIFEST) != 0) {
Manifest manifest = jar.getManifest();
if (manifest == null)
warning("JAR has no manifest " + file);
else {
out.println("[MANIFEST " + jar.getName() + "]");
printManifest(manifest);
}
out.println();
}
if ((options & IMPEXP) != 0) {
out.println("[IMPEXP]");
Manifest m = jar.getManifest();
if (m != null) {
Domain domain = Domain.domain(m);
Parameters imports = domain.getImportPackage();
Parameters exports = domain.getExportPackage();
for (String p : exports.keySet()) {
if (imports.containsKey(p)) {
Attrs attrs = imports.get(p);
if (attrs.containsKey(VERSION_ATTRIBUTE)) {
exports.get(p).put("imported-as", attrs.get(VERSION_ATTRIBUTE));
}
}
}
print("Import-Package", new TreeMap<String,Attrs>(imports));
print("Export-Package", new TreeMap<String,Attrs>(exports));
} else
warning("File has no manifest");
}
if ((options & (USES | USEDBY)) != 0) {
out.println();
Analyzer analyzer = new Analyzer();
try {
analyzer.setPedantic(isPedantic());
analyzer.setJar(jar);
analyzer.analyze();
if ((options & USES) != 0) {
out.println("[USES]");
printMultiMap(analyzer.getUses());
out.println();
}
if ((options & USEDBY) != 0) {
out.println("[USEDBY]");
Map<PackageRef,Set<PackageRef>> usedBy = CollectionUtil.invertMapOfCollection(analyzer.getUses());
printMultiMap(usedBy);
}
analyzer.setJar((Jar) null);
} finally {
analyzer.close();
}
out.println();
}
if ((options & COMPONENT) != 0) {
printComponents(jar);
out.println();
}
if ((options & METATYPE) != 0) {
printMetatype(jar);
out.println();
}
if ((options & LIST) != 0) {
out.println("[LIST]");
for (Map.Entry<String,Map<String,Resource>> entry : jar.getDirectories().entrySet()) {
String name = entry.getKey();
Map<String,Resource> contents = entry.getValue();
out.println(name);
if (contents != null) {
for (String element : contents.keySet()) {
int n = element.lastIndexOf('/');
if (n > 0)
element = element.substring(n + 1);
out.print(" ");
out.print(element);
String path = element;
if (name.length() != 0)
path = name + "/" + element;
Resource r = contents.get(path);
if (r != null) {
String extra = r.getExtra();
if (extra != null) {
out.print(" extra='" + escapeUnicode(extra) + "'");
}
}
out.println();
}
}
}
out.println();
}
} finally {
jar.close();
}
}