]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1301] add back problem reporting for POM in the wrong location
authorBrett Porter <brett@apache.org>
Wed, 16 Dec 2009 00:53:37 +0000 (00:53 +0000)
committerBrett Porter <brett@apache.org>
Wed, 16 Dec 2009 00:53:37 +0000 (00:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@891087 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
archiva-modules/plugins/maven2-repository/src/test/repositories/test/com/example/test/mislocated-pom/1.0/mislocated-pom-1.0.pom [new file with mode: 0644]

index 02bf6af68002ac097dcba5de21ced233cb3e1e66..2a90d7b7ca68303d8273ae9b9217f310d45fe4fb 100644 (file)
@@ -140,15 +140,8 @@ public class Maven2RepositoryMetadataResolver
         if ( !file.exists() )
         {
             // TODO: an event mechanism would remove coupling to the problem reporting plugin
-            RepositoryProblemFacet problem = new RepositoryProblemFacet();
-            problem.setProblem( "missing-pom" );
-            problem.setMessage( "The artifact's POM file '" + file + "' was missing" );
-            problem.setProject( projectId );
-            problem.setNamespace( namespace );
-            problem.setRepositoryId( repoId );
-            problem.setVersion( projectVersion );
-
-            metadataRepository.addMetadataFacet( repoId, problem );
+            addProblemReport( repoId, namespace, projectId, projectVersion, "missing-pom",
+                              "The artifact's POM file '" + file + "' was missing" );
 
             // metadata could not be resolved
             return null;
@@ -167,16 +160,34 @@ public class Maven2RepositoryMetadataResolver
         }
         catch ( ModelBuildingException e )
         {
-            // TODO: an event mechanism would remove coupling to the problem reporting plugin
-            RepositoryProblemFacet problem = new RepositoryProblemFacet();
-            problem.setProblem( "invalid-pom" );
-            problem.setMessage( "The artifact's POM file '" + file + "' was invalid: " + e.getMessage() );
-            problem.setProject( projectId );
-            problem.setNamespace( namespace );
-            problem.setRepositoryId( repoId );
-            problem.setVersion( projectVersion );
+            addProblemReport( repoId, namespace, projectId, projectVersion, "invalid-pom",
+                              "The artifact's POM file '" + file + "' was invalid: " + e.getMessage() );
 
-            metadataRepository.addMetadataFacet( repoId, problem );
+            // metadata could not be resolved
+            return null;
+        }
+
+        // Check if the POM is in the correct location
+        boolean correctGroupId = namespace.equals( model.getGroupId() );
+        boolean correctArtifactId = projectId.equals( model.getArtifactId() );
+        boolean correctVersion = projectVersion.equals( model.getVersion() );
+        if ( !correctGroupId || !correctArtifactId || !correctVersion )
+        {
+            StringBuilder message = new StringBuilder( "Incorrect POM coordinates in '" + file + "':" );
+            if ( !correctGroupId )
+            {
+                message.append( "\nIncorrect group ID: " ).append( model.getGroupId() );
+            }
+            if ( !correctArtifactId )
+            {
+                message.append( "\nIncorrect artifact ID: " ).append( model.getArtifactId() );
+            }
+            if ( !correctVersion )
+            {
+                message.append( "\nIncorrect version: " ).append( model.getVersion() );
+            }
+
+            addProblemReport( repoId, namespace, projectId, projectVersion, "mislocated-pom", message.toString() );
 
             // metadata could not be resolved
             return null;
@@ -212,6 +223,21 @@ public class Maven2RepositoryMetadataResolver
         return metadata;
     }
 
+    private void addProblemReport( String repoId, String namespace, String projectId, String projectVersion,
+                                   String problemId, String message )
+    {
+        // TODO: an event mechanism would remove coupling to the problem reporting plugin
+        RepositoryProblemFacet problem = new RepositoryProblemFacet();
+        problem.setProblem( problemId );
+        problem.setMessage( message );
+        problem.setProject( projectId );
+        problem.setNamespace( namespace );
+        problem.setRepositoryId( repoId );
+        problem.setVersion( projectVersion );
+
+        metadataRepository.addMetadataFacet( repoId, problem );
+    }
+
     private List<org.apache.archiva.metadata.model.Dependency> convertDependencies( List<Dependency> dependencies )
     {
         List<org.apache.archiva.metadata.model.Dependency> l =
index 167e51cf92160d008b67ac77dace7ece9b7d617a..531b59fd52195616b1e75f6abc247dc7d9206f89 100644 (file)
@@ -225,6 +225,22 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( "invalid-pom", facet.getProblem() );
     }
 
+    public void testGetProjectVersionMetadataForMislocatedPom()
+        throws MetadataResolverException
+    {
+        assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
+
+        ProjectVersionMetadata metadata =
+            resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
+        assertNull( metadata );
+
+        assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
+        RepositoryProblemFacet facet =
+            (RepositoryProblemFacet) metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID,
+                                                                          "com.example.test/mislocated-pom/1.0" );
+        assertEquals( "mislocated-pom", facet.getProblem() );
+    }
+
     public void testGetProjectVersionMetadataForMissingPom()
         throws MetadataResolverException
     {
@@ -271,8 +287,8 @@ public class Maven2RepositoryMetadataResolverTest
     {
         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com" ) );
         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com.example" ) );
-        assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "missing-metadata" ),
-                      resolver.getProjects( TEST_REPO_ID, "com.example.test" ) );
+        assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
+                                     "missing-metadata" ), resolver.getProjects( TEST_REPO_ID, "com.example.test" ) );
 
         assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org" ) );
         assertEquals( Arrays.asList( "apache" ), resolver.getProjects( TEST_REPO_ID, "org.apache" ) );
diff --git a/archiva-modules/plugins/maven2-repository/src/test/repositories/test/com/example/test/mislocated-pom/1.0/mislocated-pom-1.0.pom b/archiva-modules/plugins/maven2-repository/src/test/repositories/test/com/example/test/mislocated-pom/1.0/mislocated-pom-1.0.pom
new file mode 100644 (file)
index 0000000..96cc440
--- /dev/null
@@ -0,0 +1,26 @@
+<!--
+  ~ 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>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.example.test</groupId>
+  <artifactId>not-the-right-artifactId</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+</project>
\ No newline at end of file