]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1102] don't swallow parsing exception too early where it still has context,...
authorBrett Porter <brett@apache.org>
Tue, 10 Mar 2009 01:09:34 +0000 (01:09 +0000)
committerBrett Porter <brett@apache.org>
Tue, 10 Mar 2009 01:09:34 +0000 (01:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@751932 13f79535-47bb-0310-9956-ffa450edef68

archiva-cli/src/main/java/org/apache/maven/archiva/cli/ProjectReaderConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelReader.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300Reader.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/readers/ProjectModel400Reader.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/ProjectModelExpressionExpanderTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/readers/ProjectModel300ReaderTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/readers/ProjectModel400ReaderTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/writers/ProjectModel400WriterTest.java

index 2ceb7a0d93c0505d4660d29b759f6a18323b17b1..b0eb6edc06f22d5f7bc53383d68647ebcfcf00b7 100644 (file)
@@ -28,9 +28,9 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.consumers.ConsumerException;
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
-import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
 import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
+import org.apache.maven.archiva.xml.XMLException;
 
 /**
  * ProjectReaderConsumer 
@@ -117,7 +117,7 @@ public class ProjectReaderConsumer
                 System.err.println( "Got null model on " + pomFile );
             }
         }
-        catch ( ProjectModelException e )
+        catch ( XMLException e )
         {
             System.err.println( "Unable to process: " + pomFile );
             e.printStackTrace( System.out );
index 28f5c0a9d128a1ab10f794e4a9922a9d4f273834..f06f866ea73ef2e353ca062e2df51dff6d1e9ed3 100644 (file)
@@ -41,11 +41,11 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent;
 import org.apache.maven.archiva.repository.RepositoryContentFactory;
 import org.apache.maven.archiva.repository.RepositoryException;
 import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
-import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
 import org.apache.maven.archiva.repository.project.filters.EffectiveProjectModelFilter;
 import org.apache.maven.archiva.repository.project.readers.ProjectModel300Reader;
 import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
+import org.apache.maven.archiva.xml.XMLException;
 import org.codehaus.plexus.cache.Cache;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -178,9 +178,9 @@ public class ProjectModelToDatabaseConsumer
             }
 
         }
-        catch ( ProjectModelException e )
+        catch ( XMLException e )
         {
-            log.warn( "Unable to read project model " + artifactFile + " : " + e.getMessage(), e );
+            log.warn( "Unable to read project model " + artifactFile + " : " + e.getMessage() );
 
             addProblem( artifact, "Unable to read project model " + artifactFile + " : " + e.getMessage() );
         }
index 419a905d164c7da3d30e5b032f03ef172e6ab050..a795a445d5ca5aaf4a631a5c6f7a71ebb1c9d032 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.maven.archiva.repository.project;
  */
 
 import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.xml.XMLException;
 
 import java.io.File;
 
@@ -30,5 +31,6 @@ import java.io.File;
  */
 public interface ProjectModelReader
 {
-    public ArchivaProjectModel read( File pomFile ) throws ProjectModelException;
+    public ArchivaProjectModel read( File pomFile )
+        throws XMLException;
 }
index 34cc0cec6dffc20e4cc37e730b1709dd0e33f337..600f738ae2c1a44902965fb4d953a376f2750515 100644 (file)
@@ -19,6 +19,12 @@ package org.apache.maven.archiva.repository.project.readers;
  * under the License.
  */
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.model.ArtifactReference;
@@ -30,18 +36,11 @@ import org.apache.maven.archiva.model.MailingList;
 import org.apache.maven.archiva.model.Organization;
 import org.apache.maven.archiva.model.ProjectRepository;
 import org.apache.maven.archiva.model.Scm;
-import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
 import org.apache.maven.archiva.xml.XMLException;
 import org.apache.maven.archiva.xml.XMLReader;
 import org.dom4j.Element;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
 /**
  * ProjectModel300Reader 
  *
@@ -52,66 +51,54 @@ public class ProjectModel300Reader
 {
 
     public ArchivaProjectModel read( File pomFile )
-        throws ProjectModelException
+        throws XMLException
     {
-        try
-        {
-            XMLReader xml = new XMLReader( "project", pomFile );
-
-            ArchivaProjectModel model = new ArchivaProjectModel();
-
-            xml.removeNamespaces();
+        XMLReader xml = new XMLReader( "project", pomFile );
 
-            Element project = xml.getElement( "//project" );
+        ArchivaProjectModel model = new ArchivaProjectModel();
 
-            // TODO: Handle <extend /> ?? (is this even possible?)
+        xml.removeNamespaces();
 
-            model.setGroupId( project.elementTextTrim( "groupId" ) );
-            model.setArtifactId( project.elementTextTrim( "artifactId" ) );
-            // TODO: Handle <id />
-            model.setVersion( project.elementTextTrim( "currentVersion" ) );
-            model.setName( project.elementTextTrim( "name" ) );
-            model.setDescription( project.elementTextTrim( "description" ) );
-            // TODO: what to do with <shortDescription /> ?
-            model.setUrl( project.elementTextTrim( "url" ) );
-            // TODO: Handle <logo />
-            // TODO: Handle <inceptionYear />
-
-            model.setIssueManagement( getIssueManagement( xml ) );
-            // TODO: What to do with <gumpRepositoryId /> ?
-            // TODO: Handle <siteAddress />
-            // TODO: Handle <siteDirectory /> ?
-            // TODO: Handle <distributionSite />
-            // TODO: Handle <distributionDirectory />
-            model.setMailingLists( getMailingLists( xml ) );
-            model.setIndividuals( getIndividuals( xml ) );
-            model.setLicenses( getLicenses( xml ) );
-            model.setReports( getReports( xml ) );
-            model.setRepositories( getRepositories( xml ) );
-            model.setScm( getSCM( xml ) );
-            model.setOrganization( getOrganization( xml ) );
-            model.setProperties( getProperties( xml.getElement( "//project/properties" ) ) );
-            model.setDependencies( getDependencies( xml ) );
-            
-            model.setOrigin("filesystem");
-
-            /* Following are not valid for <pomVersion>3</pomVersion> / Maven 1 pom files.
-             * 
-             * model.setDependencyManagement()
-             * model.setPlugins()
-             * model.setParentProject()
-             * model.setPackaging()
-             * model.setCiManagement()
-             * model.setBuildExtensions()
-             * model.setRelocation()
-             */
+        Element project = xml.getElement( "//project" );
 
-            return model;
-        }
-        catch ( XMLException e )
-        {
-            throw new ProjectModelException( e.getMessage(), e );
-        }
+        // TODO: Handle <extend /> ?? (is this even possible?)
+
+        model.setGroupId( project.elementTextTrim( "groupId" ) );
+        model.setArtifactId( project.elementTextTrim( "artifactId" ) );
+        // TODO: Handle <id />
+        model.setVersion( project.elementTextTrim( "currentVersion" ) );
+        model.setName( project.elementTextTrim( "name" ) );
+        model.setDescription( project.elementTextTrim( "description" ) );
+        // TODO: what to do with <shortDescription /> ?
+        model.setUrl( project.elementTextTrim( "url" ) );
+        // TODO: Handle <logo />
+        // TODO: Handle <inceptionYear />
+
+        model.setIssueManagement( getIssueManagement( xml ) );
+        // TODO: What to do with <gumpRepositoryId /> ?
+        // TODO: Handle <siteAddress />
+        // TODO: Handle <siteDirectory /> ?
+        // TODO: Handle <distributionSite />
+        // TODO: Handle <distributionDirectory />
+        model.setMailingLists( getMailingLists( xml ) );
+        model.setIndividuals( getIndividuals( xml ) );
+        model.setLicenses( getLicenses( xml ) );
+        model.setReports( getReports( xml ) );
+        model.setRepositories( getRepositories( xml ) );
+        model.setScm( getSCM( xml ) );
+        model.setOrganization( getOrganization( xml ) );
+        model.setProperties( getProperties( xml.getElement( "//project/properties" ) ) );
+        model.setDependencies( getDependencies( xml ) );
+
+        model.setOrigin( "filesystem" );
+
+        /*
+         * Following are not valid for <pomVersion>3</pomVersion> / Maven 1 pom files. model.setDependencyManagement()
+         * model.setPlugins() model.setParentProject() model.setPackaging() model.setCiManagement()
+         * model.setBuildExtensions() model.setRelocation()
+         */
+
+        return model;
     }
 
     private ArtifactReference getArtifactReference( Element elemPlugin, String defaultType )
