Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-15025] no additional info in console log about failures
Conflicts:
	maven-plugin/src/main/java/hudson/maven/Maven3Builder.java
  • Loading branch information
kohsuke committed Jul 27, 2013
2 parents 3376cf0 + d0d27ac commit 6af9127
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 19 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -58,6 +58,9 @@
<li class=rfe>
Can't build using maven 3.1.0
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15935">issue 15935</a>)
<li class=bug>
Maven buid failure wasn't describing errors like Maven CLI does.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15025">issue 15025</a>)
<li class=bug>
Fixed Winstone+mod_proxy_ajp+SSL combo issue.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-5753">issue 5753</a>)
Expand Down
25 changes: 6 additions & 19 deletions maven-plugin/src/main/java/hudson/maven/Maven3Builder.java
Expand Up @@ -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 );

Expand All @@ -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");
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 );
}

Expand Down
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -139,6 +146,8 @@ public void sessionEnded( ExecutionEvent event )

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

logErrors( event.getSession() );
}

private void logReactorSummary( MavenSession session )
Expand Down Expand Up @@ -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 ) );
Expand Down

0 comments on commit 6af9127

Please sign in to comment.