use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _settings.
@Description("Set bnd/jpm global variables")
public void _settings(settingOptions opts) throws Exception {
try {
Settings settings = this.settings;
char[] password = this.password;
if (opts.location() != null) {
password = opts.password();
File f = getFile(opts.location());
settings = new Settings(f.getAbsolutePath());
settings.load(password);
logger.debug("getting settings from {}", f);
}
if (opts.clear()) {
settings.clear();
logger.debug("clear {}", settings.entrySet());
}
if (opts.generate()) {
logger.debug("Generating new key pair");
settings.generate(password);
}
logger.debug("settings {}", opts.clear());
List<String> rest = opts._arguments();
if (opts.publicKey()) {
out.println(tos(!opts.base64(), settings.getPublicKey()));
}
if (opts.secretKey()) {
out.println(tos(!opts.base64(), settings.getPrivateKey()));
}
if (opts.mac()) {
for (String s : rest) {
byte[] data = s.getBytes(UTF_8);
byte[] signature = settings.sign(data);
out.printf("%s\n", tos(!opts.base64(), signature));
}
}
if (rest.isEmpty()) {
list(null, settings);
} else {
boolean set = false;
for (String s : rest) {
s = s.trim();
Matcher m = ASSIGNMENT.matcher(s);
logger.debug("try {}", s);
if (m.matches()) {
String key = m.group(1);
Instructions instr = new Instructions(key);
Collection<String> select = instr.select(settings.keySet(), true);
// check if there is a value a='b'
String value = m.group(4);
if (value == null || value.trim().length() == 0) {
// check '=' presence
if (m.group(2) == null) {
list(select, settings);
} else {
// we have 'a=', remove
for (String k : select) {
logger.debug("remove {}={}", k, settings.get(k));
settings.remove(k);
set = true;
}
}
} else {
logger.debug("assignment {}={}", key, value);
settings.put(key, value);
set = true;
}
} else {
err.printf("Cannot assign %s\n", s);
}
}
if (set) {
logger.debug("saving");
settings.save(password);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _deliverables.
@Description("Show all deliverables from this workspace. with their current version and path.")
public void _deliverables(deliverableOptions options) throws Exception {
Project project = getProject(options.project());
if (project == null) {
messages.NoProject();
return;
}
Collection<Project> projects;
if (options.limit())
projects = Arrays.asList(project);
else
projects = project.getWorkspace().getAllProjects();
List<Container> containers = new ArrayList<Container>();
for (Project p : projects) {
containers.addAll(p.getDeliverables());
}
for (Container c : containers) {
Version v = new Version(c.getVersion());
err.printf("%-40s %8s %s\n", c.getBundleSymbolicName(), v.getWithoutQualifier(), c.getFile());
}
getInfo(project);
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _bash.
@Description("Generate autocompletion file for bash")
public void _bash(Options options) throws Exception {
File tmp = File.createTempFile("bnd-completion", ".tmp");
tmp.deleteOnExit();
try {
IO.copy(getClass().getResource("bnd-completion.bash"), tmp);
Sed sed = new Sed(tmp);
sed.setBackup(false);
Reporter r = new ReporterAdapter();
CommandLine c = new CommandLine(r);
Map<String, Method> commands = c.getCommands(this);
StringBuilder sb = new StringBuilder();
for (String commandName : commands.keySet()) {
sb.append(" " + commandName);
}
sb.append(" help");
sed.replace("%listCommands%", sb.toString().substring(1));
sed.doIt();
IO.copy(tmp, out);
} finally {
IO.delete(tmp);
}
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _bump.
/**
* Bump a version number
*
* @throws Exception
*/
@Description("Bumps the version of a project")
public void _bump(bumpoptions options) throws Exception {
Project project = getProject(options.project());
if (project == null) {
messages.NoProject();
return;
}
String mask = null;
if (!options._arguments().isEmpty()) {
mask = options._arguments().get(0);
if (mask.equalsIgnoreCase("major"))
mask = "+00";
else if (mask.equalsIgnoreCase("minor"))
mask = "=+0";
else if (mask.equalsIgnoreCase("micro"))
mask = "==+";
else if (!mask.matches("[+=0]{1,3}")) {
messages.InvalidBumpMask_(mask);
return;
}
}
if (mask == null)
project.bump();
else
project.bump(mask);
getInfo(project);
err.println(project.getProperty(BUNDLE_VERSION, "No version found"));
}
use of aQute.lib.getopt.Description in project bnd by bndtools.
the class bnd method _create.
/**
* Create jar file
*
* <pre>
* jar c[v0M]f jarfile [-C dir] inputfiles [-Joption]
* jar c[v0]mf manifest jarfile [-C dir] inputfiles [-Joption] jar c[v0M]
* [-C dir] inputfiles [-Joption] jar c[v0]m manifest [-C dir] inputfiles
* [-Joption]
* </pre>
*
* @param options
* @throws Exception
*/
@Description("Create jar, used to support backward compatible java jar commands")
public void _create(createOptions options) throws Exception {
Jar jar = new Jar("dot");
File dir = getBase().getAbsoluteFile();
String sdir = options.cdir();
if (sdir != null)
dir = getFile(sdir);
if (options._arguments().isEmpty())
add(jar, dir, ".", options.verbose());
else
for (String f : options._arguments()) {
f = f.replace(File.separatorChar, '/');
add(jar, dir, f, options.verbose());
}
String manifest = options.manifest();
if (manifest != null) {
if (options.verbose())
err.printf("Adding manifest from %s\n", manifest);
jar.setManifest(getFile(manifest));
}
if (options.Manifest()) {
jar.setManifest((Manifest) null);
} else {
if (options.wrap()) {
Analyzer w = new Analyzer(this);
addClose(w);
w.setBase(getBase());
w.use(this);
w.setDefaults(options.bsn(), options.version());
w.calcManifest();
getInfo(w);
w.setJar((Jar) null);
w.close();
}
}
if (options.nocompression())
jar.setCompression(Jar.Compression.STORE);
if (isOk()) {
String jarFile = options.file();
if (jarFile == null)
jar.write(System.out);
else
jar.write(jarFile);
}
jar.close();
}
Aggregations