Search in sources :

Example 1 with ManagedPatch

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

the class GitPatchManagementServiceImpl method loadPatch.

/**
 * Retrieves patch information from existing file
 * @param patchDescriptor existing file with patch descriptor (<code>*.patch</code> file)
 * @param details whether the returned {@link Patch} should contain {@link ManagedPatch} information
 * @return
 * @throws IOException
 */
private Patch loadPatch(File patchDescriptor, boolean details) throws IOException {
    Patch p = new Patch();
    if (!patchDescriptor.exists() || !patchDescriptor.isFile()) {
        return null;
    }
    PatchData data = PatchData.load(new FileInputStream(patchDescriptor));
    p.setPatchData(data);
    File patchDirectory = new File(patchesDir, FilenameUtils.getBaseName(patchDescriptor.getName()));
    if (patchDirectory.exists() && patchDirectory.isDirectory()) {
        // not every descriptor downloaded may be a ZIP file, not every patch has content
        data.setPatchDirectory(patchDirectory);
    }
    data.setPatchLocation(patchesDir);
    File resultFile = new File(patchesDir, FilenameUtils.getBaseName(patchDescriptor.getName()) + ".patch.result");
    if (resultFile.exists() && resultFile.isFile()) {
        PatchResult result = PatchResult.load(data, new FileInputStream(resultFile));
        p.setResult(result);
    }
    if (details) {
        ManagedPatch mp = gitPatchRepository.getManagedPatch(data.getId());
        p.setManagedPatch(mp);
    }
    return p;
}
Also used : ManagedPatch(io.fabric8.patch.management.ManagedPatch) PatchData(io.fabric8.patch.management.PatchData) PatchResult(io.fabric8.patch.management.PatchResult) ManagedPatch(io.fabric8.patch.management.ManagedPatch) Patch(io.fabric8.patch.management.Patch) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with ManagedPatch

use of io.fabric8.patch.management.ManagedPatch 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 3 with ManagedPatch

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

the class ShowAction method doExecute.

@Override
protected void doExecute(Service service) throws Exception {
    Patch patch = patchManagement.loadPatch(new PatchDetailsRequest(patchId, bundles, files, diff));
    if (patch == null) {
        throw new PatchException("Patch '" + patchId + "' not found");
    }
    System.out.println(String.format("Patch ID: %s", patch.getPatchData().getId()));
    if (patch.getManagedPatch() != null) {
        System.out.println(String.format("Patch Commit ID: %s", patch.getManagedPatch().getCommitId()));
    }
    if (bundles) {
        System.out.println(String.format("#### %d Bundles%s", patch.getPatchData().getBundles().size(), patch.getPatchData().getBundles().size() == 0 ? "" : ":"));
        iterate(patch.getPatchData().getBundles());
    }
    if (files) {
        ManagedPatch details = patch.getManagedPatch();
        System.out.println(String.format("#### %d Files added%s", details.getFilesAdded().size(), details.getFilesAdded().size() == 0 ? "" : ":"));
        iterate(details.getFilesAdded());
        System.out.println(String.format("#### %d Files modified%s", details.getFilesModified().size(), details.getFilesModified().size() == 0 ? "" : ":"));
        iterate(details.getFilesModified());
        System.out.println(String.format("#### %d Files removed%s", details.getFilesRemoved().size(), details.getFilesRemoved().size() == 0 ? "" : ":"));
        iterate(details.getFilesRemoved());
    }
    if (diff) {
        System.out.println("#### Patch changes:\n" + patch.getManagedPatch().getUnifiedDiff());
    }
}
Also used : ManagedPatch(io.fabric8.patch.management.ManagedPatch) PatchException(io.fabric8.patch.management.PatchException) ManagedPatch(io.fabric8.patch.management.ManagedPatch) Patch(io.fabric8.patch.management.Patch) PatchDetailsRequest(io.fabric8.patch.management.PatchDetailsRequest)

Example 4 with ManagedPatch

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

the class GitPatchRepositoryImpl method getManagedPatch.

@Override
public ManagedPatch getManagedPatch(String id) throws IOException {
    // basic ManagedPatch information is only commit id of the relevant branch name
    ObjectId commitId = mainRepository.getRepository().resolve("refs/heads/patch-" + id);
    if (commitId == null) {
        // this patch is not tracked (yet?)
        return null;
    }
    ManagedPatch mp = new ManagedPatch();
    mp.setPatchId(id);
    mp.setCommitId(commitId.getName());
    return mp;
}
Also used : ManagedPatch(io.fabric8.patch.management.ManagedPatch) ObjectId(org.eclipse.jgit.lib.ObjectId)

Aggregations

ManagedPatch (io.fabric8.patch.management.ManagedPatch)3 Patch (io.fabric8.patch.management.Patch)2 File (java.io.File)2 PatchData (io.fabric8.patch.management.PatchData)1 PatchDetailsRequest (io.fabric8.patch.management.PatchDetailsRequest)1 PatchException (io.fabric8.patch.management.PatchException)1 PatchResult (io.fabric8.patch.management.PatchResult)1 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)1 FileInputStream (java.io.FileInputStream)1 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)1 Git (org.eclipse.jgit.api.Git)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 Ref (org.eclipse.jgit.lib.Ref)1 Test (org.junit.Test)1