Search in sources :

Example 11 with GitPatchRepository

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

the class GitPatchManagementServiceIT method rollbackRollupPatchInstallation.

@Test
public void rollbackRollupPatchInstallation() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement();
    PatchManagement management = (PatchManagement) pm;
    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));
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    ObjectId master1 = fork.getRepository().resolve("master");
    String tx = management.beginInstallation(PatchKind.ROLLUP);
    management.install(tx, patch, null);
    management.rollbackInstallation(tx);
    fork.pull().call();
    ObjectId master2 = fork.getRepository().resolve("master");
    assertThat(master1, equalTo(master2));
    assertThat(fork.tagList().call().size(), equalTo(2));
    assertTrue(repository.containsTag(fork, "patch-management"));
    assertTrue(repository.containsTag(fork, "baseline-7.0.0"));
}
Also used : Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Example 12 with GitPatchRepository

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

the class GitPatchManagementServiceIT method installRollupPatchWithFeatureProcessingConflicts.

@Test
public void installRollupPatchWithFeatureProcessingConflicts() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement("baseline5");
    PatchManagement management = (PatchManagement) pm;
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    // conflicting user change to critical "etc/org.apache.karaf.features.xml" file
    FileUtils.copyFile(new File("src/test/resources/processing/oakf.3.xml"), new File(fork.getRepository().getWorkTree(), "etc/org.apache.karaf.features.xml"));
    // non-conflicting
    ((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
    repository.closeRepository(fork, true);
    preparePatchZip("src/test/resources/content/patch9", "target/karaf/patches/source/patch-9.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-9.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] Rollup patch patch-9 - resetting overrides", "[PATCH] Installing rollup patch patch-9");
    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"));
    String rPatchVersion = FileUtils.readFileToString(new File("src/test/resources/content/patch9/etc/org.apache.karaf.features.xml"), "UTF-8");
    String afterPatching = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/org.apache.karaf.features.xml"), "UTF-8");
    assertEquals(rPatchVersion, afterPatching);
}
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 13 with GitPatchRepository

use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf 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", "UTF-8");
    ((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-7.0.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-7.0.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"), "UTF-8"), equalTo("JAVA_MIN_MEM=2G # Minimum memory for the JVM\n"));
}
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 14 with GitPatchRepository

use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf 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(org.jboss.fuse.patch.management.impl.GitPatchRepository) File(java.io.File) Test(org.junit.Test)

Example 15 with GitPatchRepository

use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf 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();
    Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
    List<Ref> tags = fork.tagList().call();
    boolean found = false;
    for (Ref tag : tags) {
        if ("refs/tags/baseline-7.0.0".equals(tag.getName())) {
            found = true;
            break;
        }
    }
    assertTrue("Repository should contain baseline tag for version 7.0.0", found);
    // look in etc/startup.properties for installed patch-management bundle
    List<String> lines = FileUtils.readLines(new File(karafHome, "etc/startup.properties"), "UTF-8");
    found = false;
    for (String line : lines) {
        if ("mvn:org.jboss.fuse.modules.patch/patch-management/1.1.9=2".equals(line)) {
            fail("Should not contain old patch-management bundle in etc/startup.properties");
        }
        if ("mvn:org.jboss.fuse.modules.patch/patch-management/1.2.0=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(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)

Aggregations

GitPatchRepository (org.jboss.fuse.patch.management.impl.GitPatchRepository)28 Test (org.junit.Test)25 Git (org.eclipse.jgit.api.Git)24 File (java.io.File)23 GitPatchManagementServiceImpl (org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)21 ObjectId (org.eclipse.jgit.lib.ObjectId)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Map (java.util.Map)8 Ref (org.eclipse.jgit.lib.Ref)7 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 IOException (java.io.IOException)4 FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 PatchManagement (org.jboss.fuse.patch.management.PatchManagement)4 Bundle (org.osgi.framework.Bundle)4 BundleContext (org.osgi.framework.BundleContext)4 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)4 ComponentContext (org.osgi.service.component.ComponentContext)4 FileReader (java.io.FileReader)3 LinkedList (java.util.LinkedList)3