Search in sources :

Example 61 with Description

use of aQute.lib.getopt.Description in project bnd by bndtools.

the class Main method _start.

/**
	 * Start a service.
	 * 
	 * @param options
	 * @throws Exception
	 */
@Description("Start a service")
public void _start(startOptions options) throws Exception {
    if (!jpm.hasAccess()) {
        error("No write acces, might require administrator or root privileges (sudo in *nix)");
        return;
    }
    for (String s : options._arguments()) {
        Service service = jpm.getService(s);
        if (service == null)
            error("Non existent service %s", s);
        else {
            if (!service.isRunning()) {
                try {
                    ServiceData d = service.getServiceData();
                    logger.debug("starting {} as user {}, lock={}, log={}", d.name, d.user, d.lock, d.log);
                    if (options.clean())
                        service.clear();
                    String result = service.start();
                    if (result != null)
                        error("Failed to start: %s", result);
                } catch (Exception e) {
                    exception(e, "Could not start service %s due to %s", s, e);
                }
            } else
                warning("Service %s already running", s);
        }
    }
}
Also used : Service(aQute.jpm.lib.Service) ServiceData(aQute.jpm.lib.ServiceData) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Description(aQute.lib.getopt.Description)

Example 62 with Description

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;
    }
}
Also used : CommandLine(aQute.lib.getopt.CommandLine) Description(aQute.lib.getopt.Description)

Example 63 with Description

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);
}
Also used : ArrayList(java.util.ArrayList) Glob(aQute.libg.glob.Glob) Service(aQute.jpm.lib.Service) CommandData(aQute.jpm.lib.CommandData) ServiceData(aQute.jpm.lib.ServiceData) Description(aQute.lib.getopt.Description)

Aggregations

Description (aQute.lib.getopt.Description)63 File (java.io.File)31 Jar (aQute.bnd.osgi.Jar)14 Project (aQute.bnd.build.Project)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 Instructions (aQute.bnd.osgi.Instructions)10 CommandLine (aQute.lib.getopt.CommandLine)10 Justif (aQute.lib.justif.Justif)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Workspace (aQute.bnd.build.Workspace)7 PomFromManifest (aQute.bnd.maven.PomFromManifest)7 Service (aQute.jpm.lib.Service)7 Manifest (java.util.jar.Manifest)7 FileResource (aQute.bnd.osgi.FileResource)6 Resource (aQute.bnd.osgi.Resource)6 Analyzer (aQute.bnd.osgi.Analyzer)5 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)5 CommandData (aQute.jpm.lib.CommandData)5 ServiceData (aQute.jpm.lib.ServiceData)5