mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
Compare commits
56 Commits
introduce-
...
java-diff-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71981d8faa | ||
|
|
af9d84cd71 | ||
|
|
1d8148ac05 | ||
|
|
0307c80edb | ||
|
|
5245ee8b77 | ||
|
|
b7c1aaeb2e | ||
|
|
1560c22034 | ||
|
|
1fdcf13803 | ||
|
|
509d5071fd | ||
|
|
94aafa7e68 | ||
|
|
23c80bc30d | ||
|
|
52e61d653f | ||
|
|
dad43159a8 | ||
|
|
0f7c32b983 | ||
|
|
ace11bc484 | ||
|
|
74586e6763 | ||
|
|
f955268003 | ||
|
|
aff6bfed29 | ||
|
|
5cc2cf4021 | ||
|
|
903982517a | ||
|
|
ba60ae8ca4 | ||
|
|
6279142d0a | ||
|
|
50da99fed0 | ||
|
|
54324fb792 | ||
|
|
8df690fdd2 | ||
|
|
281c073c56 | ||
|
|
1664490a9f | ||
|
|
02532a9720 | ||
|
|
9f88cf91fb | ||
|
|
dc5ecb8ded | ||
|
|
4cad0ea2b9 | ||
|
|
5aed9f2d9a | ||
|
|
2224a15ecf | ||
|
|
7d0fd54f66 | ||
|
|
15934d5b75 | ||
|
|
5aac378e9f | ||
|
|
912be299da | ||
|
|
a1f170eaa0 | ||
|
|
0fd3bd8e06 | ||
|
|
eeb819cad4 | ||
|
|
e73742c4fc | ||
|
|
0545519fc3 | ||
|
|
bc65f9703c | ||
|
|
ea9942da12 | ||
|
|
8fdd239961 | ||
|
|
37f9eafaa9 | ||
|
|
0fd38db8ae | ||
|
|
3663cb5d87 | ||
|
|
8ae1f6cbbf | ||
|
|
ab1e38c57b | ||
|
|
286e807232 | ||
|
|
c85296b63d | ||
|
|
4c457b39dc | ||
|
|
7dea4e2298 | ||
|
|
2b02951e89 | ||
|
|
89ce301123 |
8
.github/release.yml
vendored
Normal file
8
.github/release.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
changelog:
|
||||
categories:
|
||||
- title: Bugs solved
|
||||
labels:
|
||||
- "bug"
|
||||
- title: Changes and new Features
|
||||
labels:
|
||||
- "*"
|
||||
11
.github/workflows/maven.yml
vendored
11
.github/workflows/maven.yml
vendored
@@ -14,13 +14,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
java: [8, 11]
|
||||
java: [8, 11, 17]
|
||||
name: Java ${{ matrix.java }} building ...
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Java ${{ matrix.java }}
|
||||
uses: actions/setup-java@v1
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'zulu'
|
||||
java-version: ${{ matrix.java }}
|
||||
cache: 'maven'
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
10
CHANGELOG.md
10
CHANGELOG.md
@@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
This project uses a custom versioning scheme (and not [Semantic Versioning](https://semver.org/spec/v2.0.0.html)).
|
||||
|
||||
## [unreleased]
|
||||
## [4.13]
|
||||
|
||||
* API change: due to Issue #159: the author of the algorithm is Eugene Myers, therefore classes and methods were renamed accordingly
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -13,6 +15,12 @@ This project uses a custom versioning scheme (and not [Semantic Versioning](http
|
||||
|
||||
### Changed
|
||||
|
||||
* bugfixing new UnifiedDiff reader
|
||||
* header for each file
|
||||
* skip empty lines
|
||||
* introduction of Meyers Diff Algorithm with Linear Space improvment (until matured this will not be the default diff algorithm)
|
||||
* introduction of DiffAlgorithmFactory to set the default diff algorithm DiffUtils use (`DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiffWithLinearSpace.factory());`)
|
||||
|
||||
## [4.10]
|
||||
|
||||
### Changed
|
||||
|
||||
45
README.md
45
README.md
@@ -20,7 +20,7 @@ Main reason to build this library was the lack of easy-to-use libraries with all
|
||||
|
||||
## API
|
||||
|
||||
Javadocs of the actual release version: [JavaDocs java-diff-utils](https://java-diff-utils.github.io/java-diff-utils/4.7/docs/api/)
|
||||
Javadocs of the actual release version: [JavaDocs java-diff-utils](https://java-diff-utils.github.io/java-diff-utils/4.10/docs/apidocs/)
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -30,10 +30,46 @@ These two outputs are generated using this java-diff-utils. The source code can
|
||||
|
||||
**Producing a one liner including all difference information.**
|
||||
|
||||
```Java
|
||||
//create a configured DiffRowGenerator
|
||||
DiffRowGenerator generator = DiffRowGenerator.create()
|
||||
.showInlineDiffs(true)
|
||||
.mergeOriginalRevised(true)
|
||||
.inlineDiffByWord(true)
|
||||
.oldTag(f -> "~") //introduce markdown style for strikethrough
|
||||
.newTag(f -> "**") //introduce markdown style for bold
|
||||
.build();
|
||||
|
||||
//compute the differences for two test texts.
|
||||
List<DiffRow> rows = generator.generateDiffRows(
|
||||
Arrays.asList("This is a test senctence."),
|
||||
Arrays.asList("This is a test for diffutils."));
|
||||
|
||||
System.out.println(rows.get(0).getOldLine());
|
||||
```
|
||||
|
||||
This is a test ~senctence~**for diffutils**.
|
||||
|
||||
**Producing a side by side view of computed differences.**
|
||||
|
||||
```Java
|
||||
DiffRowGenerator generator = DiffRowGenerator.create()
|
||||
.showInlineDiffs(true)
|
||||
.inlineDiffByWord(true)
|
||||
.oldTag(f -> "~")
|
||||
.newTag(f -> "**")
|
||||
.build();
|
||||
List<DiffRow> rows = generator.generateDiffRows(
|
||||
Arrays.asList("This is a test senctence.", "This is the second line.", "And here is the finish."),
|
||||
Arrays.asList("This is a test for diffutils.", "This is the second line."));
|
||||
|
||||
System.out.println("|original|new|");
|
||||
System.out.println("|--------|---|");
|
||||
for (DiffRow row : rows) {
|
||||
System.out.println("|" + row.getOldLine() + "|" + row.getNewLine() + "|");
|
||||
}
|
||||
```
|
||||
|
||||
|original|new|
|
||||
|--------|---|
|
||||
|This is a test ~senctence~.|This is a test **for diffutils**.|
|
||||
@@ -49,7 +85,8 @@ This is a test ~senctence~**for diffutils**.
|
||||
* producing human-readable differences
|
||||
* inline difference construction
|
||||
* Algorithms:
|
||||
* Myer
|
||||
* Myers Standard Algorithm
|
||||
* Myers with linear space improvement
|
||||
* HistogramDiff using JGit Library
|
||||
|
||||
### Algorithms
|
||||
@@ -88,7 +125,7 @@ Just add the code below to your maven dependencies:
|
||||
<dependency>
|
||||
<groupId>io.github.java-diff-utils</groupId>
|
||||
<artifactId>java-diff-utils</artifactId>
|
||||
<version>4.9</version>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -96,5 +133,5 @@ or using gradle:
|
||||
|
||||
```groovy
|
||||
// https://mvnrepository.com/artifact/io.github.java-diff-utils/java-diff-utils
|
||||
implementation "io.github.java-diff-utils:java-diff-utils:4.5"
|
||||
implementation "io.github.java-diff-utils:java-diff-utils:4.12"
|
||||
```
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>io.github.java-diff-utils</groupId>
|
||||
<artifactId>java-diff-utils-parent</artifactId>
|
||||
<version>4.11-SNAPSHOT</version>
|
||||
<version>4.15</version>
|
||||
</parent>
|
||||
<artifactId>java-diff-utils-jgit</artifactId>
|
||||
<name>java-diff-utils-jgit</name>
|
||||
@@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jgit</groupId>
|
||||
<artifactId>org.eclipse.jgit</artifactId>
|
||||
<version>5.8.1.202007141445-r</version>
|
||||
<version>5.13.3.202401111512-r</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.googlecode.javaewah</groupId>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>io.github.java-diff-utils</groupId>
|
||||
<artifactId>java-diff-utils-parent</artifactId>
|
||||
<version>4.11-SNAPSHOT</version>
|
||||
<version>4.15</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.github.difflib;
|
||||
import com.github.difflib.algorithm.DiffAlgorithmFactory;
|
||||
import com.github.difflib.algorithm.DiffAlgorithmI;
|
||||
import com.github.difflib.algorithm.DiffAlgorithmListener;
|
||||
import com.github.difflib.algorithm.myers.MeyersDiff;
|
||||
import com.github.difflib.algorithm.myers.MyersDiff;
|
||||
import com.github.difflib.patch.AbstractDelta;
|
||||
import com.github.difflib.patch.Patch;
|
||||
import com.github.difflib.patch.PatchFailedException;
|
||||
@@ -30,47 +30,72 @@ import java.util.Objects;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* Implements the difference and patching engine
|
||||
* Utility class to implement the difference and patching engine.
|
||||
*/
|
||||
public final class DiffUtils {
|
||||
|
||||
/**
|
||||
* This factory generates the DEFAULT_DIFF algorithm for all these routines.
|
||||
*/
|
||||
static DiffAlgorithmFactory DEFAULT_DIFF = MeyersDiff.factory();
|
||||
static DiffAlgorithmFactory DEFAULT_DIFF = MyersDiff.factory();
|
||||
|
||||
/**
|
||||
* Sets the default diff algorithm factory to be used by all diff routines.
|
||||
*
|
||||
* @param factory a {@link DiffAlgorithmFactory} represnting the new default diff algorithm factory.
|
||||
*/
|
||||
public static void withDefaultDiffAlgorithmFactory(DiffAlgorithmFactory factory) {
|
||||
DEFAULT_DIFF = factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the difference between the original and revised list of elements
|
||||
* with default diff algorithm
|
||||
* Computes the difference between two sequences of elements using the default diff algorithm.
|
||||
*
|
||||
* @param <T> types to be diffed
|
||||
* @param original The original text. Must not be {@code null}.
|
||||
* @param revised The revised text. Must not be {@code null}.
|
||||
* @param progress progress listener
|
||||
* @return The patch describing the difference between the original and
|
||||
* revised sequences. Never {@code null}.
|
||||
* @param <T> a generic representing the type of the elements to be compared.
|
||||
* @param original a {@link List} represnting the original sequence of elements. Must not be {@code null}.
|
||||
* @param revised a {@link List} represnting the revised sequence of elements. Must not be {@code null}.
|
||||
* @param progress a {@link DiffAlgorithmListener} represnting the progress listener. Can be {@code null}.
|
||||
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithmListener progress) {
|
||||
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), progress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the difference between two sequences of elements using the default diff algorithm.
|
||||
*
|
||||
* @param <T> a generic representing the type of the elements to be compared.
|
||||
* @param original a {@link List} represnting the original sequence of elements. Must not be {@code null}.
|
||||
* @param revised a {@link List} represnting the revised sequence of elements. Must not be {@code null}.
|
||||
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised) {
|
||||
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the difference between two sequences of elements using the default diff algorithm.
|
||||
*
|
||||
* @param <T> a generic representing the type of the elements to be compared.
|
||||
* @param original a {@link List} represnting the original sequence of elements. Must not be {@code null}.
|
||||
* @param revised a {@link List} represnting the revised sequence of elements. Must not be {@code null}.
|
||||
* @param includeEqualParts a {@link boolean} represnting whether to include equal parts in the resulting patch.
|
||||
* @return The patch describing the difference between the original and revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised, boolean includeEqualParts) {
|
||||
return DiffUtils.diff(original, revised, DEFAULT_DIFF.create(), null, includeEqualParts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the difference between the original and revised text.
|
||||
* Computes the difference between two strings using the default diff algorithm.
|
||||
*
|
||||
* @param sourceText a {@link String} represnting the original string. Must not be {@code null}.
|
||||
* @param targetText a {@link String} represnting the revised string. Must not be {@code null}.
|
||||
* @param progress a {@link DiffAlgorithmListener} represnting the progress listener. Can be {@code null}.
|
||||
* @return The patch describing the difference between the original and revised strings. Never {@code null}.
|
||||
*/
|
||||
public static Patch<String> diff(String sourceText, String targetText,
|
||||
DiffAlgorithmListener progress) {
|
||||
DiffAlgorithmListener progress) {
|
||||
return DiffUtils.diff(
|
||||
Arrays.asList(sourceText.split("\n")),
|
||||
Arrays.asList(targetText.split("\n")), progress);
|
||||
@@ -80,26 +105,25 @@ public final class DiffUtils {
|
||||
* Computes the difference between the original and revised list of elements
|
||||
* with default diff algorithm
|
||||
*
|
||||
* @param source The original text. Must not be {@code null}.
|
||||
* @param target The revised text. Must not be {@code null}.
|
||||
*
|
||||
* @param equalizer the equalizer object to replace the default compare
|
||||
* @param source a {@link List} represnting the original text. Must not be {@code null}.
|
||||
* @param target a {@link List} represnting the revised text. Must not be {@code null}.
|
||||
* @param equalizer a {@link BiPredicate} represnting the equalizer object to replace the default compare
|
||||
* algorithm (Object.equals). If {@code null} the default equalizer of the
|
||||
* default algorithm is used..
|
||||
* default algorithm is used.
|
||||
* @return The patch describing the difference between the original and
|
||||
* revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> source, List<T> target,
|
||||
BiPredicate<T, T> equalizer) {
|
||||
BiPredicate<T, T> equalizer) {
|
||||
if (equalizer != null) {
|
||||
return DiffUtils.diff(source, target,
|
||||
DEFAULT_DIFF.create(equalizer));
|
||||
}
|
||||
return DiffUtils.diff(source, target, new MeyersDiff<>());
|
||||
return DiffUtils.diff(source, target, new MyersDiff<>());
|
||||
}
|
||||
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised,
|
||||
DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) {
|
||||
DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress) {
|
||||
return diff(original, revised, algorithm, progress, false);
|
||||
}
|
||||
|
||||
@@ -107,17 +131,17 @@ public final class DiffUtils {
|
||||
* Computes the difference between the original and revised list of elements
|
||||
* with default diff algorithm
|
||||
*
|
||||
* @param original The original text. Must not be {@code null}.
|
||||
* @param revised The revised text. Must not be {@code null}.
|
||||
* @param algorithm The diff algorithm. Must not be {@code null}.
|
||||
* @param progress The diff algorithm listener.
|
||||
* @param original a {@link List} represnting the original text. Must not be {@code null}.
|
||||
* @param revised a {@link List} represnting the revised text. Must not be {@code null}.
|
||||
* @param algorithm a {@link DiffAlgorithmI} represnting the diff algorithm. Must not be {@code null}.
|
||||
* @param progress a {@link DiffAlgorithmListener} represnting the diff algorithm listener.
|
||||
* @param includeEqualParts Include equal data parts into the patch.
|
||||
* @return The patch describing the difference between the original and
|
||||
* revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static <T> Patch<T> diff(List<T> original, List<T> revised,
|
||||
DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress,
|
||||
boolean includeEqualParts) {
|
||||
DiffAlgorithmI<T> algorithm, DiffAlgorithmListener progress,
|
||||
boolean includeEqualParts) {
|
||||
Objects.requireNonNull(original, "original must not be null");
|
||||
Objects.requireNonNull(revised, "revised must not be null");
|
||||
Objects.requireNonNull(algorithm, "algorithm must not be null");
|
||||
@@ -125,13 +149,14 @@ public final class DiffUtils {
|
||||
return Patch.generate(original, revised, algorithm.computeDiff(original, revised, progress), includeEqualParts);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the difference between the original and revised list of elements
|
||||
* with default diff algorithm
|
||||
*
|
||||
* @param original The original text. Must not be {@code null}.
|
||||
* @param revised The revised text. Must not be {@code null}.
|
||||
* @param algorithm The diff algorithm. Must not be {@code null}.
|
||||
* @param original a {@link List} represnting the original text. Must not be {@code null}.
|
||||
* @param revised a {@link List} represnting the revised text. Must not be {@code null}.
|
||||
* @param algorithm a {@link DiffAlgorithmI} represnting the diff algorithm. Must not be {@code null}.
|
||||
* @return The patch describing the difference between the original and
|
||||
* revised sequences. Never {@code null}.
|
||||
*/
|
||||
@@ -144,9 +169,10 @@ public final class DiffUtils {
|
||||
* "trick" to make out of texts lists of characters, like DiffRowGenerator
|
||||
* does and merges those changes at the end together again.
|
||||
*
|
||||
* @param original
|
||||
* @param revised
|
||||
* @return
|
||||
* @param original a {@link String} represnting the original text. Must not be {@code null}.
|
||||
* @param revised a {@link String} represnting the revised text. Must not be {@code null}.
|
||||
* @return The patch describing the difference between the original and
|
||||
* revised sequences. Never {@code null}.
|
||||
*/
|
||||
public static Patch<String> diffInline(String original, String revised) {
|
||||
List<String> origList = new ArrayList<>();
|
||||
@@ -165,20 +191,13 @@ public final class DiffUtils {
|
||||
return patch;
|
||||
}
|
||||
|
||||
private static List<String> compressLines(List<String> lines, String delimiter) {
|
||||
if (lines.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(String.join(delimiter, lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch the original text with given patch
|
||||
* Applies the given patch to the original list and returns the revised list.
|
||||
*
|
||||
* @param original the original text
|
||||
* @param patch the given patch
|
||||
* @return the revised text
|
||||
* @throws PatchFailedException if can't apply patch
|
||||
* @param original a {@link List} represnting the original list.
|
||||
* @param patch a {@link List} represnting the patch to apply.
|
||||
* @return the revised list.
|
||||
* @throws PatchFailedException if the patch cannot be applied.
|
||||
*/
|
||||
public static <T> List<T> patch(List<T> original, Patch<T> patch)
|
||||
throws PatchFailedException {
|
||||
@@ -186,16 +205,24 @@ public final class DiffUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpatch the revised text for a given patch
|
||||
* Applies the given patch to the revised list and returns the original list.
|
||||
*
|
||||
* @param revised the revised text
|
||||
* @param patch the given patch
|
||||
* @return the original text
|
||||
* @param revised a {@link List} represnting the revised list.
|
||||
* @param patch a {@link Patch} represnting the patch to apply.
|
||||
* @return the original list.
|
||||
* @throws PatchFailedException if the patch cannot be applied.
|
||||
*/
|
||||
public static <T> List<T> unpatch(List<T> revised, Patch<T> patch) {
|
||||
return patch.restore(revised);
|
||||
}
|
||||
|
||||
private static List<String> compressLines(List<String> lines, String delimiter) {
|
||||
if (lines.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.singletonList(String.join(delimiter, lines));
|
||||
}
|
||||
|
||||
private DiffUtils() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,15 @@ import com.github.difflib.patch.ChangeDelta;
|
||||
import com.github.difflib.patch.Chunk;
|
||||
import com.github.difflib.patch.AbstractDelta;
|
||||
import com.github.difflib.patch.Patch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -129,7 +133,7 @@ public final class UnifiedDiffUtils {
|
||||
|
||||
/**
|
||||
* generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format
|
||||
* text representing the Patch.
|
||||
* text representing the Patch. Author: Bill James (tankerbay@gmail.com).
|
||||
*
|
||||
* @param originalFileName - Filename of the original (unrevised file)
|
||||
* @param revisedFileName - Filename of the revised file
|
||||
@@ -137,7 +141,6 @@ public final class UnifiedDiffUtils {
|
||||
* @param patch - Patch created by the diff() function
|
||||
* @param contextSize - number of lines of context output around each difference in the file.
|
||||
* @return List of strings representing the Unified Diff representation of the Patch argument.
|
||||
* @author Bill James (tankerbay@gmail.com)
|
||||
*/
|
||||
public static List<String> generateUnifiedDiff(String originalFileName,
|
||||
String revisedFileName, List<String> originalLines, Patch<String> patch,
|
||||
@@ -200,13 +203,12 @@ public final class UnifiedDiffUtils {
|
||||
|
||||
/**
|
||||
* processDeltas takes a list of Deltas and outputs them together in a single block of
|
||||
* Unified-Diff-format text.
|
||||
* Unified-Diff-format text. Author: Bill James (tankerbay@gmail.com).
|
||||
*
|
||||
* @param origLines - the lines of the original file
|
||||
* @param deltas - the Deltas to be output as a single block
|
||||
* @param contextSize - the number of lines of context to place around block
|
||||
* @return
|
||||
* @author Bill James (tankerbay@gmail.com)
|
||||
*/
|
||||
private static List<String> processDeltas(List<String> origLines,
|
||||
List<AbstractDelta<String>> deltas, int contextSize, boolean newFile) {
|
||||
@@ -297,11 +299,10 @@ public final class UnifiedDiffUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter
|
||||
* getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter. Author: Bill James (tankerbay@gmail.com).
|
||||
*
|
||||
* @param delta - the Delta to output
|
||||
* @return list of String lines of code.
|
||||
* @author Bill James (tankerbay@gmail.com)
|
||||
*/
|
||||
private static List<String> getDeltaText(AbstractDelta<String> delta) {
|
||||
List<String> buffer = new ArrayList<>();
|
||||
@@ -316,4 +317,151 @@ public final class UnifiedDiffUtils {
|
||||
|
||||
private UnifiedDiffUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the differences between two files and return to the original file and diff format
|
||||
*
|
||||
* (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file.
|
||||
* You can see all the differences and unmodified places from the original file.
|
||||
* Also, this will be very easy and useful for making side-by-side comparison display applications,
|
||||
* for example, if you use diff2html (https://github.com/rtfpessoa/diff2html#usage)
|
||||
* Wait for tools to display your differences on html pages, you only need to insert the return value into your js code)
|
||||
*
|
||||
* @param original Original file content
|
||||
* @param revised revised file content
|
||||
*
|
||||
*/
|
||||
public static List<String> generateOriginalAndDiff(List<String> original, List<String> revised) {
|
||||
return generateOriginalAndDiff(original, revised, null, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare the differences between two files and return to the original file and diff format
|
||||
*
|
||||
* (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file.
|
||||
* You can see all the differences and unmodified places from the original file.
|
||||
* Also, this will be very easy and useful for making side-by-side comparison display applications,
|
||||
* for example, if you use diff2html (https://github.com/rtfpessoa/diff2html#usage)
|
||||
* Wait for tools to display your differences on html pages, you only need to insert the return value into your js code)
|
||||
*
|
||||
* @param original Original file content
|
||||
* @param revised revised file content
|
||||
* @param originalFileName Original file name
|
||||
* @param revisedFileName revised file name
|
||||
*/
|
||||
public static List<String> generateOriginalAndDiff(List<String> original, List<String> revised, String originalFileName, String revisedFileName) {
|
||||
String originalFileNameTemp = originalFileName;
|
||||
String revisedFileNameTemp = originalFileName;
|
||||
if (originalFileNameTemp == null) {
|
||||
originalFileNameTemp = "original";
|
||||
}
|
||||
if (revisedFileNameTemp == null) {
|
||||
revisedFileNameTemp = "revised";
|
||||
}
|
||||
Patch<String> patch = DiffUtils.diff(original, revised);
|
||||
List<String> unifiedDiff = generateUnifiedDiff(originalFileNameTemp, revisedFileNameTemp, original, patch, 0);
|
||||
if (unifiedDiff.isEmpty()) {
|
||||
unifiedDiff.add("--- " + originalFileNameTemp);
|
||||
unifiedDiff.add("+++ " + revisedFileNameTemp);
|
||||
unifiedDiff.add("@@ -0,0 +0,0 @@");
|
||||
} else if (unifiedDiff.size() >= 3 && !unifiedDiff.get(2).contains("@@ -1,")) {
|
||||
unifiedDiff.set(1, unifiedDiff.get(1));
|
||||
unifiedDiff.add(2, "@@ -0,0 +0,0 @@");
|
||||
}
|
||||
List<String> originalWithPrefix = original.stream().map(v -> " " + v).collect(Collectors.toList());
|
||||
return insertOrig(originalWithPrefix, unifiedDiff);
|
||||
}
|
||||
|
||||
//Insert the diff format to the original file
|
||||
private static List<String> insertOrig(List<String> original, List<String> unifiedDiff) {
|
||||
List<String> result = new ArrayList<>();
|
||||
List<List<String>> diffList = new ArrayList<>();
|
||||
List<String> diff = new ArrayList<>();
|
||||
for (int i = 0; i < unifiedDiff.size(); i++) {
|
||||
String u = unifiedDiff.get(i);
|
||||
if (u.startsWith("@@") && !"@@ -0,0 +0,0 @@".equals(u) && !u.contains("@@ -1,")) {
|
||||
List<String> twoList = new ArrayList<>();
|
||||
twoList.addAll(diff);
|
||||
diffList.add(twoList);
|
||||
diff.clear();
|
||||
diff.add(u);
|
||||
continue;
|
||||
}
|
||||
if (i == unifiedDiff.size() - 1) {
|
||||
diff.add(u);
|
||||
List<String> twoList = new ArrayList<>();
|
||||
twoList.addAll(diff);
|
||||
diffList.add(twoList);
|
||||
diff.clear();
|
||||
break;
|
||||
}
|
||||
diff.add(u);
|
||||
}
|
||||
insertOrig(diffList, result, original);
|
||||
return result;
|
||||
}
|
||||
|
||||
//Insert the diff format to the original file
|
||||
private static void insertOrig(List<List<String>> diffList, List<String> result, List<String> original) {
|
||||
for (int i = 0; i < diffList.size(); i++) {
|
||||
List<String> diff = diffList.get(i);
|
||||
List<String> nexDiff = i == diffList.size() - 1 ? null : diffList.get(i + 1);
|
||||
String simb = i == 0 ? diff.get(2) : diff.get(0);
|
||||
String nexSimb = nexDiff == null ? null : nexDiff.get(0);
|
||||
insert(result, diff);
|
||||
Map<String, Integer> map = getRowMap(simb);
|
||||
if (null != nexSimb) {
|
||||
Map<String, Integer> nexMap = getRowMap(nexSimb);
|
||||
int start = 0;
|
||||
if (map.get("orgRow") != 0) {
|
||||
start = map.get("orgRow") + map.get("orgDel") - 1;
|
||||
}
|
||||
int end = nexMap.get("revRow") - 2;
|
||||
insert(result, getOrigList(original, start, end));
|
||||
}
|
||||
int start = map.get("orgRow") + map.get("orgDel") - 1;
|
||||
start = start == -1 ? 0 : start;
|
||||
if (simb.contains("@@ -1,") && null == nexSimb && map.get("orgDel") != original.size()) {
|
||||
insert(result, getOrigList(original, start, original.size() - 1));
|
||||
} else if (null == nexSimb && (map.get("orgRow") + map.get("orgDel") - 1) < original.size()) {
|
||||
insert(result, getOrigList(original, start, original.size() - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Insert the unchanged content in the source file into result
|
||||
private static void insert(List<String> result, List<String> noChangeContent) {
|
||||
for (String ins : noChangeContent) {
|
||||
result.add(ins);
|
||||
}
|
||||
}
|
||||
|
||||
//Parse the line containing @@ to get the modified line number to delete or add a few lines
|
||||
private static Map<String, Integer> getRowMap(String str) {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
if (str.startsWith("@@")) {
|
||||
String[] sp = str.split(" ");
|
||||
String org = sp[1];
|
||||
String[] orgSp = org.split(",");
|
||||
map.put("orgRow", Integer.valueOf(orgSp[0].substring(1)));
|
||||
map.put("orgDel", Integer.valueOf(orgSp[1]));
|
||||
String[] revSp = org.split(",");
|
||||
map.put("revRow", Integer.valueOf(revSp[0].substring(1)));
|
||||
map.put("revAdd", Integer.valueOf(revSp[1]));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
//Get the specified part of the line from the original file
|
||||
private static List<String> getOrigList(List<String> originalWithPrefix, int start, int end) {
|
||||
List<String> list = new ArrayList<>();
|
||||
if (originalWithPrefix.size() >= 1 && start <= end && end < originalWithPrefix.size()) {
|
||||
int startTemp = start;
|
||||
for (; startTemp <= end; startTemp++) {
|
||||
list.add(originalWithPrefix.get(startTemp));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,17 +27,17 @@ import java.util.Objects;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
/**
|
||||
* A clean-room implementation of Eugene Meyers greedy differencing algorithm.
|
||||
* A clean-room implementation of Eugene Myers greedy differencing algorithm.
|
||||
*/
|
||||
public final class MeyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
public final class MyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
|
||||
private final BiPredicate<T, T> equalizer;
|
||||
|
||||
public MeyersDiff() {
|
||||
public MyersDiff() {
|
||||
equalizer = Object::equals;
|
||||
}
|
||||
|
||||
public MeyersDiff(final BiPredicate<T, T> equalizer) {
|
||||
public MyersDiff(final BiPredicate<T, T> equalizer) {
|
||||
Objects.requireNonNull(equalizer, "equalizer must not be null");
|
||||
this.equalizer = equalizer;
|
||||
}
|
||||
@@ -187,13 +187,13 @@ public final class MeyersDiff<T> implements DiffAlgorithmI<T> {
|
||||
@Override
|
||||
public <T> DiffAlgorithmI<T>
|
||||
create() {
|
||||
return new MeyersDiff<T>();
|
||||
return new MyersDiff<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DiffAlgorithmI<T>
|
||||
create(BiPredicate < T, T > equalizer) {
|
||||
return new MeyersDiff<T>(equalizer);
|
||||
return new MyersDiff<>(equalizer);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -30,15 +30,15 @@ import java.util.function.Consumer;
|
||||
*
|
||||
* @author tw
|
||||
*/
|
||||
public class MeyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> {
|
||||
public class MyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> {
|
||||
|
||||
private final BiPredicate<T, T> equalizer;
|
||||
|
||||
public MeyersDiffWithLinearSpace() {
|
||||
public MyersDiffWithLinearSpace() {
|
||||
equalizer = Object::equals;
|
||||
}
|
||||
|
||||
public MeyersDiffWithLinearSpace(final BiPredicate<T, T> equalizer) {
|
||||
public MyersDiffWithLinearSpace(final BiPredicate<T, T> equalizer) {
|
||||
Objects.requireNonNull(equalizer, "equalizer must not be null");
|
||||
this.equalizer = equalizer;
|
||||
}
|
||||
@@ -231,13 +231,13 @@ public class MeyersDiffWithLinearSpace<T> implements DiffAlgorithmI<T> {
|
||||
@Override
|
||||
public <T> DiffAlgorithmI<T>
|
||||
create() {
|
||||
return new MeyersDiffWithLinearSpace<T>();
|
||||
return new MyersDiffWithLinearSpace<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> DiffAlgorithmI<T>
|
||||
create(BiPredicate < T, T > equalizer) {
|
||||
return new MeyersDiffWithLinearSpace<T>(equalizer);
|
||||
return new MyersDiffWithLinearSpace<>(equalizer);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public abstract class AbstractDelta<T> implements Serializable {
|
||||
return getSource().verifyChunk(target);
|
||||
}
|
||||
|
||||
protected VerifyChunk verifyAntApplyTo(List<T> target) throws PatchFailedException {
|
||||
protected VerifyChunk verifyAndApplyTo(List<T> target) throws PatchFailedException {
|
||||
final VerifyChunk verify = verifyChunkToFitTarget(target);
|
||||
if (verify == VerifyChunk.OK) {
|
||||
applyTo(target);
|
||||
@@ -70,6 +70,19 @@ public abstract class AbstractDelta<T> implements Serializable {
|
||||
|
||||
protected abstract void restore(List<T> target);
|
||||
|
||||
/**
|
||||
* Apply patch fuzzy.
|
||||
*
|
||||
* @param target the list this patch will be applied to
|
||||
* @param fuzz the number of elements to ignore before/after the patched elements
|
||||
* @param position the position this patch will be applied to. ignores {@code source.getPosition()}
|
||||
* @see <a href="https://www.gnu.org/software/diffutils/manual/html_node/Inexact.html">Description of Fuzzy Patch</a> for more information.
|
||||
*/
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
protected void applyFuzzyToAt(List<T> target, int fuzz, int position) throws PatchFailedException {
|
||||
throw new UnsupportedOperationException(this.getClass().getSimpleName() + " does not supports applying patch fuzzy");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new delta of the actual instance with customized chunk data.
|
||||
*/
|
||||
|
||||
@@ -66,6 +66,19 @@ public final class ChangeDelta<T> extends AbstractDelta<T> {
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyFuzzyToAt(List<T> target, int fuzz, int position) throws PatchFailedException {
|
||||
int size = getSource().size();
|
||||
for (int i = fuzz; i < size - fuzz; i++) {
|
||||
target.remove(position + fuzz);
|
||||
}
|
||||
|
||||
int i = fuzz;
|
||||
for (T line : getTarget().getLines().subList(fuzz, getTarget().size() - fuzz)) {
|
||||
target.add(position + i, line);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ChangeDelta, position: " + getSource().getPosition() + ", lines: "
|
||||
|
||||
@@ -95,10 +95,28 @@ public final class Chunk<T> implements Serializable {
|
||||
* @throws com.github.difflib.patch.PatchFailedException
|
||||
*/
|
||||
public VerifyChunk verifyChunk(List<T> target) throws PatchFailedException {
|
||||
if (position > target.size() || last() > target.size()) {
|
||||
return verifyChunk(target, 0, getPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that this chunk's saved text matches the corresponding text in
|
||||
* the given sequence.
|
||||
*
|
||||
* @param target the sequence to verify against.
|
||||
* @param fuzz the count of ignored prefix/suffix
|
||||
* @param position the position of target
|
||||
* @throws com.github.difflib.patch.PatchFailedException
|
||||
*/
|
||||
public VerifyChunk verifyChunk(List<T> target, int fuzz, int position) throws PatchFailedException {
|
||||
//noinspection UnnecessaryLocalVariable
|
||||
int startIndex = fuzz;
|
||||
int lastIndex = size() - fuzz;
|
||||
int last = position + size() - 1;
|
||||
|
||||
if (position + fuzz > target.size() || last - fuzz > target.size()) {
|
||||
return VerifyChunk.POSITION_OUT_OF_TARGET;
|
||||
}
|
||||
for (int i = 0; i < size(); i++) {
|
||||
for (int i = startIndex; i < lastIndex; i++) {
|
||||
if (!target.get(position + i).equals(lines.get(i))) {
|
||||
return VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,14 @@ public class EqualDelta<T> extends AbstractDelta<T> {
|
||||
protected void restore(List<T> target) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void applyFuzzyToAt(List<T> target, int fuzz, int delta) {
|
||||
// equals so no operations
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[EqualDelta, position: " + getSource().getPosition() + ", lines: "
|
||||
|
||||
@@ -48,22 +48,146 @@ public final class Patch<T> implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this patch to the given target
|
||||
* Creates a new list, the patch is being applied to.
|
||||
*
|
||||
* @return the patched text
|
||||
* @throws PatchFailedException if can't apply patch
|
||||
* @param target The list to apply the changes to.
|
||||
* @return A new list containing the applied patch.
|
||||
* @throws PatchFailedException if the patch cannot be applied
|
||||
*/
|
||||
public List<T> applyTo(List<T> target) throws PatchFailedException {
|
||||
List<T> result = new ArrayList<>(target);
|
||||
applyToExisting(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the patch to the supplied list.
|
||||
*
|
||||
* @param target The list to apply the changes to. This list has to be modifiable,
|
||||
* otherwise exceptions may be thrown, depending on the used type of list.
|
||||
* @throws PatchFailedException if the patch cannot be applied
|
||||
* @throws RuntimeException (or similar) if the list is not modifiable.
|
||||
*/
|
||||
public void applyToExisting(List<T> target) throws PatchFailedException {
|
||||
ListIterator<AbstractDelta<T>> it = getDeltas().listIterator(deltas.size());
|
||||
while (it.hasPrevious()) {
|
||||
AbstractDelta<T> delta = it.previous();
|
||||
VerifyChunk valid = delta.verifyAntApplyTo(result);
|
||||
VerifyChunk valid = delta.verifyAndApplyTo(target);
|
||||
if (valid != VerifyChunk.OK) {
|
||||
conflictOutput.processConflict(valid, delta, result);
|
||||
conflictOutput.processConflict(valid, delta, target);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class PatchApplyingContext<T> {
|
||||
public final List<T> result;
|
||||
public final int maxFuzz;
|
||||
|
||||
// the position last patch applied to.
|
||||
public int lastPatchEnd = -1;
|
||||
|
||||
///// passing values from find to apply
|
||||
public int currentFuzz = 0;
|
||||
|
||||
public int defaultPosition;
|
||||
public boolean beforeOutRange = false;
|
||||
public boolean afterOutRange = false;
|
||||
|
||||
private PatchApplyingContext(List<T> result, int maxFuzz) {
|
||||
this.result = result;
|
||||
this.maxFuzz = maxFuzz;
|
||||
}
|
||||
}
|
||||
|
||||
public List<T> applyFuzzy(List<T> target, int maxFuzz) throws PatchFailedException {
|
||||
PatchApplyingContext<T> ctx = new PatchApplyingContext<>(new ArrayList<>(target), maxFuzz);
|
||||
|
||||
// the difference between patch's position and actually applied position
|
||||
int lastPatchDelta = 0;
|
||||
|
||||
for (AbstractDelta<T> delta : getDeltas()) {
|
||||
ctx.defaultPosition = delta.getSource().getPosition() + lastPatchDelta;
|
||||
int patchPosition = findPositionFuzzy(ctx, delta);
|
||||
if (0 <= patchPosition) {
|
||||
delta.applyFuzzyToAt(ctx.result, ctx.currentFuzz, patchPosition);
|
||||
lastPatchDelta = patchPosition - delta.getSource().getPosition();
|
||||
ctx.lastPatchEnd = delta.getSource().last() + lastPatchDelta;
|
||||
} else {
|
||||
conflictOutput.processConflict(VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET, delta, ctx.result);
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.result;
|
||||
}
|
||||
|
||||
// negative for not found
|
||||
private int findPositionFuzzy(PatchApplyingContext<T> ctx, AbstractDelta<T> delta) throws PatchFailedException {
|
||||
for (int fuzz = 0; fuzz <= ctx.maxFuzz; fuzz++) {
|
||||
ctx.currentFuzz = fuzz;
|
||||
int foundPosition = findPositionWithFuzz(ctx, delta, fuzz);
|
||||
if (foundPosition >= 0) {
|
||||
return foundPosition;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// negative for not found
|
||||
private int findPositionWithFuzz(PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz) throws PatchFailedException {
|
||||
if (delta.getSource().verifyChunk(ctx.result, fuzz, ctx.defaultPosition) == VerifyChunk.OK) {
|
||||
return ctx.defaultPosition;
|
||||
}
|
||||
|
||||
ctx.beforeOutRange = false;
|
||||
ctx.afterOutRange = false;
|
||||
|
||||
// moreDelta >= 0: just for overflow guard, not a normal condition
|
||||
//noinspection OverflowingLoopIndex
|
||||
for (int moreDelta = 0; moreDelta >= 0; moreDelta++) {
|
||||
int pos = findPositionWithFuzzAndMoreDelta(ctx, delta, fuzz, moreDelta);
|
||||
if (pos >= 0) {
|
||||
return pos;
|
||||
}
|
||||
if (ctx.beforeOutRange && ctx.afterOutRange) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// negative for not found
|
||||
private int findPositionWithFuzzAndMoreDelta(PatchApplyingContext<T> ctx, AbstractDelta<T> delta, int fuzz, int moreDelta) throws PatchFailedException {
|
||||
// range check: can't apply before end of last patch
|
||||
if (!ctx.beforeOutRange) {
|
||||
int beginAt = ctx.defaultPosition - moreDelta + fuzz;
|
||||
// We can't apply patch before end of last patch.
|
||||
if (beginAt <= ctx.lastPatchEnd) {
|
||||
ctx.beforeOutRange = true;
|
||||
}
|
||||
}
|
||||
// range check: can't apply after end of result
|
||||
if (!ctx.afterOutRange) {
|
||||
int beginAt = ctx.defaultPosition + moreDelta + delta.getSource().size() - fuzz;
|
||||
// We can't apply patch before end of last patch.
|
||||
if (ctx.result.size() < beginAt) {
|
||||
ctx.afterOutRange = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctx.beforeOutRange) {
|
||||
VerifyChunk before = delta.getSource().verifyChunk(ctx.result, fuzz, ctx.defaultPosition - moreDelta);
|
||||
if (before == VerifyChunk.OK) {
|
||||
return ctx.defaultPosition - moreDelta;
|
||||
}
|
||||
}
|
||||
if (!ctx.afterOutRange) {
|
||||
VerifyChunk after = delta.getSource().verifyChunk(ctx.result, fuzz, ctx.defaultPosition + moreDelta);
|
||||
if (after == VerifyChunk.OK) {
|
||||
return ctx.defaultPosition + moreDelta;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,19 +233,33 @@ public final class Patch<T> implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the text to original. Opposite to applyTo() method.
|
||||
* Creates a new list, containing the restored state of the given list.
|
||||
* Opposite to {@link #applyTo(List)} method.
|
||||
*
|
||||
* @param target the given target
|
||||
* @return the restored text
|
||||
* @param target The list to copy and apply changes to.
|
||||
* @return A new list, containing the restored state.
|
||||
*/
|
||||
public List<T> restore(List<T> target) {
|
||||
List<T> result = new ArrayList<>(target);
|
||||
restoreToExisting(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restores all changes within the given list.
|
||||
* Opposite to {@link #applyToExisting(List)} method.
|
||||
*
|
||||
* @param target The list to restore changes in. This list has to be modifiable,
|
||||
* otherwise exceptions may be thrown, depending on the used type of list.
|
||||
* @throws RuntimeException (or similar) if the list is not modifiable.
|
||||
*/
|
||||
public void restoreToExisting(List<T> target) {
|
||||
ListIterator<AbstractDelta<T>> it = getDeltas().listIterator(deltas.size());
|
||||
while (it.hasPrevious()) {
|
||||
AbstractDelta<T> delta = it.previous();
|
||||
delta.restore(result);
|
||||
delta.restore(target);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,7 @@ public final class DiffRowGenerator {
|
||||
return list;
|
||||
};
|
||||
|
||||
public static final Pattern SPLIT_BY_WORD_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#]");
|
||||
public static final Pattern SPLIT_BY_WORD_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#<>;:&\\']+");
|
||||
|
||||
/**
|
||||
* Splitting lines by word to achieve word by word diff checking.
|
||||
@@ -173,6 +173,7 @@ public final class DiffRowGenerator {
|
||||
|
||||
private final boolean showInlineDiffs;
|
||||
private final boolean replaceOriginalLinefeedInChangesWithSpaces;
|
||||
private final boolean decompressDeltas;
|
||||
|
||||
private DiffRowGenerator(Builder builder) {
|
||||
showInlineDiffs = builder.showInlineDiffs;
|
||||
@@ -182,6 +183,7 @@ public final class DiffRowGenerator {
|
||||
columnWidth = builder.columnWidth;
|
||||
mergeOriginalRevised = builder.mergeOriginalRevised;
|
||||
inlineDiffSplitter = builder.inlineDiffSplitter;
|
||||
decompressDeltas = builder.decompressDeltas;
|
||||
|
||||
if (builder.equalizer != null) {
|
||||
equalizer = builder.equalizer;
|
||||
@@ -225,8 +227,14 @@ public final class DiffRowGenerator {
|
||||
int endPos = 0;
|
||||
final List<AbstractDelta<String>> deltaList = patch.getDeltas();
|
||||
|
||||
for (AbstractDelta<String> originalDelta : deltaList) {
|
||||
for (AbstractDelta<String> delta : decompressDeltas(originalDelta)) {
|
||||
if (decompressDeltas) {
|
||||
for (AbstractDelta<String> originalDelta : deltaList) {
|
||||
for (AbstractDelta<String> delta : decompressDeltas(originalDelta)) {
|
||||
endPos = transformDeltaIntoDiffRow(original, endPos, diffRows, delta);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (AbstractDelta<String> delta : deltaList) {
|
||||
endPos = transformDeltaIntoDiffRow(original, endPos, diffRows, delta);
|
||||
}
|
||||
}
|
||||
@@ -442,6 +450,7 @@ public final class DiffRowGenerator {
|
||||
|
||||
private boolean showInlineDiffs = false;
|
||||
private boolean ignoreWhiteSpaces = false;
|
||||
private boolean decompressDeltas = true;
|
||||
|
||||
private BiFunction<Tag, Boolean, String> oldTag
|
||||
= (tag, f) -> f ? "<span class=\"editOldInline\">" : "</span>";
|
||||
@@ -483,11 +492,10 @@ public final class DiffRowGenerator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the originial old and new text lines to Diffrow without any
|
||||
* additional processing and without any tags to highlight the change.
|
||||
* Report all lines without markup on the old or new text.
|
||||
*
|
||||
* @param val the value to set. Default: false.
|
||||
* @return builder with configured reportLinesUnWrapped parameter
|
||||
* @return builder with configured reportLinesUnchanged parameter
|
||||
*/
|
||||
public Builder reportLinesUnchanged(final boolean val) {
|
||||
reportLinesUnchanged = val;
|
||||
@@ -554,8 +562,9 @@ public final class DiffRowGenerator {
|
||||
* Set the column width of generated lines of original and revised
|
||||
* texts.
|
||||
*
|
||||
* @param width the width to set. Making it < 0 doesn't make any sense.
|
||||
* Default 80. @return builder with config of column width
|
||||
* @param width the width to set. Making it < 0 doesn't make any
|
||||
* sense. Default 80.
|
||||
* @return builder with config of column width
|
||||
*/
|
||||
public Builder columnWidth(int width) {
|
||||
if (width >= 0) {
|
||||
@@ -586,6 +595,19 @@ public final class DiffRowGenerator {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deltas could be in a state, that would produce some unreasonable
|
||||
* results within an inline diff. So the deltas are decompressed into
|
||||
* smaller parts and rebuild. But this could result in more differences.
|
||||
*
|
||||
* @param decompressDeltas
|
||||
* @return
|
||||
*/
|
||||
public Builder decompressDeltas(boolean decompressDeltas) {
|
||||
this.decompressDeltas = decompressDeltas;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Per default each character is separatly processed. This variant
|
||||
* introduces processing by word, which does not deliver in word
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class UnifiedDiff {
|
||||
return tail;
|
||||
}
|
||||
|
||||
public List<String> spplyPatchTo(Predicate<String> findFile, List<String> originalLines) throws PatchFailedException {
|
||||
public List<String> applyPatchTo(Predicate<String> findFile, List<String> originalLines) throws PatchFailedException {
|
||||
UnifiedDiffFile file = files.stream()
|
||||
.filter(diff -> findFile.test(diff.getFromFile()))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
@@ -30,10 +30,17 @@ public final class UnifiedDiffFile {
|
||||
private String toFile;
|
||||
private String renameFrom;
|
||||
private String renameTo;
|
||||
private String copyFrom;
|
||||
private String copyTo;
|
||||
private String toTimestamp;
|
||||
private String index;
|
||||
private String newFileMode;
|
||||
private String oldMode;
|
||||
private String newMode;
|
||||
private String deletedFileMode;
|
||||
private String binaryAdded;
|
||||
private String binaryDeleted;
|
||||
private String binaryEdited;
|
||||
private Patch<String> patch = new Patch<>();
|
||||
private boolean noNewLineAtTheEndOfTheFile = false;
|
||||
private Integer similarityIndex;
|
||||
@@ -114,6 +121,22 @@ public final class UnifiedDiffFile {
|
||||
this.renameTo = renameTo;
|
||||
}
|
||||
|
||||
public String getCopyFrom() {
|
||||
return copyFrom;
|
||||
}
|
||||
|
||||
public void setCopyFrom(String copyFrom) {
|
||||
this.copyFrom = copyFrom;
|
||||
}
|
||||
|
||||
public String getCopyTo() {
|
||||
return copyTo;
|
||||
}
|
||||
|
||||
public void setCopyTo(String copyTo) {
|
||||
this.copyTo = copyTo;
|
||||
}
|
||||
|
||||
public static UnifiedDiffFile from(String fromFile, String toFile, Patch<String> patch) {
|
||||
UnifiedDiffFile file = new UnifiedDiffFile();
|
||||
file.setFromFile(fromFile);
|
||||
@@ -138,6 +161,46 @@ public final class UnifiedDiffFile {
|
||||
this.deletedFileMode = deletedFileMode;
|
||||
}
|
||||
|
||||
public String getOldMode() {
|
||||
return oldMode;
|
||||
}
|
||||
|
||||
public void setOldMode(String oldMode) {
|
||||
this.oldMode = oldMode;
|
||||
}
|
||||
|
||||
public String getNewMode() {
|
||||
return newMode;
|
||||
}
|
||||
|
||||
public void setNewMode(String newMode) {
|
||||
this.newMode = newMode;
|
||||
}
|
||||
|
||||
public String getBinaryAdded() {
|
||||
return binaryAdded;
|
||||
}
|
||||
|
||||
public void setBinaryAdded(String binaryAdded) {
|
||||
this.binaryAdded = binaryAdded;
|
||||
}
|
||||
|
||||
public String getBinaryDeleted() {
|
||||
return binaryDeleted;
|
||||
}
|
||||
|
||||
public void setBinaryDeleted(String binaryDeleted) {
|
||||
this.binaryDeleted = binaryDeleted;
|
||||
}
|
||||
|
||||
public String getBinaryEdited() {
|
||||
return binaryEdited;
|
||||
}
|
||||
|
||||
public void setBinaryEdited(String binaryEdited) {
|
||||
this.binaryEdited = binaryEdited;
|
||||
}
|
||||
|
||||
public boolean isNoNewLineAtTheEndOfTheFile() {
|
||||
return noNewLineAtTheEndOfTheFile;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,18 @@ public final class UnifiedDiffReader {
|
||||
private final UnifiedDiffLine TO_FILE = new UnifiedDiffLine(true, "^\\+\\+\\+\\s", this::processToFile);
|
||||
private final UnifiedDiffLine RENAME_FROM = new UnifiedDiffLine(true, "^rename\\sfrom\\s(.+)$", this::processRenameFrom);
|
||||
private final UnifiedDiffLine RENAME_TO = new UnifiedDiffLine(true, "^rename\\sto\\s(.+)$", this::processRenameTo);
|
||||
|
||||
private final UnifiedDiffLine COPY_FROM = new UnifiedDiffLine(true, "^copy\\sfrom\\s(.+)$", this::processCopyFrom);
|
||||
private final UnifiedDiffLine COPY_TO = new UnifiedDiffLine(true, "^copy\\sto\\s(.+)$", this::processCopyTo);
|
||||
|
||||
private final UnifiedDiffLine NEW_FILE_MODE = new UnifiedDiffLine(true, "^new\\sfile\\smode\\s(\\d+)", this::processNewFileMode);
|
||||
|
||||
private final UnifiedDiffLine DELETED_FILE_MODE = new UnifiedDiffLine(true, "^deleted\\sfile\\smode\\s(\\d+)", this::processDeletedFileMode);
|
||||
|
||||
private final UnifiedDiffLine OLD_MODE = new UnifiedDiffLine(true, "^old\\smode\\s(\\d+)", this::processOldMode);
|
||||
private final UnifiedDiffLine NEW_MODE = new UnifiedDiffLine(true, "^new\\smode\\s(\\d+)", this::processNewMode);
|
||||
private final UnifiedDiffLine BINARY_ADDED = new UnifiedDiffLine(true, "^Binary\\sfiles\\s/dev/null\\sand\\sb/(.+)\\sdiffer", this::processBinaryAdded);
|
||||
private final UnifiedDiffLine BINARY_DELETED = new UnifiedDiffLine(true, "^Binary\\sfiles\\sa/(.+)\\sand\\s/dev/null\\sdiffer", this::processBinaryDeleted);
|
||||
private final UnifiedDiffLine BINARY_EDITED = new UnifiedDiffLine(true, "^Binary\\sfiles\\sa/(.+)\\sand\\sb/(.+)\\sdiffer", this::processBinaryEdited);
|
||||
private final UnifiedDiffLine CHUNK = new UnifiedDiffLine(false, UNIFIED_DIFF_CHUNK_REGEXP, this::processChunk);
|
||||
private final UnifiedDiffLine LINE_NORMAL = new UnifiedDiffLine("^\\s", this::processNormalLine);
|
||||
private final UnifiedDiffLine LINE_DEL = new UnifiedDiffLine("^-", this::processDelLine);
|
||||
@@ -99,8 +106,11 @@ public final class UnifiedDiffReader {
|
||||
if (validLine(line, DIFF_COMMAND, SIMILARITY_INDEX, INDEX,
|
||||
FROM_FILE, TO_FILE,
|
||||
RENAME_FROM, RENAME_TO,
|
||||
NEW_FILE_MODE, DELETED_FILE_MODE,
|
||||
CHUNK)) {
|
||||
COPY_FROM, COPY_TO,
|
||||
NEW_FILE_MODE, DELETED_FILE_MODE,
|
||||
OLD_MODE, NEW_MODE,
|
||||
BINARY_ADDED, BINARY_DELETED,
|
||||
BINARY_EDITED, CHUNK)) {
|
||||
break;
|
||||
} else {
|
||||
headerTxt += line + "\n";
|
||||
@@ -116,7 +126,11 @@ public final class UnifiedDiffReader {
|
||||
if (!processLine(line, DIFF_COMMAND, SIMILARITY_INDEX, INDEX,
|
||||
FROM_FILE, TO_FILE,
|
||||
RENAME_FROM, RENAME_TO,
|
||||
NEW_FILE_MODE, DELETED_FILE_MODE)) {
|
||||
COPY_FROM, COPY_TO,
|
||||
NEW_FILE_MODE, DELETED_FILE_MODE,
|
||||
OLD_MODE, NEW_MODE,
|
||||
BINARY_ADDED , BINARY_DELETED,
|
||||
BINARY_EDITED)) {
|
||||
throw new UnifiedDiffParserException("expected file start line not found");
|
||||
}
|
||||
line = READER.readLine();
|
||||
@@ -335,6 +349,14 @@ public final class UnifiedDiffReader {
|
||||
private void processRenameTo(MatchResult match, String line) {
|
||||
actualFile.setRenameTo(match.group(1));
|
||||
}
|
||||
|
||||
private void processCopyFrom(MatchResult match, String line) {
|
||||
actualFile.setCopyFrom(match.group(1));
|
||||
}
|
||||
|
||||
private void processCopyTo(MatchResult match, String line) {
|
||||
actualFile.setCopyTo(match.group(1));
|
||||
}
|
||||
|
||||
private void processNewFileMode(MatchResult match, String line) {
|
||||
//initFileIfNecessary();
|
||||
@@ -346,6 +368,26 @@ public final class UnifiedDiffReader {
|
||||
actualFile.setDeletedFileMode(match.group(1));
|
||||
}
|
||||
|
||||
private void processOldMode(MatchResult match, String line) {
|
||||
actualFile.setOldMode(match.group(1));
|
||||
}
|
||||
|
||||
private void processNewMode(MatchResult match, String line) {
|
||||
actualFile.setNewMode(match.group(1));
|
||||
}
|
||||
|
||||
private void processBinaryAdded(MatchResult match, String line) {
|
||||
actualFile.setBinaryAdded(match.group(1));
|
||||
}
|
||||
|
||||
private void processBinaryDeleted(MatchResult match, String line) {
|
||||
actualFile.setBinaryDeleted(match.group(1));
|
||||
}
|
||||
|
||||
private void processBinaryEdited(MatchResult match, String line) {
|
||||
actualFile.setBinaryEdited(match.group(1));
|
||||
}
|
||||
|
||||
private String extractFileName(String _line) {
|
||||
Matcher matcher = TIMESTAMP_REGEXP.matcher(_line);
|
||||
String line = _line;
|
||||
@@ -353,7 +395,7 @@ public final class UnifiedDiffReader {
|
||||
line = line.substring(0, matcher.start());
|
||||
}
|
||||
line = line.split("\t")[0];
|
||||
return line.substring(4).replaceFirst("^(a|b|old|new)(\\/)?", "")
|
||||
return line.substring(4).replaceFirst("^(a|b|old|new)/", "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
|
||||
@@ -189,10 +189,10 @@ public class UnifiedDiffWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter
|
||||
* getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter.
|
||||
*
|
||||
* @param delta - the Delta to output
|
||||
* @return list of String lines of code.
|
||||
* @param writer consumer for the list of String lines of code
|
||||
* @param delta the Delta to output
|
||||
*/
|
||||
private static void getDeltaText(Consumer<String> writer, AbstractDelta<String> delta) {
|
||||
for (String line : delta.getSource().getLines()) {
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -132,7 +134,7 @@ public class DiffUtilsTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test this, the greedy meyer algorithm is not suitable.
|
||||
* To test this, the greedy Myer algorithm is not suitable.
|
||||
*/
|
||||
@Test
|
||||
@Disabled
|
||||
@@ -227,4 +229,14 @@ public class DiffUtilsTest {
|
||||
assertEquals(new Chunk<>(3, Arrays.asList("brown")), delta.getSource());
|
||||
assertEquals(new Chunk<>(3, Arrays.asList("down")), delta.getTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiffPatchIssue189Problem() throws IOException {
|
||||
String original = new String(Files.readAllBytes(Paths.get("target/test-classes/com/github/difflib/text/issue_189_insert_original.txt")));
|
||||
String revised = new String(Files.readAllBytes(Paths.get("target/test-classes/com/github/difflib/text/issue_189_insert_revised.txt")));
|
||||
|
||||
Patch patch = DiffUtils.diff(Arrays.asList(original.split("\n")), Arrays.asList(revised.split("\n")));
|
||||
|
||||
assertEquals(1, patch.getDeltas().size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MyersDiffTest {
|
||||
public void testDiffMyersExample1Forward() {
|
||||
List<String> original = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
|
||||
List<String> revised = Arrays.asList("C", "B", "A", "B", "A", "C");
|
||||
final Patch<String> patch = Patch.generate(original, revised, new MeyersDiff<String>().computeDiff(original, revised, null));
|
||||
final Patch<String> patch = Patch.generate(original, revised, new MyersDiff<String>().computeDiff(original, revised, null));
|
||||
assertNotNull(patch);
|
||||
assertEquals(4, patch.getDeltas().size());
|
||||
assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [InsertDelta, position: 3, lines: [B]], [DeleteDelta, position: 5, lines: [B]], [InsertDelta, position: 7, lines: [C]]]}", patch.toString());
|
||||
@@ -47,7 +47,7 @@ public class MyersDiffTest {
|
||||
|
||||
List<String> logdata = new ArrayList<>();
|
||||
final Patch<String> patch = Patch.generate(original, revised,
|
||||
new MeyersDiff<String>().computeDiff(original, revised, new DiffAlgorithmListener() {
|
||||
new MyersDiff<String>().computeDiff(original, revised, new DiffAlgorithmListener() {
|
||||
@Override
|
||||
public void diffStart() {
|
||||
logdata.add("start");
|
||||
|
||||
@@ -30,13 +30,13 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
*
|
||||
* @author tw
|
||||
*/
|
||||
public class MeyersDiffWithLinearSpaceTest {
|
||||
public class MyersDiffWithLinearSpaceTest {
|
||||
|
||||
@Test
|
||||
public void testDiffMyersExample1Forward() {
|
||||
List<String> original = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
|
||||
List<String> revised = Arrays.asList("C", "B", "A", "B", "A", "C");
|
||||
final Patch<String> patch = Patch.generate(original, revised, new MeyersDiffWithLinearSpace<String>().computeDiff(original, revised, null));
|
||||
final Patch<String> patch = Patch.generate(original, revised, new MyersDiffWithLinearSpace<String>().computeDiff(original, revised, null));
|
||||
assertNotNull(patch);
|
||||
System.out.println(patch);
|
||||
assertEquals(5, patch.getDeltas().size());
|
||||
@@ -50,7 +50,7 @@ public class MeyersDiffWithLinearSpaceTest {
|
||||
|
||||
List<String> logdata = new ArrayList<>();
|
||||
final Patch<String> patch = Patch.generate(original, revised,
|
||||
new MeyersDiffWithLinearSpace<String>().computeDiff(original, revised, new DiffAlgorithmListener() {
|
||||
new MyersDiffWithLinearSpace<String>().computeDiff(original, revised, new DiffAlgorithmListener() {
|
||||
@Override
|
||||
public void diffStart() {
|
||||
logdata.add("start");
|
||||
@@ -84,7 +84,7 @@ public class MeyersDiffWithLinearSpaceTest {
|
||||
.collect(toList());
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
Patch<String> diff = DiffUtils.diff(old, newl, new MeyersDiffWithLinearSpace<String>());
|
||||
Patch<String> diff = DiffUtils.diff(old, newl, new MyersDiffWithLinearSpace<String>());
|
||||
long end = System.currentTimeMillis();
|
||||
System.out.println("Finished in " + (end - start) + "ms and resulted " + diff.getDeltas().size() + " deltas");
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package com.github.difflib.algorithm.myers;
|
||||
|
||||
import com.github.difflib.patch.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
|
||||
public class WithMeyersDiffWithLinearSpacePatchTest {
|
||||
|
||||
@Test
|
||||
public void testPatch_Insert() {
|
||||
final List<String> insertTest_from = Arrays.asList("hhh");
|
||||
final List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(insertTest_from, insertTest_to, new MeyersDiffWithLinearSpace<String>());
|
||||
try {
|
||||
assertEquals(insertTest_to, DiffUtils.patch(insertTest_from, patch));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Delete() {
|
||||
final List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh");
|
||||
final List<String> deleteTest_to = Arrays.asList("ggg");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(deleteTest_from, deleteTest_to, new MeyersDiffWithLinearSpace<String>());
|
||||
try {
|
||||
assertEquals(deleteTest_to, DiffUtils.patch(deleteTest_from, patch));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Change() {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MeyersDiffWithLinearSpace<String>());
|
||||
try {
|
||||
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, patch));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Serializable() throws IOException, ClassNotFoundException {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MeyersDiffWithLinearSpace<String>());
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(baos);
|
||||
out.writeObject(patch);
|
||||
out.close();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream in = new ObjectInputStream(bais);
|
||||
Patch<String> result = (Patch<String>) in.readObject();
|
||||
in.close();
|
||||
|
||||
try {
|
||||
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, result));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Change_withExceptionProcessor() {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MeyersDiffWithLinearSpace<String>());
|
||||
|
||||
changeTest_from.set(2, "CDC");
|
||||
|
||||
patch.withConflictOutput(Patch.CONFLICT_PRODUCES_MERGE_CONFLICT);
|
||||
|
||||
try {
|
||||
List<String> data = DiffUtils.patch(changeTest_from, patch);
|
||||
assertEquals(11, data.size());
|
||||
|
||||
assertEquals(Arrays.asList("aaa", "bxb", "cxc", "<<<<<< HEAD", "bbb", "CDC", "======", "bbb", "ccc", ">>>>>>> PATCH", "ddd"), data);
|
||||
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
package com.github.difflib.algorithm.myers;
|
||||
|
||||
import com.github.difflib.patch.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
|
||||
public class WithMyersDiffWithLinearSpacePatchTest {
|
||||
|
||||
@Test
|
||||
public void testPatch_Insert() {
|
||||
final List<String> insertTest_from = Arrays.asList("hhh");
|
||||
final List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(insertTest_from, insertTest_to, new MyersDiffWithLinearSpace<String>());
|
||||
try {
|
||||
assertEquals(insertTest_to, DiffUtils.patch(insertTest_from, patch));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Delete() {
|
||||
final List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh");
|
||||
final List<String> deleteTest_to = Arrays.asList("ggg");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(deleteTest_from, deleteTest_to, new MyersDiffWithLinearSpace<String>());
|
||||
try {
|
||||
assertEquals(deleteTest_to, DiffUtils.patch(deleteTest_from, patch));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Change() {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MyersDiffWithLinearSpace<String>());
|
||||
try {
|
||||
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, patch));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// region testPatch_fuzzyApply utils
|
||||
|
||||
private List<String> intRange(int count) {
|
||||
return IntStream.range(0, count)
|
||||
.mapToObj(Integer::toString)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private final List<String> join(List<String>... lists) {
|
||||
return Arrays.stream(lists).flatMap(Collection::stream).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static class FuzzyApplyTestPair {
|
||||
public final List<String> from;
|
||||
public final List<String> to;
|
||||
public final int requiredFuzz;
|
||||
|
||||
private FuzzyApplyTestPair(List<String> from, List<String> to, int requiredFuzz) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.requiredFuzz = requiredFuzz;
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
@Test
|
||||
public void fuzzyApply() throws PatchFailedException {
|
||||
Patch<String> patch = new Patch<>();
|
||||
List<String> deltaFrom = Arrays.asList("aaa", "bbb", "ccc", "ddd", "eee", "fff");
|
||||
List<String> deltaTo = Arrays.asList("aaa", "bbb", "cxc", "dxd", "eee", "fff");
|
||||
patch.addDelta(new ChangeDelta<>(
|
||||
new Chunk<>(6, deltaFrom),
|
||||
new Chunk<>(6, deltaTo)));
|
||||
|
||||
//noinspection unchecked
|
||||
List<String>[] moves = new List[] {
|
||||
intRange(6), // no patch move
|
||||
intRange(3), // forward patch move
|
||||
intRange(9), // backward patch move
|
||||
intRange(0), // apply to the first
|
||||
};
|
||||
|
||||
for (FuzzyApplyTestPair pair : FUZZY_APPLY_TEST_PAIRS) {
|
||||
for (List<String> move : moves) {
|
||||
List<String> from = join(move, pair.from);
|
||||
List<String> to = join(move, pair.to);
|
||||
|
||||
for (int i = 0; i < pair.requiredFuzz; i++) {
|
||||
int maxFuzz = i;
|
||||
assertThrows(PatchFailedException.class, () ->
|
||||
patch.applyFuzzy(from, maxFuzz),
|
||||
() -> "fail for " + from + " -> " + to + " for fuzz " + maxFuzz + " required " + pair.requiredFuzz);
|
||||
}
|
||||
for (int i = pair.requiredFuzz; i < 4; i++) {
|
||||
int maxFuzz = i;
|
||||
assertEquals(to, patch.applyFuzzy(from, maxFuzz),
|
||||
() -> "with " + maxFuzz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fuzzyApplyTwoSideBySidePatches() throws PatchFailedException {
|
||||
Patch<String> patch = new Patch<>();
|
||||
List<String> deltaFrom = Arrays.asList("aaa", "bbb", "ccc", "ddd", "eee", "fff");
|
||||
List<String> deltaTo = Arrays.asList("aaa", "bbb", "cxc", "dxd", "eee", "fff");
|
||||
patch.addDelta(new ChangeDelta<>(
|
||||
new Chunk<>(0, deltaFrom),
|
||||
new Chunk<>(0, deltaTo)));
|
||||
patch.addDelta(new ChangeDelta<>(
|
||||
new Chunk<>(6, deltaFrom),
|
||||
new Chunk<>(6, deltaTo)));
|
||||
|
||||
|
||||
assertEquals(join(deltaTo, deltaTo), patch.applyFuzzy(join(deltaFrom, deltaFrom), 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fuzzyApplyToNearest() throws PatchFailedException {
|
||||
Patch<String> patch = new Patch<>();
|
||||
List<String> deltaFrom = Arrays.asList("aaa", "bbb", "ccc", "ddd", "eee", "fff");
|
||||
List<String> deltaTo = Arrays.asList("aaa", "bbb", "cxc", "dxd", "eee", "fff");
|
||||
patch.addDelta(new ChangeDelta<>(
|
||||
new Chunk<>(0, deltaFrom),
|
||||
new Chunk<>(0, deltaTo)));
|
||||
patch.addDelta(new ChangeDelta<>(
|
||||
new Chunk<>(10, deltaFrom),
|
||||
new Chunk<>(10, deltaTo)));
|
||||
|
||||
assertEquals(join(deltaTo, deltaFrom, deltaTo),
|
||||
patch.applyFuzzy(join(deltaFrom, deltaFrom, deltaFrom), 0));
|
||||
assertEquals(join(intRange(1), deltaTo, deltaFrom, deltaTo),
|
||||
patch.applyFuzzy(join(intRange(1), deltaFrom, deltaFrom, deltaFrom), 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Serializable() throws IOException, ClassNotFoundException {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MyersDiffWithLinearSpace<String>());
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(baos);
|
||||
out.writeObject(patch);
|
||||
out.close();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream in = new ObjectInputStream(bais);
|
||||
Patch<String> result = (Patch<String>) in.readObject();
|
||||
in.close();
|
||||
|
||||
try {
|
||||
assertEquals(changeTest_to, DiffUtils.patch(changeTest_from, result));
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatch_Change_withExceptionProcessor() {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");
|
||||
|
||||
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to, new MyersDiffWithLinearSpace<String>());
|
||||
|
||||
changeTest_from.set(2, "CDC");
|
||||
|
||||
patch.withConflictOutput(Patch.CONFLICT_PRODUCES_MERGE_CONFLICT);
|
||||
|
||||
try {
|
||||
List<String> data = DiffUtils.patch(changeTest_from, patch);
|
||||
assertEquals(11, data.size());
|
||||
|
||||
assertEquals(Arrays.asList("aaa", "bxb", "cxc", "<<<<<< HEAD", "bbb", "CDC", "======", "bbb", "ccc", ">>>>>>> PATCH", "ddd"), data);
|
||||
|
||||
} catch (PatchFailedException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
static class FuzzyApplyTestDataGenerator {
|
||||
private static String createList(List<String> values) {
|
||||
return values.stream()
|
||||
.map(x -> '"' + x + '"')
|
||||
.collect(Collectors.joining(", ", "Arrays.asList(", ")"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String[] deltaFrom = new String[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff" };
|
||||
String[] deltaTo = new String[] { "aaa", "bbb", "cxc", "dxd", "eee", "fff" };
|
||||
|
||||
List<FuzzyApplyTestPair> pairs = new ArrayList<>();
|
||||
|
||||
// create test data.
|
||||
// Brute-force search
|
||||
String[] changedValue = new String[]{"axa", "bxb", "czc", "dzd", "exe", "fxf"};
|
||||
for (int i = 0; i < 1 << 6; i++) {
|
||||
if ((i & 0b001100) != 0 && (i & 0b001100) != 0b001100) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] from = deltaFrom.clone();
|
||||
String[] to = deltaTo.clone();
|
||||
for (int j = 0; j < 6; j++) {
|
||||
if ((i & (1 << j)) != 0) {
|
||||
from[j] = changedValue[j];
|
||||
to[j] = changedValue[j];
|
||||
}
|
||||
}
|
||||
|
||||
int requiredFuzz;
|
||||
if ((i & 0b001100) != 0) {
|
||||
requiredFuzz = 3;
|
||||
} else if ((i & 0b010010) != 0) {
|
||||
requiredFuzz = 2;
|
||||
} else if ((i & 0b100001) != 0) {
|
||||
requiredFuzz = 1;
|
||||
} else {
|
||||
requiredFuzz = 0;
|
||||
}
|
||||
|
||||
pairs.add(new FuzzyApplyTestPair(Arrays.asList(from), Arrays.asList(to), requiredFuzz));
|
||||
}
|
||||
pairs.sort(Comparator.comparingInt(a -> a.requiredFuzz));
|
||||
System.out.println("FuzzyApplyTestPair[] pairs = new FuzzyApplyTestPair[] {");
|
||||
for (FuzzyApplyTestPair pair : pairs) {
|
||||
System.out.println(" new FuzzyApplyTestPair(");
|
||||
System.out.println(" " + createList(pair.from) + ",");
|
||||
System.out.println(" " + createList(pair.to) + ",");
|
||||
System.out.println(" " + pair.requiredFuzz + "),");
|
||||
}
|
||||
System.out.println("};");
|
||||
}
|
||||
}
|
||||
|
||||
private static final FuzzyApplyTestPair[] FUZZY_APPLY_TEST_PAIRS = new FuzzyApplyTestPair[] {
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "ccc", "ddd", "eee", "fff"),
|
||||
Arrays.asList("aaa", "bbb", "cxc", "dxd", "eee", "fff"),
|
||||
0),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "ccc", "ddd", "eee", "fff"),
|
||||
Arrays.asList("axa", "bbb", "cxc", "dxd", "eee", "fff"),
|
||||
1),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "ccc", "ddd", "eee", "fxf"),
|
||||
Arrays.asList("aaa", "bbb", "cxc", "dxd", "eee", "fxf"),
|
||||
1),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "ccc", "ddd", "eee", "fxf"),
|
||||
Arrays.asList("axa", "bbb", "cxc", "dxd", "eee", "fxf"),
|
||||
1),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "ccc", "ddd", "eee", "fff"),
|
||||
Arrays.asList("aaa", "bxb", "cxc", "dxd", "eee", "fff"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "ccc", "ddd", "eee", "fff"),
|
||||
Arrays.asList("axa", "bxb", "cxc", "dxd", "eee", "fff"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "ccc", "ddd", "exe", "fff"),
|
||||
Arrays.asList("aaa", "bbb", "cxc", "dxd", "exe", "fff"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "ccc", "ddd", "exe", "fff"),
|
||||
Arrays.asList("axa", "bbb", "cxc", "dxd", "exe", "fff"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "ccc", "ddd", "exe", "fff"),
|
||||
Arrays.asList("aaa", "bxb", "cxc", "dxd", "exe", "fff"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "ccc", "ddd", "exe", "fff"),
|
||||
Arrays.asList("axa", "bxb", "cxc", "dxd", "exe", "fff"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "ccc", "ddd", "eee", "fxf"),
|
||||
Arrays.asList("aaa", "bxb", "cxc", "dxd", "eee", "fxf"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "ccc", "ddd", "eee", "fxf"),
|
||||
Arrays.asList("axa", "bxb", "cxc", "dxd", "eee", "fxf"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "ccc", "ddd", "exe", "fxf"),
|
||||
Arrays.asList("aaa", "bbb", "cxc", "dxd", "exe", "fxf"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "ccc", "ddd", "exe", "fxf"),
|
||||
Arrays.asList("axa", "bbb", "cxc", "dxd", "exe", "fxf"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "ccc", "ddd", "exe", "fxf"),
|
||||
Arrays.asList("aaa", "bxb", "cxc", "dxd", "exe", "fxf"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "ccc", "ddd", "exe", "fxf"),
|
||||
Arrays.asList("axa", "bxb", "cxc", "dxd", "exe", "fxf"),
|
||||
2),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "eee", "fff"),
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "eee", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "eee", "fff"),
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "eee", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "eee", "fff"),
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "eee", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "eee", "fff"),
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "eee", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "exe", "fff"),
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "exe", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "exe", "fff"),
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "exe", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "exe", "fff"),
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "exe", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "exe", "fff"),
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "exe", "fff"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "eee", "fxf"),
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "eee", "fxf"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "eee", "fxf"),
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "eee", "fxf"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "eee", "fxf"),
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "eee", "fxf"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "eee", "fxf"),
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "eee", "fxf"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "exe", "fxf"),
|
||||
Arrays.asList("aaa", "bbb", "czc", "dzd", "exe", "fxf"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "exe", "fxf"),
|
||||
Arrays.asList("axa", "bbb", "czc", "dzd", "exe", "fxf"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "exe", "fxf"),
|
||||
Arrays.asList("aaa", "bxb", "czc", "dzd", "exe", "fxf"),
|
||||
3),
|
||||
new FuzzyApplyTestPair(
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "exe", "fxf"),
|
||||
Arrays.asList("axa", "bxb", "czc", "dzd", "exe", "fxf"),
|
||||
3),
|
||||
};
|
||||
}
|
||||
@@ -12,11 +12,11 @@ import java.util.List;
|
||||
public class ComputeDifference {
|
||||
|
||||
private static final String ORIGINAL = TestConstants.MOCK_FOLDER + "original.txt";
|
||||
private static final String RIVISED = TestConstants.MOCK_FOLDER + "revised.txt";
|
||||
private static final String REVISED = TestConstants.MOCK_FOLDER + "revised.txt";
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
List<String> original = Files.readAllLines(new File(ORIGINAL).toPath());
|
||||
List<String> revised = Files.readAllLines(new File(RIVISED).toPath());
|
||||
List<String> revised = Files.readAllLines(new File(REVISED).toPath());
|
||||
|
||||
// Compute diff. Get the Patch object. Patch is the container for computed deltas.
|
||||
Patch<String> patch = DiffUtils.diff(original, revised);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.github.difflib.examples;
|
||||
|
||||
import com.github.difflib.TestConstants;
|
||||
import com.github.difflib.UnifiedDiffUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class OriginalAndDiffTest {
|
||||
|
||||
@Test
|
||||
public void testGenerateOriginalAndDiff() {
|
||||
List<String> origLines = null;
|
||||
List<String> revLines = null;
|
||||
try {
|
||||
origLines = fileToLines(TestConstants.MOCK_FOLDER + "original.txt");
|
||||
revLines = fileToLines(TestConstants.MOCK_FOLDER + "revised.txt");
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
List<String> originalAndDiff = UnifiedDiffUtils.generateOriginalAndDiff(origLines, revLines);
|
||||
System.out.println(originalAndDiff.stream().collect(joining("\n")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateOriginalAndDiffFirstLineChange() {
|
||||
List<String> origLines = null;
|
||||
List<String> revLines = null;
|
||||
try {
|
||||
origLines = fileToLines(TestConstants.MOCK_FOLDER + "issue_170_original.txt");
|
||||
revLines = fileToLines(TestConstants.MOCK_FOLDER + "issue_170_revised.txt");
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
List<String> originalAndDiff = UnifiedDiffUtils.generateOriginalAndDiff(origLines, revLines);
|
||||
System.out.println(originalAndDiff.stream().collect(joining("\n")));
|
||||
}
|
||||
|
||||
public static List<String> fileToLines(String filename) throws FileNotFoundException, IOException {
|
||||
List<String> lines = new ArrayList<>();
|
||||
String line = "";
|
||||
try (BufferedReader in = new BufferedReader(new FileReader(filename))) {
|
||||
while ((line = in.readLine()) != null) {
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.github.difflib.patch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ChunkTest {
|
||||
@Test
|
||||
void verifyChunk() throws PatchFailedException {
|
||||
Chunk<Character> chunk = new Chunk<>(7, toCharList("test"));
|
||||
|
||||
// normal check
|
||||
assertEquals(VerifyChunk.OK,
|
||||
chunk.verifyChunk(toCharList("prefix test suffix")));
|
||||
assertEquals(VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET,
|
||||
chunk.verifyChunk(toCharList("prefix es suffix"), 0, 7));
|
||||
|
||||
// position
|
||||
assertEquals(VerifyChunk.OK,
|
||||
chunk.verifyChunk(toCharList("short test suffix"), 0, 6));
|
||||
assertEquals(VerifyChunk.OK,
|
||||
chunk.verifyChunk(toCharList("loonger test suffix"), 0, 8));
|
||||
assertEquals(VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET,
|
||||
chunk.verifyChunk(toCharList("prefix test suffix"), 0, 6));
|
||||
assertEquals(VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET,
|
||||
chunk.verifyChunk(toCharList("prefix test suffix"), 0, 8));
|
||||
|
||||
// fuzz
|
||||
assertEquals(VerifyChunk.OK,
|
||||
chunk.verifyChunk(toCharList("prefix test suffix"), 1, 7));
|
||||
assertEquals(VerifyChunk.OK,
|
||||
chunk.verifyChunk(toCharList("prefix es suffix"), 1, 7));
|
||||
assertEquals(VerifyChunk.CONTENT_DOES_NOT_MATCH_TARGET,
|
||||
chunk.verifyChunk(toCharList("prefix suffix"), 1, 7));
|
||||
}
|
||||
|
||||
private List<Character> toCharList(String str) {
|
||||
return str.chars().mapToObj(x -> (char) x).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ import java.util.List;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
import com.github.difflib.algorithm.DiffAlgorithmFactory;
|
||||
import com.github.difflib.algorithm.myers.MeyersDiff;
|
||||
import com.github.difflib.algorithm.myers.MeyersDiffWithLinearSpace;
|
||||
import com.github.difflib.algorithm.myers.MyersDiff;
|
||||
import com.github.difflib.algorithm.myers.MyersDiffWithLinearSpace;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -25,14 +25,13 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
public class PatchWithAllDiffAlgorithmsTest {
|
||||
|
||||
private static Stream<Arguments> provideAlgorithms() {
|
||||
return Stream.of(
|
||||
Arguments.of(MeyersDiff.factory()),
|
||||
Arguments.of(MeyersDiffWithLinearSpace.factory()));
|
||||
return Stream.of(Arguments.of(MyersDiff.factory()),
|
||||
Arguments.of(MyersDiffWithLinearSpace.factory()));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void afterAll() {
|
||||
DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiff.factory());
|
||||
DiffUtils.withDefaultDiffAlgorithmFactory(MyersDiff.factory());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
package com.github.difflib.patch;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
import static com.github.difflib.patch.Patch.CONFLICT_PRODUCES_MERGE_CONFLICT;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -26,7 +28,8 @@ import org.junit.jupiter.api.Test;
|
||||
*
|
||||
* @author tw
|
||||
*/
|
||||
public class PatchWithMeyerDiffTest {
|
||||
public class PatchWithMyerDiffTest {
|
||||
|
||||
@Test
|
||||
public void testPatch_Change_withExceptionProcessor() {
|
||||
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
|
||||
@@ -48,4 +51,18 @@ public class PatchWithMeyerDiffTest {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPatchThreeWayIssue138() throws PatchFailedException {
|
||||
List<String> base = Arrays.asList("Imagine there's no heaven".split("\\s+"));
|
||||
List<String> left = Arrays.asList("Imagine there's no HEAVEN".split("\\s+"));
|
||||
List<String> right = Arrays.asList("IMAGINE there's no heaven".split("\\s+"));
|
||||
|
||||
Patch<String> rightPatch = DiffUtils.diff(base, right)
|
||||
.withConflictOutput(CONFLICT_PRODUCES_MERGE_CONFLICT);
|
||||
|
||||
List<String> applied = rightPatch.applyTo(left);
|
||||
|
||||
assertEquals("IMAGINE there's no HEAVEN", applied.stream().collect(joining(" ")));
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,8 @@
|
||||
package com.github.difflib.patch;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
import com.github.difflib.algorithm.myers.MeyersDiff;
|
||||
import com.github.difflib.algorithm.myers.MeyersDiffWithLinearSpace;
|
||||
import com.github.difflib.algorithm.myers.MyersDiff;
|
||||
import com.github.difflib.algorithm.myers.MyersDiffWithLinearSpace;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
@@ -30,16 +30,16 @@ import org.junit.jupiter.api.Test;
|
||||
*
|
||||
* @author tw
|
||||
*/
|
||||
public class PatchWithMeyerDiffWithLinearSpaceTest {
|
||||
public class PatchWithMyerDiffWithLinearSpaceTest {
|
||||
|
||||
@BeforeAll
|
||||
public static void setupClass() {
|
||||
DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiffWithLinearSpace.factory());
|
||||
DiffUtils.withDefaultDiffAlgorithmFactory(MyersDiffWithLinearSpace.factory());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void resetClass() {
|
||||
DiffUtils.withDefaultDiffAlgorithmFactory(MeyersDiff.factory());
|
||||
DiffUtils.withDefaultDiffAlgorithmFactory(MyersDiff.factory());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.github.difflib.text;
|
||||
|
||||
import com.github.difflib.DiffUtils;
|
||||
import com.github.difflib.algorithm.myers.MyersDiffWithLinearSpace;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
@@ -641,7 +646,7 @@ public class DiffRowGeneratorTest {
|
||||
|
||||
assertThat(rows).extracting(item -> item.getTag().name()).containsExactly("CHANGE", "DELETE", "EQUAL", "CHANGE", "EQUAL");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCorrectChangeIssue114_2() throws IOException {
|
||||
List<String> original = Arrays.asList("A", "B", "C", "D", "E");
|
||||
@@ -662,7 +667,7 @@ public class DiffRowGeneratorTest {
|
||||
assertThat(rows).extracting(item -> item.getTag().name()).containsExactly("CHANGE", "DELETE", "EQUAL", "CHANGE", "EQUAL");
|
||||
assertThat(rows.get(1).toString()).isEqualTo("[DELETE,~B~,]");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIssue119WrongContextLength() throws IOException {
|
||||
String original = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue_119_original.txt")).collect(joining("\n"));
|
||||
@@ -683,4 +688,130 @@ public class DiffRowGeneratorTest {
|
||||
.filter(item -> item.getTag() != DiffRow.Tag.EQUAL)
|
||||
.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue129WithDeltaDecompression() {
|
||||
List<String> lines1 = Arrays.asList(
|
||||
"apple1",
|
||||
"apple2",
|
||||
"apple3",
|
||||
"A man named Frankenstein abc to Switzerland for cookies!",
|
||||
"banana1",
|
||||
"banana2",
|
||||
"banana3");
|
||||
List<String> lines2 = Arrays.asList(
|
||||
"apple1",
|
||||
"apple2",
|
||||
"apple3",
|
||||
"A man named Frankenstein",
|
||||
"xyz",
|
||||
"to Switzerland for cookies!",
|
||||
"banana1",
|
||||
"banana2",
|
||||
"banana3");
|
||||
int[] entry = {1};
|
||||
String txt = DiffRowGenerator.create()
|
||||
.showInlineDiffs(true)
|
||||
.oldTag((tag, isOpening) -> isOpening ? "==old" + tag + "==>" : "<==old==")
|
||||
.newTag((tag, isOpening) -> isOpening ? "==new" + tag + "==>" : "<==new==")
|
||||
.build()
|
||||
.generateDiffRows(lines1, lines2)
|
||||
.stream()
|
||||
.map(row -> row.getTag().toString())
|
||||
.collect(joining(" "));
|
||||
// .forEachOrdered(row -> {
|
||||
// System.out.printf("%4d %-8s %-80s %-80s\n", entry[0]++,
|
||||
// row.getTag(), row.getOldLine(), row.getNewLine());
|
||||
// });
|
||||
|
||||
assertThat(txt).isEqualTo("EQUAL EQUAL EQUAL CHANGE INSERT INSERT EQUAL EQUAL EQUAL");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue129SkipDeltaDecompression() {
|
||||
List<String> lines1 = Arrays.asList(
|
||||
"apple1",
|
||||
"apple2",
|
||||
"apple3",
|
||||
"A man named Frankenstein abc to Switzerland for cookies!",
|
||||
"banana1",
|
||||
"banana2",
|
||||
"banana3");
|
||||
List<String> lines2 = Arrays.asList(
|
||||
"apple1",
|
||||
"apple2",
|
||||
"apple3",
|
||||
"A man named Frankenstein",
|
||||
"xyz",
|
||||
"to Switzerland for cookies!",
|
||||
"banana1",
|
||||
"banana2",
|
||||
"banana3");
|
||||
int[] entry = {1};
|
||||
String txt
|
||||
= DiffRowGenerator.create()
|
||||
.showInlineDiffs(true)
|
||||
.decompressDeltas(false)
|
||||
.oldTag((tag, isOpening) -> isOpening ? "==old" + tag + "==>" : "<==old==")
|
||||
.newTag((tag, isOpening) -> isOpening ? "==new" + tag + "==>" : "<==new==")
|
||||
.build()
|
||||
.generateDiffRows(lines1, lines2)
|
||||
.stream()
|
||||
.map(row -> row.getTag().toString())
|
||||
.collect(joining(" "));
|
||||
// .forEachOrdered(row -> {
|
||||
// System.out.printf("%4d %-8s %-80s %-80s\n", entry[0]++,
|
||||
// row.getTag(), row.getOldLine(), row.getNewLine());
|
||||
// });
|
||||
|
||||
assertThat(txt).isEqualTo("EQUAL EQUAL EQUAL CHANGE CHANGE CHANGE EQUAL EQUAL EQUAL");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue129SkipWhitespaceChanges() throws IOException {
|
||||
String original = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue129_1.txt")).collect(joining("\n"));
|
||||
String revised = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue129_2.txt")).collect(joining("\n"));
|
||||
|
||||
DiffRowGenerator generator = DiffRowGenerator.create()
|
||||
.showInlineDiffs(true)
|
||||
.mergeOriginalRevised(true)
|
||||
.inlineDiffByWord(true)
|
||||
.ignoreWhiteSpaces(true)
|
||||
.oldTag((tag, isOpening) -> isOpening ? "==old" + tag + "==>" : "<==old==")
|
||||
.newTag((tag, isOpening) -> isOpening ? "==new" + tag + "==>" : "<==new==")
|
||||
.build();
|
||||
List<DiffRow> rows = generator.generateDiffRows(
|
||||
Arrays.asList(original.split("\n")),
|
||||
Arrays.asList(revised.split("\n")));
|
||||
|
||||
assertThat(rows).hasSize(13);
|
||||
|
||||
rows.stream()
|
||||
.filter(item -> item.getTag() != DiffRow.Tag.EQUAL)
|
||||
.forEach(System.out::println);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue188HangOnExamples() throws IOException, URISyntaxException {
|
||||
try (FileSystem zipFs = FileSystems.newFileSystem(Paths.get("target/test-classes/com/github/difflib/text/test.zip"), null);) {
|
||||
List<String> original = Files.readAllLines(zipFs.getPath("old.html"));
|
||||
List<String> revised = Files.readAllLines(zipFs.getPath("new.html"));
|
||||
|
||||
DiffRowGenerator generator = DiffRowGenerator.create()
|
||||
.lineNormalizer(line -> line)
|
||||
.showInlineDiffs(true)
|
||||
.mergeOriginalRevised(true)
|
||||
.inlineDiffByWord(true)
|
||||
.decompressDeltas(true)
|
||||
.oldTag(f -> f ? "<s style=\"background-color: #bbbbbb\">" : "</s>")
|
||||
.newTag(f -> f ? "<b style=\"background-color: #aaffaa\">" : "</b>")
|
||||
.build();
|
||||
|
||||
//List<DiffRow> rows = generator.generateDiffRows(original, revised);
|
||||
List<DiffRow> rows = generator.generateDiffRows(original, DiffUtils.diff(original, revised, new MyersDiffWithLinearSpace<>() ));
|
||||
|
||||
System.out.println(rows);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public class UnifiedDiffReaderTest {
|
||||
assertThat(diff.getFiles().size()).isEqualTo(1);
|
||||
|
||||
UnifiedDiffFile file1 = diff.getFiles().get(0);
|
||||
assertThat(file1.getFromFile()).isEqualTo(".vhd");
|
||||
assertThat(file1.getFromFile()).isEqualTo("a.vhd");
|
||||
assertThat(file1.getPatch().getDeltas().size()).isEqualTo(1);
|
||||
|
||||
assertThat(diff.getTail()).isNull();
|
||||
@@ -384,4 +384,66 @@ public class UnifiedDiffReaderTest {
|
||||
|
||||
assertThat(diff.getFiles()).extracting(f -> f.getFromFile()).contains("src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIssue141() throws IOException {
|
||||
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
|
||||
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue141.diff"));
|
||||
UnifiedDiffFile file1 = diff.getFiles().get(0);
|
||||
|
||||
assertThat(file1.getFromFile()).isEqualTo("a.txt");
|
||||
assertThat(file1.getToFile()).isEqualTo("a1.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIssue182add() throws IOException {
|
||||
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
|
||||
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue182_add.diff"));
|
||||
|
||||
UnifiedDiffFile file1 = diff.getFiles().get(0);
|
||||
|
||||
assertThat(file1.getBinaryAdded()).isEqualTo("some-image.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIssue182delete() throws IOException {
|
||||
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
|
||||
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue182_delete.diff"));
|
||||
|
||||
UnifiedDiffFile file1 = diff.getFiles().get(0);
|
||||
|
||||
assertThat(file1.getBinaryDeleted()).isEqualTo("some-image.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIssue182edit() throws IOException {
|
||||
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
|
||||
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue182_edit.diff"));
|
||||
|
||||
UnifiedDiffFile file1 = diff.getFiles().get(0);
|
||||
|
||||
assertThat(file1.getBinaryEdited()).isEqualTo("some-image.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIssue182mode() throws IOException {
|
||||
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
|
||||
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue182_mode.diff"));
|
||||
|
||||
UnifiedDiffFile file1 = diff.getFiles().get(0);
|
||||
|
||||
assertThat(file1.getOldMode()).isEqualTo("100644");
|
||||
assertThat(file1.getNewMode()).isEqualTo("100755");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseIssue193Copy() throws IOException {
|
||||
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
|
||||
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_parsing_issue193.diff"));
|
||||
|
||||
UnifiedDiffFile file1 = diff.getFiles().get(0);
|
||||
|
||||
assertThat(file1.getCopyFrom()).isEqualTo("modules/configuration/config/web/pcf/account/AccountContactCV.pcf");
|
||||
assertThat(file1.getCopyTo()).isEqualTo("modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2022 java-diff-utils.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.github.difflib.unifieddiff;
|
||||
|
||||
import com.github.difflib.patch.PatchFailedException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Disabled("for next release")
|
||||
public class UnifiedDiffRoundTripNewLineTest {
|
||||
@Test
|
||||
public void testIssue135MissingNoNewLineInPatched() throws IOException, PatchFailedException {
|
||||
String beforeContent = "rootProject.name = \"sample-repo\"";
|
||||
String afterContent = "rootProject.name = \"sample-repo\"\n";
|
||||
String patch = "diff --git a/settings.gradle b/settings.gradle\n" +
|
||||
"index ef3b8e2..ab30124 100644\n" +
|
||||
"--- a/settings.gradle\n" +
|
||||
"+++ b/settings.gradle\n" +
|
||||
"@@ -1 +1 @@\n" +
|
||||
"-rootProject.name = \"sample-repo\"\n" +
|
||||
"\\ No newline at end of file\n" +
|
||||
"+rootProject.name = \"sample-repo\"\n";
|
||||
UnifiedDiff unifiedDiff = UnifiedDiffReader.parseUnifiedDiff(new ByteArrayInputStream(patch.getBytes()));
|
||||
String unifiedAfterContent = unifiedDiff.getFiles().get(0).getPatch()
|
||||
.applyTo(Arrays.asList(beforeContent.split("\n"))).stream().collect(joining("\n"));
|
||||
assertEquals(afterContent, unifiedAfterContent);
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class UnifiedDiffRoundTripTest {
|
||||
// Patch<String> fromUnifiedPatch = unifiedDiff.getFiles().get(0).getPatch();
|
||||
// patchedLines = fromUnifiedPatch.applyTo(origLines);
|
||||
// }
|
||||
patchedLines = unifiedDiff.spplyPatchTo(file -> originalFile.equals(file), origLines);
|
||||
patchedLines = unifiedDiff.applyPatchTo(file -> originalFile.equals(file), origLines);
|
||||
assertEquals(revLines.size(), patchedLines.size());
|
||||
for (int i = 0; i < revLines.size(); i++) {
|
||||
String l1 = revLines.get(i);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated
|
||||
to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or
|
||||
any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to
|
||||
dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live.
|
||||
It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not
|
||||
consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it,
|
||||
far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never
|
||||
forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought
|
||||
here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that
|
||||
from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that
|
||||
we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of
|
||||
freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.
|
||||
@@ -0,0 +1,13 @@
|
||||
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and
|
||||
dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether
|
||||
that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that
|
||||
war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives
|
||||
that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we
|
||||
can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who
|
||||
struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long
|
||||
remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated
|
||||
here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here
|
||||
dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause
|
||||
for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died
|
||||
in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the
|
||||
people, for the people, shall not perish from the earth.
|
||||
@@ -0,0 +1,19 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut nec mattis ipsum. Aliquam faucibus, augue quis faucibus scelerisque, sapien eros consequat erat, in semper quam nisi id ex. In viverra pulvinar tortor, non mollis eros ornare a. Praesent sagittis tincidunt ante, sed vulputate tellus faucibus quis. Sed efficitur, mi eu fringilla lobortis, lacus nisl aliquet ante, nec fermentum felis dui vel nunc. Fusce luctus rutrum ligula, sit amet suscipit est sollicitudin at. Suspendisse convallis ac dui a porttitor. Ut eget efficitur odio. In a facilisis quam, in imperdiet libero. Cras a orci in mi accumsan elementum. Duis at venenatis neque. Sed vel tellus ex.
|
||||
|
||||
Nam non velit at nunc tempus cursus ut vel ipsum. Nam nec nisi a nisl pellentesque faucibus ut et purus. Nulla in felis efficitur, facilisis turpis volutpat, consequat nisi. Vivamus ullamcorper euismod ex, et lobortis erat tristique id. Etiam rhoncus ante non eros lacinia, in porttitor lorem blandit. Duis porta malesuada blandit. Suspendisse tincidunt id dolor non semper. Morbi et enim sem. Proin vitae elit purus. Phasellus vel enim eget nisl tristique fringilla ac sit amet leo. In malesuada commodo condimentum. Aliquam erat volutpat. Curabitur et nibh nulla. In accumsan odio vel tortor semper euismod. Vivamus ex orci, elementum id pellentesque nec, blandit imperdiet magna.
|
||||
|
||||
Fusce congue lectus pulvinar odio finibus semper. Donec id quam dignissim, suscipit elit pharetra, scelerisque enim. Cras sit amet consectetur nisl. Fusce ornare velit lectus, a volutpat est finibus quis. Vestibulum dui odio, facilisis vel neque eu, blandit placerat purus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent quis nunc fermentum, rutrum velit nec, feugiat odio. Quisque euismod nunc eu orci pharetra, eu egestas lectus hendrerit. Vivamus interdum, felis ac fringilla volutpat, elit purus rhoncus dui, ac vulputate turpis elit a nunc. Integer et nisl quis sapien euismod tempus. Duis feugiat leo a ipsum aliquam elementum nec non sapien. Mauris egestas lorem fermentum nisi mollis consequat. Donec velit elit, ornare vel erat at, placerat consequat ex.
|
||||
|
||||
Sed gravida fermentum sapien, nec finibus odio imperdiet eu. Phasellus ornare non dui ac blandit. Fusce eu tristique dolor. Vivamus non interdum nisl. Mauris feugiat euismod purus sit amet bibendum. Nullam sit amet libero nec dui viverra lobortis. Phasellus quis velit in risus maximus fringilla.
|
||||
|
||||
Nullam sed ipsum mollis ante lacinia ornare sed quis massa. Pellentesque finibus accumsan odio commodo fermentum. Morbi malesuada tincidunt tellus sit amet interdum. Cras consequat posuere maximus. In mauris metus, ornare vel augue id, ornare aliquam leo. Sed sapien mauris, laoreet rhoncus pharetra eget, placerat vel quam. Curabitur congue varius tellus vel porttitor. Ut ornare semper sem, et maximus dolor eleifend quis. Ut fringilla est diam, eget euismod justo tempus at. Nulla egestas, dolor a mollis imperdiet, velit ligula porta urna, nec laoreet nisl neque convallis turpis. Nulla non blandit lectus.
|
||||
|
||||
Nunc gravida est ipsum, in mattis purus ultrices ac. Cras ultrices nulla interdum, pulvinar urna imperdiet, egestas dui. Morbi vitae euismod ex. In gravida id elit in ullamcorper. Sed nisl lacus, tristique ut dapibus in, mattis tristique quam. Nam pulvinar in purus id lacinia. Nulla faucibus orci elementum neque feugiat cursus. Fusce quis faucibus turpis. Phasellus eleifend rutrum elit, at viverra erat consequat id. Suspendisse vehicula, dui et dapibus tincidunt, metus metus sagittis sapien, ut sagittis neque urna ac lectus. Phasellus eleifend, augue ut facilisis elementum, quam nisi ornare diam, sit amet accumsan leo justo id augue. Aenean feugiat, leo vitae semper rutrum, velit odio vulputate enim, eget finibus dui eros in dui. Aenean aliquet metus sed est malesuada, sit amet posuere purus rutrum. Ut sed iaculis mauris. Proin at arcu congue, auctor diam pulvinar, iaculis magna.
|
||||
|
||||
Suspendisse faucibus dapibus nisl, imperdiet tristique nibh lobortis sodales. Integer pretium laoreet dui non molestie. Morbi dignissim sit amet ex at semper. Proin venenatis augue quis magna aliquam, molestie ultricies sem auctor. Nulla ullamcorper eros dolor, at efficitur nunc egestas id. Integer leo eros, suscipit pharetra pharetra fringilla, tempus sed quam. Nam eu fringilla metus. Quisque in dolor turpis.
|
||||
|
||||
Integer faucibus ligula at vulputate mattis. Donec in fringilla metus, vel consequat dui. Pellentesque et maximus massa. Aenean iaculis, neque in vestibulum gravida, ligula lorem interdum libero, ut luctus justo purus a neque. Fusce luctus placerat hendrerit. Integer tempor, nibh eget viverra bibendum, massa est lobortis lectus, et pretium mi odio eu justo. Suspendisse et commodo eros. Quisque consectetur quam libero, nec pulvinar nunc lacinia eget. Nunc vulputate blandit risus, vitae viverra ante pharetra id.
|
||||
|
||||
Mauris convallis neque id hendrerit elementum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales orci felis, rutrum dapibus velit sodales vitae. Donec rhoncus fringilla neque sit amet blandit. Donec vel nisl volutpat, porta ligula a, dignissim massa. Praesent varius, orci a congue lobortis, nisi odio finibus felis, finibus gravida ligula ipsum maximus eros. Vestibulum id diam ac augue lobortis molestie. In hac habitasse platea dictumst. Quisque vulputate maximus gravida. Donec lobortis, velit in tempus cursus, sapien libero cursus ante, at ornare arcu massa id risus. Etiam metus erat, commodo vitae sodales sed, dignissim a metus. Aliquam eros ligula, dictum sit amet quam ullamcorper, iaculis congue quam. Vestibulum sollicitudin interdum enim vel aliquam. Fusce et leo sit amet nibh consectetur fringilla.
|
||||
|
||||
Nullam ultrices est tincidunt turpis pellentesque, eget dapibus quam laoreet. Maecenas convallis suscipit nunc sed dignissim. Aliquam ex turpis, congue quis porttitor quis, efficitur nec sapien. Vivamus mattis elementum posuere. Aenean quis eros vitae sapien rhoncus posuere. Donec ultricies elit sed arcu ultrices imperdiet ut quis sem. Nullam sit amet mauris suscipit, porta massa at, porttitor leo. Duis tempor purus nec mollis pretium. Ut bibendum posuere mollis. Nulla vehicula, sapien id bibendum eleifend, ipsum est rhoncus ante, eget pulvinar justo magna a ante. Sed luctus arcu hendrerit, auctor sem ac, rhoncus tellus. Integer eu quam scelerisque, eleifend massa eu, congue sem.
|
||||
@@ -0,0 +1,13 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut nec mattis ipsum. Aliquam faucibus, augue quis faucibus scelerisque, sapien eros consequat erat, in semper quam nisi id ex. In viverra pulvinar tortor, non mollis eros ornare a. Praesent sagittis tincidunt ante, sed vulputate tellus faucibus quis. Sed efficitur, mi eu fringilla lobortis, lacus nisl aliquet ante, nec fermentum felis dui vel nunc. Fusce luctus rutrum ligula, sit amet suscipit est sollicitudin at. Suspendisse convallis ac dui a porttitor. Ut eget efficitur odio. In a facilisis quam, in imperdiet libero. Cras a orci in mi accumsan elementum. Duis at venenatis neque. Sed vel tellus ex.
|
||||
|
||||
Nam non velit at nunc tempus cursus ut vel ipsum. Nam nec nisi a nisl pellentesque faucibus ut et purus. Nulla in felis efficitur, facilisis turpis volutpat, consequat nisi. Vivamus ullamcorper euismod ex, et lobortis erat tristique id. Etiam rhoncus ante non eros lacinia, in porttitor lorem blandit. Duis porta malesuada blandit. Suspendisse tincidunt id dolor non semper. Morbi et enim sem. Proin vitae elit purus. Phasellus vel enim eget nisl tristique fringilla ac sit amet leo. In malesuada commodo condimentum. Aliquam erat volutpat. Curabitur et nibh nulla. In accumsan odio vel tortor semper euismod. Vivamus ex orci, elementum id pellentesque nec, blandit imperdiet magna.
|
||||
|
||||
Fusce congue lectus pulvinar odio finibus semper. Donec id quam dignissim, suscipit elit pharetra, scelerisque enim. Cras sit amet consectetur nisl. Fusce ornare velit lectus, a volutpat est finibus quis. Vestibulum dui odio, facilisis vel neque eu, blandit placerat purus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent quis nunc fermentum, rutrum velit nec, feugiat odio. Quisque euismod nunc eu orci pharetra, eu egestas lectus hendrerit. Vivamus interdum, felis ac fringilla volutpat, elit purus rhoncus dui, ac vulputate turpis elit a nunc. Integer et nisl quis sapien euismod tempus. Duis feugiat leo a ipsum aliquam elementum nec non sapien. Mauris egestas lorem fermentum nisi mollis consequat. Donec velit elit, ornare vel erat at, placerat consequat ex.
|
||||
|
||||
Sed gravida fermentum sapien, nec finibus odio imperdiet eu. Phasellus ornare non dui ac blandit. Fusce eu tristique dolor. Vivamus non interdum nisl. Mauris feugiat euismod purus sit amet bibendum. Nullam sit amet libero nec dui viverra lobortis. Phasellus quis velit in risus maximus fringilla.
|
||||
|
||||
Nullam sed ipsum mollis ante lacinia ornare sed quis massa. Pellentesque finibus accumsan odio commodo fermentum. Morbi malesuada tincidunt tellus sit amet interdum. Cras consequat posuere maximus. In mauris metus, ornare vel augue id, ornare aliquam leo. Sed sapien mauris, laoreet rhoncus pharetra eget, placerat vel quam. Curabitur congue varius tellus vel porttitor. Ut ornare semper sem, et maximus dolor eleifend quis. Ut fringilla est diam, eget euismod justo tempus at. Nulla egestas, dolor a mollis imperdiet, velit ligula porta urna, nec laoreet nisl neque convallis turpis. Nulla non blandit lectus.
|
||||
|
||||
Mauris convallis neque id hendrerit elementum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales orci felis, rutrum dapibus velit sodales vitae. Donec rhoncus fringilla neque sit amet blandit. Donec vel nisl volutpat, porta ligula a, dignissim massa. Praesent varius, orci a congue lobortis, nisi odio finibus felis, finibus gravida ligula ipsum maximus eros. Vestibulum id diam ac augue lobortis molestie. In hac habitasse platea dictumst. Quisque vulputate maximus gravida. Donec lobortis, velit in tempus cursus, sapien libero cursus ante, at ornare arcu massa id risus. Etiam metus erat, commodo vitae sodales sed, dignissim a metus. Aliquam eros ligula, dictum sit amet quam ullamcorper, iaculis congue quam. Vestibulum sollicitudin interdum enim vel aliquam. Fusce et leo sit amet nibh consectetur fringilla.
|
||||
|
||||
Nullam ultrices est tincidunt turpis pellentesque, eget dapibus quam laoreet. Maecenas convallis suscipit nunc sed dignissim. Aliquam ex turpis, congue quis porttitor quis, efficitur nec sapien. Vivamus mattis elementum posuere. Aenean quis eros vitae sapien rhoncus posuere. Donec ultricies elit sed arcu ultrices imperdiet ut quis sem. Nulla vehicula, sapien id bibendum eleifend, ipsum est rhoncus ante, eget pulvinar justo magna a ante. Sed luctus arcu hendrerit, auctor sem ac, rhoncus tellus. Integer eu quam scelerisque, eleifend massa eu, congue sem.
|
||||
@@ -0,0 +1,19 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut nec mattis ipsum. Aliquam faucibus, augue quis faucibus scelerisque, sapien eros consequat erat, in semper quam nisi id ex. In viverra pulvinar tortor, non mollis eros ornare a. Praesent sagittis tincidunt ante, sed vulputate tellus faucibus quis. Sed efficitur, mi eu fringilla lobortis, lacus nisl aliquet ante, nec fermentum felis dui vel nunc. Fusce luctus rutrum ligula, sit amet suscipit est sollicitudin at. Suspendisse convallis ac dui a porttitor. Ut eget efficitur odio. In a facilisis quam, in imperdiet libero. Cras a orci in mi accumsan elementum. Duis at venenatis neque. Sed vel tellus ex.
|
||||
|
||||
Nam non velit at nunc tempus cursus ut vel ipsum. Nam nec nisi a nisl pellentesque faucibus ut et purus. Nulla in felis efficitur, facilisis turpis volutpat, consequat nisi. Vivamus ullamcorper euismod ex, et lobortis erat tristique id. Etiam rhoncus ante non eros lacinia, in porttitor lorem blandit. Duis porta malesuada blandit. Suspendisse tincidunt id dolor non semper. Morbi et enim sem. Proin vitae elit purus. Phasellus vel enim eget nisl tristique fringilla ac sit amet leo. In malesuada commodo condimentum. Aliquam erat volutpat. Curabitur et nibh nulla. In accumsan odio vel tortor semper euismod. Vivamus ex orci, elementum id pellentesque nec, blandit imperdiet magna.
|
||||
|
||||
Fusce congue lectus pulvinar odio finibus semper. Donec id quam dignissim, suscipit elit pharetra, scelerisque enim. Cras sit amet consectetur nisl. Fusce ornare velit lectus, a volutpat est finibus quis. Vestibulum dui odio, facilisis vel neque eu, blandit placerat purus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent quis nunc fermentum, rutrum velit nec, feugiat odio. Quisque euismod nunc eu orci pharetra, eu egestas lectus hendrerit. Vivamus interdum, felis ac fringilla volutpat, elit purus rhoncus dui, ac vulputate turpis elit a nunc. Integer et nisl quis sapien euismod tempus. Duis feugiat leo a ipsum aliquam elementum nec non sapien. Mauris egestas lorem fermentum nisi mollis consequat. Donec velit elit, ornare vel erat at, placerat consequat ex.
|
||||
|
||||
Sed gravida fermentum sapien, nec finibus odio imperdiet eu. Phasellus ornare non dui ac blandit. Fusce eu tristique dolor. Vivamus non interdum nisl. Mauris feugiat euismod purus sit amet bibendum. Nullam sit amet libero nec dui viverra lobortis. Phasellus quis velit in risus maximus fringilla.
|
||||
|
||||
Nullam sed ipsum mollis ante lacinia ornare sed quis massa. Pellentesque finibus accumsan odio commodo fermentum. Morbi malesuada tincidunt tellus sit amet interdum. Cras consequat posuere maximus. In mauris metus, ornare vel augue id, ornare aliquam leo. Sed sapien mauris, laoreet rhoncus pharetra eget, placerat vel quam. Curabitur congue varius tellus vel porttitor. Ut ornare semper sem, et maximus dolor eleifend quis. Ut fringilla est diam, eget euismod justo tempus at. Nulla egestas, dolor a mollis imperdiet, velit ligula porta urna, nec laoreet nisl neque convallis turpis. Nulla non blandit lectus.
|
||||
|
||||
Nunc gravida est ipsum, in mattis purus ultrices ac. Cras ultrices nulla interdum, pulvinar urna imperdiet, egestas dui. Morbi vitae euismod ex. In gravida id elit in ullamcorper. Sed nisl lacus, tristique ut dapibus in, mattis tristique quam. Nam pulvinar in purus id lacinia. Nulla faucibus orci elementum neque feugiat cursus. Fusce quis faucibus turpis. Phasellus eleifend rutrum elit, at viverra erat consequat id. Suspendisse vehicula, dui et dapibus tincidunt, metus metus sagittis sapien, ut sagittis neque urna ac lectus. Phasellus eleifend, augue ut facilisis elementum, quam nisi ornare diam, sit amet accumsan leo justo id augue. Aenean feugiat, leo vitae semper rutrum, velit odio vulputate enim, eget finibus dui eros in dui. Aenean aliquet metus sed est malesuada, sit amet posuere purus rutrum. Ut sed iaculis mauris. Proin at arcu congue, auctor diam pulvinar, iaculis magna.
|
||||
|
||||
Suspendisse faucibus dapibus nisl, imperdiet tristique nibh lobortis sodales. Integer pretium laoreet dui non molestie. Morbi dignissim sit amet ex at semper. Proin venenatis augue quis magna aliquam, molestie ultricies sem auctor. Nulla ullamcorper eros dolor, at efficitur nunc egestas id. Integer leo eros, suscipit pharetra pharetra fringilla, tempus sed quam. Nam eu fringilla metus. Quisque in dolor turpis.
|
||||
|
||||
Integer faucibus ligula at vulputate mattis. Donec in fringilla metus, vel consequat dui. Pellentesque et maximus massa. Aenean iaculis, neque in vestibulum gravida, ligula lorem interdum libero, ut luctus justo purus a neque. Fusce luctus placerat hendrerit. Integer tempor, nibh eget viverra bibendum, massa est lobortis lectus, et pretium mi odio eu justo. Suspendisse et commodo eros. Quisque consectetur quam libero, nec pulvinar nunc lacinia eget. Nunc vulputate blandit risus, vitae viverra ante pharetra id.
|
||||
|
||||
Mauris convallis neque id hendrerit elementum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales orci felis, rutrum dapibus velit sodales vitae. Donec rhoncus fringilla neque sit amet blandit. Donec vel nisl volutpat, porta ligula a, dignissim massa. Praesent varius, orci a congue lobortis, nisi odio finibus felis, finibus gravida ligula ipsum maximus eros. Vestibulum id diam ac augue lobortis molestie. In hac habitasse platea dictumst. Quisque vulputate maximus gravida. Donec lobortis, velit in tempus cursus, sapien libero cursus ante, at ornare arcu massa id risus. Etiam metus erat, commodo vitae sodales sed, dignissim a metus. Aliquam eros ligula, dictum sit amet quam ullamcorper, iaculis congue quam. Vestibulum sollicitudin interdum enim vel aliquam. Fusce et leo sit amet nibh consectetur fringilla.
|
||||
|
||||
Nullam ultrices est tincidunt turpis pellentesque, eget dapibus quam laoreet. Maecenas convallis suscipit nunc sed dignissim. Aliquam ex turpis, congue quis porttitor quis, efficitur nec sapien. Vivamus mattis elementum posuere. Aenean quis eros vitae sapien rhoncus posuere. Donec ultricies elit sed arcu ultrices imperdiet ut quis sem. Nullam sit amet mauris suscipit, porta massa at, porttitor leo. Duis tempor purus nec mollis pretium. Ut bibendum posuere mollis. Nulla vehicula, sapien id bibendum eleifend, ipsum est rhoncus ante, eget pulvinar justo magna a ante. Sed luctus arcu hendrerit, auctor sem ac, rhoncus tellus. Integer eu quam scelerisque, eleifend massa eu, congue sem.
|
||||
@@ -0,0 +1,25 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut nec mattis ipsum. Aliquam faucibus, augue quis faucibus scelerisque, sapien eros consequat erat, in semper quam nisi id ex. In viverra pulvinar tortor, non mollis eros ornare a. Praesent sagittis tincidunt ante, sed vulputate tellus faucibus quis. Sed efficitur, mi eu fringilla lobortis, lacus nisl aliquet ante, nec fermentum felis dui vel nunc. Fusce luctus rutrum ligula, sit amet suscipit est sollicitudin at. Suspendisse convallis ac dui a porttitor. Ut eget efficitur odio. In a facilisis quam, in imperdiet libero. Cras a orci in mi accumsan elementum. Duis at venenatis neque. Sed vel tellus ex.
|
||||
|
||||
Nam non velit at nunc tempus cursus ut vel ipsum. Nam nec nisi a nisl pellentesque faucibus ut et purus. Nulla in felis efficitur, facilisis turpis volutpat, consequat nisi. Vivamus ullamcorper euismod ex, et lobortis erat tristique id. Etiam rhoncus ante non eros lacinia, in porttitor lorem blandit. Duis porta malesuada blandit. Suspendisse tincidunt id dolor non semper. Morbi et enim sem. Proin vitae elit purus. Phasellus vel enim eget nisl tristique fringilla ac sit amet leo. In malesuada commodo condimentum. Aliquam erat volutpat. Curabitur et nibh nulla. In accumsan odio vel tortor semper euismod. Vivamus ex orci, elementum id pellentesque nec, blandit imperdiet magna.
|
||||
|
||||
Fusce congue lectus pulvinar odio finibus semper. Donec id quam dignissim, suscipit elit pharetra, scelerisque enim. Cras sit amet consectetur nisl. Fusce ornare velit lectus, a volutpat est finibus quis. Vestibulum dui odio, facilisis vel neque eu, blandit placerat purus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent quis nunc fermentum, rutrum velit nec, feugiat odio. Quisque euismod nunc eu orci pharetra, eu egestas lectus hendrerit. Vivamus interdum, felis ac fringilla volutpat, elit purus rhoncus dui, ac vulputate turpis elit a nunc. Integer et nisl quis sapien euismod tempus. Duis feugiat leo a ipsum aliquam elementum nec non sapien. Mauris egestas lorem fermentum nisi mollis consequat. Donec velit elit, ornare vel erat at, placerat consequat ex.
|
||||
|
||||
Sed gravida fermentum sapien, nec finibus odio imperdiet eu. Phasellus ornare non dui ac blandit. Fusce eu tristique dolor. Vivamus non interdum nisl. Mauris feugiat euismod purus sit amet bibendum. Nullam sit amet libero nec dui viverra lobortis. Phasellus quis velit in risus maximus fringilla.
|
||||
|
||||
Nullam sed ipsum mollis ante lacinia ornare sed quis massa. Pellentesque finibus accumsan odio commodo fermentum. Morbi malesuada tincidunt tellus sit amet interdum. Cras consequat posuere maximus. In mauris metus, ornare vel augue id, ornare aliquam leo. Sed sapien mauris, laoreet rhoncus pharetra eget, placerat vel quam. Curabitur congue varius tellus vel porttitor. Ut ornare semper sem, et maximus dolor eleifend quis. Ut fringilla est diam, eget euismod justo tempus at. Nulla egestas, dolor a mollis imperdiet, velit ligula porta urna, nec laoreet nisl neque convallis turpis. Nulla non blandit lectus.
|
||||
|
||||
Nunc gravida est ipsum, in mattis purus ultrices ac. Cras ultrices nulla interdum, pulvinar urna imperdiet, egestas dui. Morbi vitae euismod ex. In gravida id elit in ullamcorper. Sed nisl lacus, tristique ut dapibus in, mattis tristique quam. Nam pulvinar in purus id lacinia. Nulla faucibus orci elementum neque feugiat cursus. Fusce quis faucibus turpis. Phasellus eleifend rutrum elit, at viverra erat consequat id. Suspendisse vehicula, dui et dapibus tincidunt, metus metus sagittis sapien, ut sagittis neque urna ac lectus. Phasellus eleifend, augue ut facilisis elementum, quam nisi ornare diam, sit amet accumsan leo justo id augue. Aenean feugiat, leo vitae semper rutrum, velit odio vulputate enim, eget finibus dui eros in dui. Aenean aliquet metus sed est malesuada, sit amet posuere purus rutrum. Ut sed iaculis mauris. Proin at arcu congue, auctor diam pulvinar, iaculis magna.
|
||||
|
||||
Sed gravida fermentum sapien, nec finibus odio imperdiet eu. Phasellus ornare non dui ac blandit. Fusce eu tristique dolor. Vivamus non interdum nisl. Mauris feugiat euismod purus sit amet bibendum. Nullam sit amet libero nec dui viverra lobortis. Phasellus quis velit in risus maximus fringilla.
|
||||
|
||||
Nullam sed ipsum mollis ante lacinia ornare sed quis massa. Pellentesque finibus accumsan odio commodo fermentum. Morbi malesuada tincidunt tellus sit amet interdum. Cras consequat posuere maximus. In mauris metus, ornare vel augue id, ornare aliquam leo. Sed sapien mauris, laoreet rhoncus pharetra eget, placerat vel quam. Curabitur congue varius tellus vel porttitor. Ut ornare semper sem, et maximus dolor eleifend quis. Ut fringilla est diam, eget euismod justo tempus at. Nulla egestas, dolor a mollis imperdiet, velit ligula porta urna, nec laoreet nisl neque convallis turpis. Nulla non blandit lectus.
|
||||
|
||||
Mauris convallis neque id hendrerit elementum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales orci felis, rutrum dapibus velit sodales vitae. Donec rhoncus fringilla neque sit amet blandit. Donec vel nisl volutpat, porta ligula a, dignissim massa. Praesent varius, orci a congue lobortis, nisi odio finibus felis, finibus gravida ligula ipsum maximus eros. Vestibulum id diam ac augue lobortis molestie. In hac habitasse platea dictumst. Quisque vulputate maximus gravida. Donec lobortis, velit in tempus cursus, sapien libero cursus ante, at ornare arcu massa id risus. Etiam metus erat, commodo vitae sodales sed, dignissim a metus. Aliquam eros ligula, dictum sit amet quam ullamcorper, iaculis congue quam. Vestibulum sollicitudin interdum enim vel aliquam. Fusce et leo sit amet nibh consectetur fringilla.
|
||||
|
||||
Suspendisse faucibus dapibus nisl, imperdiet tristique nibh lobortis sodales. Integer pretium laoreet dui non molestie. Morbi dignissim sit amet ex at semper. Proin venenatis augue quis magna aliquam, molestie ultricies sem auctor. Nulla ullamcorper eros dolor, at efficitur nunc egestas id. Integer leo eros, suscipit pharetra pharetra fringilla, tempus sed quam. Nam eu fringilla metus. Quisque in dolor turpis.
|
||||
|
||||
Integer faucibus ligula at vulputate mattis. Donec in fringilla metus, vel consequat dui. Pellentesque et maximus massa. Aenean iaculis, neque in vestibulum gravida, ligula lorem interdum libero, ut luctus justo purus a neque. Fusce luctus placerat hendrerit. Integer tempor, nibh eget viverra bibendum, massa est lobortis lectus, et pretium mi odio eu justo. Suspendisse et commodo eros. Quisque consectetur quam libero, nec pulvinar nunc lacinia eget. Nunc vulputate blandit risus, vitae viverra ante pharetra id.
|
||||
|
||||
Mauris convallis neque id hendrerit elementum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales orci felis, rutrum dapibus velit sodales vitae. Donec rhoncus fringilla neque sit amet blandit. Donec vel nisl volutpat, porta ligula a, dignissim massa. Praesent varius, orci a congue lobortis, nisi odio finibus felis, finibus gravida ligula ipsum maximus eros. Vestibulum id diam ac augue lobortis molestie. In hac habitasse platea dictumst. Quisque vulputate maximus gravida. Donec lobortis, velit in tempus cursus, sapien libero cursus ante, at ornare arcu massa id risus. Etiam metus erat, commodo vitae sodales sed, dignissim a metus. Aliquam eros ligula, dictum sit amet quam ullamcorper, iaculis congue quam. Vestibulum sollicitudin interdum enim vel aliquam. Fusce et leo sit amet nibh consectetur fringilla.
|
||||
|
||||
Nullam ultrices est tincidunt turpis pellentesque, eget dapibus quam laoreet. Maecenas convallis suscipit nunc sed dignissim. Aliquam ex turpis, congue quis porttitor quis, efficitur nec sapien. Vivamus mattis elementum posuere. Aenean quis eros vitae sapien rhoncus posuere. Donec ultricies elit sed arcu ultrices imperdiet ut quis sem. Nullam sit amet mauris suscipit, porta massa at, porttitor leo. Duis tempor purus nec mollis pretium. Ut bibendum posuere mollis. Nulla vehicula, sapien id bibendum eleifend, ipsum est rhoncus ante, eget pulvinar justo magna a ante. Sed luctus arcu hendrerit, auctor sem ac, rhoncus tellus. Integer eu quam scelerisque, eleifend massa eu, congue sem.
|
||||
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
--- a.txt
|
||||
+++ a1.txt
|
||||
@@ -8,7 +8,7 @@
|
||||
<Setting>
|
||||
<Setting a>
|
||||
<setting b>
|
||||
- <value>23</value>
|
||||
+ <value>24</value>
|
||||
</setting b>
|
||||
<setting c>
|
||||
<value>1</value>
|
||||
@@ -0,0 +1,4 @@
|
||||
diff --git a/some-image.png b/some-image.png
|
||||
new file mode 100644
|
||||
index 0000000..bc3b5b4
|
||||
Binary files /dev/null and b/some-image.png differ
|
||||
@@ -0,0 +1,4 @@
|
||||
diff --git a/some-image.png b/some-image.png
|
||||
deleted file mode 100644
|
||||
index 0e68078..0000000
|
||||
Binary files a/some-image.png and /dev/null differ
|
||||
@@ -0,0 +1,3 @@
|
||||
diff --git a/some-image.png b/some-image.png
|
||||
index bc3b5b4..0e68078 100644
|
||||
Binary files a/some-image.png and b/some-image.png differ
|
||||
@@ -0,0 +1,3 @@
|
||||
diff --git a/some-image.png b/some-image.png
|
||||
old mode 100644
|
||||
new mode 100755
|
||||
@@ -0,0 +1,26 @@
|
||||
diff --git src://modules/configuration/config/web/pcf/account/AccountContactCV.pcf dst://modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
|
||||
similarity index 99%
|
||||
copy from modules/configuration/config/web/pcf/account/AccountContactCV.pcf
|
||||
copy to modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
|
||||
index 13efef5778..1a08b0befc 100644
|
||||
--- src://modules/configuration/config/web/pcf/account/AccountContactCV.pcf
|
||||
+++ dst://modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
|
||||
@@ -1,16 +1,17 @@
|
||||
<?xml version="1.0"?>
|
||||
<PCF
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../../../pcf.xsd">
|
||||
<CardViewPanel
|
||||
- id="AccountContactCV">
|
||||
+ id="AccountContactCV"
|
||||
+ mode="default">
|
||||
<Require
|
||||
name="acctContact"
|
||||
type="AccountContact"/>
|
||||
<Require
|
||||
name="showAddressTools"
|
||||
type="boolean"/>
|
||||
<Require
|
||||
name="showRolesTab"
|
||||
type="boolean"/>
|
||||
<Variable
|
||||
@@ -0,0 +1,95 @@
|
||||
//According to the original text, an html will be generated by comparing the text
|
||||
public class generateDiffHtmlTest {
|
||||
/**
|
||||
* Here's a simple example of getting a nice html page based on the original text and the contrasted text,Read n1.txt and n2.txt of D disk, and finally generate an html file
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public static void generateOriginalAndDiffDemo(){
|
||||
List<String> origLines = getFileContent("D:\\n1.txt");
|
||||
List<String> revLines =getFileContent("D:\\n2.txt");
|
||||
List<String> originalAndDiff =UnifiedDiffUtils.generateOriginalAndDiff(origLines, revLines);
|
||||
//System.out.println(originalAndDiff.size());
|
||||
generateDiffHtml(originalAndDiff,"D:\\diff.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* get file content
|
||||
* @param filePath file path
|
||||
*/
|
||||
public static List<String> getFileContent(String filePath) {
|
||||
//origin
|
||||
List<String> fileContent =null;
|
||||
File file = new File(filePath);
|
||||
try {
|
||||
fileContent = Files.readAllLines(file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The html file is generated by the difference diff between the two files, and the detailed content of the file comparison can be seen by opening the html file
|
||||
*
|
||||
*/
|
||||
public static void generateDiffHtml(List<String> diffString, String htmlPath) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String line : diffString) {
|
||||
builder.append(line);
|
||||
builder.append("\n");
|
||||
}
|
||||
String githubCss = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.1/styles/github.min.css";
|
||||
String diff2htmlCss = "https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css";
|
||||
String diff2htmlJs = "https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js";
|
||||
|
||||
String template = "<!DOCTYPE html>\n" +
|
||||
"<html lang=\"en-us\">\n" +
|
||||
" <head>\n" +
|
||||
" <meta charset=\"utf-8\" />\n" +
|
||||
" <link rel=\"stylesheet\" href=\"" + githubCss + "\" />\n" +
|
||||
" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + diff2htmlCss + "\" />\n" +
|
||||
" <script type=\"text/javascript\" src=\"" + diff2htmlJs + "\"></script>\n" +
|
||||
" </head>\n" +
|
||||
" <script>\n" +
|
||||
" const diffString = `\n" +
|
||||
"temp\n" +
|
||||
"`;\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" document.addEventListener('DOMContentLoaded', function () {\n" +
|
||||
" var targetElement = document.getElementById('myDiffElement');\n" +
|
||||
" var configuration = {\n" +
|
||||
" drawFileList: true,\n" +
|
||||
" fileListToggle: true,\n" +
|
||||
" fileListStartVisible: true,\n" +
|
||||
" fileContentToggle: true,\n" +
|
||||
" matching: 'lines',\n" +
|
||||
" outputFormat: 'side-by-side',\n" +
|
||||
" synchronisedScroll: true,\n" +
|
||||
" highlight: true,\n" +
|
||||
" renderNothingWhenEmpty: true,\n" +
|
||||
" };\n" +
|
||||
" var diff2htmlUi = new Diff2HtmlUI(targetElement, diffString, configuration);\n" +
|
||||
" diff2htmlUi.draw();\n" +
|
||||
" diff2htmlUi.highlightCode();\n" +
|
||||
" });\n" +
|
||||
" </script>\n" +
|
||||
" <body>\n" +
|
||||
" <div id=\"myDiffElement\"></div>\n" +
|
||||
" </body>\n" +
|
||||
"</html>";
|
||||
template = template.replace("temp", builder.toString());
|
||||
FileWriter fileWriter = null;
|
||||
try {
|
||||
fileWriter = new FileWriter(htmlPath);
|
||||
BufferedWriter buf = new BufferedWriter(fileWriter);
|
||||
buf.write(template);
|
||||
buf.close();
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
114
java-diff-utils/src/test/resources/mocks/issue_170_revised.txt
Normal file
114
java-diff-utils/src/test/resources/mocks/issue_170_revised.txt
Normal file
@@ -0,0 +1,114 @@
|
||||
package com.github.difflib.examples;
|
||||
|
||||
import com.github.difflib.UnifiedDiffUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
// According to the original text, an html will be generated by comparing the text.
|
||||
public class generateDiffHtmlTest {
|
||||
|
||||
/**
|
||||
* Here's a simple example of getting a nice html page based on the original text and the contrasted text,
|
||||
* Read n1.txt and n2.txt of D disk, and finally generate an html file
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public static void generateOriginalAndDiffDemo(){
|
||||
List<String> origLines = getFileContent("D:\\n1.txt");
|
||||
List<String> revLines = getFileContent("D:\\n2.txt");
|
||||
List<String> originalAndDiff = UnifiedDiffUtils.generateOriginalAndDiff(origLines, revLines);
|
||||
|
||||
//generateDiffHtml
|
||||
generateDiffHtml(originalAndDiff,"D:\\diff.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* get file content
|
||||
*
|
||||
* @param filePath file path
|
||||
*/
|
||||
public static List<String> getFileContent(String filePath) {
|
||||
//原始文件
|
||||
List<String> fileContent = null;
|
||||
File file = new File(filePath);
|
||||
try {
|
||||
fileContent = Files.readAllLines(file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The html file is generated by the difference diff between the two files,
|
||||
* and the detailed content of the file comparison can be seen by opening the html file
|
||||
*
|
||||
* @param diffString The comparison result obtained by calling the above diffString method
|
||||
* @param htmlPath Generated html path,e.g:/user/var/mbos/ent/21231/diff.html
|
||||
*/
|
||||
public static void generateDiffHtml(List<String> diffString, String htmlPath) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String line : diffString) {
|
||||
builder.append(line);
|
||||
builder.append("\n");
|
||||
}
|
||||
String githubCss = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.1/styles/github.min.css";
|
||||
String diff2htmlCss = "https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css";
|
||||
String diff2htmlJs = "https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js";
|
||||
|
||||
String template = "<!DOCTYPE html>\n" +
|
||||
"<html lang=\"en-us\">\n" +
|
||||
" <head>\n" +
|
||||
" <meta charset=\"utf-8\" />\n" +
|
||||
" <link rel=\"stylesheet\" href=\"" + githubCss + "\" />\n" +
|
||||
" <link rel=\"stylesheet\" type=\"text/css\" href=\"" + diff2htmlCss + "\" />\n" +
|
||||
" <script type=\"text/javascript\" src=\"" + diff2htmlJs + "\"></script>\n" +
|
||||
" </head>\n" +
|
||||
" <script>\n" +
|
||||
" const diffString = `\n" +
|
||||
"temp\n" +
|
||||
"`;\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" document.addEventListener('DOMContentLoaded', function () {\n" +
|
||||
" var targetElement = document.getElementById('myDiffElement');\n" +
|
||||
" var configuration = {\n" +
|
||||
" drawFileList: true,\n" +
|
||||
" fileListToggle: true,\n" +
|
||||
" fileListStartVisible: true,\n" +
|
||||
" fileContentToggle: true,\n" +
|
||||
" matching: 'lines',\n" +
|
||||
" outputFormat: 'side-by-side',\n" +
|
||||
" synchronisedScroll: true,\n" +
|
||||
" highlight: true,\n" +
|
||||
" renderNothingWhenEmpty: true,\n" +
|
||||
" };\n" +
|
||||
" var diff2htmlUi = new Diff2HtmlUI(targetElement, diffString, configuration);\n" +
|
||||
" diff2htmlUi.draw();\n" +
|
||||
" diff2htmlUi.highlightCode();\n" +
|
||||
" });\n" +
|
||||
" </script>\n" +
|
||||
" <body>\n" +
|
||||
" <div id=\"myDiffElement\"></div>\n" +
|
||||
" </body>\n" +
|
||||
"</html>";
|
||||
template = template.replace("temp", builder.toString());
|
||||
FileWriter fileWriter = null;
|
||||
try {
|
||||
fileWriter = new FileWriter(htmlPath);
|
||||
BufferedWriter buf = new BufferedWriter(fileWriter);
|
||||
buf.write(template);
|
||||
buf.close();
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
pom.xml
17
pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.github.java-diff-utils</groupId>
|
||||
<artifactId>java-diff-utils-parent</artifactId>
|
||||
<version>4.11-SNAPSHOT</version>
|
||||
<version>4.15</version>
|
||||
<name>java-diff-utils-parent</name>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
@@ -29,7 +29,7 @@
|
||||
<connection>scm:git:https://github.com/java-diff-utils/java-diff-utils.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com:java-diff-utils/java-diff-utils.git</developerConnection>
|
||||
<url>https://github.com/java-diff-utils/java-diff-utils.git</url>
|
||||
<tag>HEAD</tag>
|
||||
<tag>java-diff-utils-parent-4.15</tag>
|
||||
</scm>
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
@@ -65,13 +65,13 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.7.1</version>
|
||||
<version>5.11.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.19.0</version>
|
||||
<version>3.26.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -86,12 +86,13 @@
|
||||
<localCheckout>true</localCheckout>
|
||||
<pushChanges>false</pushChanges>
|
||||
<mavenExecutorId>forked-path</mavenExecutorId>
|
||||
<releaseProfiles>sign-release-artifacts</releaseProfiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.5.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>bundle-manifest</id>
|
||||
@@ -122,7 +123,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>verify-style</id>
|
||||
@@ -176,7 +177,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M4</version>
|
||||
<version>3.5.2</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/LR*.java</exclude>
|
||||
@@ -199,7 +200,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.4</version>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
|
||||
Reference in New Issue
Block a user