From: Maria Odea B. Ching Date: Mon, 24 May 2010 10:29:58 +0000 (+0000) Subject: [MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic... X-Git-Tag: archiva-1.4-M1~937 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2d781734b668bfbf1b7fcd936d3d23427037d8b3;p=archiva.git [MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic metadata" plugin o move out util for formatting project metadata to a custom tag o do not show metadata section name (organization, issueManagement, ciManagement, scm, dependencies, mailing lists, licenses) when they are empty git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@947591 13f79535-47bb-0310-9956-ffa450edef68 --- 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 2d3182d8c..d148be496 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 @@ -29,7 +29,6 @@ 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; -import org.apache.maven.archiva.web.util.ProjectMetadataDisplayUtil; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.repository.ManagedRepositoryContent; @@ -290,13 +289,6 @@ public class ShowArtifactAction return SUCCESS; } - public String getMetadataOutput() - { - ProjectMetadataDisplayUtil metadataDisplayUtil = new ProjectMetadataDisplayUtil(); - - return metadataDisplayUtil.formatProjectMetadata( projectMetadata ); - } - public String updateProjectMetadata() { metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java new file mode 100644 index 000000000..f3581276d --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java @@ -0,0 +1,258 @@ +package org.apache.maven.archiva.web.tags; + +/* + * 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. + */ + +import java.io.IOException; +import java.util.List; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.archiva.metadata.model.Dependency; +import org.apache.archiva.metadata.model.License; +import org.apache.archiva.metadata.model.MailingList; +import org.apache.archiva.metadata.model.ProjectVersionMetadata; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ProjectMetadataTag + * + * Outputs the project metadata attributes, used in the Metadata tab in artifact browse. + */ +@SuppressWarnings( "serial" ) +public class ProjectMetadataTag + extends TagSupport +{ + private Logger log = LoggerFactory.getLogger( ProjectMetadataTag.class ); + + private Object object; + + @Override + public void release() + { + object = null; + super.release(); + } + + @Override + public int doStartTag() + throws JspException + { + StringBuffer buf = new StringBuffer(); + + if ( object == null ) + { + buf.append( "Error generating project metadata." ); + log.error( "Unable to generate project metadata for null object." ); + } + else if ( object instanceof ProjectVersionMetadata ) + { + ProjectVersionMetadata metadata = (ProjectVersionMetadata) object; + + buildProjectMetadata( buf, metadata ); + } + else + { + buf.append( "Unable to generate project metadata for object " ).append( object.getClass().getName() ); + } + + out( buf.toString() ); + + return EVAL_BODY_INCLUDE; + } + + private void out( String msg ) + throws JspException + { + try + { + pageContext.getOut().print( msg ); + } + catch ( IOException e ) + { + throw new JspException( "Unable to output to jsp page context." ); + } + } + + private void buildProjectMetadata( StringBuffer metadataEntries, ProjectVersionMetadata projectMetadata ) + { + startList( metadataEntries ); + + addListItem( "project.metadata.id=", projectMetadata.getId(), metadataEntries ); + addListItem( "project.url=", projectMetadata.getUrl(), metadataEntries ); + addListItem( "project.name=", projectMetadata.getName(), metadataEntries ); + addListItem( "project.description=", projectMetadata.getDescription(), metadataEntries ); + + if ( projectMetadata.getOrganization() != null ) + { + startListItem( "organization", metadataEntries ); + startList( metadataEntries ); + addListItem( "organization.name=", projectMetadata.getOrganization().getName(), metadataEntries ); + addListItem( "organization.url=", projectMetadata.getOrganization().getUrl(), metadataEntries ); + endList( metadataEntries ); + } + endListItem( metadataEntries ); + + if ( projectMetadata.getIssueManagement() != null ) + { + startListItem( "issueManagement", metadataEntries ); + startList( metadataEntries ); + addListItem( "issueManagement.system=", projectMetadata.getIssueManagement().getSystem(), metadataEntries ); + addListItem( "issueManagement.url=", projectMetadata.getIssueManagement().getUrl(), metadataEntries ); + endList( metadataEntries ); + } + endListItem( metadataEntries ); + + if ( projectMetadata.getScm() != null ) + { + startListItem( "scm", metadataEntries ); + startList( metadataEntries ); + addListItem( "scm.url=", projectMetadata.getScm().getUrl(), metadataEntries ); + addListItem( "scm.connection=", projectMetadata.getScm().getConnection(), metadataEntries ); + addListItem( "scm.developer.connection=", projectMetadata.getScm().getDeveloperConnection(), + metadataEntries ); + endList( metadataEntries ); + } + endListItem( metadataEntries ); + + if ( projectMetadata.getCiManagement() != null ) + { + startListItem( "ciManagement", metadataEntries ); + startList( metadataEntries ); + addListItem( "ciManagement.system=", projectMetadata.getCiManagement().getSystem(), metadataEntries ); + addListItem( "ciManagement.url=", projectMetadata.getCiManagement().getUrl(), metadataEntries ); + endList( metadataEntries ); + } + endListItem( metadataEntries ); + + if ( projectMetadata.getLicenses() != null && !projectMetadata.getLicenses().isEmpty() ) + { + startListItem( "licenses", metadataEntries ); + List licenses = projectMetadata.getLicenses(); + int ctr = 0; + startList( metadataEntries ); + for ( License license : licenses ) + { + addListItem( "licenses." + ctr + ".name=", license.getName(), metadataEntries ); + addListItem( "licenses." + ctr + ".url=", license.getUrl(), metadataEntries ); + ctr++; + } + endList( metadataEntries ); + } + endListItem( metadataEntries ); + + if ( projectMetadata.getMailingLists() != null && !projectMetadata.getMailingLists().isEmpty() ) + { + startListItem( "mailingLists", metadataEntries ); + List lists = projectMetadata.getMailingLists(); + List otherArchives; + int ctr = 0; + int archiveCtr = 0; + + startList( metadataEntries ); + for ( MailingList list : lists ) + { + addListItem( "mailingLists." + ctr + ".name=", list.getName(), metadataEntries ); + addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl(), metadataEntries ); + addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress(), metadataEntries ); + addListItem( "mailingLists." + ctr + ".subscribe=", list.getSubscribeAddress(), metadataEntries ); + addListItem( "mailingLists." + ctr + ".unsubscribe=", list.getUnsubscribeAddress(), metadataEntries ); + startListItem( "mailingLists." + ctr + ".otherArchives", metadataEntries ); + + if ( list.getOtherArchives() != null && list.getOtherArchives().size() > 0 ) + { + archiveCtr = 0; + otherArchives = list.getOtherArchives(); + + startList( metadataEntries ); + for ( String archive : otherArchives ) + { + addListItem( "mailingLists." + ctr + ".otherArchives." + archiveCtr + "=", archive, + metadataEntries ); + metadataEntries.append( archive ); + archiveCtr++; + } + endList( metadataEntries ); + } + endListItem( metadataEntries ); + ctr++; + } + endList( metadataEntries ); + } + endListItem( metadataEntries ); + + if ( projectMetadata.getDependencies() != null && !projectMetadata.getDependencies().isEmpty() ) + { + startListItem( "dependencies", metadataEntries ); + List dependencies = projectMetadata.getDependencies(); + int ctr = 0; + + startList( metadataEntries ); + for ( Dependency dependency : dependencies ) + { + addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId(), metadataEntries ); + addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId(), metadataEntries ); + addListItem( "dependency." + ctr + ".version=", dependency.getVersion(), metadataEntries ); + addListItem( "dependency." + ctr + ".classifier=", dependency.getClassifier(), metadataEntries ); + addListItem( "dependency." + ctr + ".type=", dependency.getType(), metadataEntries ); + addListItem( "dependency." + ctr + ".scope=", dependency.getScope(), metadataEntries ); + addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath(), metadataEntries ); + ctr++; + } + endList( metadataEntries ); + } + endListItem( metadataEntries ); + + endList( metadataEntries ); + } + + private void startList( StringBuffer metadataEntries ) + { + metadataEntries.append( "\n
    " ); + } + + private void endList( StringBuffer metadataEntries ) + { + metadataEntries.append( "\n
" ); + } + + private void addListItem( String label, String value, StringBuffer metadataEntries ) + { + String newValue = StringUtils.isEmpty( value ) ? "" : value; + metadataEntries.append( "\n
  • " ).append( label ).append( newValue ).append( "
  • " ); + } + + private void startListItem( String value, StringBuffer metadataEntries ) + { + metadataEntries.append( "\n
  • " ).append( value ); + } + + private void endListItem( StringBuffer metadataEntries ) + { + metadataEntries.append( "\n
  • " ); + } + + public void setObject( Object object ) + { + this.object = object; + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/ProjectMetadataDisplayUtil.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/ProjectMetadataDisplayUtil.java deleted file mode 100644 index af3ba7ed0..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/ProjectMetadataDisplayUtil.java +++ /dev/null @@ -1,199 +0,0 @@ -package org.apache.maven.archiva.web.util; - -/* - * 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. - */ - -import org.apache.archiva.metadata.model.Dependency; -import org.apache.archiva.metadata.model.License; -import org.apache.archiva.metadata.model.MailingList; -import org.apache.archiva.metadata.model.ProjectVersionMetadata; -import org.apache.commons.lang.StringUtils; - -import java.util.List; - -/** - * ProjectMetadataDisplayUtil - * - */ - -public class ProjectMetadataDisplayUtil -{ - private StringBuilder metadataEntries; - - public String formatProjectMetadata( ProjectVersionMetadata projectMetadata ) - { - metadataEntries = new StringBuilder(); - - startList(); - - addListItem( "project.metadata.id=", projectMetadata.getId() ); - addListItem( "project.url=", projectMetadata.getUrl() ); - addListItem( "project.name=", projectMetadata.getName() ); - addListItem( "project.description=", projectMetadata.getDescription() ); - - startListItem( "organization" ); - if ( projectMetadata.getOrganization() != null ) - { - startList(); - addListItem( "organization.name=", projectMetadata.getOrganization().getName() ); - addListItem( "organization.url=", projectMetadata.getOrganization().getUrl() ); - endList(); - } - endListItem(); - - startListItem( "issueManagement" ); - if ( projectMetadata.getIssueManagement() != null ) - { - startList(); - addListItem( "issueManagement.system=", projectMetadata.getIssueManagement().getSystem() ); - addListItem( "issueManagement.url=", projectMetadata.getIssueManagement().getUrl() ); - endList(); - } - endListItem(); - - startListItem( "scm" ); - if ( projectMetadata.getScm() != null ) - { - startList(); - addListItem( "scm.url=", projectMetadata.getScm().getUrl() ); - addListItem( "scm.connection=", projectMetadata.getScm().getConnection() ); - addListItem( "scm.developer.connection=", projectMetadata.getScm().getDeveloperConnection() ); - endList(); - } - endListItem(); - - startListItem( "ciManagement" ); - if ( projectMetadata.getCiManagement() != null ) - { - startList(); - addListItem( "ciManagement.system=", projectMetadata.getCiManagement().getSystem() ); - addListItem( "ciManagement.url=", projectMetadata.getCiManagement().getUrl() ); - endList(); - } - endListItem(); - - startListItem( "licenses" ); - if ( projectMetadata.getLicenses() != null ) - { - List licenses = projectMetadata.getLicenses(); - int ctr = 0; - startList(); - for ( License license : licenses ) - { - addListItem( "licenses." + ctr + ".name=", license.getName() ); - addListItem( "licenses." + ctr + ".url=", license.getUrl() ); - ctr++; - } - endList(); - } - endListItem(); - - startListItem( "mailingLists" ); - if ( projectMetadata.getMailingLists() != null ) - { - List lists = projectMetadata.getMailingLists(); - List otherArchives; - int ctr = 0; - int archiveCtr = 0; - - startList(); - for ( MailingList list : lists ) - { - addListItem( "mailingLists." + ctr + ".name=", list.getName() ); - addListItem( "mailingLists." + ctr + ".archive.url=", list.getMainArchiveUrl() ); - addListItem( "mailingLists." + ctr + ".post=", list.getPostAddress() ); - addListItem( "mailingLists." + ctr + ".subscribe=", list.getSubscribeAddress() ); - addListItem( "mailingLists." + ctr + ".unsubscribe=", list.getUnsubscribeAddress() ); - startListItem( "mailingLists." + ctr + ".otherArchives" ); - - if ( list.getOtherArchives() != null && list.getOtherArchives().size() > 0 ) - { - archiveCtr = 0; - otherArchives = list.getOtherArchives(); - - startList(); - for ( String archive : otherArchives ) - { - addListItem( "mailingLists." + ctr + ".otherArchives." + archiveCtr + "=", archive ); - metadataEntries.append( archive ); - archiveCtr++; - } - endList(); - } - endListItem(); - ctr++; - } - endList(); - } - endListItem(); - - startListItem( "dependencies" ); - if ( projectMetadata.getDependencies() != null ) - { - List dependencies = projectMetadata.getDependencies(); - int ctr = 0; - - startList(); - for ( Dependency dependency : dependencies ) - { - addListItem( "dependency." + ctr + ".group.id=", dependency.getGroupId() ); - addListItem( "dependency." + ctr + ".artifact.id=", dependency.getArtifactId() ); - addListItem( "dependency." + ctr + ".version=", dependency.getVersion() ); - addListItem( "dependency." + ctr + ".classifier=", dependency.getClassifier() ); - addListItem( "dependency." + ctr + ".type=", dependency.getType() ); - addListItem( "dependency." + ctr + ".scope=", dependency.getScope() ); - addListItem( "dependency." + ctr + ".system.path=", dependency.getSystemPath() ); - ctr++; - } - endList(); - } - endListItem(); - - endList(); - - return metadataEntries.toString(); - } - - private void startList() - { - metadataEntries.append( "\n
      " ); - } - - private void endList() - { - metadataEntries.append( "\n
    " ); - } - - private void addListItem( String label, String value ) - { - String newValue = StringUtils.isEmpty( value ) ? "" : value; - metadataEntries.append( "\n
  • " ).append( label ).append( newValue ).append( "
  • " ); - } - - private void startListItem( String value ) - { - metadataEntries.append( "\n
  • " ).append( value ); - } - - private void endListItem() - { - metadataEntries.append( "\n
  • " ); - } -} - 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 index 452050aac..498fdabb0 100644 --- 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 @@ -36,5 +36,5 @@

    - ${metadataOutput} +
    diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/taglib.tld b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/taglib.tld index 5f0a5ed1c..fc83554e0 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/taglib.tld +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/taglib.tld @@ -110,4 +110,21 @@ + + + project-metadata + org.apache.maven.archiva.web.tags.ProjectMetadataTag + empty + + + + object + true + true + + + + + + \ No newline at end of file