Search in sources :

Example 6 with FeatureUpdate

use of io.fabric8.patch.management.FeatureUpdate in project fabric8 by jboss-fuse.

the class Presentation method displayFeatureUpdates.

/**
 * Displays a table with installed (<code>install == true</code>) or rolledback features
 * @param featureUpdates
 * @param install is this displayed during patch install (<code>true</code>) or rollback (<code>false</code>)
 */
public static void displayFeatureUpdates(Collection<FeatureUpdate> featureUpdates, boolean install) {
    Set<String> toKeep = new TreeSet<>();
    Set<String> toRemove = new TreeSet<>();
    Set<String> toAdd = new TreeSet<>();
    for (FeatureUpdate fu : featureUpdates) {
        if (install) {
            toRemove.add(fu.getPreviousRepository());
        } else if (fu.getNewRepository() != null) {
            toRemove.add(fu.getNewRepository());
        }
        if (fu.getNewRepository() != null) {
            toAdd.add(install ? fu.getNewRepository() : fu.getPreviousRepository());
        } else if (install) {
            // keep old only during installation, when rolling back rollup patch, we don't want to keep
            // any new repository
            toKeep.add(fu.getPreviousRepository());
        }
    }
    toRemove.removeAll(toKeep);
    System.out.printf("========== Repositories to remove (%d):%n", toRemove.size());
    for (String repo : toRemove) {
        System.out.println(" - " + repo);
    }
    System.out.printf("========== Repositories to add (%d):%n", toAdd.size());
    for (String repo : toAdd) {
        System.out.println(" - " + repo);
    }
    System.out.printf("========== Repositories to keep (%d):%n", toKeep.size());
    for (String repo : toKeep) {
        System.out.println(" - " + repo);
    }
    System.out.printf("========== Features to (%s):%n", install ? "update" : "downgrade");
    int l1 = "[name]".length();
    int l2 = "[version]".length();
    int l3 = install ? "[new version]".length() : "[previous version]".length();
    Map<String, FeatureUpdate> map = new TreeMap<>();
    for (FeatureUpdate fu : featureUpdates) {
        if (fu.getName() == null) {
            continue;
        }
        if (fu.getName().length() > l1) {
            l1 = fu.getName().length();
        }
        if (install) {
            if (fu.getPreviousVersion().length() > l2) {
                l2 = fu.getPreviousVersion().length();
            }
            if (fu.getNewVersion() != null) {
                if (fu.getNewVersion().length() > l3) {
                    l3 = fu.getNewVersion().length();
                }
            }
        } else {
            if (fu.getNewVersion() != null) {
                if (fu.getNewVersion().length() > l2) {
                    l2 = fu.getNewVersion().length();
                }
            }
            if (fu.getPreviousVersion().length() > l3) {
                l3 = fu.getPreviousVersion().length();
            }
        }
        map.put(fu.getName(), fu);
    }
    System.out.printf("%-" + l1 + "s   %-" + l2 + "s   %-" + l3 + "s%n", "[name]", "[version]", install ? "[new version]" : "[previous version]");
    for (FeatureUpdate fu : map.values()) {
        System.out.printf("%-" + l1 + "s   %-" + l2 + "s   %-" + l3 + "s%n", fu.getName(), install ? fu.getPreviousVersion() : fu.getNewVersion() == null ? "<reinstall>" : fu.getNewVersion(), install ? fu.getNewVersion() == null ? "<reinstall>" : fu.getNewVersion() : fu.getPreviousVersion());
    }
    System.out.flush();
}
Also used : TreeSet(java.util.TreeSet) TreeMap(java.util.TreeMap) FeatureUpdate(io.fabric8.patch.management.FeatureUpdate)

Aggregations

FeatureUpdate (io.fabric8.patch.management.FeatureUpdate)6 File (java.io.File)4 HashMap (java.util.HashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 BundleUpdate (io.fabric8.patch.management.BundleUpdate)3 PatchException (io.fabric8.patch.management.PatchException)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3 Bundle (org.osgi.framework.Bundle)3 BundleException (org.osgi.framework.BundleException)3 Patch (io.fabric8.patch.management.Patch)2 PatchResult (io.fabric8.patch.management.PatchResult)2 FileInputStream (java.io.FileInputStream)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 Feature (org.apache.karaf.features.Feature)2 Version (org.osgi.framework.Version)2 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)2