KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > usability > ProjectBuildDiagnoser


1 package org.apache.maven.usability;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 JavaDoc error )
30     {
31         return DiagnosisUtils.containsInCausality( error, ProjectBuildingException.class );
32     }
33
34     public String JavaDoc diagnose( Throwable JavaDoc error )
35     {
36         ProjectBuildingException pbe =
37             (ProjectBuildingException) DiagnosisUtils.getFromCausality( error, ProjectBuildingException.class );
38
39         StringBuffer JavaDoc message = new StringBuffer JavaDoc();
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