Search in sources :

Example 1 with UpdateMemo

use of aQute.jpm.lib.JustAnotherPackageManager.UpdateMemo in project bnd by bndtools.

the class Main method _update.

@Description("Perform updates for installed commands and services")
public void _update(UpdateOptions opts) throws Exception {
    if (!jpm.hasAccess()) {
        error("No write acces, might require administrator or root privileges (sudo in *nix)");
        return;
    }
    ArrayList<String> refs = new ArrayList<String>();
    for (CommandData data : jpm.getCommands()) {
        refs.add(data.name);
    }
    for (ServiceData data : jpm.getServices()) {
        refs.add(data.name);
    }
    ArrayList<UpdateMemo> notFound = new ArrayList<JustAnotherPackageManager.UpdateMemo>();
    ArrayList<UpdateMemo> upToDate = new ArrayList<JustAnotherPackageManager.UpdateMemo>();
    ArrayList<UpdateMemo> toUpdate = new ArrayList<JustAnotherPackageManager.UpdateMemo>();
    ArrayList<CommandData> datas = new ArrayList<CommandData>();
    if (opts._arguments().size() == 0) {
        datas.addAll(jpm.getCommands());
        datas.addAll(jpm.getServices());
    } else {
        for (String pattern : opts._arguments()) {
            Glob glob = new Glob(pattern);
            for (String name : refs) {
                if (glob.matcher(name).matches()) {
                    CommandData data = jpm.getCommand(name);
                    if (data == null) {
                        Service service = jpm.getService(name);
                        if (service != null) {
                            data = service.getServiceData();
                        }
                    }
                    if (data != null) {
                        datas.add(data);
                    }
                }
            }
        }
    }
    for (CommandData data : datas) {
        jpm.listUpdates(notFound, upToDate, toUpdate, data, opts.staged());
    }
    if (opts.all() || opts._arguments().size() > 0) {
        for (UpdateMemo memo : toUpdate) {
            jpm.update(memo);
        }
        out.format("%d command(s) updated%n", toUpdate.size());
    } else {
        Justif justif = new Justif(100, 20, 50);
        StringBuilder sb = new StringBuilder();
        Formatter f = new Formatter(sb);
        if (upToDate.size() > 0) {
            f.format("Up to date:%n");
            for (UpdateMemo memo : upToDate) {
                if (memo.current instanceof ServiceData) {
                    f.format(" - %s (service) \t0- %s%n", memo.current.name, memo.current.version);
                } else {
                    f.format(" - %s \t0- %s%n", memo.current.name, memo.current.version);
                }
            }
            f.format("%n");
        }
        if (toUpdate.size() > 0) {
            f.format("Update available:%n");
            for (UpdateMemo memo : toUpdate) {
                if (memo.current instanceof ServiceData) {
                    f.format(" - %s (service) \t0- %s \t1-> %s%n", memo.current.name, memo.current.version, memo.best.version);
                } else {
                    f.format(" - %s \t0- %s \t1-> %s%n", memo.current.name, memo.current.version, memo.best.version);
                }
            }
            f.format("%n");
        }
        if (notFound.size() > 0) {
            if (opts.staged()) {
                f.format("Information not found (local install ?):%n");
            } else {
                f.format("Information not found (try including staging versions with the --staged (-s) flag)%n");
            }
            for (UpdateMemo memo : notFound) {
                if (memo.current instanceof ServiceData) {
                    f.format(" - %s (service)%n", memo.current.name);
                } else {
                    f.format(" - %s%n", memo.current.name);
                }
            }
        }
        if (toUpdate.size() > 0) {
            f.format("%nIn order to apply all possible updates, run jpm update again with the --all (or -a) flag.%n");
        }
        f.flush();
        justif.wrap(sb);
        out.println(sb.toString());
        f.close();
    }
}
Also used : JustAnotherPackageManager(aQute.jpm.lib.JustAnotherPackageManager) Justif(aQute.lib.justif.Justif) Formatter(java.util.Formatter) ArrayList(java.util.ArrayList) UpdateMemo(aQute.jpm.lib.JustAnotherPackageManager.UpdateMemo) Service(aQute.jpm.lib.Service) ServiceData(aQute.jpm.lib.ServiceData) Glob(aQute.libg.glob.Glob) CommandData(aQute.jpm.lib.CommandData) Description(aQute.lib.getopt.Description)

Aggregations

CommandData (aQute.jpm.lib.CommandData)1 JustAnotherPackageManager (aQute.jpm.lib.JustAnotherPackageManager)1 UpdateMemo (aQute.jpm.lib.JustAnotherPackageManager.UpdateMemo)1 Service (aQute.jpm.lib.Service)1 ServiceData (aQute.jpm.lib.ServiceData)1 Description (aQute.lib.getopt.Description)1 Justif (aQute.lib.justif.Justif)1 Glob (aQute.libg.glob.Glob)1 ArrayList (java.util.ArrayList)1 Formatter (java.util.Formatter)1