use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.
the class PatchCommandSupport method display.
/**
* Displays a list of {@link Patch patches} in short format. Each {@link Patch#getManagedPatch()} is already
* tracked.
* @param patches
* @param listBundles
* @param lessInformation
*/
protected void display(Iterable<Patch> patches, boolean listBundles, boolean lessInformation) {
int l1 = "[name]".length();
int l2 = "[installed]".length();
int l3 = "[rollup]".length();
int l4 = "[description]".length();
List<Patch> sorted = new ArrayList<>();
patches.forEach(sorted::add);
sorted.sort(Comparator.comparing(p -> p.getPatchData().getId()));
for (Patch patch : sorted) {
if (patch.getPatchData().getId().length() > l1) {
l1 = patch.getPatchData().getId().length();
}
if (patch.getResult() != null) {
java.util.List<String> versions = patch.getResult().getVersions();
if (versions.size() > 0) {
// patch installed in fabric
for (String v : versions) {
if (("Version " + v).length() > l2) {
l2 = ("Version " + v).length();
}
}
}
java.util.List<String> karafBases = patch.getResult().getKarafBases();
if (karafBases.size() > 0) {
// patch installed in standalone mode (root, admin:create)
for (String kbt : karafBases) {
String[] kb = kbt.split("\\s*\\|\\s*");
if (kb[0].length() > l2) {
l2 = kb[0].length();
}
}
}
}
String desc = patch.getPatchData().getDescription() != null && !"".equals(patch.getPatchData().getDescription().trim()) ? patch.getPatchData().getDescription() : patch.getPatchData().getId();
if (desc.length() > l4) {
l4 = desc.length();
}
}
if (!lessInformation) {
System.out.println(String.format("%-" + l1 + "s %-" + l2 + "s %-" + l3 + "s %-" + l4 + "s", "[name]", "[installed]", "[rollup]", "[description]"));
} else {
System.out.println(String.format("%-" + l1 + "s %-" + l2 + "s %-" + l4 + "s", "[name]", "[installed]", "[description]"));
}
for (Patch patch : sorted) {
String desc = patch.getPatchData().getDescription() != null && !"".equals(patch.getPatchData().getDescription().trim()) ? patch.getPatchData().getDescription() : patch.getPatchData().getId();
String installed = Boolean.toString(patch.isInstalled());
String rollup = Boolean.toString(patch.getPatchData().isRollupPatch());
if (patch.getResult() != null) {
if (patch.getResult().getKarafBases().size() > 0) {
String kbt = patch.getResult().getKarafBases().get(0);
String[] kb = kbt.split("\\s*\\|\\s*");
installed = kb[0];
}
}
if (!lessInformation) {
System.out.println(String.format("%-" + l1 + "s %-" + l2 + "s %-" + l3 + "s %-" + l4 + "s", patch.getPatchData().getId(), installed, rollup, desc));
} else {
System.out.println(String.format("%-" + l1 + "s %-" + l2 + "s %-" + l4 + "s", patch.getPatchData().getId(), installed, desc));
}
if (patch.getResult() != null && patch.getResult().getKarafBases().size() > 1) {
for (String kbt : patch.getResult().getKarafBases().subList(1, patch.getResult().getKarafBases().size())) {
String[] kb = kbt.split("\\s*\\|\\s*");
if (!lessInformation) {
System.out.println(String.format("%-" + l1 + "s %-" + l2 + "s %-" + l3 + "s %-" + l4 + "s", " ", kb[0], " ", " "));
} else {
System.out.println(String.format("%-" + l1 + "s %-" + l2 + "s %-" + l4 + "s", " ", kb[0], " "));
}
}
}
if (listBundles) {
for (String b : patch.getPatchData().getBundles()) {
System.out.println(String.format(" - %s", b));
}
}
}
}
use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.
the class RollbackCommand method doExecute.
@Override
protected void doExecute(PatchService service) throws Exception {
Patch patch = service.getPatch(patchId);
if (patch == null) {
throw new PatchException("Patch '" + patchId + "' not found");
}
if (!patch.isInstalled()) {
throw new PatchException("Patch '" + patchId + "' is not installed");
}
if (patch.getPatchData().getMigratorBundle() != null) {
throw new PatchException("Patch '" + patchId + "' does not support rollback");
}
service.rollback(patch, simulation, false);
}
use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.
the class ShowCommand method doExecute.
@Override
protected void doExecute(PatchService service) throws Exception {
Patch patch = patchManagement.loadPatch(new PatchDetailsRequest(patchId, bundles, files, diff));
if (patch == null) {
throw new PatchException("Patch '" + patchId + "' not found");
}
System.out.println(String.format("Patch ID: %s", patch.getPatchData().getId()));
if (patch.getManagedPatch() != null) {
System.out.println(String.format("Patch Commit ID: %s", patch.getManagedPatch().getCommitId()));
}
if (bundles) {
System.out.println(String.format("#### %d Bundles%s", patch.getPatchData().getBundles().size(), patch.getPatchData().getBundles().size() == 0 ? "" : ":"));
iterate(patch.getPatchData().getBundles());
}
if (files) {
ManagedPatch details = patch.getManagedPatch();
System.out.println(String.format("#### %d Files added%s", details.getFilesAdded().size(), details.getFilesAdded().size() == 0 ? "" : ":"));
iterate(details.getFilesAdded());
System.out.println(String.format("#### %d Files modified%s", details.getFilesModified().size(), details.getFilesModified().size() == 0 ? "" : ":"));
iterate(details.getFilesModified());
System.out.println(String.format("#### %d Files removed%s", details.getFilesRemoved().size(), details.getFilesRemoved().size() == 0 ? "" : ":"));
iterate(details.getFilesRemoved());
}
if (diff) {
System.out.println("#### Patch changes:\n" + patch.getManagedPatch().getUnifiedDiff());
}
}
use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.
the class SimulateCommand method doExecute.
@Override
protected void doExecute(PatchService service) throws Exception {
Patch patch = service.getPatch(patchId);
if (patch == null) {
throw new PatchException("Patch '" + patchId + "' not found");
}
if (patch.isInstalled()) {
throw new PatchException("Patch '" + patchId + "' is already installed");
}
PatchResult result = service.install(patch, true);
// display(result);
}
use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceImpl method listPatches.
@Override
public List<Patch> listPatches(boolean details) throws PatchException {
List<Patch> patches = new LinkedList<>();
File[] patchDescriptors = patchesDir.listFiles((dir, name) -> name.endsWith(".patch") && new File(dir, name).isFile());
try {
if (patchDescriptors != null) {
for (File pd : patchDescriptors) {
Patch p = loadPatch(pd, details);
patches.add(p);
}
}
} catch (IOException e) {
throw new PatchException(e.getMessage(), e);
}
return patches;
}
Aggregations