Search in sources :

Example 6 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method installPPatchAndThenRPatch.

@Test
public void installPPatchAndThenRPatch() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
    // simulation of P patch installed using old patching mechanism
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    FileUtils.write(new File(karafHome, "etc/overrides.properties"), "mvn:org.jboss.fuse/fuse-oceans/1.4.2\n", "UTF-8");
    // non-conflicting
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.closeRepository(fork, true);
    // overrides.properties as after installing P patch with old mechanism
    String etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"), "UTF-8");
    assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-oceans/1.4.2\n"));
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData4 = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
    Patch patch4 = service.trackPatch(patchData4);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch1, null);
    service.commitInstallation(tx);
    assertTrue("There should be no changes to etc/overrides.properties after installing non-rollup patch", new File(karafHome, "etc/overrides.properties").exists());
    // overrides.properties as after installing P patch with new mechanism
    etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"), "UTF-8");
    assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-oceans/1.4.2\n"));
    // override from P-Patch should go to etc/org.apache.karaf.features.xml
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(1));
    assertThat(bundles.get(0).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
    assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    repository.closeRepository(fork, true);
    tx = service.beginInstallation(PatchKind.ROLLUP);
    service.install(tx, patch4, null);
    service.commitInstallation(tx);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    assertFalse("There should be no etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
    repository.closeRepository(fork, true);
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 7 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method installPPatchHotFixPPatchAndThenRPatch.

/**
 * Installation of R patch <strong>may</strong> leave P patches installed when they provide <strong>only</strong>
 * bundles and the bundles are at higher version
 * @throws IOException
 * @throws GitAPIException
 */
@Test
public void installPPatchHotFixPPatchAndThenRPatch() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    preparePatchZip("src/test/resources/baselines/baseline5", "target/karaf/system/org/jboss/fuse/fuse-karaf/7.0.0/fuse-karaf-7.0.0-baseline.zip", true);
    validateInitialGitRepository();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch2", "target/karaf/patches/source/patch-2.zip", false);
    preparePatchZip("src/test/resources/content/patch9", "target/karaf/patches/source/patch-9.zip", false);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData2 = service.fetchPatches(new File("target/karaf/patches/source/patch-2.zip").toURI().toURL()).get(0);
    Patch patch2 = service.trackPatch(patchData2);
    PatchData patchData9 = service.fetchPatches(new File("target/karaf/patches/source/patch-9.zip").toURI().toURL()).get(0);
    Patch patch9 = service.trackPatch(patchData9);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch1, null);
    service.commitInstallation(tx);
    tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    service.install(tx, patch2, null);
    service.commitInstallation(tx);
    assertFalse("There should be no etc/overrides.properties after installing non-rollup patches", new File(karafHome, "etc/overrides.properties").exists());
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertThat(bundles.get(0).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-observations/3.2"));
    assertThat(bundles.get(1).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-temporary-workaround/2.2.1"));
    assertThat(bundles.get(2).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.5"));
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
    assertTrue(repository.containsTag(fork, "patch-my-patch-2"));
    assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    repository.closeRepository(fork, true);
    tx = service.beginInstallation(PatchKind.ROLLUP);
    service.install(tx, patch9, null);
    service.commitInstallation(tx);
    fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
    assertFalse(repository.containsTag(fork, "patch-my-patch-2"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
    assertFalse("There still should be no etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
    // features processing should be conflict-resolved (R-patch version and P-patch version).
    // newer version of fuse-tranquility (from P-Patch) should win
    fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(2));
    assertThat(bundles.get(1).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.5"));
    repository.closeRepository(fork, true);
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) Test(org.junit.Test)

Example 8 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method installRollupPatch.

@Test
public void installRollupPatch() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement();
    PatchManagement management = (PatchManagement) pm;
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
    repository.prepareCommit(fork, "artificial change, not treated as user change").call();
    // no changes, but commit
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    FileUtils.write(new File(karafHome, "bin/start"), "echo \"another user change\"\n", "UTF-8", true);
    // conflicting change, but commit
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    FileUtils.write(new File(karafHome, "bin/test"), "echo \"another user change\"\n", "UTF-8");
    // non-conflicting
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.closeRepository(fork, true);
    preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL());
    Patch patch = management.trackPatch(patches.get(0));
    String tx = management.beginInstallation(PatchKind.ROLLUP);
    management.install(tx, patch, null);
    @SuppressWarnings("unchecked") Map<String, Git> transactions = (Map<String, Git>) getField(management, "pendingTransactions");
    assertThat(transactions.size(), equalTo(1));
    fork = transactions.values().iterator().next();
    ObjectId since = fork.getRepository().resolve("baseline-7.0.0^{commit}");
    ObjectId to = fork.getRepository().resolve(tx);
    Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
    // only one "user change", because we had two conflicts with new baseline - they were resolved
    // by picking what already comes from rollup patch ("ours"):
    /*
         * Problem with applying the change 657f11c4b65bb7893a2b82f888bb9731a6d5f7d0:
         *  - bin/start: BOTH_MODIFIED
         * Choosing "ours" change
         * Problem with applying the change d9272b97582582f4b056f7170130ec91fc21aeac:
         *  - bin/start: BOTH_MODIFIED
         * Choosing "ours" change
         */
    List<String> commitList = Arrays.asList("[PATCH] Apply user changes", "[PATCH] Apply user changes", "[PATCH] Apply user changes", "[PATCH] Rollup patch patch-4 - resetting overrides", "[PATCH] Installing rollup patch patch-4");
    int n = 0;
    for (RevCommit c : commits) {
        String msg = c.getShortMessage();
        assertThat(msg, equalTo(commitList.get(n++)));
    }
    assertThat(n, equalTo(commitList.size()));
    assertThat(fork.tagList().call().size(), equalTo(3));
    assertTrue(repository.containsTag(fork, "patch-management"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) Git(org.eclipse.jgit.api.Git) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) File(java.io.File) Map(java.util.Map) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 9 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method installThreeNonRollupPatches.

@Test
public void installThreeNonRollupPatches() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    preparePatchZip("src/test/resources/content/patch5", "target/karaf/patches/source/patch-5.zip", false);
    preparePatchZip("src/test/resources/content/patch6", "target/karaf/patches/source/patch-6.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    Patch patch1 = service.trackPatch(patchData1);
    PatchData patchData5 = service.fetchPatches(new File("target/karaf/patches/source/patch-5.zip").toURI().toURL()).get(0);
    Patch patch5 = service.trackPatch(patchData5);
    PatchData patchData6 = service.fetchPatches(new File("target/karaf/patches/source/patch-6.zip").toURI().toURL()).get(0);
    Patch patch6 = service.trackPatch(patchData6);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
    List<BundleUpdate> patch1Updates = new LinkedList<>();
    patch1Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-tranquility/1.2.0").to("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
    service.install(tx, patch1, patch1Updates);
    List<BundleUpdate> patch5Updates = new LinkedList<>();
    patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.1.44/war").to("mvn:org.jboss.fuse/fuse-zen/1.2.0/war"));
    service.install(tx, patch5, patch5Updates);
    List<BundleUpdate> patch6Updates = new LinkedList<>();
    patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.2.4/war").to("mvn:org.jboss.fuse/fuse-zen/1.3.0/war"));
    service.install(tx, patch6, patch6Updates);
    service.commitInstallation(tx);
    String binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    String etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    // version from patch-5 should be chosen, because there's 1.1.44->1.2.0
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    assertFalse(new File(karafHome, "etc/overrides.properties").exists());
    FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(karafHome);
    List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.2.0/war".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    /* rollback time! */
    Patch p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
    service.rollback(p5.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    // rollback wasn't successful
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertFalse(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.1.44/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    fp = InternalUtils.loadFeatureProcessing(karafHome);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(3));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.2.0/war".equals(b.getReplacement())));
    assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    Patch p6 = service.loadPatch(new PatchDetailsRequest("my-patch-6"));
    service.rollback(p6.getPatchData());
    binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
    assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
    etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
    assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
    fp = InternalUtils.loadFeatureProcessing(karafHome);
    bundles = fp.getBundleReplacements().getOverrideBundles();
    assertThat(bundles.size(), equalTo(2));
    assertTrue(bundles.stream().noneMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
    repository.closeRepository(fork, true);
}
Also used : Arrays(java.util.Arrays) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) BundleReplacements(org.apache.karaf.features.internal.model.processing.BundleReplacements) RevWalk(org.eclipse.jgit.revwalk.RevWalk) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Map(java.util.Map) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) InternalUtils(org.jboss.fuse.patch.management.impl.InternalUtils) LinkedList(java.util.LinkedList) Before(org.junit.Before) Properties(java.util.Properties) Iterator(java.util.Iterator) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) SystemUtils(org.apache.commons.lang3.SystemUtils) FeatureReplacements(org.apache.karaf.features.internal.model.processing.FeatureReplacements) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) File(java.io.File) ObjectId(org.eclipse.jgit.lib.ObjectId) BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) Mockito(org.mockito.Mockito) List(java.util.List) Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementService(org.jboss.fuse.patch.management.impl.GitPatchManagementService) FileReader(java.io.FileReader) Git(org.eclipse.jgit.api.Git) ListBranchCommand(org.eclipse.jgit.api.ListBranchCommand) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Assert(org.junit.Assert) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) LinkedList(java.util.LinkedList) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) File(java.io.File) Test(org.junit.Test)

