Search in sources :

Example 6 with PatchException

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

the class SimulateCommand method doExecute.

@Override
protected void doExecute(PatchService service) throws Exception {
    Patch patch = service.getPatch(patchId);
    if (patch == null) {
        throw new PatchException("Patch '" + patchId + "' not found");
    }
    if (patch.isInstalled()) {
        throw new PatchException("Patch '" + patchId + "' is already installed");
    }
    PatchResult result = service.install(patch, true);
// display(result);
}
Also used : PatchResult(org.jboss.fuse.patch.management.PatchResult) PatchException(org.jboss.fuse.patch.management.PatchException) Patch(org.jboss.fuse.patch.management.Patch)

Example 7 with PatchException

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

the class GitPatchManagementServiceImpl method beginInstallation.

@Override
public String beginInstallation(PatchKind kind) {
    try {
        Git fork = gitPatchRepository.cloneRepository(gitPatchRepository.findOrCreateMainGitRepository(), true);
        Ref installationBranch = null;
        // let's pick up latest user changes
        applyUserChanges(fork);
        switch(kind) {
            case ROLLUP:
                // create temporary branch from the current baseline - rollup patch installation is a rebase
                // of existing user changes on top of new baseline (more precisely - cherry pick)
                RevTag currentBaseline = gitPatchRepository.findCurrentBaseline(fork);
                installationBranch = gitPatchRepository.checkout(fork).setName(String.format("patch-install-%s", GitPatchRepository.TS.format(new Date()))).setCreateBranch(true).setStartPoint(currentBaseline.getTagName() + "^{commit}").call();
                break;
            case NON_ROLLUP:
                // create temporary branch from main-patch-branch/HEAD - non-rollup patch installation is cherry-pick
                // of non-rollup patch commit over existing user changes - we can fast forward when finished
                installationBranch = gitPatchRepository.checkout(fork).setName(String.format("patch-install-%s", GitPatchRepository.TS.format(new Date()))).setCreateBranch(true).setStartPoint(gitPatchRepository.getMainBranchName()).call();
                break;
        }
        pendingTransactionsTypes.put(installationBranch.getName(), kind);
        pendingTransactions.put(installationBranch.getName(), fork);
        return installationBranch.getName();
    } catch (IOException | GitAPIException e) {
        throw new PatchException(e.getMessage(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) RevTag(org.eclipse.jgit.revwalk.RevTag) IOException(java.io.IOException) PatchException(org.jboss.fuse.patch.management.PatchException) Date(java.util.Date)

Example 8 with PatchException

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

the class GitPatchManagementServiceImpl method listPatches.

@Override
public List<Patch> listPatches(boolean details) throws PatchException {
    List<Patch> patches = new LinkedList<>();
    File[] patchDescriptors = patchesDir.listFiles((dir, name) -> name.endsWith(".patch") && new File(dir, name).isFile());
    try {
        if (patchDescriptors != null) {
            for (File pd : patchDescriptors) {
                Patch p = loadPatch(pd, details);
                patches.add(p);
            }
        }
    } catch (IOException e) {
        throw new PatchException(e.getMessage(), e);
    }
    return patches;
}
Also used : IOException(java.io.IOException) PatchException(org.jboss.fuse.patch.management.PatchException) 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) LinkedList(java.util.LinkedList)

Example 9 with PatchException

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

the class GitPatchManagementServiceImpl method loadPatchData.

/**
 * Reads content of patch descriptor into non-(yet)-managed patch data structure
 * @param patchDescriptor
 * @return
 */
private PatchData loadPatchData(File patchDescriptor) throws IOException {
    Properties properties = new Properties();
    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(patchDescriptor);
        properties.load(inputStream);
        boolean ok = properties.containsKey("id") && properties.containsKey("bundle.count");
        if (!ok) {
            throw new PatchException("Patch descriptor is not valid");
        }
        return PatchData.load(properties);
    } finally {
        Utils.closeQuietly(inputStream);
    }
}
Also used : PatchException(org.jboss.fuse.patch.management.PatchException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 10 with PatchException

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

the class GitPatchManagementServiceImpl method loadPatch.

@Override
public Patch loadPatch(PatchDetailsRequest request) throws PatchException {
    File descriptor = new File(patchesDir, request.getPatchId() + ".patch");
    try {
        Patch patch = loadPatch(descriptor, true);
        if (patch == null) {
            return null;
        }
        Git repo = gitPatchRepository.findOrCreateMainGitRepository();
        List<DiffEntry> diff = null;
        if (request.isFiles() || request.isDiff()) {
            // fetch the information from git
            ObjectId commitId = repo.getRepository().resolve(patch.getManagedPatch().getCommitId());
            RevCommit commit = new RevWalk(repo.getRepository()).parseCommit(commitId);
            diff = gitPatchRepository.diff(repo, commit.getParent(0), commit);
        }
        if (request.isBundles()) {
        // it's already in PatchData
        }
        if (request.isFiles() && diff != null) {
            for (DiffEntry de : diff) {
                DiffEntry.ChangeType ct = de.getChangeType();
                String newPath = de.getNewPath();
                String oldPath = de.getOldPath();
                switch(ct) {
                    case ADD:
                        patch.getManagedPatch().getFilesAdded().add(newPath);
                        break;
                    case MODIFY:
                        patch.getManagedPatch().getFilesModified().add(newPath);
                        break;
                    case DELETE:
                        patch.getManagedPatch().getFilesRemoved().add(oldPath);
                        break;
                    default:
                        break;
                }
            }
        }
        if (request.isDiff() && diff != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DiffFormatter formatter = new DiffFormatter(baos);
            formatter.setContext(4);
            formatter.setRepository(repo.getRepository());
            for (DiffEntry de : diff) {
                formatter.format(de);
            }
            formatter.flush();
            patch.getManagedPatch().setUnifiedDiff(new String(baos.toByteArray(), "UTF-8"));
        }
        return patch;
    } catch (IOException | GitAPIException e) {
        throw new PatchException(e.getMessage(), e);
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) PatchException(org.jboss.fuse.patch.management.PatchException) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) Patch(org.jboss.fuse.patch.management.Patch) ManagedPatch(org.jboss.fuse.patch.management.ManagedPatch) DiffEntry(org.eclipse.jgit.diff.DiffEntry) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

PatchException (org.jboss.fuse.patch.management.PatchException)25 IOException (java.io.IOException)14 Patch (org.jboss.fuse.patch.management.Patch)14 File (java.io.File)12 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)8 Git (org.eclipse.jgit.api.Git)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 LinkedList (java.util.LinkedList)6 URISyntaxException (java.net.URISyntaxException)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 BundleException (org.osgi.framework.BundleException)5 Map (java.util.Map)4 RevTag (org.eclipse.jgit.revwalk.RevTag)4 ManagedPatch (org.jboss.fuse.patch.management.ManagedPatch)4 LinkedHashSet (java.util.LinkedHashSet)3 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)3