use of aQute.lib.getopt.Description in project bnd by bndtools.
the class RepoCommand method _diff.
@Description("Diff jars (or show tree)")
public void _diff(diffOptions options) throws UnsupportedEncodingException, IOException, Exception {
List<String> args = options._arguments();
String newer = args.remove(0);
String older = args.size() > 0 ? args.remove(0) : null;
RepositoryPlugin rnewer = findRepo(newer);
RepositoryPlugin rolder = older == null ? null : findRepo(older);
if (rnewer == null) {
bnd.messages.NoSuchRepository_(newer);
return;
}
if (older != null && rolder == null) {
bnd.messages.NoSuchRepository_(newer);
return;
}
PrintWriter pw = IO.writer(bnd.out, UTF_8);
Tree tNewer = RepositoryElement.getTree(rnewer);
if (rolder == null) {
if (options.json())
codec.enc().to(pw).put(tNewer.serialize()).flush();
else
DiffCommand.show(pw, tNewer, 0);
} else {
Tree tOlder = RepositoryElement.getTree(rolder);
Diff diff = new DiffImpl(tNewer, tOlder);
MultiMap<String, String> map = new MultiMap<String, String>();
for (Diff bsn : diff.getChildren()) {
for (Diff version : bsn.getChildren()) {
if (version.getDelta() == Delta.UNCHANGED)
continue;
if (options.remove() == false && options.added() == false || (//
options.remove() && version.getDelta() == Delta.REMOVED) || (options.added() && version.getDelta() == Delta.ADDED)) {
map.add(bsn.getName(), version.getName());
}
}
}
if (options.json())
codec.enc().to(pw).put(map).flush();
else if (!options.diff())
bnd.printMultiMap(map);
else
DiffCommand.show(pw, diff, 0, !options.full());
}
pw.flush();
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class RepoCommand method _repos.
@Description("List the current repositories")
public void _repos(@SuppressWarnings("unused") reposOptions opts) {
int n = 1;
for (RepositoryPlugin repo : repos) {
String location = "";
try {
location = repo.getLocation();
} catch (Throwable e) {
// Ignore
}
bnd.out.printf("%03d: %-20s %4s %-20s %s%n", n++, repo.getName(), repo.canWrite() ? "r/w" : "r/o", Descriptors.getShortName(repo.getClass().getName()), location);
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class RepoCommand method _versions.
@Description("Displays a list of versions for a given bsn that can be found in the current repositories.")
public void _versions(VersionsOptions opts) throws Exception {
TreeSet<Version> versions = new TreeSet<Version>();
String bsn = opts._arguments().remove(0);
for (RepositoryPlugin repo : repos) {
versions.addAll(repo.versions(bsn));
}
bnd.out.println(versions);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _syntax.
@Description("Access the internal bnd database of keywords and options")
public void _syntax(syntaxOptions opts) throws Exception {
int w = opts.width() < 80 ? 120 : opts.width();
Justif justif = new Justif(w, opts.width(), 40, 42, w - 10);
List<String> args = opts._arguments();
StringBuilder sb = new StringBuilder();
Formatter f = new Formatter(sb);
for (String s : args) {
f.format(" \n[%s]\n", s);
Syntax sx = Syntax.HELP.get(s);
if (s == null)
f.format("Unknown");
else {
print(f, sx, " ");
}
}
f.flush();
justif.wrap(sb);
err.println(sb);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _package.
/**
* Package a bnd or bndrun file for packaging.
*
* @throws Exception
*/
@Description("Package a bnd or bndrun file into a single jar that executes with java -jar <>.jar")
public void _package(packageOptions opts) throws Exception {
List<String> cmdline = opts._arguments();
File output = null;
if (opts.output() != null) {
output = getFile(opts.output());
} else
output = getBase();
if (opts._arguments().size() > 1) {
IO.mkdirs(output);
} else {
File pf = output.getParentFile();
IO.mkdirs(pf);
}
String profile = opts.profile() == null ? "exec" : opts.profile();
if (cmdline.isEmpty())
// default project itself
cmdline.add(Project.BNDFILE);
for (String path : cmdline) {
Run run;
File file = getFile(path);
if (file.isDirectory())
file = new File(file, Project.BNDFILE);
if (!file.isFile()) {
messages.NoSuchFile_(file);
continue;
}
File dir = file.getParentFile();
File workspaceDir = dir.getParentFile();
if (workspaceDir == null) {
// We are in the filesystem root?? Create a standalone run.
run = Run.createRun(null, file);
} else {
Workspace ws = Workspace.getWorkspaceWithoutException(workspaceDir);
run = Run.createRun(ws, file);
}
// Tricky because we can be run inside the context of a
// project (in which case
// we need to inherit from the project or outside.
run.setProperty(PROFILE, profile);
run.use(this);
if (opts.jpm())
run.setProperty(Constants.PACKAGE, Constants.PACKAGE_JPM);
try {
Jar jar = run.pack(profile);
path = path.replaceAll(".bnd(run)?$", "") + ".jar";
File out = output;
if (output.isDirectory())
out = new File(output, path);
jar.write(out);
jar.close();
} catch (Exception e) {
messages.ForProject_File_FailedToCreateExecutableException_(run, path, e);
}
getInfo(run);
}
}
Aggregations