Example 10 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method addPatch1.

/**
 * Patch 1 is non-rollup patch
 * @throws IOException
 * @throws GitAPIException
 */
@Test
public void addPatch1() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
    assertThat(patchData.getId(), equalTo("my-patch-1"));
    Patch patch = service.trackPatch(patchData);
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    // we should see remote branch for the patch, but without checking it out, it won't be available in the clone's local branches
    List<Ref> branches = fork.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
    Ref patchBranch = null;
    for (Ref remoteBranch : branches) {
        if (String.format("refs/remotes/origin/patch-%s", patchData.getId()).equals(remoteBranch.getName())) {
            patchBranch = remoteBranch;
            break;
        }
    }
    assertNotNull("Should find remote branch for the added patch", patchBranch);
    assertThat(patch.getManagedPatch().getCommitId(), equalTo(patchBranch.getObjectId().getName()));
    RevCommit patchCommit = new RevWalk(fork.getRepository()).parseCommit(patchBranch.getObjectId());
    // patch commit should be child of baseline commit
    RevCommit baselineCommit = new RevWalk(fork.getRepository()).parseCommit(patchCommit.getParent(0));
    // this baseline commit should be tagged "baseline-VERSION"
    Ref tag = fork.tagList().call().get(0);
    assertThat(tag.getName(), equalTo("refs/tags/baseline-7.0.0"));
    RevCommit baselineCommitFromTag = new RevWalk(fork.getRepository()).parseCommit(tag.getTarget().getObjectId());
    assertThat(baselineCommit.getId(), equalTo(baselineCommitFromTag.getId()));
    // let's see the patch applied to baseline-7.0.0
    fork.checkout().setName("my-patch-1").setStartPoint("origin/patch-my-patch-1").setCreateBranch(true).call();
    String myProperties = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/my.properties"), "UTF-8");
    assertTrue(myProperties.contains("p1 = v1"));
    repository.closeRepository(fork, true);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

GitPatchManagementServiceImpl (org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)31 Test (org.junit.Test)25 GitPatchRepository (org.jboss.fuse.patch.management.impl.GitPatchRepository)22 File (java.io.File)18 Git (org.eclipse.jgit.api.Git)18 ObjectId (org.eclipse.jgit.lib.ObjectId)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 Map (java.util.Map)8 Ref (org.eclipse.jgit.lib.Ref)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 IOException (java.io.IOException)5 Patch (org.jboss.fuse.patch.management.Patch)5 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)5 FileReader (java.io.FileReader)4 LinkedList (java.util.LinkedList)4 Properties (java.util.Properties)4 FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 PatchData (org.jboss.fuse.patch.management.PatchData)4 PatchManagement (org.jboss.fuse.patch.management.PatchManagement)4