From 2a5c2bb81a01346573cf298e9b285747cf9a31ca Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 16 Dec 2009 00:53:37 +0000 Subject: [PATCH] [MRM-1301] add back problem reporting for POM in the wrong location git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@891087 13f79535-47bb-0310-9956-ffa450edef68 --- .../Maven2RepositoryMetadataResolver.java | 62 +++++++++++++------ .../Maven2RepositoryMetadataResolverTest.java | 20 +++++- .../mislocated-pom/1.0/mislocated-pom-1.0.pom | 26 ++++++++ 3 files changed, 88 insertions(+), 20 deletions(-) create mode 100644 archiva-modules/plugins/maven2-repository/src/test/repositories/test/com/example/test/mislocated-pom/1.0/mislocated-pom-1.0.pom diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java index 02bf6af68..2a90d7b7c 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java @@ -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 convertDependencies( List dependencies ) { List l = diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java index 167e51cf9..531b59fd5 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java @@ -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.emptyList(), resolver.getProjects( TEST_REPO_ID, "com" ) ); assertEquals( Collections.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.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 index 000000000..96cc44033 --- /dev/null +++ b/archiva-modules/plugins/maven2-repository/src/test/repositories/test/com/example/test/mislocated-pom/1.0/mislocated-pom-1.0.pom @@ -0,0 +1,26 @@ + + + + 4.0.0 + com.example.test + not-the-right-artifactId + 1.0 + pom + \ No newline at end of file -- 2.39.5