Search in sources :

Example 11 with GitPatchManagementServiceImpl

use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl 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 12 with GitPatchManagementServiceImpl

use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl 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 13 with GitPatchManagementServiceImpl

use of org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl 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)

Example 14 with GitPatchManagementServiceImpl

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

the class PatchServiceImplTest method testLoadWithoutRanges.

@Test
public void testLoadWithoutRanges() throws IOException, GitAPIException {
    BundleContext bundleContext = mock(BundleContext.class);
    ComponentContext componentContext = mock(ComponentContext.class);
    Bundle sysBundle = mock(Bundle.class);
    BundleContext sysBundleContext = mock(BundleContext.class);
    Bundle bundle = mock(Bundle.class);
    Bundle bundle2 = mock(Bundle.class);
    FrameworkWiring wiring = mock(FrameworkWiring.class);
    GitPatchRepository repository = mock(GitPatchRepository.class);
    // 
    // Create a new service, download a patch
    // 
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    when(bundleContext.getBundle(0)).thenReturn(sysBundle);
    when(sysBundle.getBundleContext()).thenReturn(sysBundleContext);
    when(sysBundleContext.getProperty(PatchService.PATCH_LOCATION)).thenReturn(storage.toString());
    when(repository.getManagedPatch(anyString())).thenReturn(null);
    when(repository.findOrCreateMainGitRepository()).thenReturn(null);
    when(sysBundleContext.getProperty("karaf.default.repository")).thenReturn("system");
    when(sysBundleContext.getProperty("karaf.home")).thenReturn(karaf.getCanonicalPath());
    when(sysBundleContext.getProperty("karaf.base")).thenReturn(karaf.getCanonicalPath());
    when(sysBundleContext.getProperty("karaf.name")).thenReturn("root");
    when(sysBundleContext.getProperty("karaf.instances")).thenReturn(karaf.getCanonicalPath() + "/instances");
    when(sysBundleContext.getProperty("karaf.data")).thenReturn(karaf.getCanonicalPath() + "/data");
    when(sysBundleContext.getProperty("karaf.etc")).thenReturn(karaf.getCanonicalPath() + "/etc");
    PatchManagement pm = new GitPatchManagementServiceImpl(bundleContext);
    ((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
    PatchServiceImpl service = new PatchServiceImpl();
    setField(service, "patchManagement", pm);
    service.activate(componentContext);
    PatchData pd = PatchData.load(getClass().getClassLoader().getResourceAsStream("test1.patch"));
    assertEquals(2, pd.getBundles().size());
    assertTrue(pd.getRequirements().isEmpty());
}
Also used : GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) PatchData(org.jboss.fuse.patch.management.PatchData) ComponentContext(org.osgi.service.component.ComponentContext) Bundle(org.osgi.framework.Bundle) PatchManagement(org.jboss.fuse.patch.management.PatchManagement) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 15 with GitPatchManagementServiceImpl

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

the class PatchServiceImplTest method testPatchWithVersionRanges.

@Test
public void testPatchWithVersionRanges() throws Exception {
    ComponentContext componentContext = mock(ComponentContext.class);
    BundleContext bundleContext = mock(BundleContext.class);
    Bundle sysBundle = mock(Bundle.class);
    BundleContext sysBundleContext = mock(BundleContext.class);
    Bundle bundle = mock(Bundle.class);
    Bundle bundle2 = mock(Bundle.class);
    FrameworkWiring wiring = mock(FrameworkWiring.class);
    GitPatchRepository repository = mock(GitPatchRepository.class);
    // 
    // Create a new service, download a patch
    // 
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    when(bundleContext.getBundle(0)).thenReturn(sysBundle);
    when(sysBundle.getBundleContext()).thenReturn(sysBundleContext);
    when(sysBundleContext.getProperty(PatchService.PATCH_LOCATION)).thenReturn(storage.toString());
    when(repository.getManagedPatch(anyString())).thenReturn(null);
    when(repository.findOrCreateMainGitRepository()).thenReturn(null);
    when(sysBundleContext.getProperty("karaf.default.repository")).thenReturn("system");
    when(sysBundleContext.getProperty("karaf.home")).thenReturn(karaf.getCanonicalPath());
    when(sysBundleContext.getProperty("karaf.base")).thenReturn(karaf.getCanonicalPath());
    when(sysBundleContext.getProperty("karaf.name")).thenReturn("root");
    when(sysBundleContext.getProperty("karaf.instances")).thenReturn(karaf.getCanonicalPath() + "/instances");
    when(sysBundleContext.getProperty("karaf.data")).thenReturn(karaf.getCanonicalPath() + "/data");
    when(sysBundleContext.getProperty("karaf.etc")).thenReturn(karaf.getCanonicalPath() + "/etc");
    PatchManagement pm = mockManagementService(bundleContext);
    ((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
    PatchServiceImpl service = new PatchServiceImpl();
    setField(service, "patchManagement", pm);
    service.activate(componentContext);
    Iterable<Patch> patches = service.download(patch140.toURI().toURL());
    assertNotNull(patches);
    Iterator<Patch> it = patches.iterator();
    assertTrue(it.hasNext());
    Patch patch = it.next();
    assertNotNull(patch);
    assertEquals("patch-1.4.0", patch.getPatchData().getId());
    assertNotNull(patch.getPatchData().getBundles());
    assertEquals(1, patch.getPatchData().getBundles().size());
    Iterator<String> itb = patch.getPatchData().getBundles().iterator();
    assertEquals("mvn:foo/my-bsn/1.4.0", itb.next());
    assertNull(patch.getResult());
    // 
    // Simulate the patch
    // 
    when(sysBundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
    when(sysBundleContext.getServiceReference("io.fabric8.api.FabricService")).thenReturn(null);
    when(bundle.getSymbolicName()).thenReturn("my-bsn");
    when(bundle.getVersion()).thenReturn(new Version("1.3.1"));
    when(bundle.getLocation()).thenReturn("location");
    when(bundle.getBundleId()).thenReturn(123L);
    BundleStartLevel bsl = mock(BundleStartLevel.class);
    when(bsl.getStartLevel()).thenReturn(30);
    when(bundle.adapt(BundleStartLevel.class)).thenReturn(bsl);
    when(bundle.getState()).thenReturn(1);
    when(sysBundleContext.getProperty("karaf.default.repository")).thenReturn("system");
    PatchResult result = service.install(patch, true);
    assertNotNull(result);
    assertEquals(1, result.getBundleUpdates().size());
    assertTrue(result.isSimulation());
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) ComponentContext(org.osgi.service.component.ComponentContext) Bundle(org.osgi.framework.Bundle) GitPatchRepository(org.jboss.fuse.patch.management.impl.GitPatchRepository) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GitPatchManagementServiceImpl(org.jboss.fuse.patch.management.impl.GitPatchManagementServiceImpl) Version(org.osgi.framework.Version) PatchManagement(org.jboss.fuse.patch.management.PatchManagement) PatchResult(org.jboss.fuse.patch.management.PatchResult) Patch(org.jboss.fuse.patch.management.Patch) BundleContext(org.osgi.framework.BundleContext) 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