diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java index cab0b91fd..e422afb71 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactory.java @@ -125,7 +125,17 @@ public class StandardArtifactIndexRecordFactory } else { - populatePomEntries( readPom( file ), record ); + Model model = readPom( file ); + + if ( !"pom".equals( model.getPackaging() ) ) + { + // Don't return a record for a POM that is does not belong on its own + record = null; + } + else + { + populatePomEntries( model, record ); + } } } } diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java index bffd0ca15..6a91d3da7 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/MinimalArtifactIndexRecordFactoryTest.java @@ -107,6 +107,29 @@ public class MinimalArtifactIndexRecordFactoryTest assertNull( "Check no record", record ); } + public void testNonIndexedPom() + throws RepositoryIndexException + { + // If we pass in only the POM that belongs to a JAR, then expect null not the POM + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0", "pom" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-plugin", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-archetype", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + } + public void testIndexedPlugin() throws RepositoryIndexException, IOException, XmlPullParserException { diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java index 8c345752b..27219f877 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/record/StandardArtifactIndexRecordFactoryTest.java @@ -139,6 +139,29 @@ public class StandardArtifactIndexRecordFactoryTest assertEquals( "check record", expectedRecord, record ); } + public void testNonIndexedPom() + throws RepositoryIndexException + { + // If we pass in only the POM that belongs to a JAR, then expect null not the POM + Artifact artifact = createArtifact( "test-jar-and-pom", "1.0", "pom" ); + + RepositoryIndexRecord record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-plugin", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + + artifact = createArtifact( "test-archetype", "1.0", "pom" ); + + record = factory.createRecord( artifact ); + + assertNull( "Check no record", record ); + } + public void testIndexedPlugin() throws RepositoryIndexException, IOException, XmlPullParserException {