Search in sources :

Example 1 with CommandLine

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);
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Sed(aQute.libg.sed.Sed) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) Method(java.lang.reflect.Method) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 2 with CommandLine

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());
}
Also used : Processor(aQute.bnd.osgi.Processor) ResolverLogger(biz.aQute.resolve.ResolverLogger) RemoteOptions(aQute.bnd.main.RemoteCommand.RemoteOptions) ArrayList(java.util.ArrayList) MockRegistry(aQute.bnd.main.testlib.MockRegistry) Resource(org.osgi.resource.Resource) CommandLine(aQute.lib.getopt.CommandLine) DistroOptions(aQute.bnd.main.RemoteCommand.DistroOptions) ResolveProcess(biz.aQute.resolve.ResolveProcess) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) File(java.io.File)

Example 3 with CommandLine

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:"));
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) DistroOptions(aQute.bnd.main.RemoteCommand.DistroOptions) Parameters(aQute.bnd.header.Parameters) RemoteOptions(aQute.bnd.main.RemoteCommand.RemoteOptions) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 4 with CommandLine

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());
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Justif(aQute.lib.justif.Justif) InvocationTargetException(java.lang.reflect.InvocationTargetException) Description(aQute.lib.getopt.Description)

Example 5 with CommandLine

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());
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Justif(aQute.lib.justif.Justif) Formatter(java.util.Formatter) InvocationTargetException(java.lang.reflect.InvocationTargetException) Description(aQute.lib.getopt.Description)

Aggregations

CommandLine (aQute.lib.getopt.CommandLine)19 Description (aQute.lib.getopt.Description)10 File (java.io.File)8 Justif (aQute.lib.justif.Justif)6 DistroOptions (aQute.bnd.main.RemoteCommand.DistroOptions)4 RemoteOptions (aQute.bnd.main.RemoteCommand.RemoteOptions)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 Formatter (java.util.Formatter)3 Workspace (aQute.bnd.build.Workspace)2 Domain (aQute.bnd.osgi.Domain)2 ExtList (aQute.lib.collections.ExtList)2 ReporterAdapter (aQute.libg.reporter.ReporterAdapter)2 Sed (aQute.libg.sed.Sed)2 Reporter (aQute.service.reporter.Reporter)2 RandomAccessFile (java.io.RandomAccessFile)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 Resource (org.osgi.resource.Resource)2 Project (aQute.bnd.build.Project)1