archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r921671 - in /archiva/trunk/archiva-modules/plugins: maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/ metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/ metadata-reposit...
Date Thu, 11 Mar 2010 02:40:40 GMT
Author: brett
Date: Thu Mar 11 02:40:39 2010
New Revision: 921671

URL: http://svn.apache.org/viewvc?rev=921671&view=rev
Log:
[MRM-1360] store artifact metadata in the repository and make maven facet's compliant

Added:
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java
      - copied, changed from r920722, archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java
Modified:
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
    archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
    archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
    archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java

Modified: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java?rev=921671&r1=921670&r2=921671&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
Thu Mar 11 02:40:39 2010
@@ -241,7 +241,8 @@ public class Maven2RepositoryMetadataRes
     private void addProblemReport( String repoId, String namespace, String projectId, String
projectVersion,
                                    String problemId, String message )
     {
-        // TODO: an event mechanism would remove coupling to the problem reporting plugin
+        // TODO: an event mechanism would remove coupling to the problem reporting plugin
and allow other plugins to
+        //       generate metadata on the fly if appropriately checked for missing facets
in the resolver
         RepositoryProblemFacet problem = new RepositoryProblemFacet();
         problem.setProblem( problemId );
         problem.setMessage( message );

Modified: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java?rev=921671&r1=921670&r2=921671&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacet.java
Thu Mar 11 02:40:39 2010
@@ -91,19 +91,28 @@ public class MavenArtifactFacet
     public Map<String, String> toProperties()
     {
         HashMap<String, String> properties = new HashMap<String, String>();
-        properties.put( FACET_ID + ":type", type );
-        properties.put( FACET_ID + ":classifier", classifier );
-        properties.put( FACET_ID + ":timestamp", timestamp );
-        properties.put( FACET_ID + ":buildNumber", Integer.toString( buildNumber ));
+        properties.put( "type", type );
+        if ( classifier != null )
+        {
+            properties.put( "classifier", classifier );
+        }
+        if ( timestamp != null )
+        {
+            properties.put( "timestamp", timestamp );
+        }
+        if ( buildNumber > 0 )
+        {
+            properties.put( "buildNumber", Integer.toString( buildNumber ) );
+        }
         return properties;
     }
 
     public void fromProperties( Map<String, String> properties )
     {
-        type = properties.get( FACET_ID + ":type" );
-        classifier = properties.get( FACET_ID + ":classifier" );
-        timestamp = properties.get( FACET_ID + ":timestamp" );
-        String buildNumber = properties.get( FACET_ID + ":buildNumber" );
+        type = properties.get( "type" );
+        classifier = properties.get( "classifier" );
+        timestamp = properties.get( "timestamp" );
+        String buildNumber = properties.get( "buildNumber" );
         if ( buildNumber != null )
         {
             this.buildNumber = Integer.valueOf( buildNumber );

Copied: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java
(from r920722, archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java)
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java?p2=archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java&p1=archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java&r1=920722&r2=921671&rev=921671&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenArtifactFacetFactory.java
Thu Mar 11 02:40:39 2010
@@ -23,18 +23,18 @@ import org.apache.archiva.metadata.model
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 
 /**
- * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2.project"
+ * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2.artifact"
  */
-public class MavenProjectFacetFactory
+public class MavenArtifactFacetFactory
     implements MetadataFacetFactory
 {
     public MetadataFacet createMetadataFacet()
     {
-        return new MavenProjectFacet();
+        return new MavenArtifactFacet();
     }
 
     public MetadataFacet createMetadataFacet( String repositoryId, String name )
     {
-        throw new UnsupportedOperationException( "There is no valid name for project version
facets" );
+        throw new UnsupportedOperationException( "There is no valid name for artifact facets"
);
     }
-}
+}
\ No newline at end of file

Modified: archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java?rev=921671&r1=921670&r2=921671&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
(original)
+++ archiva/trunk/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
Thu Mar 11 02:40:39 2010
@@ -91,30 +91,30 @@ public class MavenProjectFacet
     public Map<String, String> toProperties()
     {
         HashMap<String, String> properties = new HashMap<String, String>();
-        properties.put( FACET_ID + ":groupId", groupId );
-        properties.put( FACET_ID + ":artifactId", artifactId );
-        properties.put( FACET_ID + ":packaging", packaging );
+        properties.put( "groupId", groupId );
+        properties.put( "artifactId", artifactId );
+        properties.put( "packaging", packaging );
         if ( parent != null )
         {
-            properties.put( FACET_ID + ":parent.groupId", parent.getGroupId() );
-            properties.put( FACET_ID + ":parent.artifactId", parent.getArtifactId() );
-            properties.put( FACET_ID + ":parent.version", parent.getVersion() );
+            properties.put( "parent.groupId", parent.getGroupId() );
+            properties.put( "parent.artifactId", parent.getArtifactId() );
+            properties.put( "parent.version", parent.getVersion() );
         }
         return properties;
     }
 
     public void fromProperties( Map<String, String> properties )
     {
-        groupId = properties.get( FACET_ID + ":groupId" );
-        artifactId = properties.get( FACET_ID + ":artifactId" );
-        packaging = properties.get( FACET_ID + ":packaging" );
-        String parentArtifactId = properties.get( FACET_ID + ":parent.artifactId" );
+        groupId = properties.get( "groupId" );
+        artifactId = properties.get( "artifactId" );
+        packaging = properties.get( "packaging" );
+        String parentArtifactId = properties.get( "parent.artifactId" );
         if ( parentArtifactId != null )
         {
             MavenProjectParent parent = new MavenProjectParent();
-            parent.setGroupId( properties.get( FACET_ID + ":parent.groupId" ) );
+            parent.setGroupId( properties.get( "parent.groupId" ) );
             parent.setArtifactId( parentArtifactId );
-            parent.setVersion( properties.get( FACET_ID + ":parent.version" ) );
+            parent.setVersion( properties.get( "parent.version" ) );
             this.parent = parent;
         }
     }

Modified: archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java?rev=921671&r1=921670&r2=921671&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
(original)
+++ archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
Thu Mar 11 02:40:39 2010
@@ -201,10 +201,7 @@ public class FileMetadataRepository
         facetIds.addAll( Arrays.asList( properties.getProperty( "facetIds", "" ).split( ","
) ) );
         properties.setProperty( "facetIds", join( facetIds ) );
 
-        for ( MetadataFacet facet : versionMetadata.getFacetList() )
-        {
-            properties.putAll( facet.toProperties() );
-        }
+        updateProjectVersionFacets( versionMetadata, properties );
 
         try
         {
@@ -217,6 +214,17 @@ public class FileMetadataRepository
         }
     }
 
+    private void updateProjectVersionFacets( ProjectVersionMetadata versionMetadata, Properties
properties )
+    {
+        for ( MetadataFacet facet : versionMetadata.getFacetList() )
+        {
+            for ( Map.Entry<String,String> entry : facet.toProperties().entrySet()
)
+            {
+                properties.setProperty( facet.getFacetId() + ":" + entry.getKey(), entry.getValue()
);
+            }
+        }
+    }
+
     public void updateProjectReference( String repoId, String namespace, String projectId,
String projectVersion,
                                         ProjectVersionReference reference )
     {
@@ -423,7 +431,6 @@ public class FileMetadataRepository
                 String id = tok.nextToken();
 
                 ArtifactMetadata artifact = artifacts.get( id );
-                // TODO: facets (&test)
                 if ( artifact == null )
                 {
                     artifact = new ArtifactMetadata();
@@ -460,11 +467,58 @@ public class FileMetadataRepository
                 {
                     artifact.setSha1( value );
                 }
+                else if ( "facetIds".equals( field ) )
+                {
+                    if ( value.length() > 0 )
+                    {
+                        String propertyPrefix = "artifact:facet:" + id + ":";
+                        for ( String facetId : value.split( "," ) )
+                        {
+                            MetadataFacetFactory factory = metadataFacetFactories.get( facetId
);
+                            if ( factory == null )
+                            {
+                                log.error( "Attempted to load unknown artifact metadata facet:
" + facetId );
+                            }
+                            else
+                            {
+                                MetadataFacet facet = factory.createMetadataFacet();
+                                String prefix = propertyPrefix + facet.getFacetId();
+                                Map<String, String> map = new HashMap<String, String>();
+                                for ( Object key : new ArrayList( properties.keySet() ) )
+                                {
+                                    String property = (String) key;
+                                    if ( property.startsWith( prefix ) )
+                                    {
+                                        map.put( property.substring( prefix.length() + 1
), properties.getProperty(
+                                            property ) );
+                                    }
+                                }
+                                facet.fromProperties( map );
+                                artifact.addFacet( facet );
+                            }
+                        }
+                    }
+
+                    updateArtifactFacets( artifact, properties );
+                }
             }
         }
         return artifacts.values();
     }
 
+    private void updateArtifactFacets( ArtifactMetadata artifact, Properties properties )
+    {
+        String propertyPrefix = "artifact:facet:" + artifact.getId() + ":";
+        for ( MetadataFacet facet : artifact.getFacetList() )
+        {
+            for ( Map.Entry<String, String> e : facet.toProperties().entrySet() )
+            {
+                String key = propertyPrefix + facet.getFacetId() + ":" + e.getKey();
+                properties.setProperty( key, e.getValue() );
+            }
+        }
+    }
+
     public Collection<String> getRepositories()
     {
         return configuration.getConfiguration().getManagedRepositoriesAsMap().keySet();
@@ -497,6 +551,17 @@ public class FileMetadataRepository
         properties.remove( "artifact:md5:" + id );
         properties.remove( "artifact:sha1:" + id );
         properties.remove( "artifact:version:" + id );
+        properties.remove( "artifact:facetIds:" + id );
+        
+        String prefix = "artifact:facet:" + id + ":";
+        for ( Object key : new ArrayList( properties.keySet() ) )
+        {
+            String property = (String) key;
+            if ( property.startsWith( prefix ) )
+            {
+                properties.remove( property );
+            }
+        }
 
         try
         {
@@ -580,20 +645,26 @@ public class FileMetadataRepository
 
         Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY
);
 
-        properties.setProperty( "artifact:updated:" + artifact.getId(), Long.toString(
-            artifact.getFileLastModified().getTime() ) );
-        properties.setProperty( "artifact:whenGathered:" + artifact.getId(), Long.toString(
-            artifact.getWhenGathered().getTime() ) );
-        properties.setProperty( "artifact:size:" + artifact.getId(), Long.toString( artifact.getSize()
) );
+        String id = artifact.getId();
+        properties.setProperty( "artifact:updated:" + id, Long.toString( artifact.getFileLastModified().getTime()
) );
+        properties.setProperty( "artifact:whenGathered:" + id, Long.toString( artifact.getWhenGathered().getTime()
) );
+        properties.setProperty( "artifact:size:" + id, Long.toString( artifact.getSize()
) );
         if ( artifact.getMd5() != null )
         {
-            properties.setProperty( "artifact:md5:" + artifact.getId(), artifact.getMd5()
);
+            properties.setProperty( "artifact:md5:" + id, artifact.getMd5() );
         }
         if ( artifact.getSha1() != null )
         {
-            properties.setProperty( "artifact:sha1:" + artifact.getId(), artifact.getSha1()
);
+            properties.setProperty( "artifact:sha1:" + id, artifact.getSha1() );
         }
-        properties.setProperty( "artifact:version:" + artifact.getId(), artifact.getVersion()
);
+        properties.setProperty( "artifact:version:" + id, artifact.getVersion() );
+
+        Set<String> facetIds = new LinkedHashSet<String>( artifact.getFacetIds()
);
+        String property = "artifact:facetIds:" + id;
+        facetIds.addAll( Arrays.asList( properties.getProperty( property, "" ).split( ","
) ) );
+        properties.setProperty( property, join( facetIds ) );
+
+        updateArtifactFacets( artifact, properties );
 
         try
         {
@@ -790,7 +861,7 @@ public class FileMetadataRepository
                     MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
                     if ( factory == null )
                     {
-                        log.error( "Attempted to load unknown metadata facet: " + facetId
);
+                        log.error( "Attempted to load unknown project version metadata facet:
" + facetId );
                     }
                     else
                     {
@@ -801,7 +872,8 @@ public class FileMetadataRepository
                             String property = (String) key;
                             if ( property.startsWith( facet.getFacetId() ) )
                             {
-                                map.put( property, properties.getProperty( property ) );
+                                map.put( property.substring( facet.getFacetId().length()
+ 1 ), properties.getProperty(
+                                    property ) );
                             }
                         }
                         facet.fromProperties( map );
@@ -810,10 +882,7 @@ public class FileMetadataRepository
                 }
             }
 
-            for ( MetadataFacet facet : versionMetadata.getFacetList() )
-            {
-                properties.putAll( facet.toProperties() );
-            }
+            updateProjectVersionFacets( versionMetadata, properties );
         }
         return versionMetadata;
     }

Modified: archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java?rev=921671&r1=921670&r2=921671&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
(original)
+++ archiva/trunk/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
Thu Mar 11 02:40:39 2010
@@ -19,18 +19,6 @@ package org.apache.archiva.metadata.repo
  * under the License.
  */
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.MailingList;
 import org.apache.archiva.metadata.model.MetadataFacet;
@@ -44,6 +32,18 @@ import org.apache.maven.archiva.configur
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 import org.easymock.MockControl;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @todo should this be a generic MetadataRepository implementation test?
  */
@@ -198,6 +198,40 @@ public class FileMetadataRepositoryTest
         assertEquals( Collections.<String>emptyList(), new ArrayList<String>(
metadata.getFacetIds() ) );
     }
 
