Skip to content
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

[MJAVADOC-722] Log javadoc warnings and errors to file #159

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Expand Up @@ -203,6 +203,14 @@ public abstract class AbstractJavadocMojo
*/
protected static final String FILES_FILE_NAME = "files";

/**
* The <code>errors</code> file name in the output directory containing the errors and warnings returned by
* <code>javadoc.exe(or .sh)</code>.
* <br />
* This won't exist if <code>javadoc.exe(or .sh)</code> didn't return any warnings or errors.
*/
protected static final String ERRORS_FILE_NAME = "errors";
alzimmermsft marked this conversation as resolved.
Show resolved Hide resolved

/**
* Default css file name, used as file name in the output directory for the temporary custom stylesheet file
* loaded from classloader resources.
Expand Down Expand Up @@ -5848,6 +5856,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() ) )
Expand Down Expand Up @@ -6702,6 +6715,28 @@ 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.2-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 );
}
catch ( IOException e )
{
logError( "Unable to write '" + commandLineFile.getName() + "' errors file", e );
}
}

/**
* Check if the Javadoc JVM is correctly started or not.
*
Expand Down
Expand Up @@ -67,10 +67,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
Expand Down
Expand Up @@ -42,7 +42,7 @@
public class JavadocJarTest
extends AbstractMojoTestCase
{

private JavadocJar lookupMojo( File testPom )
throws Exception
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 =
Expand Down