use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _ees.
/**
* Show the class versions used in a JAR
*
* @throws Exception
*/
@Description("Show the Execution Environments of a JAR")
public void _ees(EEOptions options) throws Exception {
for (String path : options._arguments()) {
File f = getFile(path);
if (!f.isFile()) {
error("Not a file");
} else {
try (Analyzer a = new Analyzer(this)) {
a.setJar(f);
a.analyze();
out.printf("%s %s%n", a.getJar().getName(), a.getEEs());
}
}
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _bnd.
/**
* Main command. This has options the bnd base options and will then run
* another command.
*
* @param options
* @throws Exception
*/
@Description("The swiss army tool for OSGi")
public void _bnd(bndOptions options) throws Exception {
try {
set(FAIL_OK, options.failok() + "");
setExceptions(options.exceptions());
setTrace(options.trace());
if (options.trace()) {
System.setProperty(DEFAULT_LOG_LEVEL_KEY, "trace");
} else {
System.setProperty(DEFAULT_LOG_LEVEL_KEY, "warn");
}
setPedantic(options.pedantic());
if (options.base() != null)
setBase(getFile(getBase(), options.base()));
// And the properties
for (Entry<String, String> entry : options._properties().entrySet()) {
setProperty(entry.getKey(), entry.getValue());
}
CommandLine handler = options._command();
List<String> arguments = options._arguments();
// Rewrite command line to match jar commands and
// handle commands that provide file names
rewrite(arguments);
logger.debug("rewritten {}", arguments);
if (arguments.isEmpty()) {
Justif f = new Justif(80, 20, 22, 72);
handler.help(f.formatter(), this);
err.append(f.wrap());
} else {
String cmd = arguments.remove(0);
String help = handler.execute(this, cmd, arguments);
if (help != null) {
err.println(help);
}
}
if (options.secret() != null) {
password = options.secret();
settings.load(password);
}
} catch (Throwable t) {
while (t instanceof InvocationTargetException) t = t.getCause();
exception(t, "%s", t);
}
out.flush();
err.flush();
if (ws != null)
getInfo(ws);
if (!check(options.ignore())) {
System.err.flush();
System.err.flush();
Thread.sleep(1000);
exitWithCode(getErrors().size());
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _grep.
@Description("Grep the manifest of bundles/jar files. ")
public void _grep(grepOptions opts) throws Exception {
List<String> args = opts._arguments();
String s = args.remove(0);
Pattern pattern = Glob.toPattern(s);
if (pattern == null) {
messages.InvalidGlobPattern_(s);
return;
}
if (args.isEmpty()) {
args = new ExtList<String>(getBase().list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
}));
}
Set<String> headers = opts.headers();
if (headers == null)
headers = new TreeSet<String>();
if (opts.exports())
headers.add(Constants.EXPORT_PACKAGE);
if (opts.bsn())
headers.add(Constants.BUNDLE_SYMBOLICNAME);
if (opts.imports())
headers.add(Constants.IMPORT_PACKAGE);
Instructions instructions = new Instructions(headers);
for (String fileName : args) {
File file = getFile(fileName);
if (!file.isFile()) {
messages.NoSuchFile_(file);
continue;
}
try (JarInputStream in = new JarInputStream(IO.stream(file))) {
Manifest m = in.getManifest();
for (Object header : m.getMainAttributes().keySet()) {
Attributes.Name name = (Name) header;
if (instructions.isEmpty() || instructions.matches(name.toString())) {
String h = m.getMainAttributes().getValue(name);
QuotedTokenizer qt = new QuotedTokenizer(h, ",;=");
for (String value : qt.getTokenSet()) {
Matcher matcher = pattern.matcher(value);
while (matcher.find()) {
int start = matcher.start() - 8;
if (start < 0)
start = 0;
int end = matcher.end() + 8;
if (end > value.length())
end = value.length();
out.printf("%40s : %20s ...%s[%s]%s...\n", fileName, name, value.substring(start, matcher.start()), value.substring(matcher.start(), matcher.end()), value.substring(matcher.end(), end));
}
}
}
}
}
}
}
use of aQute.lib.getopt.Description 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);
}
}
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _info.
@Description("Show key project variables")
public void _info(infoOptions options) throws Exception {
Project p = getProject(options.project());
if (p == null) {
messages.NoProject();
return;
}
boolean any = options.runbundles() || options.buildpath() || options.classpath() || options.dependsOn() || options.vmpath();
MultiMap<String, Object> table = new MultiMap<String, Object>();
if (any || options.runbundles()) {
table.addAll("Run", p.getRunbundles());
}
if (any || options.buildpath()) {
table.addAll("Build", p.getBuildpath());
}
if (any || options.buildpath()) {
table.addAll("Depends on", p.getDependson());
}
if (any || options.sourcepath()) {
table.addAll("Source", p.getSourcePath());
}
if (any || options.classpath()) {
table.addAll("Class path", p.getClasspath());
}
if (any || options.vmpath()) {
table.addAll("Run path", p.getRunpath());
}
printMultiMap(table);
}
Aggregations