o collecting all logging/eventing into the core. i posted a list of possible errors that can occur in the core, the stuff we had was only

partially being use and we problems being emitted with messages like:

  NOTE: One or more purely derived expression elements were detected in this expression. 
  If you continue to get this error after any other expression elements are specified correctly
  please report this issue to the Maven development team.

  I think we have to make a very concerted effort to make useful messages because I'm tired of standing behind Maven
  users and being embarrassed when they look at me and ask "what does that mean?". "i actually have no idea."


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@572456 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-04 00:05:04 +00:00
parent 2a241710f0
commit ae1501b9f6
32 changed files with 40 additions and 1793 deletions

View File

@ -73,11 +73,6 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-error-diagnostics</artifactId>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>

View File

@ -48,7 +48,6 @@ import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.settings.Settings;
import org.apache.maven.usability.diagnostics.ErrorDiagnostics;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.context.Context;
@ -90,8 +89,6 @@ public class DefaultMaven
protected PlexusContainer container;
protected ErrorDiagnostics errorDiagnostics;
protected RuntimeInformation runtimeInformation;
private BuildExtensionScanner buildExtensionScanner;

View File

@ -20,22 +20,6 @@ package org.apache.maven.plugin;
*/
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.usability.plugin.Expression;
import org.apache.maven.usability.plugin.ExpressionDocumentationException;
import org.apache.maven.usability.plugin.ExpressionDocumenter;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -44,242 +28,26 @@ import java.util.regex.Pattern;
public class PluginConfigurationException
extends Exception
{
private final PluginDescriptor pluginDescriptor;
private PluginDescriptor pluginDescriptor;
private String originalMessage;
private static final List UNMODIFIABLE_EXPRESSIONS = Arrays.asList(
new String[]{"localRepository", "reactorProjects", "settings", "project", "session", "plugin", "basedir"} );
public PluginConfigurationException( PluginDescriptor pluginDescriptor, String message )
public PluginConfigurationException(
PluginDescriptor pluginDescriptor,
String originalMessage )
{
super( "Error configuring: " + pluginDescriptor.getPluginLookupKey() + ". Reason: " + message );
super( originalMessage );
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = message;
this.originalMessage = originalMessage;
}
public PluginConfigurationException( PluginDescriptor pluginDescriptor, Throwable cause )
public PluginConfigurationException(
PluginDescriptor pluginDescriptor,
String originalMessage,
Throwable e )
{
super( "Error configuring: " + pluginDescriptor.getPluginLookupKey() + ".", cause );
super( e );
this.pluginDescriptor = pluginDescriptor;
}
public PluginConfigurationException( PluginDescriptor pluginDescriptor, String message, Throwable cause )
{
super( "Error configuring: " + pluginDescriptor.getPluginLookupKey() + ". Reason: " + message, cause );
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = message;
}
public PluginDescriptor getPluginDescriptor()
{
return pluginDescriptor;
}
public String getOriginalMessage()
{
return originalMessage;
}
protected static void addParameterUsageInfo( String expression, StringBuffer messageBuffer )
{
StringBuffer expressionMessageBuffer = new StringBuffer();
Matcher exprMatcher = Pattern.compile( "\\$\\{(.+)\\}" ).matcher( expression );
boolean unmodifiableElementsFound = false;
boolean activeElementsFound = false;
int elementCount = 0;
while ( exprMatcher.find() )
{
elementCount++;
activeElementsFound = true;
String subExpression = exprMatcher.group( 1 );
StringTokenizer expressionParts = new StringTokenizer( subExpression, "." );
String firstPart = expressionParts.nextToken();
Map expressions = null;
try
{
expressions = ExpressionDocumenter.load();
}
catch ( ExpressionDocumentationException e )
{
expressionMessageBuffer.append( "\n\nERROR!! Failed to load expression documentation!" );
StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter( sWriter );
e.printStackTrace( pWriter );
expressionMessageBuffer.append( "\n\nException:\n\n" ).append( sWriter.toString() );
}
if ( expressions != null )
{
Expression expr = (Expression) expressions.get( subExpression );
if ( expr != null )
{
if ( !expr.isEditable() )
{
unmodifiableElementsFound = true;
}
else
{
addParameterConfigDocumentation( firstPart, exprMatcher.group( 0 ), subExpression,
expressionMessageBuffer, expressions );
}
}
else if ( UNMODIFIABLE_EXPRESSIONS.contains( subExpression ) )
{
unmodifiableElementsFound = true;
}
else
{
expressionMessageBuffer.append( "on the command line, specify: \'-D" ).append( subExpression )
.append( "=VALUE\'" );
}
}
}
if ( activeElementsFound )
{
messageBuffer.append( expressionMessageBuffer );
}
else
{
messageBuffer.append(
" (found static expression: \'" + expression + "\' which may act as a default value).\n" );
}
if ( unmodifiableElementsFound )
{
if ( elementCount > 1 )
{
messageBuffer.append( " " );
}
messageBuffer
.append( "NOTE: One or more purely derived expression elements were detected in \'" + expression +
"\'.\n If you continue to get this error after any other expression elements are specified correctly," +
"\n please report this issue to the Maven development team.\n" );
}
}
private static void addParameterConfigDocumentation( String firstPart, String wholeExpression, String subExpression,
StringBuffer expressionMessageBuffer, Map expressionDoco )
{
Expression expr = (Expression) expressionDoco.get( subExpression );
if ( expr != null )
{
expressionMessageBuffer.append( "check that the following section of " );
if ( "project".equals( firstPart ) )
{
expressionMessageBuffer.append( "the pom.xml " );
}
else if ( "settings".equals( firstPart ) )
{
expressionMessageBuffer.append( "your ~/.m2/settings.xml file " );
}
expressionMessageBuffer.append( "is present and correct:\n\n" );
String message = expr.getConfiguration();
if ( message == null )
{
message = expr.getDescription();
}
expressionMessageBuffer.append( message );
Properties cliConfig = expr.getCliOptions();
if ( cliConfig != null && !cliConfig.isEmpty() )
{
expressionMessageBuffer.append( "\n\n-OR-\n\nUse the following command-line switches:\n" );
prettyPrintCommandLineSwitches( cliConfig, '.', expressionMessageBuffer );
}
}
else
{
expressionMessageBuffer.append( "ensure that the expression: \'" + wholeExpression + "\' is satisfied" );
}
}
private static void prettyPrintCommandLineSwitches( Properties switches, char filler,
StringBuffer expressionMessageBuffer )
{
int maxKeyLen = 0;
for ( Iterator it = switches.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
int keyLen = key.length();
if ( keyLen > maxKeyLen )
{
maxKeyLen = keyLen;
}
}
final int minFillerCount = 4;
for ( Iterator it = switches.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
int keyLen = key.length();
int fillerCount = maxKeyLen - keyLen + minFillerCount;
expressionMessageBuffer.append( '\n' ).append( key ).append( ' ' );
for ( int i = 0; i < fillerCount; i++ )
{
expressionMessageBuffer.append( filler );
}
expressionMessageBuffer.append( ' ' ).append( entry.getValue() );
}
expressionMessageBuffer.append( '\n' );
}
public String buildConfigurationDiagnosticMessage( ComponentConfigurationException cce )
{
StringBuffer message = new StringBuffer();
PluginDescriptor descriptor = getPluginDescriptor();
PlexusConfiguration failedConfiguration = cce.getFailedConfiguration();
message.append( "Failed to configure plugin parameters for: " + descriptor.getId() + "\n\n" );
if ( failedConfiguration != null )
{
String value = failedConfiguration.getValue( null );
if ( value != null )
{
addParameterUsageInfo( value, message );
}
}
message.append( "\n\nCause: " ).append( cce.getMessage() );
return message.toString();
this.originalMessage = originalMessage;
}
}

