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;
}
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;
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 =
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
{
{
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" ) );
--- /dev/null
+<!--
+ ~ 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