This is an automated email from the ASF dual-hosted git repository.
olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 92526985 Specify UTF-8 (#1245)
92526985 is described below
commit 92526985d18262bef29c9f9cfa3714a0c05ecb23
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Thu Aug 21 01:33:15 2025 +0000
Specify UTF-8 (#1245)
* Specify UTF-8
---
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 19 +++++---
.../apache/maven/plugins/javadoc/JavadocUtil.java | 56 +++++++++++++---------
2 files changed, 46 insertions(+), 29 deletions(-)
diff --git
a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index cb138424..1a605db2 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -5390,13 +5390,18 @@ public abstract class AbstractJavadocMojo extends
AbstractMojo {
} catch (MavenInvocationException e) {
logError("MavenInvocationException: " + e.getMessage(), e);
- String invokerLogContent =
JavadocUtil.readFile(invokerLogFile, null /* platform encoding */);
-
- // TODO: Why are we only interested in cases where the JVM
won't start?
- // [MJAVADOC-275][jdcasey] I changed the logic here to
only throw an error WHEN
- // the JVM won't start (opposite of what it was).
- if (invokerLogContent != null &&
invokerLogContent.contains(JavadocUtil.ERROR_INIT_VM)) {
- throw new MavenReportException(e.getMessage(), e);
+ try {
+ String invokerLogContent =
+ new
String(Files.readAllBytes(invokerLogFile.toPath()), StandardCharsets.UTF_8);
+ // TODO: Why are we only interested in cases where the
JVM won't start?
+ // probably we should throw an error in all cases
+ // [MJAVADOC-275][jdcasey] I changed the logic here to
only throw an error WHEN
+ // the JVM won't start (opposite of what it was).
+ if
(invokerLogContent.contains(JavadocUtil.ERROR_INIT_VM)) {
+ throw new MavenReportException(e.getMessage(), e);
+ }
+ } catch (IOException ex) {
+ // ignore
}
} finally {
// just create the directory to prevent repeated
invocations.
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index dd8ccbc6..f42d2914 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -35,6 +35,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -825,46 +826,57 @@ public class JavadocUtil {
InvocationResult result = invoke(log, invoker, request, invokerLog,
goals, properties, null);
if (result.getExitCode() != 0) {
- String invokerLogContent = readFile(invokerLog, "UTF-8");
+ try {
+ String invokerLogContent = new
String(Files.readAllBytes(invokerLog.toPath()), StandardCharsets.UTF_8);
- // see DefaultMaven
- if (invokerLogContent != null
- && (!invokerLogContent.contains("Scanning for projects...")
- ||
invokerLogContent.contains(OutOfMemoryError.class.getName()))) {
- if (log != null) {
- log.error("Error occurred during initialization of VM,
trying to use an empty MAVEN_OPTS...");
+ // see DefaultMaven
+ if (!invokerLogContent.contains("Scanning for projects...")
+ ||
invokerLogContent.contains(OutOfMemoryError.class.getName())) {
+ if (log != null) {
+ log.error("Error occurred during initialization of VM,
trying to use an empty MAVEN_OPTS...");
- if (log.isDebugEnabled()) {
- log.debug("Reinvoking Maven for the goals: " + goals +
" with an empty MAVEN_OPTS...");
+ if (log.isDebugEnabled()) {
+ log.debug("Reinvoking Maven for the goals: " +
goals + " with an empty MAVEN_OPTS...");
+ }
}
}
- result = invoke(log, invoker, request, invokerLog, goals,
properties, "");
+ } catch (IOException e) {
+ // ignore
}
+ result = invoke(log, invoker, request, invokerLog, goals,
properties, "");
}
if (result.getExitCode() != 0) {
- String invokerLogContent = readFile(invokerLog, "UTF-8");
+ try {
+ String invokerLogContent = new
String(Files.readAllBytes(invokerLog.toPath()), StandardCharsets.UTF_8);
- // see DefaultMaven
- if (invokerLogContent != null
- && (!invokerLogContent.contains("Scanning for projects...")
- ||
invokerLogContent.contains(OutOfMemoryError.class.getName()))) {
- throw new MavenInvocationException(ERROR_INIT_VM);
- }
+ // see DefaultMaven
+ if (!invokerLogContent.contains("Scanning for projects...")
+ ||
invokerLogContent.contains(OutOfMemoryError.class.getName())) {
+ throw new MavenInvocationException(ERROR_INIT_VM);
+ }
- throw new MavenInvocationException(
- "Error when invoking Maven, consult the invoker log file:
" + invokerLog.getAbsolutePath());
+ throw new MavenInvocationException(
+ "Error when invoking Maven, consult the invoker log
file: " + invokerLog.getAbsolutePath());
+ } catch (IOException ex) {
+ // ignore
+ }
+ throw new MavenInvocationException(ERROR_INIT_VM);
}
}
/**
* Read the given file and return the content or null if an IOException
occurs.
*
- * @param javaFile not null
- * @param encoding could be null
- * @return the content of the given javaFile using the given encoding
+ * @param javaFile the file to read; not null
+ * @param encoding a character set name; not null
+ * @return the content of the given file using the given encoding; null if
an IOException occurs
* @since 2.6.1
+ * @throws java.nio.charset.UnsupportedCharsetException if the named
charset is not supported
+ * @throws NullPointerException if the javaFile or encoding is null
+ * @deprecated use Files.readString(Path, Charset) in Java 11+ or new
String(Files.readAllBytes(Path), Charset) in Java 8
*/
+ @Deprecated
protected static String readFile(final File javaFile, final String
encoding) {
try {
return new String(Files.readAllBytes(javaFile.toPath()),
Charset.forName(encoding));