View File

@ -94,7 +94,7 @@ public class PluginParameterException
messageBuffer.append( "\n\n-OR-\n\n" );
}
addParameterUsageInfo( expression, messageBuffer );
//addParameterUsageInfo( expression, messageBuffer );
}
}

View File

@ -1,62 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
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.\n" );
message.append( "\nGroupId: " ).append( exception.getGroupId() );
message.append( "\nArtifactId: " ).append( exception.getArtifactId() );
message.append( "\nVersion: " ).append( exception.getVersion() );
message.append( "\n\n" );
message.append( "Reason: " ).append( exception.getMessage() );
if ( !wagonManager.isOnline() )
{
message.append( "\n" ).append( SystemWarnings.getOfflineWarning() );
}
message.append( "\n" );
return message.toString();
}
}

View File

@ -1,68 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.ArtifactResolutionException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
import java.io.IOException;
public class ArtifactResolverDiagnoser
implements ErrorDiagnoser
{
private WagonManager wagonManager;
public boolean canDiagnose( Throwable error )
{
return DiagnosisUtils.containsInCausality( error, ArtifactResolutionException.class );
}
public String diagnose( Throwable error )
{
ArtifactResolutionException exception =
(ArtifactResolutionException) DiagnosisUtils.getFromCausality( error, ArtifactResolutionException.class );
StringBuffer message = new StringBuffer();
message.append( "Failed to resolve artifact." );
message.append( "\n\n" );
message.append( exception.getMessage() );
IOException ioe = (IOException) DiagnosisUtils.getFromCausality( exception, IOException.class );
if ( ioe != null && exception.getMessage().indexOf( ioe.getMessage() ) < 0 )
{
message.append( "\n\nCaused by I/O exception: " ).append( ioe.getMessage() );
}
if ( !wagonManager.isOnline() )
{
message.append( "\n" ).append( SystemWarnings.getOfflineWarning() );
}
message.append( "\n" );
return message.toString();
}
}

