[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
This commit is contained in:
Maria Odea B. Ching 2010-05-04 08:54:00 +00:00
parent aad0ae13cf
commit 8f4f8c83e9
5 changed files with 403 additions and 19 deletions

View File

@ -25,6 +25,7 @@ import org.apache.archiva.metadata.model.Dependency;
import org.apache.archiva.metadata.model.MailingList; import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; 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.MetadataResolutionException;
import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
@ -67,6 +68,11 @@ public class ShowArtifactAction
*/ */
private RepositoryContentFactory repositoryFactory; private RepositoryContentFactory repositoryFactory;
/**
* @plexus.requirement
*/
private MetadataRepository metadataRepository;
/* .\ Exposed Output Objects \.__________________________________ */ /* .\ Exposed Output Objects \.__________________________________ */
private String groupId; private String groupId;
@ -95,20 +101,44 @@ public class ShowArtifactAction
private boolean dependencyTree = false; private boolean dependencyTree = false;
private ProjectVersionMetadata projectMetadata;
/** /**
* Show the versioned project information tab. * Show the versioned project information tab.
* TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though
* that is rendered in the download box). * that is rendered in the download box).
*/ */
public String artifact() 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; ProjectVersionMetadata versionMetadata = null;
artifacts = new LinkedHashMap<String, List<ArtifactDownloadInfo>>(); artifacts = new LinkedHashMap<String, List<ArtifactDownloadInfo>>();
List<String> repos = getObservableRepos(); List<String> 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 ) for ( String repoId : repos )
{ {
if ( versionMetadata == null ) if ( versionMetadata == null )
@ -160,20 +190,7 @@ public class ShowArtifactAction
} }
} }
if ( versionMetadata == null ) return versionMetadata;
{
addActionError( errorMsg != null ? errorMsg : "Artifact not found" );
return ERROR;
}
if ( versionMetadata.isIncomplete() )
{
addIncompleteModelWarning();
}
model = versionMetadata;
return SUCCESS;
} }
private void addIncompleteModelWarning() private void addIncompleteModelWarning()
@ -253,6 +270,32 @@ public class ShowArtifactAction
return artifact(); 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 @Override
public void validate() public void validate()
{ {
@ -357,6 +400,16 @@ public class ShowArtifactAction
return dependencyTree; 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 // TODO: move this into the artifact metadata itself via facets where necessary
public class ArtifactDownloadInfo public class ArtifactDownloadInfo
@ -478,5 +531,7 @@ public class ShowArtifactAction
{ {
return path; return path;
} }
} }
} }

View File

@ -218,6 +218,10 @@
<result>/WEB-INF/jsp/showArtifact.jsp</result> <result>/WEB-INF/jsp/showArtifact.jsp</result>
</action> </action>
<action name="showProjectMetadata" class="showArtifactAction" method="projectMetadata">
<result>/WEB-INF/jsp/showArtifact.jsp</result>
</action>
</package> </package>
<package name="components" namespace="/components" extends="struts-default"> <package name="components" namespace="/components" extends="struts-default">

View File

