Search in sources :

Example 1 with ManagedPatch

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

the class ShowCommand method doExecute.

@Override
protected void doExecute(PatchService 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(org.jboss.fuse.patch.management.ManagedPatch) PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch) ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) PatchDetailsRequest(org.jboss.fuse.patch.management.PatchDetailsRequest)

Example 2 with ManagedPatch

use of org.jboss.fuse.patch.management.ManagedPatch in project fuse-karaf 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);
        File featureOverridesLocation = new File(patchDirectory, "org.apache.karaf.features.xml");
        if (featureOverridesLocation.isFile()) {
            // them available during all patch operations
            try {
                FeaturesProcessing featureOverrides = InternalUtils.loadFeatureProcessing(featureOverridesLocation, null);
                List<String> overrides = new LinkedList<>();
                if (featureOverrides.getFeatureReplacements().getReplacements() != null) {
                    featureOverrides.getFeatureReplacements().getReplacements().forEach(of -> overrides.add(of.getFeature().getId()));
                }
                data.setFeatureOverrides(overrides);
            } catch (Exception e) {
                Activator.log(LogService.LOG_WARNING, "Problem loading org.apache.karaf.features.xml from patch " + data.getId() + ": " + e.getMessage());
            }
        }
    }
    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(org.jboss.fuse.patch.management.ManagedPatch) PatchData(org.jboss.fuse.patch.management.PatchData) PatchResult(org.jboss.fuse.patch.management.PatchResult) Patch(org.jboss.fuse.patch.management.Patch) ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) FileInputStream(java.io.FileInputStream) FeaturesProcessing(org.apache.karaf.features.internal.model.processing.FeaturesProcessing) LinkedList(java.util.LinkedList) PatchException(org.jboss.fuse.patch.management.PatchException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException)

Example 3 with ManagedPatch

use of org.jboss.fuse.patch.management.ManagedPatch in project fuse-karaf 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(org.jboss.fuse.patch.management.ManagedPatch) ObjectId(org.eclipse.jgit.lib.ObjectId)

Aggregations

ManagedPatch (org.jboss.fuse.patch.management.ManagedPatch)3 Patch (org.jboss.fuse.patch.management.Patch)2 PatchException (org.jboss.fuse.patch.management.PatchException)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)1 FeaturesProcessing (org.apache.karaf.features.internal.model.processing.FeaturesProcessing)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 PatchData (org.jboss.fuse.patch.management.PatchData)1 PatchDetailsRequest (org.jboss.fuse.patch.management.PatchDetailsRequest)1 PatchResult (org.jboss.fuse.patch.management.PatchResult)1