Search in sources :

Example 6 with CommandData

use of aQute.jpm.lib.CommandData 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

CommandData (aQute.jpm.lib.CommandData)6 Description (aQute.lib.getopt.Description)5 Service (aQute.jpm.lib.Service)3 ServiceData (aQute.jpm.lib.ServiceData)3 ArtifactData (aQute.jpm.lib.ArtifactData)2 Justif (aQute.lib.justif.Justif)2 Glob (aQute.libg.glob.Glob)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2 Instructions (aQute.bnd.osgi.Instructions)1 JustAnotherPackageManager (aQute.jpm.lib.JustAnotherPackageManager)1 UpdateMemo (aQute.jpm.lib.JustAnotherPackageManager.UpdateMemo)1 Error (aQute.struct.struct.Error)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 Field (java.lang.reflect.Field)1