From e20a677b323a01855395b08d919040437d7fd69c Mon Sep 17 00:00:00 2001
From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com>
Date: Wed, 31 Aug 2022 15:29:54 -0400
Subject: [PATCH 1/4] Add @errors file in output directory containing Javadoc
errors and warnings reported
---
.../plugins/javadoc/AbstractJavadocMojo.java | 46 +++++++++++++++++--
.../maven/plugins/javadoc/JavadocJar.java | 3 +-
.../maven/plugins/javadoc/JavadocJarTest.java | 9 ++--
3 files changed, 49 insertions(+), 9 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 543c4000c..99f6b8522 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -183,28 +183,34 @@ public abstract class AbstractJavadocMojo
/**
* The options
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
*/
protected static final String OPTIONS_FILE_NAME = "options";
/**
* The packages
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
*/
protected static final String PACKAGES_FILE_NAME = "packages";
/**
* The argfile
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
*/
protected static final String ARGFILE_FILE_NAME = "argfile";
/**
* The files
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
*/
protected static final String FILES_FILE_NAME = "files";
+ /**
+ * The errors
file name in the output directory when calling:
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
+ */
+ protected static final String ERRORS_FILE_NAME = "errors";
+
/**
* The current class directory
*/
@@ -6077,6 +6083,11 @@ && isJavadocVMInitError( output ) )
getLog().info( output );
}
+ if ( StringUtils.isNotEmpty( err.getOutput() ) )
+ {
+ writeErrorFile( err.getOutput(), javadocOutputDirectory );
+ }
+
StringBuilder msg = new StringBuilder( "\nExit code: " );
msg.append( exitCode );
if ( StringUtils.isNotEmpty( err.getOutput() ) )
@@ -6879,6 +6890,33 @@ private void writeDebugJavadocScript( String cmdLine, File javadocOutputDirector
}
}
+ /**
+ * Write a files containing the javadoc errors and warnings.
+ *
+ * @param errorsAndWarnings the javadoc errors and warnings as string, not null.
+ * @param javadocOutputDirectory the output dir, not null.
+ * @since 3.4.1-SNAPSHOT
+ */
+ private void writeErrorFile( String errorsAndWarnings, File javadocOutputDirectory )
+ {
+ File commandLineFile = new File( javadocOutputDirectory, ERRORS_FILE_NAME );
+ commandLineFile.getParentFile().mkdirs();
+
+ try
+ {
+ FileUtils.fileWrite( commandLineFile.getAbsolutePath(), null /* platform encoding */, errorsAndWarnings );
+
+ if ( !SystemUtils.IS_OS_WINDOWS )
+ {
+ Runtime.getRuntime().exec( new String[]{ "chmod", "a+x", commandLineFile.getAbsolutePath() } );
+ }
+ }
+ catch ( IOException e )
+ {
+ logError( "Unable to write '" + commandLineFile.getName() + "' errors file", e );
+ }
+ }
+
/**
* Check if the Javadoc JVM is correctly started or not.
*
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
index 2a20bb8c2..b7de520e7 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
@@ -66,10 +66,11 @@ public class JavadocJar
* @see AbstractJavadocMojo#PACKAGES_FILE_NAME
* @see AbstractJavadocMojo#ARGFILE_FILE_NAME
* @see AbstractJavadocMojo#FILES_FILE_NAME
+ * @see AbstractJavadocMojo#ERRORS_FILE_NAME
*/
private static final String[] DEFAULT_EXCLUDES =
new String[]{ DEBUG_JAVADOC_SCRIPT_NAME, OPTIONS_FILE_NAME, PACKAGES_FILE_NAME, ARGFILE_FILE_NAME,
- FILES_FILE_NAME };
+ FILES_FILE_NAME, ERRORS_FILE_NAME };
// ----------------------------------------------------------------------
// Mojo components
diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java
index eb46b6c2e..d3cb9f28e 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocJarTest.java
@@ -42,7 +42,7 @@
public class JavadocJarTest
extends AbstractMojoTestCase
{
-
+
private JavadocJar lookupMojo( File testPom )
throws Exception
{
@@ -51,13 +51,13 @@ private JavadocJar lookupMojo( File testPom )
MojoExecution mojoExec = new MojoExecution( new Plugin(), "javadoc", null );
setVariableValueToObject( mojo, "mojo", mojoExec );
-
+
MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId( "GROUPID" );
currentProject.setArtifactId( "ARTIFACTID" );
-
+
setVariableValueToObject( mojo, "session", newMavenSession( currentProject ) );
-
+
return mojo;
}
@@ -126,6 +126,7 @@ else if ( javadocVersion.isBefore( "1.8" ) )
assertFalse( set.contains( AbstractJavadocMojo.FILES_FILE_NAME ) );
assertFalse( set.contains( AbstractJavadocMojo.OPTIONS_FILE_NAME ) );
assertFalse( set.contains( AbstractJavadocMojo.PACKAGES_FILE_NAME ) );
+ assertFalse( set.contains( AbstractJavadocMojo.ERRORS_FILE_NAME ) );
//check if the javadoc files were created
generatedFile =
From ceb342d3d2664f672dd243c39a69ad66e162f743 Mon Sep 17 00:00:00 2001
From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com>
Date: Wed, 31 Aug 2022 15:33:43 -0400
Subject: [PATCH 2/4] Update @since when pulling in upstream
---
.../org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 99f6b8522..009d77c2d 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -6895,7 +6895,7 @@ private void writeDebugJavadocScript( String cmdLine, File javadocOutputDirector
*
* @param errorsAndWarnings the javadoc errors and warnings as string, not null.
* @param javadocOutputDirectory the output dir, not null.
- * @since 3.4.1-SNAPSHOT
+ * @since 3.4.2-SNAPSHOT
*/
private void writeErrorFile( String errorsAndWarnings, File javadocOutputDirectory )
{
From d0d2b8e63247d0a15ede1d0097c817a9b9d0a087 Mon Sep 17 00:00:00 2001
From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com>
Date: Fri, 2 Sep 2022 07:16:49 -0400
Subject: [PATCH 3/4] Differentiate errors from other files as the other files
are used by Javadoc
---
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 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 009d77c2d..e2021f2ab 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -183,31 +183,33 @@ public abstract class AbstractJavadocMojo
/**
* The options
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files
*/
protected static final String OPTIONS_FILE_NAME = "options";
/**
* The packages
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files
*/
protected static final String PACKAGES_FILE_NAME = "packages";
/**
* The argfile
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files
*/
protected static final String ARGFILE_FILE_NAME = "argfile";
/**
* The files
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
+ * javadoc.exe(or .sh) @options @packages | @argfile | @files
*/
protected static final String FILES_FILE_NAME = "files";
/**
- * The errors
file name in the output directory when calling:
- * javadoc.exe(or .sh) @options @packages | @argfile | @files | @errors
+ * The errors
file name in the output directory containing the errors and warnings returned by
+ * javadoc.exe(or .sh)
.
+ *
+ * This won't exist if javadoc.exe(or .sh)
didn't return any warnings or errors.
*/
protected static final String ERRORS_FILE_NAME = "errors";
From aff286a20494495eff6598a6b9263e9ced8807ab Mon Sep 17 00:00:00 2001
From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com>
Date: Tue, 6 Sep 2022 16:53:40 -0400
Subject: [PATCH 4/4] Remove permissions modification on errors file
---
.../apache/maven/plugins/javadoc/AbstractJavadocMojo.java | 5 -----
1 file changed, 5 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 e2021f2ab..2deba093e 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -6907,11 +6907,6 @@ private void writeErrorFile( String errorsAndWarnings, File javadocOutputDirecto
try
{
FileUtils.fileWrite( commandLineFile.getAbsolutePath(), null /* platform encoding */, errorsAndWarnings );
-
- if ( !SystemUtils.IS_OS_WINDOWS )
- {
- Runtime.getRuntime().exec( new String[]{ "chmod", "a+x", commandLineFile.getAbsolutePath() } );
- }
}
catch ( IOException e )
{