Search in sources :

Example 1 with Patch

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

the class PatchApplyAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    List<Version> versions;
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    if (versionId != null && !versionId.isEmpty()) {
        Version version = profileService.getRequiredVersion(versionId);
        versions = Collections.singletonList(version);
    } else if (allVersions) {
        versions = new ArrayList<>();
        for (String versionId : profileService.getVersions()) {
            versions.add(profileService.getRequiredVersion(versionId));
        }
    } else {
        versions = Collections.singletonList(fabricService.getRequiredDefaultVersion());
    }
    username = username != null && !username.isEmpty() ? username : ShellUtils.retrieveFabricUser(session);
    password = password != null ? password : ShellUtils.retrieveFabricUserPassword(session);
    promptForJmxCredentialsIfNeeded();
    for (Version version : versions) {
        fabricService.getPatchService().applyPatch(version, patch, username, password);
    }
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) ArrayList(java.util.ArrayList)

Example 2 with Patch

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

the class DummyBatchingProgressMonitor method doPullInternal.

private PullPolicyResult doPullInternal(GitContext context, CredentialsProvider credentialsProvider, boolean allowVersionDelete, boolean allowPush, int forcedTimeoutInSeconds) {
    PullPolicyResult pullResult = pullPushPolicy.doPull(context, credentialsProvider, allowVersionDelete, allowPush, forcedTimeoutInSeconds);
    if (pullResult.getLastException() == null) {
        Map<String, PullPushPolicy.BranchChange> updatedVersions = pullResult.localUpdateVersions();
        if (!updatedVersions.isEmpty()) {
            if (updatedVersions.containsKey(GitHelpers.MASTER_BRANCH)) {
                versionCache.invalidateAll();
            } else {
                for (String version : updatedVersions.keySet()) {
                    versionCache.invalidate(version);
                }
            }
            notificationRequired = true;
        }
        Set<String> pullVersions = pullResult.getVersions();
        if (!pullVersions.isEmpty() && !pullVersions.equals(versions)) {
            versions.clear();
            for (String v : pullVersions) {
                if (!v.startsWith("patches-") && !v.startsWith("patch-") && !v.equals(HISTORY_BRANCH) && !v.equals(ADMIN_HISTORY_BRANCH)) {
                    versions.add(v);
                }
            }
        }
        if (pullResult.remoteUpdateRequired()) {
            doPushInternal(context, credentialsProvider);
        }
    }
    return pullResult;
}
Also used : PullPolicyResult(io.fabric8.git.PullPushPolicy.PullPolicyResult)

Example 3 with Patch

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

the class PatchServiceImplTest method testCheckRequirementsSatisfied.

@Test
public void testCheckRequirementsSatisfied() throws IOException {
    PatchServiceImpl.PatchDescriptor descriptor = getPatchDescriptor("test3.patch");
    Version version = buildVersion("1.1").withProfiles("karaf", "default", "patch-prereq3", "patch-somethingelse").done();
    // this should not throw a RuntimeException
    PatchServiceImpl.checkRequirements(version, descriptor);
}
Also used : Version(io.fabric8.api.Version) Test(org.junit.Test)

Example 4 with Patch

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

the class PatchServiceImplTest method testCheckRequirementsMultiplePatches.

@Test
public void testCheckRequirementsMultiplePatches() throws IOException {
    Collection<PatchServiceImpl.PatchDescriptor> patches = new LinkedList<PatchServiceImpl.PatchDescriptor>();
    patches.add(getPatchDescriptor("test3.patch"));
    patches.add(getPatchDescriptor("test4.patch"));
    Version version = buildVersion("1.1").withProfiles("karaf", "default", "patch-prereq4a", "patch-prereq3").done();
    try {
        PatchServiceImpl.checkRequirements(version, patches);
        fail("Patch should not have passed requirements check - required patch is missing");
    } catch (PatchException e) {
        assertTrue(e.getMessage().toLowerCase().contains("required patch 'prereq4b' is missing"));
    }
}
Also used : Version(io.fabric8.api.Version) PatchException(io.fabric8.api.PatchException) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with Patch

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

the class PatchServiceImplTest method testGetPatchProfile.

@Test
public void testGetPatchProfile() throws IOException {
    PatchServiceImpl.PatchDescriptor test1 = getPatchDescriptor("test1.patch");
    PatchServiceImpl.PatchDescriptor test3 = getPatchDescriptor("test3.patch");
    Version version = buildVersion("1.1").withProfiles("karaf", "default", "patch-test3").done();
    Profile profile = PatchServiceImpl.getPatchProfile(version, test3);
    assertNotNull("test3 patch profile should be found", profile);
    assertEquals("patch-test3", profile.getId());
    assertNull("test1 patch profile should not be found", PatchServiceImpl.getPatchProfile(version, test1));
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile) 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