1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.source;
16
17 import static java.nio.charset.StandardCharsets.ISO_8859_1;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.commons.io.FileUtils;
25
26
27
28
29
30
31 public final class Patch {
32
33 private Patch() {
34 }
35
36
37
38
39
40
41
42
43
44
45 public static void checkAuthor(final String baseDir, final String patchPath, final String authorName)
46 throws IOException {
47 final List<String> errors = new ArrayList<>();
48 final List<String> lines = FileUtils.readLines(new File(patchPath), ISO_8859_1);
49 for (final String line : lines) {
50 if (line.startsWith("+++")) {
51 final String fileName = line.substring(4, line.indexOf('\t', 4));
52 if (fileName.endsWith(".java")) {
53 final File file = new File(baseDir, fileName);
54 if (file.exists()) {
55 final List<String> fileLines = FileUtils.readLines(file, ISO_8859_1);
56 boolean authorFound = false;
57 for (final String fileLine : fileLines) {
58 if (fileLine.contains("@author " + authorName)) {
59 authorFound = true;
60 break;
61 }
62 }
63 if (!authorFound) {
64 System.out.println("No \"@author " + authorName + "\" in " + file.getAbsolutePath());
65 errors.add(file.getAbsolutePath());
66 }
67 }
68 else {
69 System.out.println("File does not exist: " + file);
70 }
71 }
72 }
73 }
74 if (!errors.isEmpty()) {
75 throw new RuntimeException("Total missing files: " + errors.size());
76 }
77 }
78
79
80
81
82
83
84 public static void generateHtmlString(final File htmlFile) throws IOException {
85 final List<String> lines = FileUtils.readLines(htmlFile, ISO_8859_1);
86 for (int i = 0; i < lines.size(); i++) {
87 final String line = lines.get(i).replace("\t", " ").replace("\\", "\\\\").replace("\"", "\\\"");
88 if (i == 0) {
89 System.out.println(" final String html = \"" + line + "\\n\"");
90 }
91 else {
92 System.out.print(" + \"" + line);
93 if (i == lines.size() - 1) {
94 System.out.print("\";");
95 }
96 else {
97 System.out.print("\\n\"");
98 }
99 System.out.println();
100 }
101 }
102 }
103 }