Skip to content
Permalink
Browse files
[FIXED JENKINS-15025] no additional info in console log about failures
Conflicts:
	maven-plugin/src/main/java/hudson/maven/Maven3Builder.java

Originally-Committed-As: 6af9127409255332c64ad1dd503f1ed24297f37a
  • Loading branch information
kohsuke committed Jul 27, 2013
2 parents aac8974 + 27777b6 commit 19c4a4a0e9df8e2788703b44c84187b224ae239d
Showing with 92 additions and 19 deletions.
  1. +6 −19 src/main/java/hudson/maven/Maven3Builder.java
  2. +86 −0 src/main/java/hudson/maven/util/ExecutionEventLogger.java
@@ -122,7 +122,8 @@ public Result call() throws IOException {

registerSystemProperties();

listener.getLogger().println(formatArgs(goals));
PrintStream logger = listener.getLogger();
logger.println(formatArgs(goals));

Method launchMethod = maven3MainClass.getMethod( "launch", String[].class );

@@ -144,7 +145,6 @@ public Result call() throws IOException {

if(profile) {
NumberFormat n = NumberFormat.getInstance();
PrintStream logger = listener.getLogger();
logger.println("Total overhead was "+format(n,mavenExecutionListener.overheadTime)+"ms");
Channel ch = Channel.current();
logger.println("Class loading " +format(n,ch.classLoadingTime.get()) +"ms, "+ch.classLoadingCount+" classes");
@@ -157,30 +157,18 @@ public Result call() throws IOException {

//mavenExecutionResult = Maven3Launcher.getMavenExecutionResult();

PrintStream logger = listener.getLogger();

if(r==0 && mavenExecutionResult.getThrowables().isEmpty()) {
if(mavenExecutionListener.hasTestFailures()){
return Result.UNSTABLE;
}
return Result.SUCCESS;
}

if (!mavenExecutionResult.getThrowables().isEmpty()) {
logger.println( "mavenExecutionResult exceptions not empty");
for(Throwable throwable : mavenExecutionResult.getThrowables()) {
logger.println("message : " + throwable.getMessage());
if (throwable.getCause()!=null) {
logger.println("cause : " + throwable.getCause().getMessage());
}
logger.println("Stack trace : ");
throwable.printStackTrace( logger );
}

}

// manage of Maven error are moved to ExecutionEventLogger, they are
// threaded as in MavenCli

if(markAsSuccess) {
listener.getLogger().println(Messages.MavenBuilder_Failed());
logger.println(Messages.MavenBuilder_Failed());
if(mavenExecutionListener.hasTestFailures()){
return Result.UNSTABLE;
}
@@ -328,7 +316,6 @@ public MavenExecutionListener(AbstractMavenBuilder maven3Builder) {


// E.g. there's also the option to redirect logging to a file which is handled there, but not here.

this.eventLogger = new ExecutionEventLogger( logger );
}

@@ -23,7 +23,13 @@

import java.io.IOException;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.maven.InternalErrorException;
import org.apache.maven.exception.DefaultExceptionHandler;
import org.apache.maven.exception.ExceptionHandler;
import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.AbstractExecutionListener;
import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.BuildSuccess;
@@ -34,6 +40,7 @@
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;

/**
* Logs execution events to a user-supplied logger.
@@ -139,6 +146,8 @@ public void sessionEnded( ExecutionEvent event )

logger.info( chars( '-', LINE_LENGTH ) );
}

logErrors( event.getSession() );
}

private void logReactorSummary( MavenSession session )
@@ -187,6 +196,83 @@ else if ( buildSummary instanceof BuildFailure )
}
}

private void logErrors( MavenSession session )
{
MavenExecutionResult result = session.getResult();

// show all errors and them references as in MavenCli
if ( !result.getExceptions().isEmpty() )
{
ExceptionHandler handler = new DefaultExceptionHandler();

Map<String, String> references = new LinkedHashMap<String, String>();

for ( Throwable exception : result.getExceptions() )
{
ExceptionSummary summary = handler.handleException( exception );

logErrorSummary( summary, references, "", logger.isDebugEnabled() );
}

if ( !references.isEmpty() )
{
logger.error( "For more information about the errors and possible solutions"
+ ", please read the following articles:");

for ( Map.Entry<String, String> entry : references.entrySet() ) {
logger.error( entry.getValue() + " " + entry.getKey() );
}
}
}
}

private void logErrorSummary(ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors)
{
String referenceKey = "";

if ( StringUtils.isNotEmpty( summary.getReference() ) )
{
referenceKey = references.get( summary.getReference() );
if (referenceKey == null) {
referenceKey = "[Help " + ( references.size() + 1 ) + "]";
references.put( summary.getReference(), referenceKey );
}
}

String msg = summary.getMessage();

if (StringUtils.isNotEmpty( referenceKey ))
{
if (msg.indexOf('\n') < 0)
{
msg += " -> " + referenceKey;
}
else
{
msg += "\n-> " + referenceKey;
}
}

String[] lines = msg.split("(\r\n)|(\r)|(\n)");

for ( int i = 0; i < lines.length; i++ )
{
String line = indent + lines[i].trim();

if ( i == lines.length - 1 && ( showErrors || ( summary.getException() instanceof InternalErrorException ) ) ) {
logger.error( line, summary.getException() );
} else {
logger.error(line);
}
}

indent += " ";

for ( ExceptionSummary child : summary.getChildren() ) {
logErrorSummary( child, references, indent, showErrors );
}
}

private void logResult( MavenSession session )
{
logger.info( chars( '-', LINE_LENGTH ) );

0 comments on commit 19c4a4a

Please sign in to comment.