o Improved error reporting

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@826015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-16 17:45:41 +00:00
parent 0514606a44
commit b244bda0fd
5 changed files with 43 additions and 25 deletions

View File

@ -1281,11 +1281,11 @@ public class DefaultLifecycleExecutor
}
catch ( IOException e )
{
throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), e );
throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), pluginDescriptor.getSource(), e );
}
catch ( XmlPullParserException e )
{
throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), e );
throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), pluginDescriptor.getSource(), e );
}
if ( lifecycleOverlay == null )

View File

@ -32,11 +32,6 @@ public class InvalidPluginDescriptorException
this.errors = errors;
}
public InvalidPluginDescriptorException( String message )
{
super( message );
}
private static String toMessage( String message, List<String> errors )
{
StringBuilder buffer = new StringBuilder( 256 );

View File

@ -27,11 +27,35 @@ import org.apache.maven.model.Plugin;
public class PluginDescriptorParsingException
extends Exception
{
private Plugin plugin;
public PluginDescriptorParsingException( Plugin plugin, Exception e )
public PluginDescriptorParsingException( Plugin plugin, String descriptorLocation, Throwable e )
{
super( e );
super( createMessage( plugin, descriptorLocation, e ), e );
this.plugin = plugin;
}
private static String createMessage( Plugin plugin, String descriptorLocation, Throwable e )
{
String message = "Failed to parse plugin descriptor";
if ( plugin != null )
{
message += " for " + plugin.getId();
}
if ( descriptorLocation != null )
{
message += " (" + descriptorLocation + ")";
}
if ( e != null )
{
message += ": " + e.getMessage();
}
return message;
}
}

View File

@ -195,7 +195,7 @@ public class DefaultMavenPluginManager
{
InputStream is = pluginJar.getInputStream( pluginDescriptorEntry );
pluginDescriptor = parsePluginDescriptor( is, plugin );
pluginDescriptor = parsePluginDescriptor( is, plugin, pluginFile.getAbsolutePath() );
}
}
finally
@ -207,12 +207,12 @@ public class DefaultMavenPluginManager
{
File pluginXml = new File( pluginFile, getPluginDescriptorLocation() );
if ( pluginXml.canRead() )
if ( pluginXml.isFile() )
{
InputStream is = new BufferedInputStream( new FileInputStream( pluginXml ) );
try
{
pluginDescriptor = parsePluginDescriptor( is, plugin );
pluginDescriptor = parsePluginDescriptor( is, plugin, pluginXml.getAbsolutePath() );
}
finally
{
@ -220,16 +220,15 @@ public class DefaultMavenPluginManager
}
}
}
if ( pluginDescriptor == null )
{
throw new IOException( "No plugin descriptor found at " + getPluginDescriptorLocation() );
}
}
catch ( IOException e )
{
throw new PluginDescriptorParsingException( plugin, e );
}
if ( pluginDescriptor == null )
{
throw new InvalidPluginDescriptorException( "Missing plugin descriptor for " + plugin.getId() + " ("
+ pluginFile + ")" );
throw new PluginDescriptorParsingException( plugin, pluginFile.getAbsolutePath(), e );
}
MavenPluginValidator validator = new MavenPluginValidator( pluginArtifact );
@ -252,24 +251,24 @@ public class DefaultMavenPluginManager
return "META-INF/maven/plugin.xml";
}
private PluginDescriptor parsePluginDescriptor( InputStream is, Plugin plugin )
private PluginDescriptor parsePluginDescriptor( InputStream is, Plugin plugin, String descriptorLocation )
throws PluginDescriptorParsingException
{
try
{
Reader reader = ReaderFactory.newXmlReader( is );
PluginDescriptor pluginDescriptor = builder.build( reader );
PluginDescriptor pluginDescriptor = builder.build( reader, descriptorLocation );
return pluginDescriptor;
}
catch ( IOException e )
{
throw new PluginDescriptorParsingException( plugin, e );
throw new PluginDescriptorParsingException( plugin, descriptorLocation, e );
}
catch ( PlexusConfigurationException e )
{
throw new PluginDescriptorParsingException( plugin, e );
throw new PluginDescriptorParsingException( plugin, descriptorLocation, e );
}
}

View File

@ -344,11 +344,11 @@ public class PluginDescriptorBuilder
}
catch ( IOException e )
{
throw new PlexusConfigurationException( "Error creating configuration", e );
throw new PlexusConfigurationException( e.getMessage(), e );
}
catch ( XmlPullParserException e )
{
throw new PlexusConfigurationException( "Error creating configuration", e );
throw new PlexusConfigurationException( e.getMessage(), e );
}
}
}