From 9202e38f96c8ade5f792f95579107ef0d514badc Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 7 Jun 2006 08:46:19 +0000 Subject: [PATCH] error handling git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@412327 13f79535-47bb-0310-9956-ffa450edef68 --- .../converter/DefaultRepositoryConverter.java | 1 - .../discovery/DefaultMetadataDiscoverer.java | 182 +++++++++--------- 2 files changed, 94 insertions(+), 89 deletions(-) diff --git a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java index d06f9bfdd..3c8a5b998 100644 --- a/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java +++ b/maven-repository-converter/src/main/java/org/apache/maven/repository/converter/DefaultRepositoryConverter.java @@ -463,7 +463,6 @@ public class DefaultRepositoryConverter } catch ( PomTranslationException e ) { - // TODO! check handling, fix error message reporter.addFailure( artifact, getI18NString( "failure.invalid.source.pom", e.getMessage() ) ); result = false; } diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java index f68990a08..e07cd14d3 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java @@ -26,7 +26,6 @@ import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -92,106 +91,113 @@ public class DefaultMetadataDiscoverer */ private RepositoryMetadata buildMetadata( String repo, String metadataPath ) { - RepositoryMetadata metadata = null; - + Metadata m = null; + String repoPath = repo + "/" + metadataPath; try { - URL url = new File( repo + "/" + metadataPath ).toURL(); + URL url = new File( repoPath ).toURL(); InputStream is = url.openStream(); Reader reader = new InputStreamReader( is ); MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); - Metadata m = metadataReader.read( reader ); - String metaGroupId = m.getGroupId(); - String metaArtifactId = m.getArtifactId(); - String metaVersion = m.getVersion(); - - // check if the groupId, artifactId and version is in the - // metadataPath - // parse the path, in reverse order - List pathParts = new ArrayList(); - StringTokenizer st = new StringTokenizer( metadataPath, "/\\" ); - while ( st.hasMoreTokens() ) - { - pathParts.add( st.nextToken() ); - } - - Collections.reverse( pathParts ); - // remove the metadata file - pathParts.remove( 0 ); - Iterator it = pathParts.iterator(); - String tmpDir = (String) it.next(); - - //ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - //if( metaVersion != null && !metaVersion.equals( "" ) ) - //{ - // VersionRange version = VersionRange.createFromVersion( metaVersion ); - //} - - Artifact artifact = null; - if ( metaVersion != null && !"".equals( metaVersion ) ) - { - artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" ); - } - - // snapshotMetadata - if ( tmpDir != null && tmpDir.equals( metaVersion ) ) - { - if ( artifact != null ) - { - metadata = new SnapshotArtifactRepositoryMetadata( artifact ); - } - } - else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) ) - { - // artifactMetadata - if ( artifact != null ) - { - metadata = new ArtifactRepositoryMetadata( artifact ); - } - } - else - { - - String groupDir = ""; - int ctr = 0; - for ( it = pathParts.iterator(); it.hasNext(); ) - { - String path = (String) it.next(); - if ( ctr == 0 ) - { - groupDir = path; - } - else - { - groupDir = path + "." + groupDir; - } - ctr++; - } - - // groupMetadata - if ( metaGroupId != null && metaGroupId.equals( groupDir ) ) - { - metadata = new GroupRepositoryMetadata( metaGroupId ); - } - } - + m = metadataReader.read( reader ); } - catch ( FileNotFoundException fe ) + catch ( XmlPullParserException e ) { - // TODO: log ignored metadata! - } - catch ( XmlPullParserException xe ) - { - // TODO: log ignored metadata! + getLogger().error( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e ); } catch ( MalformedURLException e ) { - // TODO: log ignored metadata! + // shouldn't happen + getLogger().error( "Error constructing metadata file '" + repoPath + "': " + e.getMessage(), e ); } - catch ( IOException ie ) + catch ( IOException e ) { - // TODO: log ignored metadata! + getLogger().error( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e ); + } + + RepositoryMetadata repositoryMetadata = null; + if ( m != null ) + { + repositoryMetadata = buildMetadata( m, metadataPath ); + } + return repositoryMetadata; + } + + private RepositoryMetadata buildMetadata( Metadata m, String metadataPath ) + { + String metaGroupId = m.getGroupId(); + String metaArtifactId = m.getArtifactId(); + String metaVersion = m.getVersion(); + + // check if the groupId, artifactId and version is in the + // metadataPath + // parse the path, in reverse order + List pathParts = new ArrayList(); + StringTokenizer st = new StringTokenizer( metadataPath, "/\\" ); + while ( st.hasMoreTokens() ) + { + pathParts.add( st.nextToken() ); + } + + Collections.reverse( pathParts ); + // remove the metadata file + pathParts.remove( 0 ); + Iterator it = pathParts.iterator(); + String tmpDir = (String) it.next(); + + //ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + //if( metaVersion != null && !metaVersion.equals( "" ) ) + //{ + // VersionRange version = VersionRange.createFromVersion( metaVersion ); + //} + + Artifact artifact = null; + if ( metaVersion != null && !"".equals( metaVersion ) ) + { + artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" ); + } + + // snapshotMetadata + RepositoryMetadata metadata = null; + if ( tmpDir != null && tmpDir.equals( metaVersion ) ) + { + if ( artifact != null ) + { + metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + } + } + else if ( tmpDir != null && tmpDir.equals( metaArtifactId ) ) + { + // artifactMetadata + if ( artifact != null ) + { + metadata = new ArtifactRepositoryMetadata( artifact ); + } + } + else + { + String groupDir = ""; + int ctr = 0; + for ( it = pathParts.iterator(); it.hasNext(); ) + { + String path = (String) it.next(); + if ( ctr == 0 ) + { + groupDir = path; + } + else + { + groupDir = path + "." + groupDir; + } + ctr++; + } + + // groupMetadata + if ( metaGroupId != null && metaGroupId.equals( groupDir ) ) + { + metadata = new GroupRepositoryMetadata( metaGroupId ); + } } return metadata;