From 8891e9fdd249872865e072fca2af18efb5abf14d Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Mon, 7 Jun 2010 07:40:26 +0000 Subject: [PATCH] [MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic metadata" plugin o removed project metadata custom tag o enable delete of generic metadata properties o added unit tests for adding and deleting properties o clear facet properties read from file before doing the update so that removed facet properties are not retained when updating project version metadata git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@952127 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/action/ShowArtifactAction.java | 157 +++------ .../archiva/web/tags/ProjectMetadataTag.java | 305 ------------------ .../src/main/resources/struts.xml | 6 +- .../WEB-INF/jsp/include/projectMetadata.jspf | 35 +- .../main/webapp/WEB-INF/jsp/showArtifact.jsp | 5 + .../src/main/webapp/WEB-INF/taglib.tld | 41 --- .../web/action/ShowArtifactActionTest.java | 75 +++++ .../AbstractMetadataRepositoryTest.java | 80 ++++- .../generic/GenericMetadataFacet.java | 1 - .../file/FileMetadataRepository.java | 24 ++ 10 files changed, 244 insertions(+), 485 deletions(-) delete mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java 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 591815986..3c84d2417 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,7 +24,6 @@ import com.opensymphony.xwork2.Validateable; 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.License; import org.apache.archiva.metadata.model.MailingList; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionReference; @@ -57,6 +56,7 @@ import java.util.Map; * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" * instantiation-strategy="per-lookup" */ +@SuppressWarnings( "serial" ) public class ShowArtifactAction extends AbstractRepositoryBasedAction implements Validateable @@ -105,13 +105,9 @@ public class ShowArtifactAction private Map> artifacts; private boolean dependencyTree = false; - - private ProjectVersionMetadata projectMetadata; - + private String deleteItem; - private String itemValue; - private Map genericMetadata; private String propertyName; @@ -335,114 +331,69 @@ public class ShowArtifactAction genericMetadata.put( propertyName, propertyValue ); - GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet(); - genericMetadataFacet.fromProperties( genericMetadata ); - - // add updated facet - projectMetadata.addFacet( genericMetadataFacet ); - - metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata ); + updateProjectMetadata( projectMetadata ); projectMetadata = getProjectVersionMetadata(); genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties(); model = projectMetadata; - + propertyName = ""; propertyValue = ""; return SUCCESS; } - public String updateProjectMetadata() - { - metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata ); - - return SUCCESS; - } - public String deleteMetadataEntry() { - projectMetadata = getProjectVersionMetadata(); - - if ( !StringUtils.isEmpty( deleteItem ) && !StringUtils.isEmpty( itemValue ) ) + ProjectVersionMetadata projectMetadata = getProjectVersionMetadata(); + String errorMsg = null; + + if ( projectMetadata == null ) { - if ( "dependency".equals( deleteItem ) ) - { - removeDependency(); - } - else if ( "mailingList".equals( deleteItem ) ) - { - removeMailingList(); - } - else if ( "license".equals( deleteItem ) ) - { - removeLicense(); - } - - deleteItem = ""; - itemValue = ""; + addActionError( errorMsg != null ? errorMsg : "Artifact not found" ); + return ERROR; } - return updateProjectMetadata(); - } - - private void removeDependency() - { - List dependencies = projectMetadata.getDependencies(); - List newDependencies = new ArrayList(); - - if ( dependencies != null ) - { - for ( Dependency dependency : dependencies ) + if ( projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ) != null ) + { + genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties(); + + if ( !StringUtils.isEmpty( deleteItem ) ) { - if ( !StringUtils.equals( itemValue, dependency.getArtifactId() ) ) - { - newDependencies.add( dependency ); - } - } - } + genericMetadata.remove( deleteItem ); + + updateProjectMetadata( projectMetadata ); + + projectMetadata = getProjectVersionMetadata(); - projectMetadata.setDependencies( newDependencies ); - } + genericMetadata = projectMetadata.getFacet( GenericMetadataFacet.FACET_ID ).toProperties(); - private void removeMailingList() - { - List mailingLists = projectMetadata.getMailingLists(); - List newMailingLists = new ArrayList(); + model = projectMetadata; - if ( mailingLists != null ) - { - for ( MailingList mailingList : mailingLists ) - { - if ( !StringUtils.equals( itemValue, mailingList.getName() ) ) - { - newMailingLists.add( mailingList ); - } + addActionMessage( "Property successfully deleted." ); } + + deleteItem = ""; + } + else + { + addActionError( errorMsg != null ? errorMsg : "No generic metadata facet for this artifact." ); + return ERROR; } - projectMetadata.setMailingLists( newMailingLists ); + return SUCCESS; } - private void removeLicense() + private void updateProjectMetadata( ProjectVersionMetadata projectMetadata ) { - List licenses = projectMetadata.getLicenses(); - List newLicenses = new ArrayList(); - - if ( licenses != null ) - { - for ( License license : licenses ) - { - if ( !StringUtils.equals( itemValue, license.getName() ) ) - { - newLicenses.add( license ); - } - } - } - - projectMetadata.setLicenses( newLicenses ); + GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet(); + genericMetadataFacet.fromProperties( genericMetadata ); + + projectMetadata.addFacet( genericMetadataFacet ); + + metadataRepository.updateProjectVersion( repositoryId, groupId, artifactId, projectMetadata ); } @Override @@ -538,37 +489,17 @@ public class ShowArtifactAction { return artifacts.keySet(); } - - public void setRepositoryFactory( RepositoryContentFactory repositoryFactory ) - { - this.repositoryFactory = repositoryFactory; - } - + public boolean isDependencyTree() { return dependencyTree; } - public ProjectVersionMetadata getProjectMetadata() - { - return projectMetadata; - } - - public void setProjectMetadata( ProjectVersionMetadata projectMetadata ) - { - this.projectMetadata = projectMetadata; - } - public void setDeleteItem( String deleteItem ) { this.deleteItem = deleteItem; } - public void setItemValue( String itemValue ) - { - this.itemValue = itemValue; - } - public Map getGenericMetadata() { return genericMetadata; @@ -598,6 +529,16 @@ public class ShowArtifactAction { this.propertyValue = propertyValue; } + + public void setRepositoryFactory( RepositoryContentFactory repositoryFactory ) + { + this.repositoryFactory = repositoryFactory; + } + + public void setMetadataRepository( MetadataRepository metadataRepository ) + { + this.metadataRepository = metadataRepository; + } // TODO: move this into the artifact metadata itself via facets where necessary 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 deleted file mode 100644 index 73653c67b..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java +++ /dev/null @@ -1,305 +0,0 @@ -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; - - private String groupId; - - private String artifactId; - - private String version; - - @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 ) - { - createDeleteLink( "license", license.getName(), metadataEntries ); - startList( metadataEntries ); - addListItem( "licenses." + ctr + ".name=", license.getName(), metadataEntries ); - addListItem( "licenses." + ctr + ".url=", license.getUrl(), metadataEntries ); - endList( metadataEntries ); - endListItem( 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 ) - { - createDeleteLink( "mailingList", list.getName(), metadataEntries ); - startList( metadataEntries ); - 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 ); - 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 ) - { - createDeleteLink( "dependency", dependency.getArtifactId(), metadataEntries ); - startList( metadataEntries ); - 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 ); - endList( metadataEntries ); - endListItem( 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
  • " ); - } - - private void createDeleteLink( String name, String value, StringBuffer metadataEntries ) - { - metadataEntries.append( "\n
  • " ).append( value ) - .append( "\n" ) - .append( "" ).append( "" ); - } - - public void setObject( Object object ) - { - this.object = object; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public void setArtifactId( String artifactId ) - { - this.artifactId = artifactId; - } - - public void setVersion( String version ) - { - this.version = version; - } -} 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 4cf08c2ce..fa127d095 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 @@ -228,10 +228,8 @@ - - showProjectMetadata - / - + /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 index da2937721..0b437910d 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 @@ -42,7 +42,7 @@ - + @@ -60,26 +60,21 @@ - - - -

    - -

    - -
    - - -
    - -
    -
    -

    - - <%-- --%> + + 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 24b7cf49a..69a82cfc0 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 @@ -249,6 +249,11 @@ + +
    + +
    +
    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 d5572f276..a843d8906 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,45 +110,4 @@ - - - project-metadata - org.apache.maven.archiva.web.tags.ProjectMetadataTag - empty - - - - object - true - true - - - - - - groupId - true - true - - - - - - artifactId - true - true - - - - - - version - true - true - - - - - - 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 cb56754ff..14bce5300 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 @@ -27,9 +27,14 @@ 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.file.FileMetadataRepository; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.maven.archiva.common.utils.VersionUtil; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.DefaultArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; @@ -395,7 +400,62 @@ public class ShowArtifactActionTest assertNull( action.getMailingLists() ); assertTrue( action.getArtifacts().isEmpty() ); } + + public void testAddAndDeleteMetadataProperty() + { + ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION ); + + metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata ); + + setActionParameters(); + action.setPropertyName( "foo" ); + action.setPropertyValue( "bar" ); + action.setRepositoryId( TEST_REPO ); + String result = action.addMetadataProperty(); + + assertActionSuccess( action, result ); + assertActionParameters( action ); + + Map genericMetadata = action.getGenericMetadata(); + assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) ); + assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), TEST_GENERIC_METADATA_PROPERTY_VALUE ); + + assertNotNull( genericMetadata.get( "foo" ) ); + assertEquals( "bar", genericMetadata.get( "foo" ) ); + + assertEquals( TEST_REPO, action.getRepositoryId() ); + assertNotNull( action.getModel() ); + assertNull( action.getDependees() ); + assertNull( action.getDependencies() ); + assertNull( action.getMailingLists() ); + assertTrue( action.getArtifacts().isEmpty() ); + + // test delete property + setActionParameters(); + action.setDeleteItem( "foo" ); + + result = action.deleteMetadataEntry(); + + assertEquals( Action.SUCCESS, result ); + assertActionParameters( action ); + assertTrue( !action.getActionMessages().isEmpty() ); + assertTrue( action.getActionMessages().contains( "Property successfully deleted." ) ); + + genericMetadata = action.getGenericMetadata(); + assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) ); + assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ), TEST_GENERIC_METADATA_PROPERTY_VALUE ); + + assertNull( genericMetadata.get( "foo" ) ); + + assertEquals( TEST_REPO, action.getRepositoryId() ); + assertNotNull( action.getModel() ); + assertNull( action.getDependees() ); + assertNull( action.getDependencies() ); + assertNull( action.getMailingLists() ); + assertTrue( action.getArtifacts().isEmpty() ); + } + private void assertArtifacts( List expectedArtifacts, Map> artifactMap ) { @@ -575,10 +635,25 @@ public class ShowArtifactActionTest ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration(); config.setId( TEST_REPO ); config.setLocation( getTestFile( "target/test-repo" ).getAbsolutePath() ); + ManagedRepositoryContent content = new ManagedDefaultRepositoryContent(); content.setRepository( config ); factory.getManagedRepositoryContent( TEST_REPO ); + + FileMetadataRepository metadataRepo = ( FileMetadataRepository ) lookup( MetadataRepository.class ); + MockControl archivaConfigControl = MockControl.createControl( ArchivaConfiguration.class ); + ArchivaConfiguration archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock(); + + Configuration configuration = new Configuration(); + configuration.addManagedRepository( config ); + metadataRepo.setConfiguration( archivaConfig ); + archivaConfig.getConfiguration(); + + action.setMetadataRepository( metadataRepo ); + + archivaConfigControl.setDefaultReturnValue( configuration ); control.setDefaultReturnValue( content ); control.replay(); + archivaConfigControl.replay(); } } diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index 606d50bc9..d301bbf14 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -164,7 +164,41 @@ public abstract class AbstractMetadataRepositoryTest metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); assertEquals( Collections.emptyList(), new ArrayList( metadata.getFacetIds() ) ); } + + public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved() + throws MetadataResolutionException + { + ProjectVersionMetadata metadata = new ProjectVersionMetadata(); + metadata.setId( TEST_PROJECT_VERSION ); + + Map additionalProps = new HashMap(); + additionalProps.put( "deleteKey", "deleteValue" ); + + MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz", additionalProps ); + metadata.addFacet( facet ); + repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata ); + + metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); + assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() ); + + TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID ); + Map facetProperties = testFacet.toProperties(); + + assertEquals( "deleteValue", facetProperties.get( "deleteKey" ) ); + + facetProperties.remove( "deleteKey" ); + + TestMetadataFacet newTestFacet = new TestMetadataFacet( TEST_FACET_ID, testFacet.getValue(), facetProperties ); + metadata.addFacet( newTestFacet ); + + repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata ); + metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); + assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() ); + testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID ); + assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) ); + } + public void testUpdateArtifactMetadataWithExistingFacets() { ArtifactMetadata metadata = createArtifact(); @@ -313,7 +347,7 @@ public abstract class AbstractMetadataRepositoryTest { repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ); } - + public void testGetArtifacts() { ArtifactMetadata artifact1 = createArtifact(); @@ -613,6 +647,10 @@ public abstract class AbstractMetadataRepositoryTest implements MetadataFacet { private String testFacetId; + + private Map additionalProps; + + private String value; private TestMetadataFacet( String value ) { @@ -625,8 +663,12 @@ public abstract class AbstractMetadataRepositoryTest this.value = value; testFacetId = facetId; } - - private String value; + + private TestMetadataFacet( String facetId, String value, Map additionalProps ) + { + this( facetId, value ); + this.additionalProps = additionalProps; + } public String getFacetId() { @@ -639,10 +681,24 @@ public abstract class AbstractMetadataRepositoryTest } public Map toProperties() - { + { if ( value != null ) { - return Collections.singletonMap( "foo", value ); + if( additionalProps == null ) + { + return Collections.singletonMap( "foo", value ); + } + else + { + Map props = new HashMap(); + props.put( "foo", value ); + + for( String key : additionalProps.keySet() ) + { + props.put( key, additionalProps.get( key ) ); + } + return props; + } } else { @@ -657,13 +713,25 @@ public abstract class AbstractMetadataRepositoryTest { this.value = value; } + + properties.remove( "foo" ); + + if( additionalProps == null ) + { + additionalProps = new HashMap(); + } + + for( String key: properties.keySet() ) + { + additionalProps.put( key, properties.get( key ) ); + } } public String getValue() { return value; } - + @Override public String toString() { diff --git a/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java index 99b78bf9d..3044e4123 100644 --- a/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java +++ b/archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java @@ -19,7 +19,6 @@ package org.apache.archiva.metadata.generic; * under the License. */ -import java.util.HashMap; import java.util.Map; import java.util.TreeMap; diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index d35f46073..aca1bace7 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -140,6 +140,9 @@ public class FileMetadataRepository { properties.remove( name ); } + + // clear the facet contents so old properties are no longer written + clearMetadataFacetProperties( versionMetadata, properties ); } properties.setProperty( "id", versionMetadata.getId() ); setProperty( properties, "name", versionMetadata.getName() ); @@ -224,6 +227,27 @@ public class FileMetadataRepository } } } + + private void clearMetadataFacetProperties( ProjectVersionMetadata versionMetadata, Properties properties ) + { + List propsToRemove = new ArrayList(); + for ( MetadataFacet facet : versionMetadata.getFacetList() ) + { + for ( Object key : properties.keySet() ) + { + String keyString = ( String ) key; + if( keyString.startsWith( facet.getFacetId() + ":" ) ) + { + propsToRemove.add( key ); + } + } + } + + for( Object key : propsToRemove ) + { + properties.remove( key ); + } + } public void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion, ProjectVersionReference reference ) -- 2.39.5