Search in sources :

Example 21 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method enabledPatchManagement.

@Test
public void enabledPatchManagement() throws IOException, GitAPIException {
    pm = new GitPatchManagementServiceImpl(bundleContext);
    pm.start();
    assertTrue(pm.isEnabled());
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Test(org.junit.Test)

Example 22 with GitPatchManagementServiceImpl

use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl in project fuse-karaf 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/fuse-karaf/7.0.0/fuse-karaf-7.0.0-baseline.zip", true);
    pm = new GitPatchManagementServiceImpl(bundleContext);
    pm.start();
    pm.ensurePatchManagementInitialized();
    return ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl)

Example 23 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method addPatch4.

/**
 * Patch 4 is rollup patch (doesn't contain descriptor, contains etc/version.properties)
 * Adding it is not different that adding non-rollup patch. Installation is different
 * @throws IOException
 * @throws GitAPIException
 */
@Test
public void addPatch4() throws IOException, GitAPIException {
    initializationPerformedBaselineDistributionFoundInSystem();
    // prepare some ZIP patches
    preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
    PatchManagement service = (PatchManagement) pm;
    PatchData patchData = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
    assertThat(patchData.getId(), equalTo("patch-4"));
    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()));
    List<DiffEntry> patchDiff = repository.diff(fork, baselineCommit, patchCommit);
    int changes = SystemUtils.IS_OS_WINDOWS ? 7 : 8;
    assertThat("patch-4 should lead to " + changes + " changes", patchDiff.size(), equalTo(changes));
    for (Iterator<DiffEntry> iterator = patchDiff.iterator(); iterator.hasNext(); ) {
        DiffEntry de = iterator.next();
        if ("bin/start".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("bin/stop".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if (!SystemUtils.IS_OS_WINDOWS && "bin/setenv".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("etc/startup.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("etc/my.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.ADD) {
            iterator.remove();
        }
        if ("etc/system.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("etc/version.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
            iterator.remove();
        }
        if ("patch-info.txt".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.ADD) {
            iterator.remove();
        }
    }
    assertThat("Unknown changes in patch-4", patchDiff.size(), equalTo(0));
    // let's see the patch applied to baseline-7.0.0
    fork.checkout().setName("patch-4").setStartPoint("origin/patch-patch-4").setCreateBranch(true).call();
    String startupProperties = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/startup.properties"), "UTF-8");
    assertTrue(startupProperties.contains("mvn\\:org.ops4j.pax.url/pax-url-gopher/2.4.0=5"));
    repository.closeRepository(fork, true);
}
Also used : GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Ref(org.eclipse.jgit.lib.Ref) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Git(org.eclipse.jgit.api.Git) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Test(org.junit.Test)

Example 24 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceIT method installNonRollupPatchWithUberJars.

@Test
public void installNonRollupPatchWithUberJars() throws IOException, GitAPIException {
    freshKarafStandaloneDistro();
    GitPatchRepository repository = patchManagement("baseline4");
    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);
    repository.closeRepository(fork, true);
    preparePatchZip("src/test/resources/content/patch8", "target/karaf/patches/source/patch-8.zip", false);
    List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-8.zip").toURI().toURL());
    Patch patch = management.trackPatch(patches.get(0));
    String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
    /*
         * bundle.0 = mvn:org.jboss.fuse/pax-romana/1.0.1
         * bundle.1 = mvn:org.jboss.fuse/pax-hellenica/1.0.1/jar
         * # for these two, bundle.getLocation() will return non-matching location
         * bundle.2 = mvn:org.jboss.fuse/pax-bohemia/1.0.1
         * bundle.3 = mvn:org.jboss.fuse/pax-pomerania/1.0.1/jar
         * # for these two, bundle.getLocation() will return matching location
         * bundle.4 = mvn:org.jboss.fuse/pax-avaria/1.0.1/jar/uber
         * bundle.5 = mvn:org.jboss.fuse/pax-mazovia/1.0.1//uber
         * # for these two, bundle.getLocation() will return non-matching location
         * bundle.6 = mvn:org.jboss.fuse/pax-novgorod/1.0.1/jar/uber
         * bundle.7 = mvn:org.jboss.fuse/pax-castile/1.0.1//uber
         */
    LinkedList<BundleUpdate> bundleUpdatesInThisPatch = new LinkedList<>();
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-romana", "1.0.1", "mvn:org.jboss.fuse/pax-romana/1.0.1", "1.0.0", "mvn:org.jboss.fuse/pax-romana/1.0.0"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-hellenica", "1.0.1", "mvn:org.jboss.fuse/pax-hellenica/1.0.1/jar", "1.0.0", "mvn:org.jboss.fuse/pax-hellenica/1.0.0/jar"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-bohemia", "1.0.1", "mvn:org.jboss.fuse/pax-bohemia/1.0.1", "1.0.0", "mvn:org.jboss.fuse/pax-bohemia/1.0.0/jar"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-pomerania", "1.0.1", "mvn:org.jboss.fuse/pax-pomerania/1.0.1/jar", "1.0.0", "mvn:org.jboss.fuse/pax-pomerania/1.0.0"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-avaria", "1.0.1", "mvn:org.jboss.fuse/pax-avaria/1.0.1/jar/uber", "1.0.0", "mvn:org.jboss.fuse/pax-avaria/1.0.0/jar/uber"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-mazovia", "1.0.1", "mvn:org.jboss.fuse/pax-mazovia/1.0.1//uber", "1.0.0", "mvn:org.jboss.fuse/pax-mazovia/1.0.0//uber"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-novgorod", "1.0.1", "mvn:org.jboss.fuse/pax-novgorod/1.0.1/jar/uber", "1.0.0", "mvn:org.jboss.fuse/pax-novgorod/1.0.0//uber"));
    bundleUpdatesInThisPatch.add(new BundleUpdate("pax-castile", "1.0.1", "mvn:org.jboss.fuse/pax-castile/1.0.1//uber", "1.0.0", "mvn:org.jboss.fuse/pax-castile/1.0.0/jar/uber"));
    management.install(tx, patch, bundleUpdatesInThisPatch);
    @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-8", "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-8"));
    Properties startup = new Properties();
    try (FileReader reader = new FileReader(new File(fork.getRepository().getWorkTree(), "etc/startup.properties"))) {
        startup.load(reader);
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-romana/1.0.1"));
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-hellenica/1.0.1"));
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-bohemia/1.0.1"));
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-pomerania/1.0.1"));
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-avaria/1.0.1/jar/uber"));
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-mazovia/1.0.1/jar/uber"));
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-novgorod/1.0.1/jar/uber"));
        assertTrue(startup.containsKey("mvn:org.jboss.fuse/pax-castile/1.0.1/jar/uber"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-romana/1.0.0"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-hellenica/1.0.0"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-bohemia/1.0.0"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-pomerania/1.0.0"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-avaria/1.0.0/jar/uber"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-mazovia/1.0.0/jar/uber"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-novgorod/1.0.0/jar/uber"));
        assertFalse(startup.containsKey("mvn:org.jboss.fuse/pax-castile/1.0.0/jar/uber"));
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) Properties(java.util.Properties) LinkedList(java.util.LinkedList) Git(org.eclipse.jgit.api.Git) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) FileReader(java.io.FileReader) File(java.io.File) Map(java.util.Map) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 25 with GitPatchManagementServiceImpl

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

the class GitPatchManagementServiceForStandaloneChildContainersIT 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 found1 = false;
    boolean found2 = false;
    for (Ref tag : tags) {
        if ("refs/tags/baseline-7.0.0".equals(tag.getName())) {
            found1 = true;
        }
        if ("refs/tags/baseline-child-4.2.0.redhat-700001".equals(tag.getName())) {
            found2 = true;
        }
    }
    assertTrue("Repository should contain baseline tags for version 7.0.0 (both for root and admin:create based child containrs)", found1 && found2);
    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)

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