index f8aa2c6fbcd8dcb4beb060dbaee78562ff53252d..16f8225a1abd0af850a1fdd7a4ce7eda81f69a76 100644 (file)
@@ -19,6 +19,12 @@ package org.apache.maven.archiva.repository.project.readers;
  * under the License.
  */
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.model.ArtifactReference;
@@ -34,18 +40,11 @@ import org.apache.maven.archiva.model.Organization;
 import org.apache.maven.archiva.model.ProjectRepository;
 import org.apache.maven.archiva.model.Scm;
 import org.apache.maven.archiva.model.VersionedReference;
-import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
 import org.apache.maven.archiva.xml.XMLException;
 import org.apache.maven.archiva.xml.XMLReader;
 import org.dom4j.Element;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
 /**
  * ProjectModel400Reader - read in modelVersion 4.0.0 pom files into archiva-model structures.
  *
@@ -54,64 +53,56 @@ import java.util.Properties;
 public class ProjectModel400Reader
     implements ProjectModelReader
 {
-
     public ArchivaProjectModel read( File pomFile )
-        throws ProjectModelException
+        throws XMLException
     {
-        try
-        {
-            XMLReader xml = new XMLReader( "project", pomFile );
+        XMLReader xml = new XMLReader( "project", pomFile );
 
-            ArchivaProjectModel model = new ArchivaProjectModel();
+        ArchivaProjectModel model = new ArchivaProjectModel();
 
-            if ( !"http://maven.apache.org/POM/4.0.0".equals( xml.getDefaultNamespaceURI() ) )
-            {
-                // No namespace defined
-                // TODO: Output to monitor the problem with the Namespace.
-            }
+        if ( !"http://maven.apache.org/POM/4.0.0".equals( xml.getDefaultNamespaceURI() ) )
+        {
+            // No namespace defined
+            // TODO: Output to monitor the problem with the Namespace.
+        }
 
-            xml.removeNamespaces();
+        xml.removeNamespaces();
 
-            Element project = xml.getElement( "//project" );
+        Element project = xml.getElement( "//project" );
 
-            model.setGroupId( project.elementTextTrim( "groupId" ) );
-            model.setArtifactId( project.elementTextTrim( "artifactId" ) );
-            model.setVersion( project.elementTextTrim( "version" ) );
-            model.setName( project.elementTextTrim( "name" ) );
-            model.setDescription( project.elementTextTrim( "description" ) );
-            model.setUrl( project.elementTextTrim( "url" ) );
+        model.setGroupId( project.elementTextTrim( "groupId" ) );
+        model.setArtifactId( project.elementTextTrim( "artifactId" ) );
+        model.setVersion( project.elementTextTrim( "version" ) );
+        model.setName( project.elementTextTrim( "name" ) );
+        model.setDescription( project.elementTextTrim( "description" ) );
+        model.setUrl( project.elementTextTrim( "url" ) );
 
-            model.setPackaging( StringUtils.defaultIfEmpty( project.elementTextTrim( "packaging" ), "jar" ) );
+        model.setPackaging( StringUtils.defaultIfEmpty( project.elementTextTrim( "packaging" ), "jar" ) );
 
-            model.setParentProject( getParentProject( xml ) );
+        model.setParentProject( getParentProject( xml ) );
 
-            model.setMailingLists( getMailingLists( xml ) );
-            model.setCiManagement( getCiManagement( xml ) );
-            model.setIndividuals( getIndividuals( xml ) );
-            model.setIssueManagement( getIssueManagement( xml ) );
-            model.setLicenses( getLicenses( xml ) );
-            model.setOrganization( getOrganization( xml ) );
-            model.setScm( getSCM( xml ) );
-            model.setRepositories( getRepositories( xml ) );
+        model.setMailingLists( getMailingLists( xml ) );
+        model.setCiManagement( getCiManagement( xml ) );
+        model.setIndividuals( getIndividuals( xml ) );
+        model.setIssueManagement( getIssueManagement( xml ) );
+        model.setLicenses( getLicenses( xml ) );
+        model.setOrganization( getOrganization( xml ) );
+        model.setScm( getSCM( xml ) );
+        model.setRepositories( getRepositories( xml ) );
 
-            model.setDependencies( getDependencies( xml ) );
-            model.setDependencyManagement( getDependencyManagement( xml ) );
-            model.setPlugins( getPlugins( xml ) );
-            model.setReports( getReports( xml ) );
-            model.setProperties( getProperties( xml.getElement( "//project/properties" ) ) );
+        model.setDependencies( getDependencies( xml ) );
+        model.setDependencyManagement( getDependencyManagement( xml ) );
+        model.setPlugins( getPlugins( xml ) );
+        model.setReports( getReports( xml ) );
+        model.setProperties( getProperties( xml.getElement( "//project/properties" ) ) );
 
-            model.setBuildExtensions( getBuildExtensions( xml ) );
+        model.setBuildExtensions( getBuildExtensions( xml ) );
 
-            model.setRelocation( getRelocation( xml ) );
-            
-            model.setOrigin("filesystem");
+        model.setRelocation( getRelocation( xml ) );
 
-            return model;
-        }
-        catch ( XMLException e )
-        {
-            throw new ProjectModelException( e.getMessage(), e );
-        }
+        model.setOrigin( "filesystem" );
+
+        return model;
     }
 
     private ArtifactReference getArtifactReference( Element elemPlugin, String defaultType )
index 691535f312859abf6e6e46bba68c867203d556ff..91e71d6d99ea53ef62c133bf79a3427ee823317e 100644 (file)
@@ -19,6 +19,8 @@ package org.apache.maven.archiva.repository.project.resolvers;
  * under the License.
  */
 
