From 8f4f8c83e98fbf9d08979effe56b2ec17a2669ba Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Tue, 4 May 2010 08:54:00 +0000 Subject: [PATCH] [MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic metadata" plugin o action methods for updating and retrieving metadata properties o updated struts config for getting project metadata o added page for metadata in webapp artifact browse o added test for getting project metadata git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@940775 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/action/ShowArtifactAction.java | 93 ++++-- .../src/main/resources/struts.xml | 4 + .../WEB-INF/jsp/include/projectMetadata.jspf | 278 ++++++++++++++++++ .../main/webapp/WEB-INF/jsp/showArtifact.jsp | 12 + .../web/action/ShowArtifactActionTest.java | 35 +++ 5 files changed, 403 insertions(+), 19 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf 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 121a8c8ce..f40cd6f08 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 @@ -25,6 +25,7 @@ import org.apache.archiva.metadata.model.Dependency; import org.apache.archiva.metadata.model.MailingList; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; +import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataResolutionException; import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; @@ -67,6 +68,11 @@ public class ShowArtifactAction */ private RepositoryContentFactory repositoryFactory; + /** + * @plexus.requirement + */ + private MetadataRepository metadataRepository; + /* .\ Exposed Output Objects \.__________________________________ */ private String groupId; @@ -95,20 +101,44 @@ public class ShowArtifactAction private boolean dependencyTree = false; + private ProjectVersionMetadata projectMetadata; + /** * Show the versioned project information tab. * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though * that is rendered in the download box). */ public String artifact() + { + + // In the future, this should be replaced by the repository grouping mechanism, so that we are only making + // simple resource requests here and letting the resolver take care of it + String errorMsg = null; + ProjectVersionMetadata versionMetadata = getProjectVersionMetadata(); + + if ( versionMetadata == null ) + { + addActionError( errorMsg != null ? errorMsg : "Artifact not found" ); + return ERROR; + } + + if ( versionMetadata.isIncomplete() ) + { + addIncompleteModelWarning(); + } + + model = versionMetadata; + + return SUCCESS; + } + + private ProjectVersionMetadata getProjectVersionMetadata() { ProjectVersionMetadata versionMetadata = null; artifacts = new LinkedHashMap>(); List repos = getObservableRepos(); - // In the future, this should be replaced by the repository grouping mechanism, so that we are only making - // simple resource requests here and letting the resolver take care of it - String errorMsg = null; + for ( String repoId : repos ) { if ( versionMetadata == null ) @@ -122,7 +152,7 @@ public class ShowArtifactAction catch ( MetadataResolutionException e ) { addIncompleteModelWarning(); - + // TODO: need a consistent way to construct this - same in ArchivaMetadataCreationConsumer versionMetadata = new ProjectVersionMetadata(); versionMetadata.setId( version ); @@ -138,7 +168,7 @@ public class ShowArtifactAction public int compare( ArtifactMetadata o1, ArtifactMetadata o2 ) { // sort by version (reverse), then ID - // TODO: move version sorting into repository handling (maven2 specific), and perhaps add a + // TODO: move version sorting into repository handling (maven2 specific), and perhaps add a // way to get latest instead int result = new DefaultArtifactVersion( o2.getVersion() ).compareTo( new DefaultArtifactVersion( o1.getVersion() ) ); @@ -160,20 +190,7 @@ public class ShowArtifactAction } } - if ( versionMetadata == null ) - { - addActionError( errorMsg != null ? errorMsg : "Artifact not found" ); - return ERROR; - } - - if ( versionMetadata.isIncomplete() ) - { - addIncompleteModelWarning(); - } - - model = versionMetadata; - - return SUCCESS; + return versionMetadata; } private void addIncompleteModelWarning() @@ -253,6 +270,32 @@ public class ShowArtifactAction return artifact(); } + public String projectMetadata() + { + projectMetadata = getProjectVersionMetadata(); + String errorMsg = null; + + if ( projectMetadata == null ) + { + addActionError( errorMsg != null ? errorMsg : "Artifact not found" ); + return ERROR; + } + + if ( projectMetadata.isIncomplete() ) + { + addIncompleteModelWarning(); + } + + return SUCCESS; + } + + public String updateProjectMetadata() + { + metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata ); + + return SUCCESS; + } + @Override public void validate() { @@ -357,6 +400,16 @@ public class ShowArtifactAction return dependencyTree; } + public ProjectVersionMetadata getProjectMetadata() + { + return projectMetadata; + } + + public void setProjectMetadata( ProjectVersionMetadata projectMetadata ) + { + this.projectMetadata = projectMetadata; + } + // TODO: move this into the artifact metadata itself via facets where necessary public class ArtifactDownloadInfo @@ -478,5 +531,7 @@ public class ShowArtifactAction { return path; } + + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml index 02659ff3d..10ad88add 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml @@ -218,6 +218,10 @@ /WEB-INF/jsp/showArtifact.jsp + + /WEB-INF/jsp/showArtifact.jsp + + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf new file mode 100644 index 000000000..2cabbe08c --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf @@ -0,0 +1,278 @@ +<%-- + ~ 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. + --%> + +<%@ taglib prefix="s" uri="/struts-tags" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="archiva" uri="/WEB-INF/taglib.tld" %> + + + +

+ + + + + + + + + ${artifactId} / + ${version} +

+ + +
${projectMetadata.description}
+
+ + + + + + + + + + + + + + + + + + + + + +

Other Details

+
Project Metadata ID${projectMetadata.id}
URL${projectMetadata.url}
Name${projectMetadata.name}
Description${projectMetadata.description}
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Organisation + + + ${projectMetadata.organization.name} + + + ${projectMetadata.organization.name} + + +
License + + + ${license.name} + + + ${license.name} + + +
Issue Tracker + + + ${projectMetadata.issueManagement.system} + + + ${projectMetadata.issueManagement.system} + + +
Continuous Integration + + + ${projectMetadata.ciManagement.system} + + + ${projectMetadata.ciManagement.system} + + +
+ + + +

SCM

+ + + + + + + + + + + + + + + + + + + +
Connection + ${projectMetadata.scm.connection} +
Dev. Connection + ${projectMetadata.scm.developerConnection} +
Viewer + ${projectMetadata.scm.url} +
+
+ + + +
+ +

Mailing Lists

+
+ +

${mailingList.name}

+ + + + + + + + + + + + + + + + + + + + + + + + + +
Subscribe + ${mailingList.subscribeAddress} +
Post + ${mailingList.postAddress} +
Unsubscribe + ${mailingList.unsubscribeAddress} +
Archive + ${mailingList.mainArchiveUrl} +
+
+
+
+ + +

Dependencies

+
+ +

Dependency

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Group ID + ${dependency.groupId} +
Artifact ID + ${dependency.artifactId} +
Version + ${dependency.version} +
Classifier + ${dependency.classifier} +
Type + ${dependency.type} +
Scope + ${dependency.scope} +
System Path + ${dependency.systemPath} +
+
+
+
+
+
\ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp index ad484deb1..ad9dbfb39 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp @@ -126,6 +126,14 @@ Mailing Lists + + + + + + + + Metadata <%-- TODO @@ -211,6 +219,9 @@ <%-- TODO: panels? this is ugly as is --%>
+ + <%@ include file="/WEB-INF/jsp/include/projectMetadata.jspf" %> + <%@ include file="/WEB-INF/jsp/include/artifactDependencies.jspf" %> @@ -229,6 +240,7 @@ <%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %> + 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 b3128337b..aa00d21ac 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 @@ -368,6 +368,41 @@ public class ShowArtifactActionTest assertTrue( action.getArtifacts().isEmpty() ); } + public void testGetProjectMetadata() + { + ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION ); + Dependency dependency1 = createDependencyBasic( "artifactId1" ); + Dependency dependency2 = createDependencyExtended( "artifactId2" ); + versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) ); + + MailingList ml1 = createMailingList( "Users List", "users" ); + MailingList ml2 = createMailingList( "Developers List", "dev" ); + versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) ); + + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata ); + + setActionParameters(); + + String result = action.projectMetadata(); + + assertActionSuccess( action, result ); + + assertActionParameters( action ); + ProjectVersionMetadata projectMetadata = action.getProjectMetadata(); + assertDefaultModel( projectMetadata ); + + assertNotNull( projectMetadata.getDependencies() ); + assertDependencyBasic( projectMetadata.getDependencies().get( 0 ), "artifactId1" ); + assertDependencyExtended( projectMetadata.getDependencies().get( 1 ), "artifactId2" ); + + assertEquals( TEST_REPO, action.getRepositoryId() ); + assertNull( action.getModel() ); + assertNull( action.getDependees() ); + assertNull( action.getDependencies() ); + assertNull( action.getMailingLists() ); + assertTrue( action.getArtifacts().isEmpty() ); + } + private void assertArtifacts( List expectedArtifacts, Map> artifactMap ) {