Be consistent about data encoding when copying files (#1215) · apache/maven-javadoc-plugin@33c9f01 (original) (raw)
`@@ -40,6 +40,20 @@
`
40
40
` */
`
41
41
`public class StaleHelper {
`
42
42
``
``
43
`+
/**
`
``
44
`+
- Compute the encoding of the stale javadoc
`
``
45
`+
`
``
46
`+
- @return the the encoding of the stale data
`
``
47
`+
*/
`
``
48
`+
private static Charset getDataCharset() {
`
``
49
`+
if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
`
``
50
`+
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
`
``
51
`+
return StandardCharsets.UTF_8;
`
``
52
`+
} else {
`
``
53
`+
return Charset.defaultCharset();
`
``
54
`+
}
`
``
55
`+
}
`
``
56
+
43
57
`/**
`
44
58
` * Compute the data used to detect a stale javadoc
`
45
59
` *
`
`@@ -55,18 +69,10 @@ public static List getStaleData(Commandline cmd) throws MavenReportExcep
`
55
69
`String[] args = cmd.getArguments();
`
56
70
`Collections.addAll(options, args);
`
57
71
``
58
``
`-
final Charset cs;
`
59
``
`-
if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
`
60
``
`-
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
`
61
``
`-
cs = StandardCharsets.UTF_8;
`
62
``
`-
} else {
`
63
``
`-
cs = Charset.defaultCharset();
`
64
``
`-
}
`
65
``
-
66
72
`for (String arg : args) {
`
67
73
`if (arg.startsWith("@")) {
`
68
74
`String name = arg.substring(1);
`
69
``
`-
options.addAll(Files.readAllLines(dir.resolve(name), cs));
`
``
75
`+
options.addAll(Files.readAllLines(dir.resolve(name), getDataCharset()));
`
70
76
`ignored.add(name);
`
71
77
` }
`
72
78
` }
`
`@@ -117,7 +123,7 @@ public static void writeStaleData(Commandline cmd, Path path) throws MavenReport
`
117
123
`try {
`
118
124
`List curdata = getStaleData(cmd);
`
119
125
`Files.createDirectories(path.getParent());
`
120
``
`-
Files.write(path, curdata, StandardCharsets.UTF_8);
`
``
126
`+
Files.write(path, curdata, getDataCharset());
`
121
127
` } catch (IOException e) {
`
122
128
`throw new MavenReportException("Error checking stale data", e);
`
123
129
` }
`