@ -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" %>
<script type="text/javascript">
$(function() {
$("#accordion2").accordion();
});
</script>
<p>
<archiva:groupIdLink var="${groupId}" includeTop="true" />
<c:set var="url">
<s:url action="browseArtifact" namespace="/">
<s:param name="groupId" value="%{#attr.groupId}"/>
<s:param name="artifactId" value="%{#attr.artifactId}"/>
</s:url>
</c:set>
<a href="${url}">${artifactId}</a> /
<strong>${version}</strong>
</p>
<c:if test="${!empty (projectMetadata.description)}">
<blockquote>${projectMetadata.description}</blockquote>
</c:if>
<table class="infoTable">
<tr>
<th>Project Metadata ID</th>
<td>${projectMetadata.id}</td>
</tr>
<tr>
<th>URL</th>
<td>${projectMetadata.url}</td>
</tr>
<tr>
<th>Name</th>
<td>${projectMetadata.name}</td>
</tr>
<tr>
<th>Description</th>
<td>${projectMetadata.description}</td>
</tr>
<c:if test="${projectMetadata.organization != null || !empty (projectMetadata.licenses)
|| projectMetadata.issueManagement != null || projectMetadata.ciManagement != null }">
<h2>Other Details</h2>
<table class="infoTable">
<c:if test="${projectMetadata.organization != null}">
<tr>
<th>Organisation</th>
<td>
<c:choose>
<c:when test="${projectMetadata.organization.url != null}">
<a href="${projectMetadata.organization.url}">${projectMetadata.organization.name}</a>
</c:when>
<c:otherwise>
${projectMetadata.organization.name}
</c:otherwise>
</c:choose>
</td>
</tr>
</c:if>
<c:if test="${!empty (projectMetadata.licenses)}">
<c:forEach items="${projectMetadata.licenses}" var="license">
<tr>
<th>License</th>
<td>
<c:choose>
<c:when test="${!empty (license.url)}">
<a href="${license.url}">${license.name}</a>
</c:when>
<c:otherwise>
${license.name}
</c:otherwise>
</c:choose>
</td>
</tr>
</c:forEach>
</c:if>
<c:if test="${projectMetadata.issueManagement != null}">
<tr>
<th>Issue Tracker</th>
<td>
<c:choose>
<c:when test="${!empty (projectMetadata.issueManagement.url)}">
<a href="${projectMetadata.issueManagement.url}">${projectMetadata.issueManagement.system}</a>
</c:when>
<c:otherwise>
${projectMetadata.issueManagement.system}
</c:otherwise>
</c:choose>
</td>
</tr>
</c:if>
<c:if test="${projectMetadata.ciManagement != null}">
<tr>
<th>Continuous Integration</th>
<td>
<c:choose>
<c:when test="${!empty (projectMetadata.ciManagement.url)}">
<a href="${projectMetadata.ciManagement.url}">${projectMetadata.ciManagement.system}</a>
</c:when>
<c:otherwise>
${projectMetadata.ciManagement.system}
</c:otherwise>
</c:choose>
</td>
</tr>
</c:if>
</table>
</c:if>
<c:if test="${projectMetadata.scm != null}">
<h2>SCM</h2>
<table class="infoTable">
<c:if test="${!empty (projectMetadata.scm.connection)}">
<tr>
<th>Connection</th>
<td>
<code>${projectMetadata.scm.connection}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (projectMetadata.scm.developerConnection)}">
<tr>
<th>Dev. Connection</th>
<td>
<code>${projectMetadata.scm.developerConnection}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (projectMetadata.scm.url)}">
<tr>
<th>Viewer</th>
<td>
<a href="${projectMetadata.scm.url}">${projectMetadata.scm.url}</a>
</td>
</tr>
</c:if>
</table>
</c:if>
<c:if test="${projectMetadata.mailingLists != null || projectMetadata.dependencies != null}">
<div id="accordion2">
<c:if test="${!empty (projectMetadata.mailingLists)}">
<h2><a href="#">Mailing Lists</a></h2>
<div>
<c:forEach items="${projectMetadata.mailingLists}" var="mailingList">
<h3>${mailingList.name}</h3>
<table class="infoTable">
<c:if test="${!empty (mailingList.subscribeAddress)}">
<tr>
<th>Subscribe</th>
<td>
<code>${mailingList.subscribeAddress}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (mailingList.postAddress)}">
<tr>
<th>Post</th>
<td>
<code>${mailingList.postAddress}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (mailingList.unsubscribeAddress)}">
<tr>
<th>Unsubscribe</th>
<td>
<code>${mailingList.unsubscribeAddress}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (mailingList.mainArchiveUrl)}">
<tr>
<th>Archive</th>
<td>
<code>${mailingList.mainArchiveUrl}</code>
</td>
</tr>
</c:if>
</table>
</c:forEach>
</div>
</c:if>
<c:if test="${!empty (projectMetadata.dependencies)}">
<h2><a href="#">Dependencies</a></h2>
<div>
<c:forEach items="${projectMetadata.dependencies}" var="dependency">
<h3>Dependency</h3>
<table class="infoTable">
<c:if test="${!empty (dependency.groupId)}">
<tr>
<th>Group ID</th>
<td>
<code>${dependency.groupId}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (dependency.artifactId)}">
<tr>
<th>Artifact ID</th>
<td>
<code>${dependency.artifactId}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (dependency.version)}">
<tr>
<th>Version</th>
<td>
<code>${dependency.version}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (dependency.classifier)}">
<tr>
<th>Classifier</th>
<td>
<code>${dependency.classifier}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (dependency.type)}">
<tr>
<th>Type</th>
<td>
<code>${dependency.type}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (dependency.scope)}">
<tr>
<th>Scope</th>
<td>
<code>${dependency.scope}</code>
</td>
</tr>
</c:if>
<c:if test="${!empty (dependency.systemPath)}">
<tr>
<th>System Path</th>
<td>
<code>${dependency.systemPath}</code>
</td>
</tr>
</c:if>
</table>
</c:forEach>
</div>
</c:if>
</div>
</c:if>

View File

@ -126,6 +126,14 @@
</s:url> </s:url>
</c:set> </c:set>
<my:currentWWUrl url="${url}">Mailing Lists</my:currentWWUrl> <my:currentWWUrl url="${url}">Mailing Lists</my:currentWWUrl>
<c:set var="url">
<s:url action="showProjectMetadata">
<s:param name="groupId" value="%{groupId}"/>
<s:param name="artifactId" value="%{artifactId}"/>
<s:param name="version" value="%{version}"/>
</s:url>
</c:set>
<my:currentWWUrl url="${url}">Metadata</my:currentWWUrl>
<%-- TODO <%-- TODO
<redback:ifAnyAuthorized permissions="archiva-access-reports"> <redback:ifAnyAuthorized permissions="archiva-access-reports">
<c:set var="url"> <c:set var="url">
@ -211,6 +219,9 @@
<%-- TODO: panels? this is ugly as is --%> <%-- TODO: panels? this is ugly as is --%>
<div id="tabArea"> <div id="tabArea">
<c:choose> <c:choose>
<c:when test="${projectMetadata != null}">
<%@ include file="/WEB-INF/jsp/include/projectMetadata.jspf" %>
</c:when>
<c:when test="${dependencies != null}"> <c:when test="${dependencies != null}">
<%@ include file="/WEB-INF/jsp/include/artifactDependencies.jspf" %> <%@ include file="/WEB-INF/jsp/include/artifactDependencies.jspf" %>
</c:when> </c:when>
@ -229,6 +240,7 @@
<c:otherwise> <c:otherwise>
<%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %> <%@ include file="/WEB-INF/jsp/include/artifactInfo.jspf" %>
</c:otherwise> </c:otherwise>
</c:choose> </c:choose>
<s:if test="hasActionMessages()"> <s:if test="hasActionMessages()">

View File

@ -368,6 +368,41 @@ public class ShowArtifactActionTest
assertTrue( action.getArtifacts().isEmpty() ); 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<ArtifactMetadata> expectedArtifacts, private void assertArtifacts( List<ArtifactMetadata> expectedArtifacts,
Map<String, List<ShowArtifactAction.ArtifactDownloadInfo>> artifactMap ) Map<String, List<ShowArtifactAction.ArtifactDownloadInfo>> artifactMap )
{ {