Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -4149,14 +4149,8 @@ private void addCommandLineOptions(Commandline cmd, List<String> arguments, File
StringBuilder options = new StringBuilder();
options.append(StringUtils.join(arguments.iterator(), SystemUtils.LINE_SEPARATOR));

Charset outputFileEncoding;
if (JAVA_VERSION.isAtLeast("9") && JAVA_VERSION.isBefore("12")) {
outputFileEncoding = StandardCharsets.UTF_8;
} else {
outputFileEncoding = Charset.defaultCharset();
}
try {
Files.write(optionsFile.toPath(), Collections.singleton(options), outputFileEncoding);
Files.write(optionsFile.toPath(), Collections.singleton(options), SystemUtils.getExpectedEncoding());
} catch (IOException e) {
throw new MavenReportException(
"Unable to write '" + optionsFile.getName() + "' temporary file for command execution", e);
Expand Down Expand Up @@ -4194,16 +4188,8 @@ private void addCommandLineArgFile(Commandline cmd, File javadocOutputDirectory,
quotedFiles.add(JavadocUtil.quotedPathArgument(file));
}

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

try {
Files.write(argfileFile.toPath(), quotedFiles, cs);
Files.write(argfileFile.toPath(), quotedFiles, SystemUtils.getExpectedEncoding());
} catch (IOException e) {
throw new MavenReportException(
"Unable to write '" + argfileFile.getName() + "' temporary file for command execution", e);
Expand Down Expand Up @@ -5005,7 +4991,8 @@ private boolean isUpToDate(Commandline cmd) throws MavenReportException {
Path cacheData = staleDataPath.toPath();
List<String> prvdata;
if (Files.isRegularFile(cacheData)) {
prvdata = Files.lines(cacheData, StandardCharsets.UTF_8).collect(Collectors.toList());
prvdata = Files.lines(cacheData, SystemUtils.getExpectedEncoding())
.collect(Collectors.toList());
} else {
prvdata = null;
}
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/org/apache/maven/plugins/javadoc/StaleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -33,13 +31,12 @@
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.plexus.util.cli.Commandline;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* Helper class to compute and write data used to detect a
* stale javadoc.
*/
public class StaleHelper {

/**
* Compute the data used to detect a stale javadoc
*
Expand All @@ -58,12 +55,8 @@ public static List<String> getStaleData(Commandline cmd) throws MavenReportExcep
for (String arg : args) {
if (arg.startsWith("@")) {
String name = arg.substring(1);
options.addAll(Files.readAllLines(dir.resolve(name), SystemUtils.getExpectedEncoding()));
ignored.add(name);
try {
options.addAll(Files.readAllLines(dir.resolve(name), UTF_8));
} catch (CharacterCodingException e) {
options.addAll(Files.readAllLines(dir.resolve(name), Charset.defaultCharset()));
}
}
}
List<String> state = new ArrayList<>(options);
Expand Down Expand Up @@ -113,7 +106,7 @@ public static void writeStaleData(Commandline cmd, Path path) throws MavenReport
try {
List<String> curdata = getStaleData(cmd);
Files.createDirectories(path.getParent());
Files.write(path, curdata, UTF_8);
Files.write(path, curdata, SystemUtils.getExpectedEncoding());
} catch (IOException e) {
throw new MavenReportException("Error checking stale data", e);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/apache/maven/plugins/javadoc/SystemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
package org.apache.maven.plugins.javadoc;

import java.io.File;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.codehaus.plexus.languages.java.version.JavaVersion;

/**
* Contains several OS-specific methods from Commons-Lang3's SystemUtils. We don't want to use that class because it
Expand Down Expand Up @@ -146,6 +150,21 @@ public static File getJavaHome() {
return new File(System.getProperty(JAVA_HOME_KEY));
}

/**
* Compute the encoding that Javadoc expects for reading and writing of data
*
* @return the expected encoding
* @since 3.12.1
*/
public static Charset getExpectedEncoding() {
if (JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast("9")
&& JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("12")) {
return StandardCharsets.UTF_8;
} else {
return Charset.defaultCharset();
}
}

/**
* <p>
* Gets a System property, defaulting to {@code null} if the property cannot be read.
Expand Down
Loading