Search in sources :

Example 11 with GitPatchRepository

use of io.fabric8.patch.management.impl.GitPatchRepository 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 12 with GitPatchRepository

use of io.fabric8.patch.management.impl.GitPatchRepository 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 13 with GitPatchRepository

use of io.fabric8.patch.management.impl.GitPatchRepository 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)

Example 14 with GitPatchRepository

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

the class ServiceImplTest method createMockServiceImpl.

/*
     * Create a mock patch service implementation with a provided patch storage location
     */
private ServiceImpl createMockServiceImpl(File patches) throws IOException {
    ComponentContext componentContext = createMock(ComponentContext.class);
    BundleContext bundleContext = createMock(BundleContext.class);
    Bundle sysBundle = createMock(Bundle.class);
    BundleContext sysBundleContext = createMock(BundleContext.class);
    Bundle bundle = createMock(Bundle.class);
    GitPatchRepository repository = createMock(GitPatchRepository.class);
    // 
    // Create a new service, download a patch
    // 
    expect(bundle.getVersion()).andReturn(new Version(1, 2, 0)).anyTimes();
    expect(componentContext.getBundleContext()).andReturn(bundleContext);
    expect(bundleContext.getBundle(0)).andReturn(sysBundle).anyTimes();
    expect(bundleContext.getBundle()).andReturn(bundle).anyTimes();
    expect(sysBundle.getBundleContext()).andReturn(sysBundleContext).anyTimes();
    expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(patches.toString()).anyTimes();
    expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
    expect(sysBundleContext.getProperty("karaf.data")).andReturn(patches.getParent() + "/data").anyTimes();
    try {
        expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
        expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
        expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.getCanonicalPath()).anyTimes();
        expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
        expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
        expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
    } catch (GitAPIException | IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
    PatchManagement pm = new GitPatchManagementServiceImpl(bundleContext);
    ((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
    ServiceImpl service = new ServiceImpl();
    setField(service, "patchManagement", pm);
    service.activate(componentContext);
    return service;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) ComponentContext(org.osgi.service.component.ComponentContext) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) PatchManagement(io.fabric8.patch.management.PatchManagement) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) IOException(java.io.IOException) BundleContext(org.osgi.framework.BundleContext)

Example 15 with GitPatchRepository

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

the class ServiceImplTest method testPatchWithVersionRanges.

@Test
public void testPatchWithVersionRanges() throws Exception {
    ComponentContext componentContext = createMock(ComponentContext.class);
    BundleContext bundleContext = createMock(BundleContext.class);
    Bundle sysBundle = createMock(Bundle.class);
    BundleContext sysBundleContext = createMock(BundleContext.class);
    Bundle bundle = createMock(Bundle.class);
    Bundle bundle2 = createMock(Bundle.class);
    FrameworkWiring wiring = createMock(FrameworkWiring.class);
    GitPatchRepository repository = createMock(GitPatchRepository.class);
    // 
    // Create a new service, download a patch
    // 
    expect(componentContext.getBundleContext()).andReturn(bundleContext);
    expect(bundleContext.getBundle(0)).andReturn(sysBundle).anyTimes();
    expect(sysBundle.getBundleContext()).andReturn(sysBundleContext).anyTimes();
    expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
    expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
    expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
    expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
    expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.getCanonicalPath()).anyTimes();
    expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
    expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
    expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
    expect(sysBundleContext.getProperty("karaf.data")).andReturn(karaf.getCanonicalPath() + "/data").anyTimes();
    replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
    PatchManagement pm = mockManagementService(bundleContext);
    ((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
    ServiceImpl service = new ServiceImpl();
    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());
    verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
    // 
    // Simulate the patch
    // 
    reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
    expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
    expect(sysBundleContext.getServiceReference("io.fabric8.api.FabricService")).andReturn(null);
    expect(bundle.getSymbolicName()).andReturn("my-bsn").anyTimes();
    expect(bundle.getVersion()).andReturn(new Version("1.3.1")).anyTimes();
    expect(bundle.getLocation()).andReturn("location").anyTimes();
    expect(bundle.getBundleId()).andReturn(123L);
    BundleStartLevel bsl = createMock(BundleStartLevel.class);
    expect(bsl.getStartLevel()).andReturn(30).anyTimes();
    expect(bundle.adapt(BundleStartLevel.class)).andReturn(bsl).anyTimes();
    expect(bundle.getState()).andReturn(1);
    expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
    replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
    PatchResult result = service.install(patch, true);
    assertNotNull(result);
    assertNull(patch.getResult());
    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) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) Version(org.osgi.framework.Version) PatchManagement(io.fabric8.patch.management.PatchManagement) PatchResult(io.fabric8.patch.management.PatchResult) Patch(io.fabric8.patch.management.Patch) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)26 Test (org.junit.Test)23 Git (org.eclipse.jgit.api.Git)22 File (java.io.File)21 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)20 ObjectId (org.eclipse.jgit.lib.ObjectId)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 Map (java.util.Map)5 Ref (org.eclipse.jgit.lib.Ref)5 PatchManagement (io.fabric8.patch.management.PatchManagement)4 Bundle (org.osgi.framework.Bundle)4 BundleContext (org.osgi.framework.BundleContext)4 ComponentContext (org.osgi.service.component.ComponentContext)4 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 Version (org.osgi.framework.Version)3 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)3 Patch (io.fabric8.patch.management.Patch)2 PatchResult (io.fabric8.patch.management.PatchResult)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2