Skip to content

[MJAVADOC-721] Parse stderr output and suppress informational lines #157

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

Merged
merged 1 commit into from
Sep 2, 2022
Merged
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 @@ -6081,7 +6081,25 @@ && isJavadocVMInitError( output ) )
msg.append( exitCode );
if ( StringUtils.isNotEmpty( err.getOutput() ) )
{
msg.append( " - " ).append( err.getOutput() );
// parse stderr, log informational output, add all other to exception message
List<String> nonInfoLines = new ArrayList<>();
for ( String str : err.getOutput().split( "\\R" ) )
{
if ( isInformationalOutput( str ) )
{
getLog().debug( str );
}
else
{
nonInfoLines.add( str );
}
}
if ( !nonInfoLines.isEmpty() )
{
msg.append( '\n' ); // new line between exit code and warnings/errors
msg.append( String.join( "\n" , nonInfoLines ) );
}

}
msg.append( '\n' );
msg.append( "Command line was: " ).append( cmdLine ).append( '\n' ).append( '\n' );
Expand Down Expand Up @@ -6117,7 +6135,16 @@ && isJavadocVMInitError( output ) )
{
String current = token.nextToken().trim();

getLog().warn( current );
// log informational output at debug level only
if ( isInformationalOutput( current ) )
{
getLog().debug( current );
}
else
{
getLog().warn( current );
}

}
}

Expand All @@ -6144,6 +6171,31 @@ private boolean containsWarnings( String output )
}
}

/**
* Determines whether the specified string is informational output of the Javadoc tool.<br/>
* Such output should not be included as exception message or logged as warning or error.
* <p>
* The following texts are either hardcoded in the tool or can be found in versions of the
* javadoc tool's English resource bundle of JDK 11 (and presumably later versions).<br/>
* This method will neither help nor harm for localized (non-English) versions of the tool.
* </p>
*
* @param str string to check
* @return true if informational output, false if not or cannot be determined
*/
private boolean isInformationalOutput( String str )
{
return str == null
|| str.trim().isEmpty()
|| str.startsWith( "Loading source files for package " ) // main.Loading_source_files_for_package
|| str.startsWith( "Loading source file " ) // main.Loading_source_file
|| str.startsWith( "Generating " )
|| str.startsWith( "Constructing Javadoc information" ) // main.Building_tree
|| str.startsWith( "Building index for " )
|| str.startsWith( "Building tree for " )
|| str.startsWith( "Standard Doclet version " );
}

/**
* Patches the given Javadoc output directory to work around CVE-2013-1571
* (see http://www.kb.cert.org/vuls/id/225657).
Expand Down