From 3529172859a08c24e40216ab05992d3b43320efc Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 26 Nov 2009 02:24:35 +0000 Subject: [PATCH] [MRM-1282] support storing facet content in the file metadata repository git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884372 13f79535-47bb-0310-9956-ffa450edef68 --- .../metadata/model/MetadataFacetFactory.java | 25 +++++++++++++ .../metadata/model/ProjectVersionFacet.java | 6 ++-- .../storage/maven2/MavenProjectFacet.java | 30 ++++++++++++---- .../maven2/MavenProjectFacetFactory.java | 35 +++++++++++++++++++ .../plugins/metadata-repository-file/pom.xml | 4 +++ .../file/FileMetadataRepository.java | 33 +++++++++++++++-- 6 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java create mode 100644 archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.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 index 000000000..80ac09c51 --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MetadataFacetFactory.java @@ -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(); +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java index a0ac18736..6d2647829 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionFacet.java @@ -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 toProperties(); + + void fromProperties( Map properties ); } diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java index 8b6b7edc6..8f595dfef 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java @@ -84,16 +84,32 @@ public class MavenProjectFacet public Map toProperties() { - Map properties = new HashMap(); - properties.put( getFacetId() + ":groupId", groupId ); - properties.put( getFacetId() + ":artifactId", artifactId ); - properties.put( getFacetId() + ":packaging", packaging ); + HashMap properties = new HashMap(); + 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 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 index 000000000..f7de28baa --- /dev/null +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacetFactory.java @@ -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(); + } +} diff --git a/archiva-modules/plugins/metadata-repository-file/pom.xml b/archiva-modules/plugins/metadata-repository-file/pom.xml index ad8019b75..ec034157b 100644 --- a/archiva-modules/plugins/metadata-repository-file/pom.xml +++ b/archiva-modules/plugins/metadata-repository-file/pom.xml @@ -36,5 +36,9 @@ commons-io commons-io + + org.slf4j + slf4j-api + 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 0c9b3ca48..6e575325d 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 @@ -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 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 map = new HashMap(); + 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() ) -- 2.39.5