View File

@ -1,65 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.InvalidArtifactRTException;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
public class InvalidArtifactDiagnoser
implements ErrorDiagnoser
{
public boolean canDiagnose( Throwable error )
{
return error instanceof InvalidArtifactRTException;
}
public String diagnose( Throwable error )
{
StringBuffer diagnosis = new StringBuffer();
InvalidArtifactRTException e = (InvalidArtifactRTException) error;
diagnosis.append( "An invalid artifact was detected.\n\n" )
.append( "This artifact might be in your project's POM, " )
.append( "or it might have been included transitively during the resolution process. " )
.append( "Here is the information we do have for this artifact:\n" )
.append( "\n o GroupID: " ).append( maybeFlag( e.getGroupId() ) )
.append( "\n o ArtifactID: " ).append( maybeFlag( e.getArtifactId() ) )
.append( "\n o Version: " ).append( maybeFlag( e.getVersion() ) )
.append( "\n o Type: " ).append( maybeFlag( e.getType() ) )
.append( "\n" );
return diagnosis.toString();
}
private String maybeFlag( String value )
{
if ( value == null || value.trim().length() < 1 )
{
return "<<< MISSING >>>";
}
else
{
return value;
}
}
}

View File

@ -1,75 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.plugin.MojoExecutionException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
public class MojoExecutionExceptionDiagnoser
implements ErrorDiagnoser
{
public boolean canDiagnose( Throwable error )
{
return DiagnosisUtils.containsInCausality( error, MojoExecutionException.class );
}
public String diagnose( Throwable error )
{
MojoExecutionException mee =
(MojoExecutionException) DiagnosisUtils.getFromCausality( error, MojoExecutionException.class );
StringBuffer message = new StringBuffer();
Object source = mee.getSource();
if ( source != null )
{
message.append( ": " ).append( mee.getSource() ).append( "\n" );
}
message.append( mee.getMessage() );
String longMessage = mee.getLongMessage();
if ( longMessage != null )
{
message.append( "\n\n" ).append( longMessage );
}
Throwable directCause = mee.getCause();
if ( directCause != null )
{
message.append( "\n" );
String directCauseMessage = directCause.getMessage();
if ( directCauseMessage != null && mee.getMessage().indexOf( directCauseMessage ) < 0 )
{
message.append( "\nEmbedded error: " ).append( directCauseMessage );
}
DiagnosisUtils.appendRootCauseIfPresentAndUnique( directCause, message, false );
}
return message.toString();
}
}

View File

@ -1,59 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.plugin.MojoFailureException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
public class MojoFailureExceptionDiagnoser
implements ErrorDiagnoser
{
public boolean canDiagnose( Throwable error )
{
return DiagnosisUtils.containsInCausality( error, MojoFailureException.class );
}
public String diagnose( Throwable error )
{
MojoFailureException mfe =
(MojoFailureException) DiagnosisUtils.getFromCausality( error, MojoFailureException.class );
StringBuffer message = new StringBuffer();
Object source = mfe.getSource();
if ( source != null )
{
message.append( ": " ).append( mfe.getSource() ).append( "\n" );
}
message.append( mfe.getMessage() );
String longMessage = mfe.getLongMessage();
if ( longMessage != null )
{
message.append( "\n\n" ).append( longMessage );
}
return message.toString();
}
}

