]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1282] support storing facet content in the file metadata repository
authorBrett Porter <brett@apache.org>
Thu, 26 Nov 2009 02:24:35 +0000 (02:24 +0000)
committerBrett Porter <brett@apache.org>
Thu, 26 Nov 2009 02:24:35 +0000 (02:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884372 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java [new file with mode: 0644]
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java [new file with mode: 0644]
archiva-modules/plugins/metadata-repository-file/pom.xml
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java
new file mode 100644 (file)
index 0000000..80ac09c
--- /dev/null
@@ -0,0 +1,25 @@
+package org.apache.archiva.metadata.model;
+
+/*
+ * 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.
+ */
+
+public interface MetadataFacetFactory
+{
+    ProjectVersionFacet createProjectVersionFacet();
+}
index a0ac18736656c6b0409fcbc013ad37c2385c9945..6d264782957e11f930c2af4aeb09da11f6500997 100644 (file)
@@ -1,7 +1,5 @@
 package org.apache.archiva.metadata.model;
 
-import java.util.Map;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,9 +19,13 @@ import java.util.Map;
  * under the License.
  */
 
+import java.util.Map;
+
 public interface ProjectVersionFacet
 {
     String getFacetId();
 
     Map<String, String> toProperties();
+
+    void fromProperties( Map<String, String> properties );
 }
index 8b6b7edc60b851476366c4a7c8cf569ca8bd43ae..8f595dfef4544880dcac2b23fe7464484798074f 100644 (file)
@@ -84,16 +84,32 @@ public class MavenProjectFacet
 
     public Map<String, String> toProperties()
     {
-        Map<String, String> properties = new HashMap<String,String>();
-        properties.put( getFacetId() + ":groupId", groupId );
-        properties.put( getFacetId() + ":artifactId", artifactId );
-        properties.put( getFacetId() + ":packaging", packaging );
+        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 );
         if ( parent != null )
         {
-            properties.put( getFacetId() + ":parent.groupId", parent.getGroupId() );
-            properties.put( getFacetId() + ":parent.artifactId", parent.getArtifactId() );
-            properties.put( getFacetId() + ":parent.version", parent.getVersion() );
+            properties.put( FACET_ID + ":parent.groupId", parent.getGroupId() );
+            properties.put( FACET_ID + ":parent.artifactId", parent.getArtifactId() );
+            properties.put( FACET_ID + ":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" );
+        if ( parentArtifactId != null )
+        {
+            MavenProjectParent parent = new MavenProjectParent();
+            parent.setGroupId( properties.get( FACET_ID + ":parent.groupId" ) );
+            parent.setArtifactId( parentArtifactId );
+            parent.setVersion( properties.get( FACET_ID + ":parent.version" ) );
+            this.parent = parent;
+        }
+    }
 }
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java
new file mode 100644 (file)
index 0000000..f7de28b
--- /dev/null
@@ -0,0 +1,35 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.metadata.model.MetadataFacetFactory;
+import org.apache.archiva.metadata.model.ProjectVersionFacet;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.model.MetadataFacetFactory" role-hint="org.apache.archiva.metadata.repository.storage.maven2"
+ */
+public class MavenProjectFacetFactory
+    implements MetadataFacetFactory
+{
+    public ProjectVersionFacet createProjectVersionFacet()
+    {
+        return new MavenProjectFacet();
+    }
+}
index ad8019b75ae056c2b6a590d1e065b86e0bb79597..ec034157b1106d3f674c0577377db89928048b57 100644 (file)
@@ -36,5 +36,9 @@
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
   </dependencies>
 </project>
index 0c9b3ca48767f23fb480bc4e8b433845bf19c0b5..6e575325d0123674285a3bf6e514bd17b2c697d8 100644 (file)
@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -34,6 +35,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.CiManagement;
 import org.apache.archiva.metadata.model.IssueManagement;
 import org.apache.archiva.metadata.model.License;
+import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionFacet;
@@ -41,6 +43,8 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository"
@@ -55,6 +59,13 @@ public class FileMetadataRepository
      */
     private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );
 
+    /**
+     * @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
+     */
+    private Map<String, MetadataFacetFactory> metadataFacetFactories;
+
+    private static final Logger log = LoggerFactory.getLogger( FileMetadataRepository.class );
+
     public void updateProject( String repoId, ProjectMetadata project )
     {
         // TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes
@@ -287,9 +298,25 @@ public class FileMetadataRepository
 
             for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) )
             {
-                // TODO: we need a factory for the facets here
-                // call fromProperties( properties )
-//                versionMetadata.addFacet(  );
+                MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
+                if ( factory == null )
+                {
+                    log.error( "Attempted to load unknown metadata facet: " + facetId );
+                }
+                else
+                {
+                    ProjectVersionFacet facet = factory.createProjectVersionFacet();
+                    Map<String, String> map = new HashMap<String, String>();
+                    for ( String key : properties.stringPropertyNames() )
+                    {
+                        if ( key.startsWith( facet.getFacetId() ) )
+                        {
+                            map.put( key, properties.getProperty( key ) );
+                        }
+                    }
+                    facet.fromProperties( map );
+                    versionMetadata.addFacet( facet );
+                }
             }
 
             for ( ProjectVersionFacet facet : versionMetadata.getAllFacets() )