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 @@ -5393,13 +5393,18 @@ private List<OfflineLink> getModulesLinks() throws MavenReportException {
} 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.
Expand Down
56 changes: 34 additions & 22 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand Down Expand Up @@ -825,46 +826,57 @@ protected static void invokeMaven(
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));
Expand Down
Loading