Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-15025] Maven-Tycho 0.15.0 build - no additional info in
console log about compilation failure Move Maven3ResultProcessor to external class CQI - change failNever variable name CQI - change return type of process method to boolean instead of int (default for CLI) Bug fix on compare project
- Loading branch information
Nikolas Falco
committed
Oct 8, 2013
1 parent
8c008c5
commit 0cb0175
Showing
2 changed files
with
175 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package hudson.maven; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.maven.InternalErrorException; | ||
import org.apache.maven.cli.CLIManager; | ||
import org.apache.maven.exception.DefaultExceptionHandler; | ||
import org.apache.maven.exception.ExceptionHandler; | ||
import org.apache.maven.exception.ExceptionSummary; | ||
import org.apache.maven.lifecycle.LifecycleExecutionException; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.util.StringUtils; | ||
import org.jvnet.hudson.maven3.listeners.HudsonMavenExecutionResult; | ||
import org.jvnet.hudson.maven3.listeners.MavenProjectInfo; | ||
|
||
public class Maven3ResultProcessor { | ||
|
||
private org.slf4j.Logger slf4jLogger; | ||
boolean showErrors = false; // default from DefaultMavenExecutionRequest.showErrors | ||
boolean failNever = false; // default from DefaultMavenExecutionRequest.reactorFailureBehavior | ||
|
||
public Maven3ResultProcessor( org.slf4j.Logger slf4jLogger ) | ||
{ | ||
this.slf4jLogger = slf4jLogger; | ||
} | ||
|
||
// partial copy paste of MavenCli.execute() | ||
public boolean processFailure(HudsonMavenExecutionResult result) { | ||
if ( !result.getThrowables().isEmpty() ) | ||
{ | ||
ExceptionHandler handler = new DefaultExceptionHandler(); | ||
|
||
Map<String, String> references = new LinkedHashMap<String, String>(); | ||
|
||
MavenProject project = null; | ||
|
||
for ( Throwable exception : result.getThrowables() ) | ||
{ | ||
ExceptionSummary summary = handler.handleException( exception ); | ||
|
||
logSummary( summary, references, "", showErrors ); | ||
|
||
if ( project == null && exception instanceof LifecycleExecutionException ) | ||
{ | ||
project = ( (LifecycleExecutionException) exception ).getProject(); | ||
} | ||
} | ||
|
||
slf4jLogger.error( "" ); | ||
|
||
if ( !showErrors ) | ||
{ | ||
slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven with the -e switch." ); | ||
} | ||
if ( !slf4jLogger.isDebugEnabled() ) | ||
{ | ||
slf4jLogger.error( "Re-run Maven using the -X switch to enable full debug logging." ); | ||
} | ||
|
||
if ( !references.isEmpty() ) | ||
{ | ||
slf4jLogger.error( "" ); | ||
slf4jLogger.error( "For more information about the errors and possible solutions" | ||
+ ", please read the following articles:" ); | ||
|
||
for ( Map.Entry<String, String> entry : references.entrySet() ) | ||
{ | ||
slf4jLogger.error( entry.getValue() + " " + entry.getKey() ); | ||
} | ||
} | ||
|
||
if ( project != null && !project.equals( convert( result.getMavenProjectInfos().get( 0 )) ) ) | ||
{ | ||
slf4jLogger.error( "" ); | ||
slf4jLogger.error( "After correcting the problems, you can resume the build with the command" ); | ||
slf4jLogger.error( " mvn <goals> -rf :" + project.getArtifactId() ); | ||
} | ||
|
||
if ( failNever ) | ||
{ | ||
slf4jLogger.info( "Build failures were ignored." ); | ||
|
||
return false; | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
// copy paste of MavenCli.logSummary() | ||
private void logSummary(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 ) ) ) { | ||
slf4jLogger.error( line, summary.getException() ); | ||
} else { | ||
slf4jLogger.error(line); | ||
} | ||
} | ||
|
||
indent += " "; | ||
|
||
for ( ExceptionSummary child : summary.getChildren() ) { | ||
logSummary( child, references, indent, showErrors ); | ||
} | ||
} | ||
|
||
private MavenProject convert(MavenProjectInfo prjInfo) | ||
{ | ||
MavenProject prj = new MavenProject(); | ||
prj.setArtifactId(prjInfo.getArtifactId()); | ||
prj.setGroupId(prjInfo.getGroupId()); | ||
prj.setVersion(prjInfo.getVersion()); | ||
|
||
return prj; | ||
} | ||
|
||
/* | ||
* Following values comes from MavenExecutionRequest that is not | ||
* reachable. Request can easily get into an | ||
* ExecutionListener.sessionEnded call from MavenSession argument, | ||
* in this scenario all implementations must be patched to handle | ||
* errors. | ||
*/ | ||
public void processCLIArguments(List<String> goals) | ||
{ | ||
// need to calculate some values as in the maven request. | ||
showErrors = goals.contains("-" + CLIManager.DEBUG) || goals.contains("-" + CLIManager.ERRORS); | ||
failNever = goals.contains("-" + CLIManager.FAIL_NEVER); | ||
} | ||
} |