]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1362] Add simple 'CRUD' pages for project-level metadata along with a "generic...
authorMaria Odea B. Ching <oching@apache.org>
Mon, 7 Jun 2010 07:40:26 +0000 (07:40 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 7 Jun 2010 07:40:26 +0000 (07:40 +0000)
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

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/tags/ProjectMetadataTag.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/main/resources/struts.xml
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/include/projectMetadata.jspf
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/taglib.tld
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
archiva-modules/plugins/generic-metadata-support/src/main/java/org/apache/archiva/metadata/generic/GenericMetadataFacet.java
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index 591815986fa0f1e284400ceab9d60ad37c7f8ce2..3c84d2417b1b4c02350a2a32079de4f6a1fc520c 100644 (file)
@@ -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<String, List<ArtifactDownloadInfo>> artifacts;
 
     private boolean dependencyTree = false;
-
-    private ProjectVersionMetadata projectMetadata;
-
+    
     private String deleteItem;
 
-    private String itemValue;
-
     private Map<String, String> 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<Dependency> dependencies = projectMetadata.getDependencies();
-        List<Dependency> newDependencies = new ArrayList<Dependency>();
-
-        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<MailingList> mailingLists = projectMetadata.getMailingLists();
-        List<MailingList> newMailingLists = new ArrayList<MailingList>();
+                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<License> licenses = projectMetadata.getLicenses();
-        List<License> newLicenses = new ArrayList<License>();
-
-        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<String, String> 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 (file)
index 73653c6..0000000
+++ /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<License> 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<MailingList> lists = projectMetadata.getMailingLists();
-            List<String> 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<Dependency> 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<ul>" );
-    }
-
-    private void endList( StringBuffer metadataEntries )
-    {
-        metadataEntries.append( "\n</ul>" );
-    }
-
-    private void addListItem( String label, String value, StringBuffer metadataEntries )
-    {
-        String newValue = StringUtils.isEmpty( value ) ? "" : value;
-        metadataEntries.append( "\n<li>" ).append( label ).append( newValue ).append( "</li>" );
-    }
-
-    private void startListItem( String value, StringBuffer metadataEntries )
-    {
-        metadataEntries.append( "\n<li>" ).append( value );
-    }
-
-    private void endListItem( StringBuffer metadataEntries )
-    {
-        metadataEntries.append( "\n</li>" );
-    }
-    
-    private void createDeleteLink( String name, String value, StringBuffer metadataEntries )
-    {
-        metadataEntries.append( "\n<li>" ).append( value )
-                       .append( "\n<a href=\"showProjectMetadata!deleteMetadataEntry.action?" )
-                       .append( "groupId=" ).append( groupId )
-                       .append( "&artifactId=" ).append( artifactId )
-                       .append( "&version=" ).append( version )
-                       .append( "&deleteItem=" ).append( name )
-                       .append( "&itemValue=").append( value ).append( "\" >" )
-                       .append( "<img src=\"images/icons/delete.gif\"/>" ).append( "</a>" );
-    }
-
-    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;
-    }
-}
index 4cf08c2cedfe6ab4c053fba279c7c937d9d98dff..fa127d095e3b0c3e202b90184ce97405ae263b45 100644 (file)
     </action>
 
     <action name="deleteMetadataEntry" class="showArtifactAction" method="deleteMetadataEntry">
-      <result name="success" type="redirect-action">
-        <param name="actionName">showProjectMetadata</param>
-        <param name="namespace">/</param>
-      </result>
+      <result name="input">/WEB-INF/jsp/showArtifact.jsp</result>
+      <result name="success">/WEB-INF/jsp/showArtifact.jsp</result>
     </action>
 
   </package>
index da2937721b3d659f58a8fc1e97f39fa6ee0069f4..0b437910dc150fc11c2e38e39be79b598805a1cc 100644 (file)
@@ -42,7 +42,7 @@
           </td>
           <td>
             <s:textfield name="propertyValue" size="30" required="true"/>
-          </td>
+          </td>          
           <td align="right">
             <s:submit value="Add"/>
           </td>
   
     <c:if test="${!empty genericMetadata}">
       <ul>
-        <c:forEach var="prop" items="${genericMetadata}">
-         <li>${prop.key}=${prop.value}</li> 
+        <c:forEach var="prop" items="${genericMetadata}">          
+         <c:url var="deletePropertyUrl" value="showProjectMetadata!deleteMetadataEntry.action">
+           <c:param name="groupId" value="${groupId}"/>
+           <c:param name="artifactId" value="${artifactId}"/>
+           <c:param name="version" value="${version}"/>
+           <c:param name="deleteItem" value="${prop.key}"/>
+          </c:url>
+         <li>${prop.key}=${prop.value} 
+           <a href="${deletePropertyUrl}">
+              <img src="<c:url value="/images/icons/delete.gif" />" alt="Delete" width="12" length="12"/>
+            </a>
+          </li>
         </c:forEach> 
       </ul>
     </c:if>  