View File

@ -1,59 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginParameterException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
public class PluginConfigurationDiagnoser
implements ErrorDiagnoser
{
public boolean canDiagnose( Throwable error )
{
return DiagnosisUtils.containsInCausality( error, PluginConfigurationException.class );
}
public String diagnose( Throwable error )
{
PluginConfigurationException pce =
(PluginConfigurationException) DiagnosisUtils.getFromCausality( error, PluginConfigurationException.class );
if ( pce instanceof PluginParameterException )
{
PluginParameterException exception = (PluginParameterException) pce;
return exception.buildDiagnosticMessage();
}
else if ( DiagnosisUtils.containsInCausality( pce, ComponentConfigurationException.class ) )
{
ComponentConfigurationException cce = (ComponentConfigurationException) DiagnosisUtils.getFromCausality(
pce, ComponentConfigurationException.class );
return pce.buildConfigurationDiagnosticMessage( cce );
}
else
{
return pce.getMessage();
}
}
}

View File

@ -1,60 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.profiles.activation.ProfileActivationException;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
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() );
}
messageBuffer.append( "\n" );
return messageBuffer.toString();
}
}

View File

@ -1,69 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.project.InvalidProjectModelException;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.usability.diagnostics.DiagnosisUtils;
import org.apache.maven.usability.diagnostics.ErrorDiagnoser;
public class ProjectBuildDiagnoser
implements ErrorDiagnoser
{
public boolean canDiagnose( Throwable error )
{
return DiagnosisUtils.containsInCausality( error, ProjectBuildingException.class );
}
public String diagnose( Throwable error )
{
ProjectBuildingException pbe =
(ProjectBuildingException) DiagnosisUtils.getFromCausality( error, ProjectBuildingException.class );
StringBuffer message = new StringBuffer();
message.append( "Error building POM (may not be this project's POM)." ).append( "\n\n" );
message.append( "\nProject ID: " ).append( pbe.getProjectId() );
if ( pbe instanceof InvalidProjectModelException )
{
InvalidProjectModelException ipme = (InvalidProjectModelException) pbe;
message.append( "\nPOM Location: " ).append( ipme.getPomLocation() );
ModelValidationResult result = ipme.getValidationResult();
if ( result != null )
{
message.append( "\nValidation Messages:\n\n" ).append( ipme.getValidationResult().render( " " ) );
}
}
message.append( "\n\n" ).append( "Reason: " ).append( pbe.getMessage() );
message.append( "\n\n" );
return message.toString();
}
}

View File

