archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r885466 - in /archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src: main/java/org/apache/archiva/metadata/repository/file/ test/java/org/apache/archiva/metadata/repository/file/
Date Mon, 30 Nov 2009 15:51:19 GMT
Author: brett
Date: Mon Nov 30 15:51:19 2009
New Revision: 885466

URL: http://svn.apache.org/viewvc?rev=885466&view=rev
Log:
[MRM-1282] correct updating of facets in the file-based repository

Modified:
    archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
    archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java?rev=885466&r1=885465&r2=885466&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
(original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
Mon Nov 30 15:51:19 2009
@@ -116,7 +116,7 @@
         // remove properties that are not references or artifacts
         for ( String name : properties.stringPropertyNames() )
         {
-            if ( !name.startsWith( "artifact:" ) && !name.startsWith( "ref:" ) )
+            if ( !name.contains( ":" ) && !name.equals( "facetIds" ) )
             {
                 properties.remove( name );
             }
@@ -176,7 +176,10 @@
             setProperty( properties, "dependency." + i + ".type", dependency.getType() );
             i++;
         }
-        properties.setProperty( "facetIds", join( versionMetadata.getFacetIds() ) );
+        Set<String> facetIds = new LinkedHashSet<String>( versionMetadata.getFacetIds()
);
+        facetIds.addAll( Arrays.asList( properties.getProperty( "facetIds", "" ).split( ","
) ) );
+        properties.setProperty( "facetIds", join( facetIds ) );
+
         for ( ProjectVersionFacet facet : versionMetadata.getFacetList() )
         {
             properties.putAll( facet.toProperties() );
@@ -613,4 +616,9 @@
     {
         this.directory = directory;
     }
+
+    public void setMetadataFacetFactories( Map<String, MetadataFacetFactory> metadataFacetFactories
)
+    {
+        this.metadataFacetFactories = metadataFacetFactories;
+    }
 }

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java?rev=885466&r1=885465&r2=885466&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
(original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
Mon Nov 30 15:51:19 2009
@@ -3,8 +3,11 @@
 import java.io.File;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Map;
 
 import org.apache.archiva.metadata.model.MailingList;
+import org.apache.archiva.metadata.model.MetadataFacetFactory;
+import org.apache.archiva.metadata.model.ProjectVersionFacet;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.commons.io.FileUtils;
@@ -40,6 +43,8 @@
 
     private static final String TEST_NAMESPACE = "namespace";
 
+    private static final String TEST_PROJECT_VERSION = "1.0";
+
     public void setUp()
         throws Exception
     {
@@ -60,11 +65,72 @@
     public void testUpdateProjectVersionMetadataWithNoOtherArchives()
     {
         ProjectVersionMetadata metadata = new ProjectVersionMetadata();
-        metadata.setId( TEST_PROJECT );
+        metadata.setId( TEST_PROJECT_VERSION );
         MailingList mailingList = new MailingList();
         mailingList.setName( "Foo List" );
         mailingList.setOtherArchives( Collections.<String>emptyList() );
         metadata.setMailingLists( Collections.singletonList( mailingList ) );
         repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata
);
     }
+
+    public void testUpdateProjectVersionMetadataWithExistingFacets()
+    {
+        repository.setMetadataFacetFactories(
+            Collections.<String, MetadataFacetFactory>singletonMap( "test", new MetadataFacetFactory()
+            {
+                public ProjectVersionFacet createProjectVersionFacet()
+                {
+                    return new TestProjectVersionFacet( "bar" );
+                }
+            } ) );
+
+        ProjectVersionMetadata metadata = new ProjectVersionMetadata();
+        metadata.setId( TEST_PROJECT_VERSION );
+        ProjectVersionFacet facet = new TestProjectVersionFacet( "baz" );
+        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" ), metadata.getFacetIds() );
+
+        metadata = new ProjectVersionMetadata();
+        metadata.setId( TEST_PROJECT_VERSION );
+        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" ), metadata.getFacetIds() );
+        TestProjectVersionFacet testFacet = (TestProjectVersionFacet) metadata.getFacet(
"test" );
+        assertEquals( "baz", testFacet.getValue() );
+    }
+
+    private static class TestProjectVersionFacet
+        implements ProjectVersionFacet
+    {
+        private TestProjectVersionFacet( String value )
+        {
+            this.value = value;
+        }
+
+        private String value;
+
+        public String getFacetId()
+        {
+            return "test";
+        }
+
+        public Map<String, String> toProperties()
+        {
+            return Collections.singletonMap( "test:foo", value );
+        }
+
+        public void fromProperties( Map<String, String> properties )
+        {
+            value = properties.get( "test:foo" );
+        }
+
+        public String getValue()
+        {
+            return value;
+        }
+    }
 }



Mime
View raw message