Search in sources :

Example 1 with Patch

use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.

the class GitConflictResolutionIT method cherryPickConflict.

@Test
public void cherryPickConflict() throws Exception {
    prepareChanges2();
    RevWalk rw = new RevWalk(git.getRepository());
    git.checkout().setName("custom").setCreateBranch(false).call();
    ObjectId commit = git.getRepository().resolve("patched");
    CherryPickResult result = git.cherryPick().include(commit).call();
    RevCommit cMaster = rw.parseCommit(git.getRepository().resolve("master"));
    RevCommit cCustom = rw.parseCommit(git.getRepository().resolve("custom"));
    RevCommit cPatched = rw.parseCommit(git.getRepository().resolve("patched"));
    assertThat(result.getStatus(), equalTo(CherryPickResult.CherryPickStatus.CONFLICTING));
    Map<String, IndexDiff.StageState> conflicts = git.status().call().getConflictingStageState();
    assertThat(conflicts.size(), equalTo(2));
    assertThat(conflicts.get("etc/org.ops4j.pax.logging.cfg"), equalTo(IndexDiff.StageState.BOTH_MODIFIED));
    assertThat(conflicts.get("etc/file.properties"), equalTo(IndexDiff.StageState.BOTH_MODIFIED));
    new GitPatchManagementServiceImpl().handleCherryPickConflict(null, git, result, git.getRepository().parseCommit(commit), true, PatchKind.NON_ROLLUP, "x", false, false);
    RevCommit cMerged = git.commit().setMessage("resolved").call();
    // we have 4 commits (7349224 is a custom change that's conflicting with "patched" branch):
    /*
           * 92a9ad8 - (HEAD -> custom) resolved
           * 7349224 - custom etc/org.ops4j.pax.logging.cfg
           | * 5777547 - (patched) patched etc/org.ops4j.pax.logging.cfg
           |/
           * 306f328 - (master) original etc/org.ops4j.pax.logging.cfg
         */
    FileWriter writer = new FileWriter("target/report.html");
    PatchData pd = new PatchData("my-patch-id2");
    PatchResult patchResult = PatchResult.load(pd, getClass().getResourceAsStream("/conflicts/example1/fuse-karaf-7.0.0.fuse-000160.patch.result"));
    DiffUtils.generateDiffReport(new Patch(pd, null), patchResult, git, new HashSet<>(), cMaster, cCustom, cPatched, cMerged, writer);
    writer.close();
}
Also used : PatchData(org.jboss.fuse.patch.management.PatchData) ObjectId(org.eclipse.jgit.lib.ObjectId) AbbreviatedObjectId(org.eclipse.jgit.lib.AbbreviatedObjectId) FileWriter(java.io.FileWriter) RevWalk(org.eclipse.jgit.revwalk.RevWalk) CherryPickResult(org.eclipse.jgit.api.CherryPickResult) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) PatchResult(org.jboss.fuse.patch.management.PatchResult) Patch(org.jboss.fuse.patch.management.Patch) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 2 with Patch

use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.

the class PatchServiceImpl method checkConsistency.

/**
 * Check if the set of patches mixes P and R patches. We can install several {@link PatchKind#NON_ROLLUP}
 * patches at once, but only one {@link PatchKind#ROLLUP} patch.
 * @param patches
 * @return kind of patches in the set
 */
private PatchKind checkConsistency(Collection<Patch> patches) throws PatchException {
    boolean hasP = false;
    boolean hasR = false;
    for (Patch patch : patches) {
        if (patch.getPatchData().isRollupPatch()) {
            if (hasR) {
                throw new PatchException("Can't install more than one rollup patch at once");
            }
            hasR = true;
        } else {
            hasP = true;
        }
    }
    if (hasR && hasP) {
        throw new PatchException("Can't install both rollup and non-rollup patches in single run");
    }
    return hasR ? PatchKind.ROLLUP : PatchKind.NON_ROLLUP;
}
Also used : PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch)

Example 3 with Patch

use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.

the class PatchServiceImplTest method testCheckPrerequisitesMissing.

@Test
public void testCheckPrerequisitesMissing() throws IOException {
    PatchServiceImpl service = createMockServiceImpl(getDirectoryForResource("prereq/patch1.patch"));
    Patch patch = service.getPatch("patch1");
    assertNotNull(patch);
    try {
        service.checkPrerequisites(patch);
        fail("Patch will missing prerequisites should not pass check");
    } catch (PatchException e) {
        assertTrue(e.getMessage().toLowerCase().contains("required patch 'prereq1' is missing"));
    }
}
Also used : PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch) Test(org.junit.Test)

Example 4 with Patch

use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.

the class PatchServiceImplTest method testCheckPrerequisitesSatisfied.

@Test
public void testCheckPrerequisitesSatisfied() throws IOException {
    PatchServiceImpl service = createMockServiceImpl(getDirectoryForResource("prereq/patch3.patch"));
    Patch patch = service.getPatch("patch3");
    assertNotNull(patch);
    // this should not throw a PatchException
    service.checkPrerequisites(patch);
}
Also used : Patch(org.jboss.fuse.patch.management.Patch) Test(org.junit.Test)

Example 5 with Patch

use of org.jboss.fuse.patch.management.Patch in project fuse-karaf by jboss-fuse.

the class AddCommand method doExecute.

@Override
protected void doExecute(PatchService service) throws Exception {
    Iterable<Patch> patches = service.download(new URL(url));
    display(patches, bundles);
}
Also used : Patch(org.jboss.fuse.patch.management.Patch) URL(java.net.URL)

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