+import java.io.File;
+
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.model.VersionedReference;
@@ -26,8 +28,7 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent;
 import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
 import org.apache.maven.archiva.repository.project.ProjectModelResolver;
-
-import java.io.File;
+import org.apache.maven.archiva.xml.XMLException;
 
 /**
  * Resolve Project from managed repository. 
@@ -55,7 +56,14 @@ public class ManagedRepositoryProjectResolver
 
         File repoFile = repository.toFile( artifact );
 
-        return reader.read( repoFile );
+        try
+        {
+            return reader.read( repoFile );
+        }
+        catch ( XMLException e )
+        {
+            throw new ProjectModelException( e.getMessage(), e );
+        }
     }
 
 }
index 26ba23322b1249648b58e5c66d96bb66c0aae79c..aa4ec3513b50d2c58e830e86ffdb5f4a902d356a 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.maven.archiva.repository.project.ProjectModelResolver;
 import org.apache.maven.archiva.repository.project.ProjectModelResolverFactory;
 import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
 import org.apache.maven.archiva.repository.project.resolvers.ManagedRepositoryProjectResolver;
+import org.apache.maven.archiva.xml.XMLException;
 
 import java.io.File;
 import java.util.HashMap;
@@ -56,7 +57,7 @@ public class EffectiveProjectModelFilterTest
     }
 
     private ArchivaProjectModel createArchivaProjectModel( String path )
-        throws ProjectModelException
+        throws XMLException
     {
         ProjectModelReader reader = new ProjectModel400Reader();
 
index c99b56023da70a10fee7b9b512ead227eff5f79f..1bb246d029bd70e6cc069c579559b7519be42535 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.maven.archiva.repository.project.ProjectModelReader;
 import org.apache.maven.archiva.repository.project.ProjectModelWriter;
 import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
 import org.apache.maven.archiva.repository.project.writers.ProjectModel400Writer;
+import org.apache.maven.archiva.xml.XMLException;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 
 import java.io.File;
@@ -136,7 +137,7 @@ public class ProjectModelExpressionExpanderTest
     }
 
     private ArchivaProjectModel createArchivaProjectModel( String path )
-        throws ProjectModelException
+        throws XMLException
     {
         ProjectModelReader reader = new ProjectModel400Reader();
 
index 99ad25a2129fdfa0799260e9941738f5e583e5a8..87910d036d8de68920e1e2897178dd02ac5ee7b3 100644 (file)
@@ -19,14 +19,14 @@ package org.apache.maven.archiva.repository.project.readers;
  * under the License.
  */
 
