o Fixed exception handling for repo metadata to properly report edge cases of inaccessible files

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1057209 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-01-10 14:14:28 +00:00
parent 8e60779cbb
commit 34146f5e76
3 changed files with 19 additions and 16 deletions

View File

@ -20,7 +20,6 @@ package org.apache.maven.repository.internal;
*/ */
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -212,17 +211,13 @@ public class DefaultVersionRangeResolver
FileInputStream fis = null; FileInputStream fis = null;
try try
{ {
if ( metadata != null && metadata.getFile() != null ) if ( metadata != null && metadata.getFile() != null && metadata.getFile().exists() )
{ {
fis = new FileInputStream( metadata.getFile() ); fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false ); org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false );
versioning = m.getVersioning(); versioning = m.getVersioning();
} }
} }
catch ( FileNotFoundException e )
{
// tolerable
}
catch ( Exception e ) catch ( Exception e )
{ {
invalidMetadata( session, metadata, repository, e ); invalidMetadata( session, metadata, repository, e );

View File

@ -21,7 +21,6 @@ package org.apache.maven.repository.internal;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -281,7 +280,7 @@ public class DefaultVersionResolver
FileInputStream fis = null; FileInputStream fis = null;
try try
{ {
if ( metadata != null && metadata.getFile() != null ) if ( metadata != null && metadata.getFile() != null && metadata.getFile().exists() )
{ {
fis = new FileInputStream( metadata.getFile() ); fis = new FileInputStream( metadata.getFile() );
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false ); org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false );
@ -309,10 +308,6 @@ public class DefaultVersionResolver
} }
} }
} }
catch ( FileNotFoundException e )
{
// tolerable
}
catch ( Exception e ) catch ( Exception e )
{ {
invalidMetadata( session, metadata, repository, e ); invalidMetadata( session, metadata, repository, e );

View File

@ -19,6 +19,8 @@ package org.apache.maven;
* under the License. * under the License.
*/ */
import java.io.FileNotFoundException;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import org.sonatype.aether.AbstractRepositoryListener; import org.sonatype.aether.AbstractRepositoryListener;
import org.sonatype.aether.RepositoryEvent; import org.sonatype.aether.RepositoryEvent;
@ -74,6 +76,8 @@ class LoggingRepositoryListener
@Override @Override
public void metadataInvalid( RepositoryEvent event ) public void metadataInvalid( RepositoryEvent event )
{ {
Exception exception = event.getException();
StringBuilder buffer = new StringBuilder( 256 ); StringBuilder buffer = new StringBuilder( 256 );
buffer.append( "The metadata " ); buffer.append( "The metadata " );
if ( event.getMetadata().getFile() != null ) if ( event.getMetadata().getFile() != null )
@ -84,16 +88,25 @@ class LoggingRepositoryListener
{ {
buffer.append( event.getMetadata() ); buffer.append( event.getMetadata() );
} }
if ( exception instanceof FileNotFoundException )
{
buffer.append( " is inaccessible" );
}
else
{
buffer.append( " is invalid" ); buffer.append( " is invalid" );
if ( event.getException() != null ) }
if ( exception != null )
{ {
buffer.append( ": " ); buffer.append( ": " );
buffer.append( event.getException().getMessage() ); buffer.append( exception.getMessage() );
} }
if ( logger.isDebugEnabled() ) if ( logger.isDebugEnabled() )
{ {
logger.warn( buffer.toString(), event.getException() ); logger.warn( buffer.toString(), exception );
} }
else else
{ {