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();
}
Aggregations