[MRM-1335] improve the message appearing when an artifact's metadata is incomplete

Submitted by: Greg Michael Meneses

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1140473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2011-06-28 08:05:07 +00:00
parent 23e2f88dfb
commit a5c5d53fa1
4 changed files with 109 additions and 14 deletions

View File

@ -24,6 +24,7 @@ import org.apache.archiva.metadata.generic.GenericMetadataFacet;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataRepository;
@ -32,6 +33,7 @@ import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
@ -41,7 +43,6 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.inject.Inject;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
@ -53,6 +54,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.inject.Inject;
/**
* Browse the repository.
@ -144,7 +146,7 @@ public class ShowArtifactAction
if ( versionMetadata.isIncomplete() )
{
addIncompleteModelWarning();
addIncompleteModelWarning( "Artifact metadata is incomplete." );
}
model = versionMetadata;
@ -170,10 +172,21 @@ public class ShowArtifactAction
{
versionMetadata = metadataResolver.resolveProjectVersion( session, repoId, groupId, artifactId,
version );
if ( versionMetadata != null )
{
MetadataFacet repoProbFacet;
if ( (repoProbFacet = versionMetadata.getFacet( RepositoryProblemFacet.FACET_ID ) ) != null )
{
addIncompleteModelWarning( "Artifact metadata is incomplete: " + ( ( RepositoryProblemFacet) repoProbFacet ).getProblem() );
//set metadata to complete so that no additional 'Artifact metadata is incomplete' warning is logged
versionMetadata.setIncomplete( false );
}
}
}
catch ( MetadataResolutionException e )
{
addIncompleteModelWarning();
addIncompleteModelWarning( "Error resolving artifact metadata: " + e.getMessage() );
// TODO: need a consistent way to construct this - same in ArchivaMetadataCreationConsumer
versionMetadata = new ProjectVersionMetadata();
@ -193,8 +206,7 @@ public class ShowArtifactAction
}
catch ( MetadataResolutionException e )
{
addIncompleteModelWarning();
addIncompleteModelWarning( "Error resolving artifact metadata: " + e.getMessage() );
artifacts = Collections.emptyList();
}
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
@ -227,10 +239,10 @@ public class ShowArtifactAction
return versionMetadata;
}
private void addIncompleteModelWarning()
private void addIncompleteModelWarning( String warningMessage )
{
addActionMessage(
"The model may be incomplete due to a previous error in resolving information. Refer to the repository problem reports for more information." );
addActionError( warningMessage );
//"The model may be incomplete due to a previous error in resolving information. Refer to the repository problem reports for more information." );
}
/**

View File

@ -30,6 +30,7 @@ import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
@ -58,6 +59,8 @@ public class ShowArtifactActionTest
private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
private static final String TEST_NAMESPACE = "namespace";
private static final String OTHER_TEST_REPO = "first-repo";
private ShowArtifactAction action;
@ -291,6 +294,56 @@ public class ShowArtifactActionTest
assertTrue( action.getArtifacts().isEmpty() );
}
public void testMetadataHasRepositoryFacetProblem()
{
String errMsg = "Error in resolving artifact's parent POM file: Sample Parent POM not found";
ProjectVersionMetadata metaData = createProjectModel(TEST_SNAPSHOT_VERSION);
metaData.addFacet( createRepositoryProblemFacet( TEST_REPO, errMsg,
TEST_GROUP_ID, TEST_SNAPSHOT_VERSION, TEST_NAMESPACE ) );
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
TEST_SNAPSHOT_ARTIFACTS );
action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID );
action.setVersion( TEST_SNAPSHOT_VERSION );
String result = action.artifact();
assertEquals( Action.SUCCESS, result );
assertTrue( action.hasActionErrors() );
assertFalse( action.hasActionMessages() );
assertEquals( "Artifact metadata is incomplete: " + errMsg, action.getActionErrors().toArray()[0].toString() );
}
public void testMetadataIncomplete()
{
ProjectVersionMetadata metaData = createProjectModel(TEST_SNAPSHOT_VERSION);
metaData.setIncomplete( true );
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
TEST_SNAPSHOT_ARTIFACTS );
action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID );
action.setVersion( TEST_SNAPSHOT_VERSION );;
String result = action.artifact();
assertEquals( Action.SUCCESS, result );
assertTrue( action.hasActionErrors() );
assertFalse( action.hasActionMessages() );
assertEquals( "Artifact metadata is incomplete.", action.getActionErrors().toArray()[0].toString() );
}
public void testGetMailingLists()
{
ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
@ -627,6 +680,19 @@ public class ShowArtifactActionTest
assertTrue( action.getActionMessages().isEmpty() );
}
private RepositoryProblemFacet createRepositoryProblemFacet( String repoId, String errMsg, String projectId, String projectVersion, String namespace )
{
RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
repoProblemFacet.setRepositoryId( repoId );
repoProblemFacet.setId( repoId );
repoProblemFacet.setMessage( errMsg );
repoProblemFacet.setProblem( errMsg );
repoProblemFacet.setProject( projectId );
repoProblemFacet.setVersion( projectVersion );
repoProblemFacet.setNamespace( namespace );
return repoProblemFacet;
}
protected void setUp()
throws Exception
{

View File

@ -37,6 +37,10 @@
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>problem-reports</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-proxy-common</artifactId>

View File

@ -30,6 +30,7 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
@ -56,9 +57,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
@ -71,6 +69,9 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
/**
* Maven 2 repository format storage implementation. This class currently takes parameters to indicate the repository to
@ -246,6 +247,18 @@ public class Maven2RepositoryStorage
facet.setPackaging( "jar" );
metadata.addFacet( facet );
String errMsg = "Error in resolving artifact's parent POM file. " + problem.getException().getMessage();
RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
repoProblemFacet.setRepositoryId( repoId );
repoProblemFacet.setId( repoId );
repoProblemFacet.setMessage( errMsg );
repoProblemFacet.setProblem( errMsg );
repoProblemFacet.setProject( projectId );
repoProblemFacet.setVersion( projectVersion );
repoProblemFacet.setNamespace( namespace );
metadata.addFacet( repoProblemFacet );
return metadata;
}
}