From a5c5d53fa11f7706ccafec757e386b33c7d3ac99 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Tue, 28 Jun 2011 08:05:07 +0000 Subject: [PATCH] [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 --- .../web/action/ShowArtifactAction.java | 34 ++++++---- .../web/action/ShowArtifactActionTest.java | 66 +++++++++++++++++++ .../plugins/maven2-repository/pom.xml | 4 ++ .../maven2/Maven2RepositoryStorage.java | 19 +++++- 4 files changed, 109 insertions(+), 14 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index f34b37b24..8a67e02a1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -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; @@ -158,7 +160,7 @@ public class ShowArtifactAction artifacts = new LinkedHashMap>(); List repos = getObservableRepos(); - + MetadataResolver metadataResolver = session.getResolver(); for ( String repoId : repos ) { @@ -170,11 +172,22 @@ 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(); versionMetadata.setId( version ); @@ -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() @@ -226,11 +238,11 @@ 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." ); } /** diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java index 7da39bc12..83cb871e5 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java @@ -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; @@ -57,6 +58,8 @@ public class ShowArtifactActionTest private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT"; 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"; @@ -290,6 +293,56 @@ public class ShowArtifactActionTest assertNull( action.getMailingLists() ); 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() { @@ -626,6 +679,19 @@ public class ShowArtifactActionTest assertTrue( action.getActionErrors().isEmpty() ); 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 diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml index 6c4df0d8a..7001fa6aa 100644 --- a/archiva-modules/plugins/maven2-repository/pom.xml +++ b/archiva-modules/plugins/maven2-repository/pom.xml @@ -37,6 +37,10 @@ org.apache.archiva metadata-repository-api + + org.apache.archiva + problem-reports + org.apache.archiva archiva-proxy-common diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java index f4291eca3..d99f1644b 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java @@ -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; } } -- 2.39.5