use of aQute.lib.getopt.Description in project bnd by bndtools.
the class Main method _generate.
@Description("Generate additional files for jpm")
public void _generate(GenerateOptions opts) throws Exception {
if (opts._arguments().isEmpty()) {
error("Syntax: jpm generate <markdown|bash-completion>");
return;
}
String genType = opts._arguments().get(0);
if (genType.equalsIgnoreCase("markdown")) {
IO.copy(this.getClass().getResourceAsStream("/static/jpm_prefix.md"), out);
CommandLine cl = new CommandLine(this);
cl.generateDocumentation(this, out);
} else if (genType.equalsIgnoreCase("bash-completion")) {
jpm.getPlatform().parseCompletion(this, out);
// IO.copy(this.getClass().getResourceAsStream("/aQute/jpm/platform/unix/jpm-completion.bash"),
// out);
} else {
error("Syntax: jpm generate <markdown|bash-completion>");
return;
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class Main method _remove.
@Description("Remove a command or a service from the system")
public void _remove(UninstallOptions opts) throws Exception {
if (!jpm.hasAccess()) {
error("No write acces, might require administrator or root privileges (sudo in *nix)");
return;
}
ArrayList<String> toDelete = new ArrayList<String>();
ArrayList<String> names = new ArrayList<String>();
List<CommandData> commands = jpm.getCommands();
for (CommandData command : commands) {
names.add(command.name);
}
List<ServiceData> services = jpm.getServices();
for (ServiceData service : services) {
names.add(service.name);
}
for (String pattern : opts._arguments()) {
Glob glob = new Glob(pattern);
for (String name : names) {
if (glob.matcher(name).matches()) {
toDelete.add(name);
}
}
}
int ccount = 0, scount = 0;
for (String name : toDelete) {
Service s = null;
if (jpm.getCommand(name) != null) {
// Try command first
logger.debug("Corresponding command found, removing");
jpm.deleteCommand(name);
ccount++;
} else if ((s = jpm.getService(name)) != null) {
// No command
// matching, try
// service
logger.debug("Corresponding service found, removing");
s.remove();
scount++;
} else {
// No match amongst commands & services
error("No matching command or service found for: %s", name);
}
}
out.format("%d command(s) removed and %d service(s) removed%n", ccount, scount);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class BaselineCommands method _baseline.
/**
* Compare
*/
@Description("Compare a newer bundle to a baselined bundle and provide versioning advice. If no parameters are given, and there " + "is a local project, then we use the projects current build and the baseline jar in the release repo.")
public void _baseline(baseLineOptions opts) throws Exception {
List<String> args = opts._arguments();
if (args.size() == 0) {
Project project = bnd.getProject();
if (project != null) {
for (Builder b : project.getSubBuilders()) {
ProjectBuilder pb = (ProjectBuilder) b;
try (Jar older = pb.getBaselineJar()) {
if (older == null) {
bnd.error("No baseline JAR available. Did you set " + Constants.BASELINE);
return;
}
// do not do
pb.setProperty(Constants.BASELINE, "");
try (Jar newer = pb.build()) {
differ.setIgnore(pb.getProperty(Constants.DIFFIGNORE));
baseline(opts, newer, older);
bnd.getInfo(b);
}
}
}
bnd.getInfo(project);
return;
}
}
if (args.size() != 2) {
throw new IllegalArgumentException("Accepts only two argument (<jar>)");
}
File newer = bnd.getFile(args.remove(0));
if (!newer.isFile())
throw new IllegalArgumentException("Not a valid newer input file: " + newer);
File older = bnd.getFile(args.remove(0));
if (!older.isFile())
throw new IllegalArgumentException("Not a valid older input file: " + older);
Jar nj = new Jar(newer);
Jar oj = new Jar(older);
baseline(opts, nj, oj);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class RepoCommand method _list.
@Description("List all artifacts from the current repositories with their versions")
public void _list(listOptions opts) throws Exception {
logger.debug("list");
Set<String> bsns = new HashSet<String>();
Instruction from = opts.from();
if (from == null)
from = new Instruction("*");
for (RepositoryPlugin repo : repos) {
if (from.matches(repo.getName()))
bsns.addAll(repo.list(opts.query()));
}
logger.debug("list {}", bsns);
for (String bsn : new SortedList<String>(bsns)) {
if (!opts.noversions()) {
Set<Version> versions = new TreeSet<Version>();
for (RepositoryPlugin repo : repos) {
logger.debug("get {} from {}", bsn, repo);
if (from.matches(repo.getName())) {
SortedSet<Version> result = repo.versions(bsn);
if (result != null)
versions.addAll(result);
}
}
bnd.out.printf("%-40s %s%n", bsn, versions);
} else {
bnd.out.printf("%s%n", bsn);
}
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class RepoCommand method _get.
/**
* get a file from the repo
*
* @param opts
*/
@Description("Get an artifact from a repository.")
public void _get(getOptions opts) throws Exception {
Instruction from = opts.from();
if (from == null)
from = new Instruction("*");
List<String> args = opts._arguments();
if (args.isEmpty()) {
bnd.error("Get needs at least a bsn");
return;
}
String bsn = args.remove(0);
String range = null;
if (!args.isEmpty()) {
range = args.remove(0);
if (!args.isEmpty()) {
bnd.error("Extra args %s", args);
}
}
VersionRange r = new VersionRange(range == null ? "0" : range);
Map<Version, RepositoryPlugin> index = new HashMap<Version, RepositoryPlugin>();
for (RepositoryPlugin repo : repos) {
if (from.matches(repo.getName())) {
SortedSet<Version> versions = repo.versions(bsn);
if (versions != null)
for (Version v : versions) {
if (r.includes(v))
index.put(v, repo);
}
}
}
SortedList<Version> l = new SortedList<Version>(index.keySet());
if (l.isEmpty()) {
bnd.out.printf("No versions found for %s%n", bsn);
return;
}
Version v;
if (opts.lowest())
v = l.first();
else
v = l.last();
RepositoryPlugin repo = index.get(v);
File file = repo.get(bsn, v, null);
File dir = bnd.getBase();
String name = file.getName();
if (opts.output() != null) {
File f = bnd.getFile(opts.output());
if (f.isDirectory())
dir = f;
else {
dir = f.getParentFile();
name = f.getName();
}
}
IO.mkdirs(dir);
IO.copy(file, new File(dir, name));
}
Aggregations