+    public void testUpdateArtifactMetadataWithExistingFacets()
+    {
+        ArtifactMetadata metadata = createArtifact();
+        MetadataFacet facet = new TestMetadataFacet( "baz" );
+        metadata.addFacet( facet );
+        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION,
metadata );
+
+        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION
).iterator().next();
+        assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
+
+        metadata = createArtifact();
+        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION,
metadata );
+
+        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION
).iterator().next();
+        assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() );
+        TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID
);
+        assertEquals( "baz", testFacet.getValue() );
+    }
+
+    public void testUpdateArtifactMetadataWithNoExistingFacets()
+    {
+        ArtifactMetadata metadata = createArtifact();
+        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION,
metadata );
+
+        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION
).iterator().next();
+        assertEquals( Collections.<String>emptyList(), new ArrayList<String>(
metadata.getFacetIds() ) );
+
+        metadata = createArtifact();
+        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION,
metadata );
+
+        metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION
).iterator().next();
+        assertEquals( Collections.<String>emptyList(), new ArrayList<String>(
metadata.getFacetIds() ) );
+    }
+
     public void testGetMetadataFacet()
     {
         repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) );
@@ -583,7 +617,7 @@ public class FileMetadataRepositoryTest
     {
         public final int compare ( ArtifactMetadata a, ArtifactMetadata b)
         {            
-            return ( (String) a.getProject() ).compareTo( (String) b.getProject() );
+            return a.getProject().compareTo( b.getProject() );
         } 
     }
     
@@ -620,7 +654,7 @@ public class FileMetadataRepositoryTest
         {
             if ( value != null )
             {
-                return Collections.singletonMap( testFacetId + ":foo", value );
+                return Collections.singletonMap( "foo", value );
             }
             else
             {
@@ -630,7 +664,7 @@ public class FileMetadataRepositoryTest
 
         public void fromProperties( Map<String, String> properties )
         {
-            String value = properties.get( testFacetId + ":foo" );
+            String value = properties.get( "foo" );
             if ( value != null )
             {
                 this.value = value;



Mime
View raw message