From 01e24b5473bbb733f7f64de1b5a0e64ea71b2768 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 5 Oct 2005 19:52:30 +0000 Subject: [PATCH] Resolving: MNG-1055 o Adding error diagnoser for ProfileActivationException, and an IT to test the formatting. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@295096 13f79535-47bb-0310-9956-ffa450edef68 --- maven-core-it/README.txt | 4 ++ maven-core-it/it1018/goals.txt | 1 + maven-core-it/it1018/pom.xml | 6 +++ maven-core-it/it1018/profiles.xml | 11 +++++ .../usability/ProfileActivationDiagnoser.java | 44 +++++++++++++++++++ .../resources/META-INF/plexus/components.xml | 10 +++++ 6 files changed, 76 insertions(+) create mode 100644 maven-core-it/it1018/goals.txt create mode 100644 maven-core-it/it1018/pom.xml create mode 100644 maven-core-it/it1018/profiles.xml create mode 100644 maven-core/src/main/java/org/apache/maven/usability/ProfileActivationDiagnoser.java diff --git a/maven-core-it/README.txt b/maven-core-it/README.txt index 782feed43e..259dc23907 100644 --- a/maven-core-it/README.txt +++ b/maven-core-it/README.txt @@ -288,6 +288,10 @@ it1015: Test that expressions that self-reference within the POM result in an error during POM interpolation. ------------------------------------------------------------------------------- +------------------------------------------------------------------------------- +it1018: Test formatting of error caused by invalid profiles.xml syntax. +------------------------------------------------------------------------------- + ------------------------------------------------------------------------------- These are a set of builds that are more complex than single-project or reactor invocations. They follow a process external to maven itself, invoking diff --git a/maven-core-it/it1018/goals.txt b/maven-core-it/it1018/goals.txt new file mode 100644 index 0000000000..7f6ea1c07d --- /dev/null +++ b/maven-core-it/it1018/goals.txt @@ -0,0 +1 @@ +initialize diff --git a/maven-core-it/it1018/pom.xml b/maven-core-it/it1018/pom.xml new file mode 100644 index 0000000000..df9d5e305a --- /dev/null +++ b/maven-core-it/it1018/pom.xml @@ -0,0 +1,6 @@ + + 4.0.0 + org.apache.maven.it + maven-core-it1018 + 1.0-SNAPSHOT + diff --git a/maven-core-it/it1018/profiles.xml b/maven-core-it/it1018/profiles.xml new file mode 100644 index 0000000000..031413ebb2 --- /dev/null +++ b/maven-core-it/it1018/profiles.xml @@ -0,0 +1,11 @@ + + + + + test + + + + diff --git a/maven-core/src/main/java/org/apache/maven/usability/ProfileActivationDiagnoser.java b/maven-core/src/main/java/org/apache/maven/usability/ProfileActivationDiagnoser.java new file mode 100644 index 0000000000..52d39e13ed --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/usability/ProfileActivationDiagnoser.java @@ -0,0 +1,44 @@ +package org.apache.maven.usability; + +import org.apache.maven.profiles.activation.ProfileActivationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +public class ProfileActivationDiagnoser + implements ErrorDiagnoser +{ + + public boolean canDiagnose( Throwable error ) + { + return DiagnosisUtils.containsInCausality( error, ProfileActivationException.class ); + } + + public String diagnose( Throwable error ) + { + ProfileActivationException activationException = (ProfileActivationException) DiagnosisUtils.getFromCausality( error, ProfileActivationException.class ); + + StringBuffer messageBuffer = new StringBuffer(); + + messageBuffer.append( "Error activating profiles." ); + messageBuffer.append( "\n\nReason: " ).append( activationException.getMessage() ); + + if ( DiagnosisUtils.containsInCausality( activationException, ComponentLookupException.class ) ) + { + ComponentLookupException cle = (ComponentLookupException) DiagnosisUtils.getFromCausality( activationException, ComponentLookupException.class ); + + messageBuffer.append( "\n\nThere was a problem retrieving one or more profile activators." ); + messageBuffer.append( "\n" ).append( cle.getMessage() ); + } + + Throwable root = DiagnosisUtils.getRootCause( error ); + + if ( root != null && root != error ) + { + messageBuffer.append( "\n\nRoot Cause: " ).append( root.getMessage() ); + } + + messageBuffer.append( "\n" ); + + return messageBuffer.toString(); + } + +} 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 fdb5a6fa0e..d467343ce7 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -93,6 +93,16 @@ + + org.apache.maven.usability.ErrorDiagnoser + ProfileActivationDiagnoser + org.apache.maven.usability.ProfileActivationDiagnoser + +