Skip to content

Commit 08c9d9e

Browse files
authored
Merge branch 'master' into master
2 parents d48a04e + 0f8365b commit 08c9d9e

File tree

13 files changed

+126
-28
lines changed

13 files changed

+126
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Just add the code below to your maven dependencies:
125125
<dependency>
126126
<groupId>io.github.java-diff-utils</groupId>
127127
<artifactId>java-diff-utils</artifactId>
128-
<version>4.12</version>
128+
<version>4.15</version>
129129
</dependency>
130130
```
131131

java-diff-utils-jgit/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.github.java-diff-utils</groupId>
66
<artifactId>java-diff-utils-parent</artifactId>
7-
<version>4.13-SNAPSHOT</version>
7+
<version>4.16-SNAPSHOT</version>
88
</parent>
99
<artifactId>java-diff-utils-jgit</artifactId>
1010
<name>java-diff-utils-jgit</name>

java-diff-utils/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>io.github.java-diff-utils</groupId>
99
<artifactId>java-diff-utils-parent</artifactId>
10-
<version>4.13-SNAPSHOT</version>
10+
<version>4.16-SNAPSHOT</version>
1111
</parent>
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ public static DiffAlgorithmFactory factory() {
187187
@Override
188188
public <T> DiffAlgorithmI<T>
189189
create() {
190-
return new MyersDiff<T>();
190+
return new MyersDiff<>();
191191
}
192192

193193
@Override
194194
public <T> DiffAlgorithmI<T>
195195
create(BiPredicate < T, T > equalizer) {
196-
return new MyersDiff<T>(equalizer);
196+
return new MyersDiff<>(equalizer);
197197
}
198198
};
199199
}

java-diff-utils/src/main/java/com/github/difflib/algorithm/myers/MyersDiffWithLinearSpace.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ public static DiffAlgorithmFactory factory() {
231231
@Override
232232
public <T> DiffAlgorithmI<T>
233233
create() {
234-
return new MyersDiffWithLinearSpace<T>();
234+
return new MyersDiffWithLinearSpace<>();
235235
}
236236

237237
@Override
238238
public <T> DiffAlgorithmI<T>
239239
create(BiPredicate < T, T > equalizer) {
240-
return new MyersDiffWithLinearSpace<T>(equalizer);
240+
return new MyersDiffWithLinearSpace<>(equalizer);
241241
}
242242
};
243243
}

java-diff-utils/src/main/java/com/github/difflib/text/DiffRowGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public final class DiffRowGenerator {
6969
return list;
7070
};
7171

72-
public static final Pattern SPLIT_BY_WORD_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#]");
72+
public static final Pattern SPLIT_BY_WORD_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#<>;:&\\']+");
7373

7474
/**
7575
* Splitting lines by word to achieve word by word diff checking.

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffFile.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class UnifiedDiffFile {
3030
private String toFile;
3131
private String renameFrom;
3232
private String renameTo;
33+
private String copyFrom;
34+
private String copyTo;
3335
private String toTimestamp;
3436
private String index;
3537
private String newFileMode;
@@ -119,6 +121,22 @@ public void setRenameTo(String renameTo) {
119121
this.renameTo = renameTo;
120122
}
121123

124+
public String getCopyFrom() {
125+
return copyFrom;
126+
}
127+
128+
public void setCopyFrom(String copyFrom) {
129+
this.copyFrom = copyFrom;
130+
}
131+
132+
public String getCopyTo() {
133+
return copyTo;
134+
}
135+
136+
public void setCopyTo(String copyTo) {
137+
this.copyTo = copyTo;
138+
}
139+
122140
public static UnifiedDiffFile from(String fromFile, String toFile, Patch<String> patch) {
123141
UnifiedDiffFile file = new UnifiedDiffFile();
124142
file.setFromFile(fromFile);

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public final class UnifiedDiffReader {
5151
private final UnifiedDiffLine TO_FILE = new UnifiedDiffLine(true, "^\\+\\+\\+\\s", this::processToFile);
5252
private final UnifiedDiffLine RENAME_FROM = new UnifiedDiffLine(true, "^rename\\sfrom\\s(.+)$", this::processRenameFrom);
5353
private final UnifiedDiffLine RENAME_TO = new UnifiedDiffLine(true, "^rename\\sto\\s(.+)$", this::processRenameTo);
54+
55+
private final UnifiedDiffLine COPY_FROM = new UnifiedDiffLine(true, "^copy\\sfrom\\s(.+)$", this::processCopyFrom);
56+
private final UnifiedDiffLine COPY_TO = new UnifiedDiffLine(true, "^copy\\sto\\s(.+)$", this::processCopyTo);
5457

5558
private final UnifiedDiffLine NEW_FILE_MODE = new UnifiedDiffLine(true, "^new\\sfile\\smode\\s(\\d+)", this::processNewFileMode);
5659

@@ -103,6 +106,7 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException {
103106
if (validLine(line, DIFF_COMMAND, SIMILARITY_INDEX, INDEX,
104107
FROM_FILE, TO_FILE,
105108
RENAME_FROM, RENAME_TO,
109+
COPY_FROM, COPY_TO,
106110
NEW_FILE_MODE, DELETED_FILE_MODE,
107111
OLD_MODE, NEW_MODE,
108112
BINARY_ADDED, BINARY_DELETED,
@@ -122,6 +126,7 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException {
122126
if (!processLine(line, DIFF_COMMAND, SIMILARITY_INDEX, INDEX,
123127
FROM_FILE, TO_FILE,
124128
RENAME_FROM, RENAME_TO,
129+
COPY_FROM, COPY_TO,
125130
NEW_FILE_MODE, DELETED_FILE_MODE,
126131
OLD_MODE, NEW_MODE,
127132
BINARY_ADDED , BINARY_DELETED,
@@ -344,6 +349,14 @@ private void processRenameFrom(MatchResult match, String line) {
344349
private void processRenameTo(MatchResult match, String line) {
345350
actualFile.setRenameTo(match.group(1));
346351
}
352+
353+
private void processCopyFrom(MatchResult match, String line) {
354+
actualFile.setCopyFrom(match.group(1));
355+
}
356+
357+
private void processCopyTo(MatchResult match, String line) {
358+
actualFile.setCopyTo(match.group(1));
359+
}
347360

348361
private void processNewFileMode(MatchResult match, String line) {
349362
//initFileIfNecessary();

java-diff-utils/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package com.github.difflib.text;
22

3+
import com.github.difflib.DiffUtils;
4+
import com.github.difflib.algorithm.myers.MyersDiffWithLinearSpace;
35
import java.io.File;
46
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
import java.nio.file.FileSystem;
9+
import java.nio.file.FileSystems;
510
import java.nio.file.Files;
611
import java.nio.file.Paths;
712
import java.util.Arrays;
@@ -726,7 +731,7 @@ public void testIssue129WithDeltaDecompression() {
726731

727732
assertThat(txt).isEqualTo("EQUAL EQUAL EQUAL CHANGE INSERT INSERT EQUAL EQUAL EQUAL");
728733
}
729-
734+
730735
@Test
731736
public void testIssue129SkipDeltaDecompression() {
732737
List<String> lines1 = Arrays.asList(
@@ -748,25 +753,25 @@ public void testIssue129SkipDeltaDecompression() {
748753
"banana2",
749754
"banana3");
750755
int[] entry = {1};
751-
String txt =
752-
DiffRowGenerator.create()
753-
.showInlineDiffs(true)
754-
.decompressDeltas(false)
755-
.oldTag((tag, isOpening) -> isOpening ? "==old" + tag + "==>" : "<==old==")
756-
.newTag((tag, isOpening) -> isOpening ? "==new" + tag + "==>" : "<==new==")
757-
.build()
758-
.generateDiffRows(lines1, lines2)
759-
.stream()
760-
.map(row -> row.getTag().toString())
761-
.collect(joining(" "));
756+
String txt
757+
= DiffRowGenerator.create()
758+
.showInlineDiffs(true)
759+
.decompressDeltas(false)
760+
.oldTag((tag, isOpening) -> isOpening ? "==old" + tag + "==>" : "<==old==")
761+
.newTag((tag, isOpening) -> isOpening ? "==new" + tag + "==>" : "<==new==")
762+
.build()
763+
.generateDiffRows(lines1, lines2)
764+
.stream()
765+
.map(row -> row.getTag().toString())
766+
.collect(joining(" "));
762767
// .forEachOrdered(row -> {
763768
// System.out.printf("%4d %-8s %-80s %-80s\n", entry[0]++,
764769
// row.getTag(), row.getOldLine(), row.getNewLine());
765770
// });
766771

767772
assertThat(txt).isEqualTo("EQUAL EQUAL EQUAL CHANGE CHANGE CHANGE EQUAL EQUAL EQUAL");
768773
}
769-
774+
770775
@Test
771776
public void testIssue129SkipWhitespaceChanges() throws IOException {
772777
String original = Files.lines(Paths.get("target/test-classes/com/github/difflib/text/issue129_1.txt")).collect(joining("\n"));
@@ -785,7 +790,7 @@ public void testIssue129SkipWhitespaceChanges() throws IOException {
785790
Arrays.asList(revised.split("\n")));
786791

787792
assertThat(rows).hasSize(13);
788-
793+
789794
rows.stream()
790795
.filter(item -> item.getTag() != DiffRow.Tag.EQUAL)
791796
.forEach(System.out::println);
@@ -831,4 +836,28 @@ private void assertInlineDiffResult(DiffRowGenerator generator, String original,
831836
assertEquals(1, rows.size());
832837
assertEquals(expected, rows.get(0).getOldLine().toString());
833838
}
839+
840+
@Test
841+
public void testIssue188HangOnExamples() throws IOException, URISyntaxException {
842+
try (FileSystem zipFs = FileSystems.newFileSystem(Paths.get("target/test-classes/com/github/difflib/text/test.zip"), null);) {
843+
List<String> original = Files.readAllLines(zipFs.getPath("old.html"));
844+
List<String> revised = Files.readAllLines(zipFs.getPath("new.html"));
845+
846+
DiffRowGenerator generator = DiffRowGenerator.create()
847+
.lineNormalizer(line -> line)
848+
.showInlineDiffs(true)
849+
.mergeOriginalRevised(true)
850+
.inlineDiffByWord(true)
851+
.decompressDeltas(true)
852+
.oldTag(f -> f ? "<s style=\"background-color: #bbbbbb\">" : "</s>")
853+
.newTag(f -> f ? "<b style=\"background-color: #aaffaa\">" : "</b>")
854+
.build();
855+
856+
//List<DiffRow> rows = generator.generateDiffRows(original, revised);
857+
List<DiffRow> rows = generator.generateDiffRows(original, DiffUtils.diff(original, revised, new MyersDiffWithLinearSpace<>() ));
858+
859+
System.out.println(rows);
860+
}
861+
}
834862
}
863+

java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffReaderTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,15 @@ public void testParseIssue182mode() throws IOException {
435435
assertThat(file1.getOldMode()).isEqualTo("100644");
436436
assertThat(file1.getNewMode()).isEqualTo("100755");
437437
}
438+
439+
@Test
440+
public void testParseIssue193Copy() throws IOException {
441+
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
442+
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_parsing_issue193.diff"));
443+
444+
UnifiedDiffFile file1 = diff.getFiles().get(0);
445+
446+
assertThat(file1.getCopyFrom()).isEqualTo("modules/configuration/config/web/pcf/account/AccountContactCV.pcf");
447+
assertThat(file1.getCopyTo()).isEqualTo("modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf");
448+
}
438449
}
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git src://modules/configuration/config/web/pcf/account/AccountContactCV.pcf dst://modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
2+
similarity index 99%
3+
copy from modules/configuration/config/web/pcf/account/AccountContactCV.pcf
4+
copy to modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
5+
index 13efef5778..1a08b0befc 100644
6+
--- src://modules/configuration/config/web/pcf/account/AccountContactCV.pcf
7+
+++ dst://modules/configuration/config/web/pcf/account/AccountContactCV.default.pcf
8+
@@ -1,16 +1,17 @@
9+
<?xml version="1.0"?>
10+
<PCF
11+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
xsi:noNamespaceSchemaLocation="../../../../../pcf.xsd">
13+
<CardViewPanel
14+
- id="AccountContactCV">
15+
+ id="AccountContactCV"
16+
+ mode="default">
17+
<Require
18+
name="acctContact"
19+
type="AccountContact"/>
20+
<Require
21+
name="showAddressTools"
22+
type="boolean"/>
23+
<Require
24+
name="showRolesTab"
25+
type="boolean"/>
26+
<Variable

pom.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>io.github.java-diff-utils</groupId>
55
<artifactId>java-diff-utils-parent</artifactId>
6-
<version>4.13-SNAPSHOT</version>
6+
<version>4.16-SNAPSHOT</version>
77
<name>java-diff-utils-parent</name>
88
<packaging>pom</packaging>
99
<modules>
@@ -65,13 +65,13 @@
6565
<dependency>
6666
<groupId>org.junit.jupiter</groupId>
6767
<artifactId>junit-jupiter</artifactId>
68-
<version>5.7.1</version>
68+
<version>5.11.3</version>
6969
<scope>test</scope>
7070
</dependency>
7171
<dependency>
7272
<groupId>org.assertj</groupId>
7373
<artifactId>assertj-core</artifactId>
74-
<version>3.19.0</version>
74+
<version>3.26.3</version>
7575
<scope>test</scope>
7676
</dependency>
7777
</dependencies>
@@ -86,12 +86,13 @@
8686
<localCheckout>true</localCheckout>
8787
<pushChanges>false</pushChanges>
8888
<mavenExecutorId>forked-path</mavenExecutorId>
89+
<releaseProfiles>sign-release-artifacts</releaseProfiles>
8990
</configuration>
9091
</plugin>
9192
<plugin>
9293
<groupId>org.apache.felix</groupId>
9394
<artifactId>maven-bundle-plugin</artifactId>
94-
<version>3.3.0</version>
95+
<version>3.5.1</version>
9596
<executions>
9697
<execution>
9798
<id>bundle-manifest</id>
@@ -122,7 +123,7 @@
122123
<plugin>
123124
<groupId>org.apache.maven.plugins</groupId>
124125
<artifactId>maven-checkstyle-plugin</artifactId>
125-
<version>3.1.0</version>
126+
<version>3.6.0</version>
126127
<executions>
127128
<execution>
128129
<id>verify-style</id>
@@ -176,7 +177,7 @@
176177
<plugin>
177178
<groupId>org.apache.maven.plugins</groupId>
178179
<artifactId>maven-surefire-plugin</artifactId>
179-
<version>3.0.0-M4</version>
180+
<version>3.5.2</version>
180181
<configuration>
181182
<excludes>
182183
<exclude>**/LR*.java</exclude>

0 commit comments

Comments
 (0)