--- /dev/null
+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();
+}
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
* under the License.
*/
+import java.util.Map;
+
public interface ProjectVersionFacet
{
String getFacetId();
Map<String, String> toProperties();
+
+ void fromProperties( Map<String, String> properties );
}
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;
+ }
+ }
}
--- /dev/null
+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();
+ }
+}
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
</dependencies>
</project>
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;
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;
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"
*/
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
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() )