Search in sources :

Example 6 with Patch

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));
            }
        }
    }
}
Also used : Action(org.apache.karaf.shell.api.action.Action) Reference(org.apache.karaf.shell.api.action.lifecycle.Reference) List(java.util.List) Patch(org.jboss.fuse.patch.management.Patch) BundleUpdate(org.jboss.fuse.patch.management.BundleUpdate) PatchResult(org.jboss.fuse.patch.management.PatchResult) Utils.stripSymbolicName(org.jboss.fuse.patch.management.Utils.stripSymbolicName) PatchService(org.jboss.fuse.patch.PatchService) Comparator(java.util.Comparator) PatchException(org.jboss.fuse.patch.management.PatchException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Patch(org.jboss.fuse.patch.management.Patch)

Example 7 with Patch

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);
}
Also used : PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch)

Example 8 with Patch

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());
    }
}
Also used : ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch) ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) PatchDetailsRequest(org.jboss.fuse.patch.management.PatchDetailsRequest)

Example 9 with Patch

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);
}
Also used : PatchResult(org.jboss.fuse.patch.management.PatchResult) PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch)

Example 10 with Patch

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;
}
Also used : IOException(java.io.IOException) PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch) ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

Patch (org.jboss.fuse.patch.management.Patch)33 PatchException (org.jboss.fuse.patch.management.PatchException)20 IOException (java.io.IOException)12 PatchResult (org.jboss.fuse.patch.management.PatchResult)11 File (java.io.File)10 ManagedPatch (org.jboss.fuse.patch.management.ManagedPatch)9 PatchData (org.jboss.fuse.patch.management.PatchData)9 Test (org.junit.Test)9 LinkedList (java.util.LinkedList)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 PatchDetailsRequest (org.jboss.fuse.patch.management.PatchDetailsRequest)7 HashMap (java.util.HashMap)6 BundleUpdate (org.jboss.fuse.patch.management.BundleUpdate)6 Bundle (org.osgi.framework.Bundle)6 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 GitPatchManagementServiceImpl (org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)5 FileInputStream (java.io.FileInputStream)4 ArrayList (java.util.ArrayList)4