@ -1,29 +0,0 @@
package org.apache.maven.usability;/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
public class SystemWarnings
{
public static String getOfflineWarning()
{
return "\nNOTE: Maven is executing in offline mode. Any artifacts not already in your local\n" +
"repository will be inaccessible.\n";
}
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.usability.plugin;/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
public class ExpressionDocumentationException
extends Exception
{
static final long serialVersionUID = 1;
public ExpressionDocumentationException( String message, Throwable cause )
{
super( message, cause );
}
public ExpressionDocumentationException( String message )
{
super( message );
}
}

View File

@ -1,147 +0,0 @@
package org.apache.maven.usability.plugin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.usability.plugin.io.xpp3.ParamdocXpp3Reader;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class ExpressionDocumenter
{
private static final String[] EXPRESSION_ROOTS = { "project", "settings", "session", "plugin", "rootless" };
private static final String EXPRESSION_DOCO_ROOTPATH = "META-INF/maven/plugin-expressions/";
private static Map expressionDocumentation;
public static Map load()
throws ExpressionDocumentationException
{
if ( expressionDocumentation == null )
{
expressionDocumentation = new HashMap();
ClassLoader docLoader = initializeDocLoader();
for ( int i = 0; i < EXPRESSION_ROOTS.length; i++ )
{
InputStream docStream = null;
try
{
docStream = docLoader
.getResourceAsStream( EXPRESSION_DOCO_ROOTPATH + EXPRESSION_ROOTS[i] + ".paramdoc.xml" );
if ( docStream != null )
{
Map doco = parseExpressionDocumentation( docStream );
expressionDocumentation.putAll( doco );
}
}
catch ( IOException e )
{
throw new ExpressionDocumentationException( "Failed to read documentation for expression root: " + EXPRESSION_ROOTS[i], e );
}
catch ( XmlPullParserException e )
{
throw new ExpressionDocumentationException( "Failed to parse documentation for expression root: " + EXPRESSION_ROOTS[i], e );
}
finally
{
IOUtil.close( docStream );
}
}
}
return expressionDocumentation;
}
/**
* <expressions>
* <expression>
* <syntax>project.distributionManagementArtifactRepository</syntax>
* <origin><![CDATA[
* <distributionManagement>
* <repository>
* <id>some-repo</id>
* <url>scp://host/path</url>
* </repository>
* <snapshotRepository>
* <id>some-snap-repo</id>
* <url>scp://host/snapshot-path</url>
* </snapshotRepository>
* </distributionManagement>
* ]]></origin>
* <usage><![CDATA[
* The repositories onto which artifacts should be deployed.
* One is for releases, the other for snapshots.
* ]]></usage>
* </expression>
* <expressions>
* @throws IOException
* @throws XmlPullParserException
*/
private static Map parseExpressionDocumentation( InputStream docStream )
throws IOException, XmlPullParserException
{
Reader reader = new BufferedReader( new InputStreamReader( docStream ) );
ParamdocXpp3Reader paramdocReader = new ParamdocXpp3Reader();
ExpressionDocumentation documentation = paramdocReader.read( reader, true );
List expressions = documentation.getExpressions();
Map bySyntax = new HashMap();
if ( expressions != null && !expressions.isEmpty() )
{
for ( Iterator it = expressions.iterator(); it.hasNext(); )
{
Expression expr = (Expression) it.next();
bySyntax.put( expr.getSyntax(), expr );
}
}
return bySyntax;
}
private static ClassLoader initializeDocLoader()
throws ExpressionDocumentationException
{
return ExpressionDocumenter.class.getClassLoader();
}
}

View File

@ -144,9 +144,6 @@ under the License.
<requirement>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
</requirement>
<requirement>
<role>org.apache.maven.usability.diagnostics.ErrorDiagnostics</role>
</requirement>
<requirement>
<role>org.apache.maven.execution.RuntimeInformation</role>
</requirement>

View File

@ -1,92 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.codehaus.plexus.PlexusTestCase;
public class InvalidArtifactDiagnoserTest
extends PlexusTestCase
{
private InvalidArtifactDiagnoser diagnoser = new InvalidArtifactDiagnoser();
public void testShouldDiagnoseArtifactWithMissingGroupId() throws Throwable
{
testDiagnosis( "Test diagnosis for missing groupId", null, "test-artifact", "1.0", "jar" );
}
public void testShouldDiagnoseArtifactWithMissingArtifactId() throws Throwable
{
testDiagnosis( "Test diagnosis for missing artifactId", "test.group.id", null, "1.0", "jar" );
}
public void testShouldDiagnoseArtifactWithMissingVersion() throws Throwable
{
testDiagnosis( "Test diagnosis for missing version", "test.group.id", "test-artifact", null, "jar" );
}
public void testShouldDiagnoseArtifactWithMissingType() throws Throwable
{
testDiagnosis( "Test diagnosis for missing type", "test.group.id", "test-artifact", "1.0", null );
}
public void testShouldDiagnoseArtifactWithMissingGroupIdAndArtifactId() throws Throwable
{
testDiagnosis( "Test diagnosis for missing groupId and artifactId", null, null, "1.0", "jar" );
}
private void testDiagnosis( String testHeader, String groupId, String artifactId, String version, String type )
throws Throwable
{
System.out.println( "------------------------------------------------------------" );
System.out.println( "| " + testHeader );
System.out.println( "------------------------------------------------------------" );
System.out.println();
try
{
createArtifact( groupId, artifactId, version, type );
fail( "artifact creation did not fail; nothing to diagnose." );
}
catch ( Throwable error )
{
assertTrue( "Unexpected error while constructing artifact: " + error, diagnoser.canDiagnose( error ) );
if ( diagnoser.canDiagnose( error ) )
{
System.out.println( diagnoser.diagnose( error ) );
}
else
{
throw error;
}
}
}
private Artifact createArtifact( String groupId, String artifactId, String version, String type )
throws Exception
{
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
return artifactFactory.createBuildArtifact( groupId, artifactId, version, type );
}
}

View File

@ -1,280 +0,0 @@
package org.apache.maven.usability;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 junit.framework.TestCase;
import org.apache.maven.plugin.PluginConfigurationException;
import org.apache.maven.plugin.PluginParameterException;
import org.apache.maven.plugin.descriptor.DuplicateParameterException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class PluginErrorDiagnoserTest
extends TestCase
{
private PluginConfigurationDiagnoser diagnoser = new PluginConfigurationDiagnoser();
private PluginParameterException buildException( String prefix, String goal, List params )
throws DuplicateParameterException
{
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setArtifactId( "maven-test-plugin" );
pluginDescriptor.setGroupId( "org.apache.maven.plugins" );
pluginDescriptor.setVersion( "1.0" );
pluginDescriptor.setGoalPrefix( prefix );
MojoDescriptor mojoDescriptor = new MojoDescriptor();
mojoDescriptor.setGoal( goal );
mojoDescriptor.setPluginDescriptor( pluginDescriptor );
mojoDescriptor.setParameters( params );
return new PluginParameterException( mojoDescriptor, params );
}
public void testShouldDiagnoseInvalidPluginConfiguration()
{
printMethodHeader();
ComponentConfigurationException cce = new ComponentConfigurationException(
"Class \'org.apache.maven.plugin.jar.JarMojo\' does not contain a field named \'addClasspath\'" );
PluginDescriptor pd = new PluginDescriptor();
pd.setGroupId("testGroup");
pd.setArtifactId("testArtifact");
PluginConfigurationException pce = new PluginConfigurationException( pd, "test", cce );
assertTrue( diagnoser.canDiagnose( pce ) );
String userMessage = diagnoser.diagnose( pce );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testShouldBeAbleToDiagnosePluginParameterExceptions()
throws DuplicateParameterException
{
Parameter param = new Parameter();
param.setName( "testName" );
param.setAlias( "testAlias" );
param.setExpression( "${project.build.finalName}" );
param.setEditable( true );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
assertTrue( diagnoser.canDiagnose( error ) );
}
public void testParamWithOneReportsExpressionAndOneProjectBasedExpression()
throws DuplicateParameterException
{
printMethodHeader();
List params = new ArrayList();
Parameter param = new Parameter();
param.setName( "param1" );
param.setExpression( "${reports}" );
param.setEditable( false );
params.add( param );
Parameter param2 = new Parameter();
param2.setName( "param2" );
param2.setExpression( "${project.build.finalName}" );
param2.setEditable( false );
params.add( param2 );
PluginParameterException error = buildException( "test", "test", params );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testParamWithNonActiveExpression()
throws DuplicateParameterException
{
printMethodHeader();
Parameter param = new Parameter();
param.setName( "testName" );
param.setAlias( "testAlias" );
param.setExpression( "${project.build.finalName" );
param.setEditable( true );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testParamWithoutExpression()
throws DuplicateParameterException
{
printMethodHeader();
Parameter param = new Parameter();
param.setName( "testName" );
param.setAlias( "testAlias" );
param.setEditable( true );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testParamWithOneLocalRepositoryExpression()
throws DuplicateParameterException
{
printMethodHeader();
Parameter param = new Parameter();
param.setName( "testName" );
param.setAlias( "testAlias" );
param.setExpression( "${localRepository}" );
param.setEditable( false );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testParamWithOneSystemPropertyExpression()
throws DuplicateParameterException
{
printMethodHeader();
Parameter param = new Parameter();
param.setName( "testName" );
param.setAlias( "testAlias" );
param.setExpression( "${maven.mode.online}" );
param.setEditable( false );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testParamWithOneProjectBasedExpression()
throws DuplicateParameterException
{
printMethodHeader();
Parameter param = new Parameter();
param.setName( "testName" );
param.setAlias( "testAlias" );
param.setExpression( "${project.build.finalName}" );
param.setEditable( true );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testParamWithOneProjectAPIBasedExpression()
throws DuplicateParameterException
{
printMethodHeader();
Parameter param = new Parameter();
param.setName( "testName" );
param.setExpression( "${project.distributionManagementArtifactRepository}" );
param.setRequired( true );
param.setEditable( false );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
public void testNonEditableParamWithOneProjectBasedExpression()
throws DuplicateParameterException
{
printMethodHeader();
Parameter param = new Parameter();
param.setName( "testName" );
param.setAlias( "testAlias" );
param.setExpression( "${project.build.finalName}" );
param.setEditable( false );
PluginParameterException error = buildException( "test", "test", Collections.singletonList( param ) );
String userMessage = diagnoser.diagnose( error );
System.out.println( userMessage );
assertNotNull( userMessage );
}
private void printMethodHeader()
{
IllegalArgumentException marker = new IllegalArgumentException();
System.out.println( "---------------------------------------------------------------------\n"
+ "Visual output for " + marker.getStackTrace()[1].getMethodName()
+ ":\n---------------------------------------------------------------------" );
}
}

View File

@ -35,9 +35,9 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.ReactorManager;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.logging.Logger;
import java.io.File;
import java.io.IOException;
@ -422,16 +422,12 @@ public class MavenCli
if ( result.hasExceptions() )
{
showError( (Exception) result.getExceptions().get( 0 ), showErrors );
logger.close();
return 1;
}
logger.close();
return 0;
else
{
return 0;
}
}
private static void showVersion()
@ -547,7 +543,6 @@ public class MavenCli
{
ReactorManager reactorManager = result.getReactorManager();
// TODO: should all the logging be left to the CLI?
logReactorSummary( reactorManager );
if ( reactorManager != null && reactorManager.hasBuildFailures() )
@ -572,11 +567,29 @@ public class MavenCli
}
}
logSuccess( reactorManager );
if ( result.hasExceptions() )
{
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
{
Exception e = (Exception) i.next();
stats( request.getStartTime() );
showError( e.getMessage(), e, request.isShowErrors() );
}
}
else
{
line();
line();
getLogger().info( "BUILD SUCCESSFUL" );
line();
stats( request.getStartTime() );
line();
}
logger.close();
}
private void logErrors( ReactorManager rm,
@ -594,10 +607,6 @@ public class MavenCli
"Error for project: " + project.getName() + " (during " + buildFailure.getTask() + ")" );
line();
logTrace(
buildFailure.getCause(),
showErrors );
}
}
@ -609,12 +618,6 @@ public class MavenCli
}
}
private static void showError( Exception e,
boolean show )
{
showError( e.getMessage(), e, show );
}
private static void showError( String message,
Exception e,
boolean show )
@ -634,36 +637,6 @@ public class MavenCli
System.err.println( "For more information, run with the -e flag" );
}
}
private void logTrace( Throwable t,
boolean showErrors )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Trace",
t );
line();
}
else if ( showErrors )
{
getLogger().info(
"Trace",
t );
line();
}
}
private void logSuccess( ReactorManager rm )
{
line();
getLogger().info( "BUILD SUCCESSFUL" );
line();
}
private void logReactorSummary( ReactorManager rm )
{

View File

@ -36,7 +36,6 @@ import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.usability.SystemWarnings;
import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
@ -125,7 +124,7 @@ public class DefaultMavenExecutionRequestPopulator
if ( request.isOffline() )
{
getLogger().info( SystemWarnings.getOfflineWarning() );
getLogger().info( "You are working in offline mode." );
wagonManager.setOnline( false );
}

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<version>2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-error-diagnostics</artifactId>
<name>Maven Error Diagnostics</name>
<description>Provides a manager component which will process a given Throwable instance through a set of diagnostic
sub-components, and return a String message with user-friendly information about the error and possibly
how to fix it.</description>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,108 +0,0 @@
package org.apache.maven.usability.diagnostics;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
public final class DiagnosisUtils
{
private DiagnosisUtils()
{
}
public static boolean containsInCausality( Throwable error, Class test )
{
Throwable cause = error;
while ( cause != null )
{
if ( test.isInstance( cause ) )
{
return true;
}
cause = cause.getCause();
}
return false;
}
public static Throwable getRootCause( Throwable error )
{
Throwable cause = error;
while ( true )
{
Throwable nextCause = cause.getCause();
if ( nextCause == null )
{
break;
}
else
{
cause = nextCause;
}
}
return cause;
}
public static Throwable getFromCausality( Throwable error, Class targetClass )
{
Throwable cause = error;
while ( cause != null )
{
if ( targetClass.isInstance( cause ) )
{
return cause;
}
cause = cause.getCause();
}
return null;
}
public static void appendRootCauseIfPresentAndUnique( Throwable error, StringBuffer message,
boolean includeTypeInfo )
{
if ( error == null )
{
return;
}
Throwable root = getRootCause( error );
if ( root != null && !root.equals( error ) )
{
String rootMsg = root.getMessage();
if ( rootMsg != null && ( error.getMessage() == null || error.getMessage().indexOf( rootMsg ) < 0 ) )
{
message.append( "\n" ).append( rootMsg );
if ( includeTypeInfo )
{
message.append( "\nRoot error type: " ).append( root.getClass().getName() );
}
}
}
}
}

View File

@ -1,30 +0,0 @@
package org.apache.maven.usability.diagnostics;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
public interface ErrorDiagnoser
{
public static final String ROLE = ErrorDiagnoser.class.getName();
public boolean canDiagnose( Throwable error );
public String diagnose( Throwable error );
}

View File

@ -1,141 +0,0 @@
package org.apache.maven.usability.diagnostics;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.util.Iterator;
import java.util.List;
public class ErrorDiagnostics
extends AbstractLogEnabled
implements Contextualizable
{
public static final String ROLE = ErrorDiagnostics.class.getName();
private PlexusContainer container;
private List errorDiagnosers;
public void setErrorDiagnosers( List errorDiagnosers )
{
this.errorDiagnosers = errorDiagnosers;
}
public String diagnose( Throwable error )
{
List diags = errorDiagnosers;
boolean releaseDiags = false;
boolean errorProcessed = false;
String message = null;
try
{
if ( diags == null )
{
releaseDiags = true;
try
{
diags = container.lookupList( ErrorDiagnoser.ROLE );
}
catch ( ComponentLookupException e )
{
getLogger().error( "Failed to lookup the list of error diagnosers.", e );
}
}
if ( diags != null )
{
for ( Iterator it = diags.iterator(); it.hasNext(); )
{
ErrorDiagnoser diagnoser = (ErrorDiagnoser) it.next();
if ( diagnoser.canDiagnose( error ) )
{
errorProcessed = true;
message = diagnoser.diagnose( error );
break;
}
}
}
}
finally
{
if ( releaseDiags && diags != null )
{
try
{
container.releaseAll( diags );
}
catch ( ComponentLifecycleException e )
{
getLogger().debug( "Failed to release error diagnoser list.", e );
}
}
if ( !errorProcessed )
{
message = new PuntErrorDiagnoser().diagnose( error );
}
}
return message;
}
public void contextualize( Context context )
throws ContextException
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
private static class PuntErrorDiagnoser
implements ErrorDiagnoser
{
public boolean canDiagnose( Throwable error )
{
return true;
}
public String diagnose( Throwable error )
{
StringBuffer message = new StringBuffer();
message.append( error.getMessage() );
DiagnosisUtils.appendRootCauseIfPresentAndUnique( error, message, false );
return message.toString();
}
}
}

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<component-set>
<components>
<component>
<role>org.apache.maven.usability.diagnostics.ErrorDiagnostics</role>
<implementation>org.apache.maven.usability.diagnostics.ErrorDiagnostics</implementation>
</component>
</components>
</component-set>

View File

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>maven</artifactId>
<groupId>org.apache.maven</groupId>
<version>2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-monitor</artifactId>
<name>Maven Monitor</name>
</project>

View File

@ -112,10 +112,8 @@ under the License.
<modules>
<module>maven-build-context</module>
<module>maven-core</module>
<module>maven-error-diagnostics</module>
<module>maven-lifecycle</module>
<module>maven-model</module>
<module>maven-monitor</module>
<module>maven-plugin-api</module>
<module>maven-plugin-descriptor</module>
<module>maven-plugin-parameter-documenter</module>