KickJava   Java API By Example, From Geeks To Geeks.

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


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.InvalidArtifactRTException;
20 import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
21
22 public class InvalidArtifactDiagnoser
23     implements ErrorDiagnoser
24 {
25
26     public boolean canDiagnose( Throwable JavaDoc error )
27     {
28         return error instanceof InvalidArtifactRTException;
29     }
30
31     public String JavaDoc diagnose( Throwable JavaDoc error )
32     {
33         StringBuffer JavaDoc diagnosis = new StringBuffer JavaDoc();
34
35         InvalidArtifactRTException e = (InvalidArtifactRTException) error;
36
37         diagnosis.append( "An invalid artifact was detected.\n\n" )
38             .append( "This artifact might be in your project's POM, " )
39             .append( "or it might have been included transitively during the resolution process. " )
40             .append( "Here is the information we do have for this artifact:\n" )
41             .append( "\n o GroupID: " ).append( maybeFlag( e.getGroupId() ) )
42             .append( "\n o ArtifactID: " ).append( maybeFlag( e.getArtifactId() ) )
43             .append( "\n o Version: " ).append( maybeFlag( e.getVersion() ) )
44             .append( "\n o Type: " ).append( maybeFlag( e.getType() ) )
45             .append( "\n" );
46
47         return diagnosis.toString();
48     }
49
50     private String JavaDoc maybeFlag( String JavaDoc value )
51     {
52         if ( value == null || value.trim().length() < 1 )
53         {
54             return "<<< MISSING >>>";
55         }
56         else
57         {
58             return value;
59         }
60     }
61
62 }
63
Popular Tags