From 6e0a157eb38dc2d52745cca3605aea79c08749f7 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 7 Oct 2005 07:19:32 +0000 Subject: [PATCH] add artifact not found diagnoser git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307039 13f79535-47bb-0310-9956-ffa450edef68 --- .../usability/ArtifactNotFoundDiagnoser.java | 61 +++++++++++++++++++ .../usability/ArtifactResolverDiagnoser.java | 7 +-- .../resources/META-INF/plexus/components.xml | 15 +++++ maven-plugins/maven-plugin-plugin/pom.xml | 2 +- 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/usability/ArtifactNotFoundDiagnoser.java diff --git a/maven-core/src/main/java/org/apache/maven/usability/ArtifactNotFoundDiagnoser.java b/maven-core/src/main/java/org/apache/maven/usability/ArtifactNotFoundDiagnoser.java new file mode 100644 index 0000000000..be1db94961 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/usability/ArtifactNotFoundDiagnoser.java @@ -0,0 +1,61 @@ +package org.apache.maven.usability; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; + +public class ArtifactNotFoundDiagnoser + implements ErrorDiagnoser +{ + + private WagonManager wagonManager; + + public boolean canDiagnose( Throwable error ) + { + return DiagnosisUtils.containsInCausality( error, ArtifactNotFoundException.class ); + } + + public String diagnose( Throwable error ) + { + ArtifactNotFoundException exception = (ArtifactNotFoundException) DiagnosisUtils.getFromCausality( error, + ArtifactNotFoundException.class ); + + StringBuffer message = new StringBuffer(); + + message.append( "Failed to resolve artifact." ); + message.append( "\n\n" ); + message.append( exception.getMessage() ); + + if ( !wagonManager.isOnline() ) + { + message.append( "\n" ).append( DiagnosisUtils.getOfflineWarning() ); + } + + Throwable root = DiagnosisUtils.getRootCause( exception ); + + if ( root != null ) + { + message.append( "\nRoot Cause: " ).append( root.getMessage() ); + } + + message.append( "\n" ); + + return message.toString(); + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java b/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java index 1bcf62e28f..b457deb1f9 100644 --- a/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java +++ b/maven-core/src/main/java/org/apache/maven/usability/ArtifactResolverDiagnoser.java @@ -17,7 +17,6 @@ package org.apache.maven.usability; */ import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; public class ArtifactResolverDiagnoser @@ -28,13 +27,13 @@ public class ArtifactResolverDiagnoser public boolean canDiagnose( Throwable error ) { - return DiagnosisUtils.containsInCausality( error, AbstractArtifactResolutionException.class ); + return DiagnosisUtils.containsInCausality( error, ArtifactResolutionException.class ); } public String diagnose( Throwable error ) { - AbstractArtifactResolutionException exception = (AbstractArtifactResolutionException) DiagnosisUtils.getFromCausality( - error, ArtifactResolutionException.class ); + ArtifactResolutionException exception = (ArtifactResolutionException) DiagnosisUtils.getFromCausality( error, + ArtifactResolutionException.class ); StringBuffer message = new StringBuffer(); diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index d467343ce7..be2011fdfc 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -121,6 +121,21 @@ PluginContainerDiagnoser org.apache.maven.usability.PluginContainerDiagnoser + + + org.apache.maven.usability.ErrorDiagnoser + ArtifactNotFoundDiagnoser + org.apache.maven.usability.ArtifactNotFoundDiagnoser + + + org.apache.maven.artifact.manager.WagonManager + + +