Search in sources :

Example 41 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceIT method installNonRollupPatch.

@Test
public void installNonRollupPatch() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement();
    PatchManagement management = (PatchManagement) pm;
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    // no changes, but commit
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
    repository.push(fork);
    FileUtils.write(new File(karafHome, "bin/shutdown"), "#!/bin/bash\nexit 42");
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.closeRepository(fork, true);
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
    Patch patch = management.trackPatch(patches.get(0));
    String tx = management.beginInstallation(PatchKind.NON_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-6.2.0^{commit}");
    ObjectId to = fork.getRepository().resolve(tx);
    Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
    List<String> commitList = Arrays.asList("[PATCH] Installing patch my-patch-1", "[PATCH] Apply user changes", "artificial change, not treated as user change (could be a patch)", "[PATCH] Apply user changes");
    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-6.2.0"));
    assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
    assertThat("The conflict should be resolved in special way", FileUtils.readFileToString(new File(karafHome, "bin/setenv")), equalTo("JAVA_MIN_MEM=2G # Minimum memory for the JVM\n"));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) Git(org.eclipse.jgit.api.Git) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) File(java.io.File) Map(java.util.Map) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 42 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 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-6.2.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-6.2.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"));
    assertTrue(myProperties.contains("p1 = v1"));
    repository.closeRepository(fork, true);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 43 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceIT method validateInitialGitRepository.

private void validateInitialGitRepository() throws IOException, GitAPIException {
    pm = new GitPatchManagementServiceImpl(bundleContext);
    pm.start();
    pm.ensurePatchManagementInitialized();
    GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
    verify(bsl, atLeastOnce()).setStartLevel(2);
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    List<Ref> tags = fork.tagList().call();
    boolean found = false;
    for (Ref tag : tags) {
        if ("refs/tags/baseline-6.2.0".equals(tag.getName())) {
            found = true;
            break;
        }
    }
    assertTrue("Repository should contain baseline tag for version 6.2.0", found);
    // look in etc/startup.properties for installed patch-management bundle
    List<String> lines = FileUtils.readLines(new File(karafHome, "etc/startup.properties"));
    found = false;
    for (String line : lines) {
        if ("io/fabric8/patch/patch-management/1.1.9/patch-management-1.1.9.jar=2".equals(line)) {
            fail("Should not contain old patch-management bundle in etc/startup.properties");
        }
        if ("io/fabric8/patch/patch-management/1.2.0/patch-management-1.2.0.jar=2".equals(line)) {
            if (found) {
                fail("Should contain only one declaration of patch-management bundle in etc/startup.properties");
            }
            found = true;
        }
    }
    repository.closeRepository(fork, true);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) File(java.io.File)

Example 44 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceIT method patchManagement.

/**
 * Install patch management inside fresh karaf distro. No validation is performed.
 * @param baseline
 * @return
 * @throws IOException
 */
private GitPatchRepository patchManagement(String baseline) throws IOException, GitAPIException {
    preparePatchZip("src/test/resources/baselines/" + baseline, "target/karaf/system/org/jboss/fuse/jboss-fuse-karaf/6.2.0/jboss-fuse-karaf-6.2.0-baseline.zip", true);
    pm = new GitPatchManagementServiceImpl(bundleContext);
    pm.start();
    pm.ensurePatchManagementInitialized();
    return ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)

Example 45 with Patch

use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.

the class GitPatchManagementServiceIT method listSingleTrackedPatch.

@Test
public void listSingleTrackedPatch() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement();
    PatchManagement management = (PatchManagement) pm;
    preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
    management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
    List<Patch> patches = management.listPatches(true);
    assertThat(patches.size(), equalTo(1));
    Patch p = patches.get(0);
    assertNotNull(p.getPatchData());
    assertNull(p.getResult());
    assertNull(p.getManagedPatch());
    ((PatchManagement) pm).trackPatch(p.getPatchData());
    p = management.listPatches(true).get(0);
    assertNotNull(p.getPatchData());
    assertNull(p.getResult());
    assertNotNull(p.getManagedPatch());
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    Ref ref = fork.checkout().setCreateBranch(true).setName("patch-my-patch-1").setStartPoint("refs/remotes/origin/patch-my-patch-1").call();
    // commit stored in ManagedPatch vs. commit of the patch branch
    assertThat(ref.getObjectId().getName(), equalTo(p.getManagedPatch().getCommitId()));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)54 Test (org.junit.Test)43 Git (org.eclipse.jgit.api.Git)35 PatchException (io.fabric8.patch.management.PatchException)34 Patch (io.fabric8.patch.management.Patch)30 IOException (java.io.IOException)28 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)27 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)26 HashMap (java.util.HashMap)18 RevCommit (org.eclipse.jgit.revwalk.RevCommit)18 LinkedList (java.util.LinkedList)17 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)17 ObjectId (org.eclipse.jgit.lib.ObjectId)17 Bundle (org.osgi.framework.Bundle)17 Version (org.osgi.framework.Version)15 PatchResult (io.fabric8.patch.management.PatchResult)13 BundleUpdate (io.fabric8.patch.management.BundleUpdate)11 PatchData (io.fabric8.patch.management.PatchData)11 ArrayList (java.util.ArrayList)11