From 9c2b960aeac54f29677b8ba87d30c4a4a7a2f631 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Wed, 25 Nov 2009 15:33:40 +0000 Subject: [PATCH] [MRM-1283] handle missing Maven facet git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884147 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/action/ShowArtifactAction.java | 21 +++++++------ .../web/action/ShowArtifactActionTest.java | 31 +++++++++++++++++++ 2 files changed, 43 insertions(+), 9 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 4d87e7203..d44348934 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 @@ -150,16 +150,19 @@ public class ShowArtifactAction // TODO: eventually, move to just use the metadata directly, with minimal JSP changes, mostly for Maven specifics model = new ArchivaProjectModel(); MavenProjectFacet projectFacet = (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID ); - model.setGroupId( projectFacet.getGroupId() ); - model.setArtifactId( projectFacet.getArtifactId() ); - model.setPackaging( projectFacet.getPackaging() ); - if ( projectFacet.getParent() != null ) + if ( projectFacet != null ) { - VersionedReference parent = new VersionedReference(); - parent.setGroupId( projectFacet.getParent().getGroupId() ); - parent.setArtifactId( projectFacet.getParent().getArtifactId() ); - parent.setVersion( projectFacet.getParent().getVersion() ); - model.setParentProject( parent ); + model.setGroupId( projectFacet.getGroupId() ); + model.setArtifactId( projectFacet.getArtifactId() ); + model.setPackaging( projectFacet.getPackaging() ); + if ( projectFacet.getParent() != null ) + { + VersionedReference parent = new VersionedReference(); + parent.setGroupId( projectFacet.getParent().getGroupId() ); + parent.setArtifactId( projectFacet.getParent().getArtifactId() ); + parent.setVersion( projectFacet.getParent().getVersion() ); + model.setParentProject( parent ); + } } model.setVersion( versionMetadata.getId() ); 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 5d4ab0853..82ef07e0c 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 @@ -308,6 +308,37 @@ public class ShowArtifactActionTest assertTrue( action.getSnapshotVersions().isEmpty() ); } + public void testGetArtifactNoMavenFacet() + { + ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata(); + versionMetadata.setId( TEST_VERSION ); + versionMetadata.setUrl( TEST_URL ); + versionMetadata.setName( TEST_NAME ); + versionMetadata.setDescription( TEST_DESCRIPTION ); + + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata ); + + setActionParameters(); + + String result = action.artifact(); + + assertActionSuccess( action, result ); + + assertActionParameters( action ); + ArchivaProjectModel model = action.getModel(); + assertEquals( TEST_VERSION, model.getVersion() ); + assertEquals( TEST_URL, model.getUrl() ); + assertEquals( TEST_NAME, model.getName() ); + assertEquals( TEST_DESCRIPTION, model.getDescription() ); + + assertEquals( TEST_REPO, action.getRepositoryId() ); + + assertNull( action.getDependees() ); + assertNull( action.getDependencies() ); + assertNull( action.getMailingLists() ); + assertTrue( action.getSnapshotVersions().isEmpty() ); + } + private void assertNoOutputFields() { assertNull( action.getModel() );