Skip to content

Be consistent about data encoding #1215

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@
*/
public class StaleHelper {

/**
* Compute the encoding of the stale javadoc
*
* @return the the encoding of the stale data
*/
private static Charset getDataCharset() {
if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
return StandardCharsets.UTF_8;
} else {
return Charset.defaultCharset();
}
}

/**
* Compute the data used to detect a stale javadoc
*
Expand All @@ -55,13 +69,7 @@ public static List<String> getStaleData(Commandline cmd) throws MavenReportExcep
String[] args = cmd.getArguments();
Collections.addAll(options, args);

final Charset cs;
if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
cs = StandardCharsets.UTF_8;
} else {
cs = Charset.defaultCharset();
}
final Charset cs = getDataCharset();

for (String arg : args) {
if (arg.startsWith("@")) {
Expand Down Expand Up @@ -115,9 +123,11 @@ public static List<String> getStaleData(Commandline cmd) throws MavenReportExcep
*/
public static void writeStaleData(Commandline cmd, Path path) throws MavenReportException {
try {
final Charset cs = getDataCharset();

List<String> curdata = getStaleData(cmd);
Files.createDirectories(path.getParent());
Files.write(path, curdata, StandardCharsets.UTF_8);
Files.write(path, curdata, cs);
} catch (IOException e) {
throw new MavenReportException("Error checking stale data", e);
}
Expand Down