Search in sources :

Example 1 with ClassDumper

use of aQute.libg.classdump.ClassDumper in project bnd by bndtools.

the class bnd method _view.

/**
	 * View files from JARs We parse the commandline and print each file on it.
	 * 
	 * @throws Exception
	 */
@Description("View a resource from a JAR file.")
public void _view(viewOptions options) throws Exception {
    Charset charset = UTF_8;
    if (options.charset() != null)
        charset = Charset.forName(options.charset());
    if (options._arguments().isEmpty()) {
        error("Need a jarfile as source");
        return;
    }
    List<String> args = options._arguments();
    File file = getFile(args.remove(0));
    if (!file.isFile()) {
        error("File does not exist %s", file);
        return;
    }
    try (Jar jar = new Jar(file)) {
        if (args.isEmpty())
            args.add("*");
        Instructions instructions = new Instructions(args);
        Collection<String> selected = instructions.select(jar.getResources().keySet(), true);
        for (String selection : selected) {
            Resource r = jar.getResource(selection);
            if (selection.endsWith(".MF")) {
                Manifest m = new Manifest(r.openInputStream());
                printManifest(m);
            } else if (selection.endsWith(".class")) {
                ClassDumper clsd = new ClassDumper(selection, r.openInputStream());
                clsd.dump(out);
            } else {
                InputStreamReader isr = new InputStreamReader(r.openInputStream(), charset);
                IO.copy(isr, out);
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Charset(java.nio.charset.Charset) Jar(aQute.bnd.osgi.Jar) Instructions(aQute.bnd.osgi.Instructions) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) ClassDumper(aQute.libg.classdump.ClassDumper) File(java.io.File) Description(aQute.lib.getopt.Description)

Aggregations

PomFromManifest (aQute.bnd.maven.PomFromManifest)1 FileResource (aQute.bnd.osgi.FileResource)1 Instructions (aQute.bnd.osgi.Instructions)1 Jar (aQute.bnd.osgi.Jar)1 Resource (aQute.bnd.osgi.Resource)1 Description (aQute.lib.getopt.Description)1 ClassDumper (aQute.libg.classdump.ClassDumper)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 Charset (java.nio.charset.Charset)1 Manifest (java.util.jar.Manifest)1