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;
}
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()));
}
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());
}
}
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;
}
Aggregations