Package org.machanism.machai.gw.tools
Class PatchApplier
java.lang.Object
org.machanism.machai.gw.tools.PatchApplier
Utility to apply unified diff patches to text files.
- Since:
- 1.2.0
- Author:
- Viktor Tovstyi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyPatch(File file, List<String> patchLines, Charset charset) Applies a unified or simplified diff patch to a file.private static intfindHunkStart(List<String> fileLines, List<String> hunkLines, int expectedStart) private static intindexOfLine(List<String> lines, String expectedLine, int startIndex) private static booleanmatchLines(List<String> fileLines, List<String> expectedLines, int startOffset) private static voidAsserts structural sanity on the patched code structure before writing to disk.
-
Constructor Details
-
PatchApplier
public PatchApplier()
-
-
Method Details
-
applyPatch
public static void applyPatch(File file, List<String> patchLines, Charset charset) throws IOException Applies a unified or simplified diff patch to a file. Supports both standard unified diff headers (e.g. "@@ -1,5 +1,6 @@") and simplified search-and-replace headers (e.g. "@@").- Parameters:
file- The target file to patch.patchLines- List of lines from the patch file.charset- Charset for reading/writing the file.- Throws:
IOException- if file operations fail or patch cannot be applied.
-
validatePatchResult
private static void validatePatchResult(List<String> original, List<String> modified, String fileName) throws IOException Asserts structural sanity on the patched code structure before writing to disk.- Throws:
IOException
-
findHunkStart
-
matchLines
-
indexOfLine
-