use of aQute.lib.getopt.CommandLine 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.CommandLine in project bnd by bndtools.
the class DistroCommandTest method testResolveAgainstDistro.
public void testResolveAgainstDistro() throws Exception {
bnd bnd = new bnd();
CommandLine cmdline = new CommandLine(null);
List<String> remoteArgs = new ArrayList<>();
RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
File distro = new File("generated/tmp/test.distro.jar");
List<String> distroArgs = new ArrayList<>();
distroArgs.add("-o");
distroArgs.add(distro.getPath());
distroArgs.add("test.distro");
distroArgs.add("1.0.0");
DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
assertTrue(distro.exists());
ResolveProcess process = new ResolveProcess();
ResolverLogger logger = new ResolverLogger();
MockRegistry registry = new MockRegistry();
Processor model = new Processor();
model.setProperty("-distro", distro.getAbsolutePath() + ";version=file");
model.setProperty("-runfw", "org.eclipse.osgi");
model.setProperty("-runrequires", "osgi.wiring.package;filter:='(osgi.wiring.package=com.liferay.dynamic.data.mapping.taglib.servlet.taglib)'");
Map<Resource, List<Wire>> requiredResources = process.resolveRequired(model, null, registry, new BndResolver(logger), Collections.<ResolutionCallback>emptyList(), logger);
assertEquals(1, requiredResources.size());
}
use of aQute.lib.getopt.CommandLine in project bnd by bndtools.
the class DistroCommandTest method testDistroJarNotResolvable.
public void testDistroJarNotResolvable() throws Exception {
bnd bnd = new bnd();
CommandLine cmdline = new CommandLine(null);
List<String> remoteArgs = new ArrayList<>();
RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
File distro = new File("generated/tmp/test.distro.jar");
if (distro.exists()) {
assertTrue(distro.delete());
}
List<String> distroArgs = new ArrayList<>();
distroArgs.add("-o");
distroArgs.add(distro.getPath());
distroArgs.add("test.distro");
distroArgs.add("1.0.0");
DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
assertTrue(distro.exists());
Domain domain = Domain.domain(distro);
Parameters providedCapabilities = domain.getProvideCapability();
assertTrue(providedCapabilities.containsKey("osgi.unresolvable"));
Parameters requiredCapabilities = domain.getRequireCapability();
assertTrue(requiredCapabilities.containsKey("osgi.unresolvable"));
Attrs attrs = requiredCapabilities.get("osgi.unresolvable");
assertEquals("(&(must.not.resolve=*)(!(must.not.resolve=*)))", attrs.get("filter:"));
}
use of aQute.lib.getopt.CommandLine 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.CommandLine in project bnd by bndtools.
the class AbstractConsoleApp method __main.
/**
* Initialize the repository and other global vars.
*
* @param opts the options
* @throws IOException
*/
@Description("")
public void __main(MainOptions opts) throws IOException {
try {
setExceptions(opts.exceptions());
setTrace(opts.trace());
setPedantic(opts.pedantic());
if (opts.base() != null)
setBase(IO.getFile(getBase(), opts.base()));
else
setBase(IO.work);
if (opts.width() > 0)
this.width = opts.width();
CommandLine handler = opts._command();
List<String> arguments = opts._arguments();
if (arguments.isEmpty()) {
Justif j = new Justif();
Formatter f = j.formatter();
handler.help(f, this);
err.println(j.wrap());
} else {
String cmd = arguments.remove(0);
String help = handler.execute(this, cmd, arguments);
if (help != null) {
err.println(help);
}
}
} catch (InvocationTargetException t) {
Throwable tt = t;
while (tt instanceof InvocationTargetException) tt = ((InvocationTargetException) tt).getTargetException();
exception(tt, "%s", tt);
} catch (Throwable t) {
exception(t, "Failed %s", t);
} finally {
// Check if we need to wait for it to finish
if (opts.key()) {
System.out.println("Hit a key to continue ...");
System.in.read();
}
}
if (!check(opts.failok())) {
System.exit(getErrors().size());
}
}
Aggregations