+import java.io.File;
+
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.model.Dependency;
-import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
+import org.apache.maven.archiva.xml.XMLException;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 
-import java.io.File;
-
 /**
  * ProjectModel300ReaderTest 
  *
@@ -36,7 +36,7 @@ public class ProjectModel300ReaderTest
     extends PlexusInSpringTestCase
 {
     public void testLoadSimple()
-        throws ProjectModelException
+        throws XMLException
     {
         File defaultRepoDir = new File( getBasedir(), "src/test/repositories/legacy-repository" );
         File pomFile = new File( defaultRepoDir, "org.apache.maven/poms/maven-model-v3-2.0.pom" );
index c35483f06b0b23afe9e2838a5ee24c46fa784be9..42c64331dbf2ebf15180e408f62f0339053877ca 100644 (file)
@@ -19,14 +19,14 @@ package org.apache.maven.archiva.repository.project.readers;
  * under the License.
  */
 
+import java.io.File;
+
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.model.VersionedReference;
-import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
+import org.apache.maven.archiva.xml.XMLException;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 
-import java.io.File;
-
 /**
  * ProjectModel400ReaderTest 
  *
@@ -36,7 +36,7 @@ public class ProjectModel400ReaderTest
     extends PlexusInSpringTestCase
 {
     public void testLoadSimple()
-        throws ProjectModelException
+        throws XMLException
     {
         File defaultRepoDir = new File( getBasedir(), "src/test/repositories/default-repository" );
         File pomFile = new File( defaultRepoDir,
@@ -66,7 +66,7 @@ public class ProjectModel400ReaderTest
     }
 
     public void testLoadWithNamespace()
-        throws ProjectModelException
+        throws XMLException
     {
         File defaultRepoDir = new File( getBasedir(), "src/test/repositories/default-repository" );
         File pomFile = new File( defaultRepoDir,
index 471010d96ed37c00cca0ffe5027b5581c407da20..e18b46aa44c787b1540da4d1a8f6aa5638b458a8 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelReader;
 import org.apache.maven.archiva.repository.project.ProjectModelWriter;
 import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
+import org.apache.maven.archiva.xml.XMLException;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 import org.custommonkey.xmlunit.DetailedDiff;
 import org.custommonkey.xmlunit.Diff;
@@ -128,7 +129,7 @@ public class ProjectModel400WriterTest
     }
 
     private ArchivaProjectModel createArchivaProjectModel( String path )
-        throws ProjectModelException
+        throws XMLException
     {
         ProjectModelReader reader = new ProjectModel400Reader();