1 package org.apache.maven.usability; 2 3 18 19 import org.apache.maven.project.InvalidProjectModelException; 20 import org.apache.maven.project.ProjectBuildingException; 21 import org.apache.maven.project.validation.ModelValidationResult; 22 import org.apache.maven.usability.diagnostics.DiagnosisUtils; 23 import org.apache.maven.usability.diagnostics.ErrorDiagnoser; 24 25 public class ProjectBuildDiagnoser 26 implements ErrorDiagnoser 27 { 28 29 public boolean canDiagnose( Throwable error ) 30 { 31 return DiagnosisUtils.containsInCausality( error, ProjectBuildingException.class ); 32 } 33 34 public String diagnose( Throwable error ) 35 { 36 ProjectBuildingException pbe = 37 (ProjectBuildingException) DiagnosisUtils.getFromCausality( error, ProjectBuildingException.class ); 38 39 StringBuffer message = new StringBuffer (); 40 41 message.append( "Error building POM (may not be this project's POM)." ).append( "\n\n" ); 42 43 message.append( "\nProject ID: " ).append( pbe.getProjectId() ); 44 45 if ( pbe instanceof InvalidProjectModelException ) 46 { 47 InvalidProjectModelException ipme = (InvalidProjectModelException) pbe; 48 49 message.append( "\nPOM Location: " ).append( ipme.getPomLocation() ); 50 51 ModelValidationResult result = ipme.getValidationResult(); 52 53 if ( result != null ) 54 { 55 message.append( "\nValidation Messages:\n\n" ).append( ipme.getValidationResult().render( " " ) ); 56 } 57 } 58 59 message.append( "\n\n" ).append( "Reason: " ).append( pbe.getMessage() ); 60 61 message.append( "\n\n" ); 62 63 return message.toString(); 64 } 65 66 } 67 | Popular Tags |