-  </div>
-  
-  
-  <p>
-    <s:if test="hasActionMessages()">
-      <div id="messages">
-        <s:actionmessage/>
-      </div>
-    </s:if>
-    <s:if test="hasActionErrors()">
-      <div id="messages">
-        <s:actionerror/>
-      </div>
-    </s:if>
-  </p>
-  
-  <%-- <archiva:project-metadata object="${projectMetadata}" groupId="${groupId}" artifactId="${artifactId}" version="${version}" /> --%>
+  </div>  
+   
 </div>
index 24b7cf49ae5c7b93c5eb4a62cc032c11e0281991..69a82cfc01dfd4c4245373a29de432212e2ad945 100644 (file)
         <s:actionmessage />
       </div>
     </s:if>
+    <s:if test="hasActionErrors()">
+      <div id="messages">
+        <s:actionerror/>
+      </div>
+    </s:if>
   </div>
 </div>
 </body>
index d5572f2768a096608f26b1b0637c32ae0bc7175b..a843d89064032016e52ece38c5be14a0aada3784 100644 (file)
 
    </tag>
    
-   <tag>
-
-      <name>project-metadata</name>
-      <tag-class>org.apache.maven.archiva.web.tags.ProjectMetadataTag</tag-class>
-      <body-content>empty</body-content>
-      <description><![CDATA[Render the project metadata tree from the provided ProjectMetadataVersion object]]></description>
-
-      <attribute>
-        <name>object</name>
-        <required>true</required>
-        <rtexprvalue>true</rtexprvalue>
-        
-        <description><![CDATA[The Object to Render]]></description>
-      </attribute>
-
-      <attribute>
-        <name>groupId</name>
-        <required>true</required>
-        <rtexprvalue>true</rtexprvalue>
-        
-        <description><![CDATA[The groupId]]></description>
-      </attribute>
-      
-      <attribute>
-        <name>artifactId</name>
-        <required>true</required>
-        <rtexprvalue>true</rtexprvalue>
-        
-        <description><![CDATA[The artifactId]]></description>
-      </attribute>
-
-      <attribute>
-        <name>version</name>
-        <required>true</required>
-        <rtexprvalue>true</rtexprvalue>
-        
-        <description><![CDATA[The version]]></description>
-      </attribute>
-   
-   </tag>
-   
 </taglib>
index cb56754fffbd27b2ca7751696be40245a872a0c4..14bce53003f60a0527214da291ab32903fe6c5b4 100644 (file)
@@ -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<String, String> 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<ArtifactMetadata> expectedArtifacts,
                                   Map<String, List<ShowArtifactAction.ArtifactDownloadInfo>> 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();
     }
 }
index 606d50bc9e5144f29ec4129dbd79dcff2f73786c..d301bbf1445bdfeecfe560173b5181e91965c7d3 100644 (file)
@@ -164,7 +164,41 @@ public abstract class AbstractMetadataRepositoryTest
         metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
         assertEquals( Collections.<String>emptyList(), new ArrayList<String>( metadata.getFacetIds() ) );
     }
+    
+    public void testUpdateProjectVersionMetadataWithExistingFacetsFacetPropertyWasRemoved()
+        throws MetadataResolutionException
+    {
+        ProjectVersionMetadata metadata = new ProjectVersionMetadata();
+        metadata.setId( TEST_PROJECT_VERSION );
+        
+        Map<String, String> additionalProps = new HashMap<String,String>();
+        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<String, String> 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<String, String> 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<String, String> additionalProps )
+        {
+            this( facetId, value );
+            this.additionalProps = additionalProps;            
+        }
 
         public String getFacetId()
         {
@@ -639,10 +681,24 @@ public abstract class AbstractMetadataRepositoryTest
         }
 
         public Map<String, String> toProperties()
-        {
+        {            
             if ( value != null )
             {
-                return Collections.singletonMap( "foo", value );
+                if( additionalProps == null )
+                {
+                    return Collections.singletonMap( "foo", value );
+                }
+                else
+                {
+                    Map<String, String> props = new HashMap<String, String>();
+                    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<String, String>();
+            }
+            
+            for( String key: properties.keySet() )
+            {
+                additionalProps.put( key, properties.get( key ) );
+            }
         }
 
         public String getValue()
         {
             return value;
         }
-
+        
         @Override
         public String toString()
         {
index d35f4607325764db4689b2d3e6a4990a42c2ea62..aca1bace7d166cc1c5ec1bdae1db8b09fe5fe0bf 100644 (file)
@@ -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<Object> propsToRemove = new ArrayList<Object>();
+        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 )