[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
This commit is contained in:
Brett Porter 2009-12-16 00:53:37 +00:00
parent 0f4bec3049
commit 2a5c2bb81a
3 changed files with 88 additions and 20 deletions

View 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 =

View 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" ) );

View File

@ -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>