Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork201
A problem was found and fixed about #164#170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
cb2cc6f
Add generateOriginalAndDiff method and test class
1506085843e791091
Add generateOriginalAndDiff method and test class.I split long code i…
150608584361407b4
fixes #164
15060858437d9d1ca
fix build issues
150608584358ef1b1
Merge branch 'java-diff-utils:master' into master
15060858439da4012
fix issues about (#164),detail:
1506085843d0b4250
add a test for #170
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 3 additions & 3 deletionsjava-diff-utils/src/main/java/com/github/difflib/UnifiedDiffUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletionsjava-diff-utils/src/test/java/com/github/difflib/examples/OriginalAndDiffTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletionsjava-diff-utils/src/test/resources/mocks/issue_170_original.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 114 additions & 0 deletionsjava-diff-utils/src/test/resources/mocks/issue_170_revised.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.