KickJava   Java API By Example, From Geeks To Geeks.

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


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.artifact.manager.WagonManager;
20 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
21 import org.apache.maven.usability.diagnostics.DiagnosisUtils;
22 import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
23
24 public class ArtifactNotFoundDiagnoser
25     implements ErrorDiagnoser
26 {
27
28     private WagonManager wagonManager;
29
30     public boolean canDiagnose( Throwable JavaDoc error )
31     {
32         return DiagnosisUtils.containsInCausality( error, ArtifactNotFoundException.class );
33     }
34
35     public String JavaDoc diagnose( Throwable JavaDoc error )
36     {
37         ArtifactNotFoundException exception =
38             (ArtifactNotFoundException) DiagnosisUtils.getFromCausality( error, ArtifactNotFoundException.class );
39
40         StringBuffer JavaDoc message = new StringBuffer JavaDoc();
41
42         message.append( "Failed to resolve artifact.\n" );
43         message.append( "\nGroupId: " ).append( exception.getGroupId() );
44         message.append( "\nArtifactId: " ).append( exception.getArtifactId() );
45         message.append( "\nVersion: " ).append( exception.getVersion() );
46         message.append( "\n\n" );
47         message.append( "Reason: " ).append( exception.getMessage() );
48
49         if ( !wagonManager.isOnline() )
50         {
51             message.append( "\n" ).append( SystemWarnings.getOfflineWarning() );
52         }
53
54         message.append( "\n" );
55
56         return message.toString();
57     }
58
59 }
60
Popular Tags