Package com.cloudbees.diff

Examples of com.cloudbees.diff.PatchException


                break;
            }
        }
        if (idx == -1)
        {
            throw new PatchException("Cannot find hunk target");
        }
        return applyHunk(target, hunk, idx, false, fuzz, hunkID);
    }
View Full Code Here


                    {
                        return new HunkReport(PatchStatus.Failure, null, idx, fuzz, hunkID);
                    }
                    else
                    {
                        throw new PatchException("Unapplicable hunk #" + hunkID + " @@ " + startIdx);
                    }
                }
                boolean match = similar(target.get(idx), hunkLine.substring(1), hunkLine.charAt(0));
                if (!match && fuzz != 0 && !isRemovalLine(hunkLine))
                {
                    match = (hunkIdx < fuzz || hunkIdx >= hunk.lines.size() - fuzz ? true : match);
                }
                if (!match)
                {
                    if (dryRun)
                    {
                        return new HunkReport(PatchStatus.Failure, null, idx, fuzz, hunkID);
                    }
                    else
                    {
                        throw new PatchException("Unapplicable hunk #" + hunkID + " @@ " + startIdx);
                    }
                }
            }
            if (dryRun)
            {
View Full Code Here

                {
                    // ignore
                }
                else
                {
                    throw new PatchException("Invalid hunk line: " + line);
                }
            }
        }
        patch.hunks = hunks.toArray(new Hunk[hunks.size()]);
    }
View Full Code Here

    private void readContextPatchContent(SinglePatch patch) throws IOException, PatchException
    {
        String base = readPatchLine();
        if (base == null || !base.startsWith("*** "))
        {
            throw new PatchException("Invalid context diff header: " + base);
        }
        String modified = readPatchLine();
        if (modified == null || !modified.startsWith("--- "))
        {
            throw new PatchException("Invalid context diff header: " + modified);
        }
        if (patch.targetPath == null)
        {
            computeTargetPath(base, modified, patch);
        }

        List<Hunk> hunks = new ArrayList<Hunk>();
        Hunk hunk = null;

        int lineCount = -1;
        for (; ; )
        {
            String line = readPatchLine();
            if (line == null || line.length() == 0 || line.startsWith("Index:"))
            {
                unreadPatchLine();
                break;
            }
            else if (line.startsWith("***************"))
            {
                hunk = new Hunk();
                parseContextRange(hunk, readPatchLine());
                hunks.add(hunk);
            }
            else if (line.startsWith("--- "))
            {
                lineCount = 0;
                parseContextRange(hunk, line);
                hunk.lines.add(line);
            }
            else
            {
                char c = line.charAt(0);
                if (c == ' ' || c == '+' || c == '-' || c == '!')
                {
                    if (lineCount < hunk.modifiedCount)
                    {
                        hunk.lines.add(line);
                        if (lineCount != -1)
                        {
                            lineCount++;
                        }
                    }
                }
                else
                {
                    throw new PatchException("Invalid hunk line: " + line);
                }
            }
        }
        patch.hunks = hunks.toArray(new Hunk[hunks.size()]);
        convertContextToUnified(patch);
View Full Code Here

                break;
            }
        }
        if (split == -1)
        {
            throw new PatchException("Missing split divider in context patch");
        }

        int baseIdx = 0;
        int modifiedIdx = split + 1;
        List<String> unifiedLines = new ArrayList<String>(hunk.lines.size());
        for (; baseIdx < split || modifiedIdx < hunk.lines.size(); )
        {
            String baseLine = baseIdx < split ? hunk.lines.get(baseIdx) : "~";
            String modifiedLine = modifiedIdx < hunk.lines.size() ? hunk.lines.get(modifiedIdx) : "~";
            if (baseLine.startsWith("- "))
            {
                unifiedLines.add("-" + baseLine.substring(2));
                unifiedHunk.baseCount++;
                baseIdx++;
            }
            else if (modifiedLine.startsWith("+ "))
            {
                unifiedLines.add("+" + modifiedLine.substring(2));
                unifiedHunk.modifiedCount++;
                modifiedIdx++;
            }
            else if (baseLine.startsWith("! "))
            {
                unifiedLines.add("-" + baseLine.substring(2));
                unifiedHunk.baseCount++;
                baseIdx++;
            }
            else if (modifiedLine.startsWith("! "))
            {
                unifiedLines.add("+" + modifiedLine.substring(2));
                unifiedHunk.modifiedCount++;
                modifiedIdx++;
            }
            else if (baseLine.startsWith("  ") && modifiedLine.startsWith("  "))
            {
                unifiedLines.add(baseLine.substring(1));
                unifiedHunk.baseCount++;
                unifiedHunk.modifiedCount++;
                baseIdx++;
                modifiedIdx++;
            }
            else if (baseLine.startsWith("  "))
            {
                unifiedLines.add(baseLine.substring(1));
                unifiedHunk.baseCount++;
                unifiedHunk.modifiedCount++;
                baseIdx++;
            }
            else if (modifiedLine.startsWith("  "))
            {
                unifiedLines.add(modifiedLine.substring(1));
                unifiedHunk.baseCount++;
                unifiedHunk.modifiedCount++;
                modifiedIdx++;
            }
            else
            {
                throw new PatchException("Invalid context patch: " + baseLine);
            }
        }
        unifiedHunk.lines = unifiedLines;
        return unifiedHunk;
    }
View Full Code Here

    private void readPatchContent(SinglePatch patch) throws IOException, PatchException
    {
        String base = readPatchLine();
        if (base == null || !base.startsWith("--- "))
        {
            throw new PatchException("Invalid unified diff header: " + base);
        }
        String modified = readPatchLine();
        if (modified == null || !modified.startsWith("+++ "))
        {
            throw new PatchException("Invalid unified diff header: " + modified);
        }
        if (patch.targetPath == null)
        {
            computeTargetPath(base, modified, patch);
        }
View Full Code Here

    private void parseRange(Hunk hunk, String range) throws PatchException
    {
        Matcher m = unifiedRangePattern.matcher(range);
        if (!m.matches())
        {
            throw new PatchException("Invalid unified diff range: " + range);
        }
        hunk.baseStart = Integer.parseInt(m.group(1));
        hunk.baseCount = m.group(2) != null ? Integer.parseInt(m.group(2).substring(1)) : 1;
        hunk.modifiedStart = Integer.parseInt(m.group(3));
        hunk.modifiedCount = m.group(4) != null ? Integer.parseInt(m.group(4).substring(1)) : 1;
View Full Code Here

        if (range.charAt(0) == '*')
        {
            Matcher m = baseRangePattern.matcher(range);
            if (!m.matches())
            {
                throw new PatchException("Invalid context diff range: " + range);
            }
            hunk.baseStart = Integer.parseInt(m.group(1));
            hunk.baseCount = m.group(2) != null ? Integer.parseInt(m.group(2).substring(1)) : 1;
            hunk.baseCount -= hunk.baseStart - 1;
        }
        else
        {
            Matcher m = modifiedRangePattern.matcher(range);
            if (!m.matches())
            {
                throw new PatchException("Invalid context diff range: " + range);
            }
            hunk.modifiedStart = Integer.parseInt(m.group(1));
            hunk.modifiedCount = m.group(2) != null ? Integer.parseInt(m.group(2).substring(1)) : 1;
            hunk.modifiedCount -= hunk.modifiedStart - 1;
        }
View Full Code Here

TOP

Related Classes of com.cloudbees.diff.PatchException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.